← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3560: rewrote viewDataEntryForm code

 

------------------------------------------------------------
revno: 3560
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-05-10 17:48:14 +0200
message:
  rewrote viewDataEntryForm code
modified:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/viewDataEntryForm.vm


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module.properties	2011-05-09 15:20:24 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/org/hisp/dhis/dataset/i18n_module.properties	2011-05-10 15:48:14 +0000
@@ -124,7 +124,10 @@
 not_change_old_but_assign_new_only                          = Do not change the old assignment but assign new only.
 datasets_different_orgunitlist                              = These selected datasets are not the same the list of organsation unit.
 optional                                                    = Optional expansion
-dataelement_is_inserted										= Data Element was inserted
+indicator_already_inserted									= Indicator already inserted
+no_indicator_was_selected									= No indicator was selected
+dataelement_already_inserted								= Data element already inserted 
+no_dataelement_was_selected									= No data element was selected
 done														= Done
 section_sort_order                                          = Section sort order
 confirm_delete_section 										= Are you sure you want to delete this section?

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js	2011-05-10 08:58:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/viewDataEntryForm.js	2011-05-10 15:48:14 +0000
@@ -7,9 +7,6 @@
 	});
 
 	leftBar.hideAnimated();
-
-	select(1);
-
 });
 
 function timedCount() {
@@ -18,77 +15,102 @@
 	byId('message').style.display = 'none';
 }
 
-function select(id) {
-	if (selected != null) {
-		jQuery("#tr" + selected).removeClass("selected");
+function localFilterSelectList( filter )
+{
+	if( jQuery("#dataElementsTab").is(":visible") ) {
+		filterSelectList( "#dataElementSelector", filter )
+	} else {
+		filterSelectList( "#indicatorSelector", filter )
 	}
-
-	jQuery("#tr" + id).addClass("selected");
-
-	selected = id;
+}
+
+function filterSelectList( selector, filter )
+{
+	$(selector).find("option").each(function() {
+		var val = $(this).val().toLowerCase();
+		
+		if(val.indexOf( filter ) != -1) {
+			$(this).removeAttr("disabled");
+		} else {
+			$(this).attr("disabled");
+		}
+	});
+}
+
+function showThenFadeOutMessage( message )
+{
+	jQuery("#message_").html(message);
+	jQuery("#message_").fadeOut(1000, function() {
+		jQuery("#message_").html("");
+		jQuery("#message_").show();
+	});
 }
 
 function insertIndicator() {
 	var oEditor = $("#designTextarea").ckeditorGet();
-
-	$("#indicatorSelector option").each(function() {
-		if($(this).attr("selected")) {
-			var id = $(this).data("id");
-			var title = $(this).val();
-			var template = '<input id="indicator' + id + '" value="[ ' + title + ' ]" name="indicator" indicatorId="' + id + '" style="width:10em;text-align:center;" readonly="readonly" />';
-
-			if(!checkExisted("indicator" + id)) {
-				oEditor.insertHtml( template )
-			}
+	var $option = $("#indicatorSelector option:selected").first();
+
+	if( $option !== undefined )
+	{
+		var id = $option.data("id");
+		var title = $option.val();
+		var template = '<input id="indicator' + id + '" value="[ ' + title + ' ]" name="indicator" indicatorId="' + id + '" style="width:10em;text-align:center;" readonly="readonly" />';
+
+		if(!checkExisted("indicator" + id)) {
+			oEditor.insertHtml( template )
+		} else {
+			showThenFadeOutMessage( "<b>" + i18n_indicator_already_inserted + "</b>" );
 		}
-	});
+	} else {
+		showThenFadeOutMessage( "<b>" + i18n_no_indicator_was_selected + "</b>" );
+	}
 }
 
 function insertDataElement() {
 	var oEditor = $("#designTextarea").ckeditorGet();
-
-	var json = JSON.parse(jQuery("#json_" + selected).val());
-
-	var dataElementId = json.dataElement.id;
-	var dataElementName = json.dataElement.name;
-	var dataElementType = json.dataElement.type;
-	var optionComboName = json.optionCombo.name;
-	var optionComboId = json.optionCombo.id;
-
-	var titleValue = dataElementId + " - " + dataElementName + " - "
-			+ optionComboId + " - " + optionComboName + " - " + dataElementType;
-
-	var displayName = "[ " + dataElementName + " " + optionComboName + " ]";
-	var dataEntryId = "value[" + dataElementId + "].value:value["
-			+ optionComboId + "].value";
-	var boolDataEntryId = "value[" + dataElementId + "].value:value["
-			+ optionComboId + "].value";
-
-	var id = "";
-	var html = "";
-
-	if (dataElementType == "bool") {
-		id = boolDataEntryId;
-		html = "<input title=\"" + titleValue
-				+ "\" value=\"" + displayName + "\" id=\"" + boolDataEntryId
-				+ "\" style=\"width:10em;text-align:center\"/>";
-	} 
-	else {
-		id = dataEntryId;
-		html = "<input title=\"" + titleValue
-				+ "\" value=\"" + displayName + "\" id=\"" + dataEntryId
-				+ "\" style=\"width:10em;text-align:center\"/>";
-	}
-
-	if (checkExisted(id)) {
-		jQuery("#message_").html("<b>" + i18n_dataelement_is_inserted + "</b>");
-		return;
-	}
-	else {
-		jQuery("#message_").html("");
-	}
-
-	oEditor.insertHtml(html);
+	var $option = $("#dataElementSelector option:selected").first();
+
+	if( $option !== undefined )
+	{
+		var dataElementId = $option.data("dataelement-id");
+		var dataElementName = $option.data("dataelement-name");
+		var dataElementType = $option.data("dataelement-type");
+		var optionComboId = $option.data("optioncombo-id");
+		var optionComboName = $option.data("optioncombo-name");
+	
+		var titleValue = dataElementId + " - " + dataElementName + " - "
+				+ optionComboId + " - " + optionComboName + " - " + dataElementType;
+	
+		var displayName = "[ " + dataElementName + " " + optionComboName + " ]";
+		var dataEntryId = "value[" + dataElementId + "].value:value["
+				+ optionComboId + "].value";
+		var boolDataEntryId = "value[" + dataElementId + "].value:value["
+				+ optionComboId + "].value";
+	
+		var id = "";
+		var html = "";
+	
+		if (dataElementType == "bool") {
+			id = boolDataEntryId;
+			html = "<input title=\"" + titleValue
+					+ "\" value=\"" + displayName + "\" id=\"" + boolDataEntryId
+					+ "\" style=\"width:10em;text-align:center\"/>";
+		} 
+		else {
+			id = dataEntryId;
+			html = "<input title=\"" + titleValue
+					+ "\" value=\"" + displayName + "\" id=\"" + dataEntryId
+					+ "\" style=\"width:10em;text-align:center\"/>";
+		}
+	
+		if (!checkExisted(id)) {
+			oEditor.insertHtml(html);
+		} else {
+			showThenFadeOutMessage( "<b>" + i18n_dataelement_already_inserted + "</b>" );
+		}
+	} else {
+		showThenFadeOutMessage( "<b>" + i18n_no_dataelement_was_selected + "</b>" );
+	}
 }
 
 function checkExisted(id) {

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/viewDataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/viewDataEntryForm.vm	2011-05-10 07:54:14 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/viewDataEntryForm.vm	2011-05-10 15:48:14 +0000
@@ -14,23 +14,66 @@
 
 		jQuery("#selectionDialog").dialog({
 			minWidth: 560,
-			minHeight: 320,
+			minHeight: 350,
 			position: [600, 60]
 		});
 
-		jQuery("#selectionTabs").tabs();
-
-		jQuery("#dataElementInsertButton").button().click(function() {
-			insertDataElement()
-		});
-
-		jQuery("#indicatorInsertButton").button().click(function() {
-			insertIndicator()
-		});
-		
+		jQuery(":button").button();
+		jQuery(":submit").button();
+
+		jQuery("#dataElementInsertButton").click(insertDataElement);
+		jQuery("#indicatorInsertButton").click(insertIndicator);
+
+		jQuery("#selectionDialog").bind("dialogopen", function(event, ui) {
+			jQuery("#showSelectionBoxButton").button("disable");
+		});
+
+		jQuery("#selectionDialog").bind("dialogclose", function(event, ui) {
+			jQuery("#showSelectionBoxButton").button("enable");
+		});
+
+		jQuery("#showSelectionBoxButton").button("disable");
+
 		jQuery("#showSelectionBoxButton").click(function() {
 			jQuery("#selectionDialog").dialog("open");
 		});
+		
+		jQuery("#dataElementsTab").show();
+		jQuery("#indicatorsTab").hide();
+
+		jQuery("#dataElementsButton").click(function() {
+			jQuery("#dataElementsButton").addClass("ui-state-active2");
+			jQuery("#indicatorsButton").removeClass("ui-state-active2");
+			
+			jQuery("#dataElementsTab").show();
+			jQuery("#indicatorsTab").hide();
+		});
+
+		jQuery("#dataElementsButton").addClass("ui-state-active2");
+
+		jQuery("#indicatorsButton").click(function() {
+			jQuery("#indicatorsButton").addClass("ui-state-active2");
+			jQuery("#dataElementsButton").removeClass("ui-state-active2");
+
+			jQuery("#indicatorsTab").show();
+			jQuery("#dataElementsTab").hide();
+		});
+
+
+		jQuery("#insertButton").click(function() {
+			if( jQuery("#dataElementsTab").is(":visible") ) {
+				insertDataElement();
+			} else {
+				insertIndicator();
+			}
+		})
+
+		jQuery("#insertButton").button("option", "icons", { primary: "ui-icon-plusthick" });
+		jQuery("#saveButton").button("option", "icons", { primary: "ui-icon-disk" });
+		jQuery("#saveCloseButton").button("option", "icons", { primary: "ui-icon-disk" });
+		jQuery("#showSelectionBoxButton").button("option", "icons", { primary: "ui-icon-newwin" });
+		jQuery("#cancelButton").button("option", "icons", { primary: "ui-icon-cancel" });
+		jQuery("#delete").button("option", "icons", { primary: "ui-icon-trash" });
 	});
 
     var stat = "ADD";
@@ -47,44 +90,24 @@
 
     var i18n_confirm_delete = '$encoder.jsEscape( $i18n.getString( "dataentryform_confirm_delete" ) , "'" )';
 	var i18n_save_success = '$encoder.jsEscape( $i18n.getString( "save_success" ) , "'" )';
-	var i18n_dataelement_is_inserted = '$encoder.jsEscape( $i18n.getString( "dataelement_is_inserted" ) , "'" )';
+	var i18n_indicator_already_inserted = '$encoder.jsEscape( $i18n.getString( "indicator_already_inserted" ) , "'" )';
+	var i18n_no_indicator_was_selected = '$encoder.jsEscape( $i18n.getString( "no_indicator_was_selected" ) , "'" )';
+	var i18n_dataelement_already_inserted = '$encoder.jsEscape( $i18n.getString( "dataelement_already_inserted" ) , "'" )';
+	var i18n_no_dataelement_was_selected = '$encoder.jsEscape( $i18n.getString( "no_dataelement_was_selected" ) , "'" )';
 </script>
 
 <style type="text/css">
-#dataElementSelection { 
-	padding: 0.5em; 
-	position:fixed;
-	top:80px;
-	left:500px;
-	z-index:999999;
-	font-size:10pt;
-}
-
-#dataElementTab h3 {
-	font-size:10pt;
-	color:#FFFFFF;
-	cursor:move;
-	text-align: center; 
-	margin: 0;
-}
-
-#dataElementTab tr {
-	cursor:default;	
-}
-
-#dataElementTab tr.selected {
-	background-color:#2B0AAF;
-	color:#FFFFFF;
-}
-
-#dataElementList,#indicatorList {
-	margin-top:5px;
-}
-
 #message_{
 	display:block;
 	color:red;	
 }
+
+.ui-state-active2, .ui-widget-content .ui-state-active2, .ui-widget-header .ui-state-active2 {
+	border: 1px solid #79b7e7;
+	background: #f5f8f9;
+	font-weight: bold;
+	color: #e17009;
+}
 </style>
 
 <h3>$i18n.getString( "dataentryform_management" ) #openHelp( "custom_forms" )</h3>
@@ -122,11 +145,11 @@
     </tr>
     <tr>
       <td>
-	    <input type="button" id="saveButton" name="save" value="$i18n.getString( 'save' )" onclick="autoSave = true; validateDataEntryForm(); autoSave = '$!autoSave';"/>
-        <input type="submit" id="saveCloseButton" name="saveClose" value="$i18n.getString( 'save_close' )"/>
-        <input type="button" id="cancelButton" name="cancel" value="$i18n.getString( 'cancel' )" onclick="window.location.href='dataSet.action'"/>&nbsp;&nbsp;<span style="color:#606060">|</span>&nbsp;
-        <input type="button" id="showSelectionBoxButton" name="showselectionbox" value="$i18n.getString( 'show_selection_box' )"/>&nbsp;&nbsp;<span style="color:#606060">|</span>&nbsp;
-        <input type="button" id="delete" name="delete" value="$i18n.getString( 'delete' )" onclick="removeDataEntryForm( '$dataSet.id', '$dataEntryForm.id', '$dataEntryForm.name' )"/>
+	    <button type="button" id="saveButton" name="save" onclick="autoSave = true; validateDataEntryForm(); autoSave = '$!autoSave';">$i18n.getString( 'save' )</button>
+        <button type="submit" id="saveCloseButton" name="saveClose">$i18n.getString( 'save_close' )</button>
+        <button type="button" id="cancelButton" name="cancel" onclick="window.location.href='dataSet.action'">$i18n.getString( 'cancel' )</button>&nbsp;&nbsp;<span style="color:#606060">|</span>&nbsp;
+        <button type="button" id="showSelectionBoxButton" name="showselectionbox">$i18n.getString( 'show_selection_box' )</button>&nbsp;&nbsp;<span style="color:#606060">|</span>&nbsp;
+        <button type="button" id="delete" name="delete" onclick="removeDataEntryForm( '$dataSet.id', '$dataEntryForm.id', '$dataEntryForm.name' )">$i18n.getString( 'delete' )</button>
       </td>          
 	  <script>
 		if(stat == "EDIT")
@@ -145,63 +168,50 @@
 </form>
 
 <div id="selectionDialog" title="Selection Box">
-
-<div id="selectionTabs">
-	<ul>
-		<li><a href="#dataElementTab">$i18n.getString( 'dataelement' )</a></li>
-		<li><a href="#indicatorTab">Indicators</a></li>
-	</ul>
-
-	<div id="dataElementTab">
-		<input type="text" style="width:440px" onkeyup="filterValues( this.value, 1 )"/>
-		<div id="dataElementList" style="height:150px;overflow:auto;border:1px solid #7AAED5">
-			<table width="100%">
-				<tbody id="list">
-				#foreach( $operand in $operands )
-					<tr id="tr$velocityCount" onclick="select($velocityCount)" ondblclick="insertDataElement()">				
-						<td>$encoder.htmlEncode( $operand.operandName )<input type="hidden" id="json_$velocityCount" value='$operand.toJSON()'/></td>
-					</tr>						
-				#end
-				</tbody>
-			</table>
-		</div>
-
-		<table>
-			<tr>
-				<td>
-					<input id="dataElementInsertButton" type="button" value="Insert" style="width:120px"/>
-				</td>
-				<td>
-					<span id="message_"></span>
-				</td>
-			</tr>
-		</table>
-	</div>
-
-	<div id="indicatorTab">
-		<input type="text" style="width:100%" onkeyup="filterValues( this.value, 1 )"/>
-		<div id="indicatorList" style="height:150px;overflow:auto;border:1px solid #7AAED5">
-			<table width="100%">
-				<tbody id="list">
-				<select id="indicatorSelector" multiple="multiple" style="height: 144px; width: 100%">
-				#foreach( $indicator in $indicators )
-					<option data-id="${indicator.id}" ondblclick="insertIndicator()">$encoder.htmlEncode( $indicator.name )</option>
-				#end
-				</input>
-				</tbody>
-			</table>
-		</div>
-
-		<table>
-			<tr>
-				<td>
-					<input id="indicatorInsertButton" type="button" value="Insert" style="width:120px"/>
-				</td>
-				<td>
-					<span id="message_"></span>
-				</td>
-			</tr>
-		</table>
+<div id="tabs">
+		<table style="width: 100%;">
+			<tr>
+				<td colspan="2">
+					<input type="text" style="width: 100%; border: 1px solid #888; padding: 0;" onkeyup="localFilterSelectList( this.value )"/>
+				</td>
+			</tr>
+
+			<tr id="dataElementsTab">
+				<td colspan="2">
+					<select id="dataElementSelector" multiple="multiple" style="height: 246px; width: 100%; margin: 1px;">
+					#foreach( $operand in $operands )
+						<option class="dataElementSelectorOption"
+								data-dataelement-id="$operand.dataElement.id" data-dataelement-name="$operand.dataElement.name" data-dataelement-type="$operand.dataElement.type"
+								data-optioncombo-id="$operand.categoryOptionCombo.id" data-optioncombo-name="$operand.categoryOptionCombo.name" ondblclick="insertDataElement()">
+							$encoder.htmlEncode( $operand.operandName )
+						</option>
+					#end
+					</select>
+				</td>
+			</tr>
+
+			<tr id="indicatorsTab">
+				<td colspan="2">
+					<select id="indicatorSelector" multiple="multiple" style="height: 246px; width: 100%; margin: 1px;">
+					#foreach( $indicator in $indicators )
+						<option class="indicatorSelectorOption"
+								data-id="${indicator.id}" ondblclick="insertIndicator()">$encoder.htmlEncode( $indicator.name )</option>
+					#end
+					</select>
+				</td>
+			</tr>
+
+			<tr>
+				<td>
+					<button type="button" id="dataElementsButton">Data Elements</button>
+					<button type="button" id="indicatorsButton">Indicators</button>&nbsp;&nbsp;<span style="color:#606060">|</span>&nbsp;
+					<button type="button" id="insertButton">Insert</button>
+				</td>
+				<td>
+					<span id="message_"></span>
+				</td>
+			</tr>
+		</table>		
 	</div>
 </div>