← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2143: Avoiding reload of page to update image

 

------------------------------------------------------------
revno: 2143
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2010-11-22 23:16:17 +0100
message:
  Avoiding reload of page to update image
modified:
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/history.vm
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/history.js


--
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-dataentry/src/main/webapp/dhis-web-dataentry/history.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/history.vm	2010-11-22 21:48:22 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/history.vm	2010-11-22 22:16:17 +0000
@@ -7,8 +7,6 @@
     $encoder.htmlEncode( $dataElementHistory.optionCombo.name )
 </h3>
 
-<input type="hidden" id="organisationUnitId" value="$dataElementHistory.organisationUnit.id"/>
-
 <table>
 	<tr>		
 		<!-- Column 1 - Comment and Followup -->
@@ -16,7 +14,7 @@
 			<h4>$i18n.getString( "dataelement_comment" )</h4>       
 			#if( $showComment == 'true' )
 			##comment       
-			    <select id="value[$dataElementHistory.dataElement.id:$dataElementHistory.optionCombo.id].comments" #if( $auth.hasAccess( "dhis-web-dataentry", "saveComment" ) ) onchange="commentSelected( $dataElementHistory.dataElement.id, $dataElementHistory.optionCombo.id )" #else disabled="disabled" #end #if( $dataValue.comment && !$standardComments.contains( $dataValue.comment ) ) style="display:none; width:100%" #end#if( $locked ) disabled="disabled"#end>
+			    <select id="value[$dataElementHistory.dataElement.id:$dataElementHistory.optionCombo.id].comments" #if( $auth.hasAccess( "dhis-web-dataentry", "saveComment" ) ) onchange="commentSelected()" #else disabled="disabled" #end #if( $dataValue.comment && !$standardComments.contains( $dataValue.comment ) ) style="display:none; width:100%" #end#if( $locked ) disabled="disabled"#end>
 			        <option value="">[$i18n.getString( "no_comment" )]</option>
 			        <option value="custom">[$i18n.getString( "custom_comment" )]</option>
 			        #foreach( $comment in $standardComments )
@@ -24,7 +22,7 @@
 			        #end
 			    </select>
 			    <input id="value[$dataElementHistory.dataElement.id:$dataElementHistory.optionCombo.id].comment" type="text" value="$!encoder.htmlEncode( $dataValue.comment )" #if( $auth.hasAccess( "dhis-web-dataentry", "saveComment" ))
-			        onblur="commentLeft( $dataElementHistory.dataElement.id, $dataElementHistory.optionCombo.id )" #else disabled="disabled" #end style="width:100% #if( !$dataValue.comment || $standardComments.contains( $dataValue.comment )) ;display:none #end"/>
+			        onblur="commentLeft()" #else disabled="disabled" #end style="width:100% #if( !$dataValue.comment || $standardComments.contains( $dataValue.comment )) ;display:none #end"/>
 			#end
 			
 			<br/><br/>
@@ -47,7 +45,7 @@
                     <td>$encoder.htmlEncode( $i18n.getString( "max_limit" ) ) </td>
                     <td><input type="text" id="maxLimit" style="width:10em" value="$!{dataElementHistory.maxLimit}" class="{validate:{digits:true}}"
                         #if( $auth.hasAccess( "dhis-web-dataentry", "saveMinMaxLimits" ) && $auth.hasAccess( "dhis-web-dataentry", "removeMinMaxLimits" ))
-                            onchange="saveMinMaxLimit( $dataElementHistory.organisationUnit.id, $dataElementHistory.dataElement.id,  $dataElementHistory.optionCombo.id )"
+                            onchange="saveMinMaxLimit()"
                         #else disabled="disabled" #end onfocus="this.select()"/>
 						<span id='maxSpan' style="color:red;"></span>
 						</td>
@@ -57,7 +55,7 @@
                     <td>$encoder.htmlEncode( $i18n.getString( "min_limit" ) ) </td>
                     <td><input type="text" id="minLimit" style="width:10em" value="$!{dataElementHistory.minLimit}"
                         #if( $auth.hasAccess( "dhis-web-dataentry", "saveMinMaxLimits" ) && $auth.hasAccess( "dhis-web-dataentry", "removeMinMaxLimits" ))
-                           onchange="saveMinMaxLimit( $dataElementHistory.organisationUnit.id, $dataElementHistory.dataElement.id, $dataElementHistory.optionCombo.id )"
+                           onchange="saveMinMaxLimit()"
                         #else disabled="disabled" #end onfocus="this.select()"/>
 						<span id='minSpan' style="color:red;"></span>
 					</td>
@@ -73,7 +71,7 @@
                     <td></td>
                 </tr>
                 <tr>
-                	<td colspan="3"><input type="button" value="$i18n.getString( 'remove' )" onclick="removeMinMaxLimit( $dataElementHistory.organisationUnit.id, $dataElementHistory.dataElement.id, $dataElementHistory.optionCombo.id )" style="width:100px"></td>
+                	<td colspan="3"><input type="button" value="$i18n.getString( 'remove' )" onclick="removeMinMaxLimit()" style="width:100px"></td>
                 </tr>
             </table>        
         </td>
@@ -86,8 +84,7 @@
 			    <h4>$encoder.htmlEncode( $i18n.getString( "history_not_valid" ) )</h4>  
 			#end    
 			
-			<img src="getHistoryChart.action?dataElementId=${dataElementHistory.dataElement.id}&
-			    categoryOptionComboId=${dataElementHistory.optionCombo.id}"/>			
+			<img id="historyChart" src="getHistoryChart.action?dataElementId=${dataElementHistory.dataElement.id}&categoryOptionComboId=${dataElementHistory.optionCombo.id}"/>			
         </td>
     </tr>
 	<tr>
@@ -106,10 +103,14 @@
 
 </table>
 
-<p><input type="button" value="$encoder.htmlEncode( $i18n.getString( 'close' ) )"/></p>
+<p><input type="button" value="$encoder.htmlEncode( $i18n.getString( 'close' ) )" onclick="javascript:self.close()"/></p>
 
 <script type="text/javascript">
 
+var currentOrganisationUnitId = $!{dataElementHistory.organisationUnit.id};
+var currentDataElementId = $!{dataElementHistory.dataElement.id};
+var currentOptionComboId = $!{dataElementHistory.optionCombo.id};
+
 var i18n_enter_digits = '$encoder.jsEscape( $i18n.getString( "enter_digits" ) , "'")';
 var i18n_max_must_be_greater_than_min = '$encoder.jsEscape( $i18n.getString( "max_must_be_greater_than_min" ) , "'")';
 var i18n_mark_value_for_followup = '$encoder.jsEscape( $i18n.getString( "mark_value_for_followup" ) , "'")';

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/history.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/history.js	2010-11-22 21:48:22 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/history.js	2010-11-22 22:16:17 +0000
@@ -3,10 +3,10 @@
 // Comments
 // -----------------------------------------------------------------------------
 
-function commentSelected( dataElementId, optionComboId )
+function commentSelected()
 {  
-    var commentSelector = document.getElementById( 'value[' + dataElementId + ':' + optionComboId + '].comments' );
-    var commentField = document.getElementById( 'value[' + dataElementId + ':' + optionComboId + '].comment' );
+    var commentSelector = document.getElementById( 'value[' + currentDataElementId + ':' + currentOptionComboId + '].comments' );
+    var commentField = document.getElementById( 'value[' + currentDataElementId + ':' + currentOptionComboId + '].comment' );
 
     var value = commentSelector.options[commentSelector.selectedIndex].value;
     
@@ -22,14 +22,14 @@
     {
         commentField.value = value;
         
-        saveComment( dataElementId, optionComboId, value );
+        saveComment( value );
     }
 }
 
-function commentLeft( dataElementId, optionComboId )
+function commentLeft()
 {
-    var commentField = document.getElementById( 'value[' + dataElementId + ':' + optionComboId + '].comment' );
-    var commentSelector = document.getElementById( 'value[' + dataElementId + ':' + optionComboId + '].comments' );
+    var commentField = document.getElementById( 'value[' + currentDataElementId + ':' + currentOptionComboId + '].comment' );
+    var commentSelector = document.getElementById( 'value[' + currentDataElementId + ':' + currentOptionComboId + '].comments' );
 
     saveComment( dataElementId, optionComboId, commentField.value );
 
@@ -44,16 +44,15 @@
     }
 }
 
-function saveComment( dataElementId, optionComboId, commentValue )
+function saveComment( commentValue )
 {
-    var field = document.getElementById( 'value[' + dataElementId + ':' + optionComboId + '].comment' );                
-    var select = document.getElementById( 'value[' + dataElementId + ':' + optionComboId + '].comments' );
-    var organisationUnitId = getFieldValue( 'organisationUnitId' );
+    var field = document.getElementById( 'value[' + currentDataElementId + ':' + currentOptionComboId + '].comment' );                
+    var select = document.getElementById( 'value[' + currentDataElementId + ':' + currentOptionComboId + '].comments' );
 
     field.style.backgroundColor = '#ffffcc';
     select.style.backgroundColor = '#ffffcc';
     
-    var commentSaver = new CommentSaver( dataElementId, optionComboId, organisationUnitId, commentValue );
+    var commentSaver = new CommentSaver( currentDataElementId, currentOptionComboId, currentOrganisationUnitId, commentValue );
     commentSaver.save();
 }
 
@@ -118,14 +117,17 @@
 	} 
 }
 
-function removeMinMaxLimit( organisationUnitId, dataElementId, optionComboId )
+function removeMinMaxLimit()
 {
-	var url = 'removeMinMaxLimits.action?organisationUnitId=' + organisationUnitId + '&dataElementId=' + dataElementId + '&optionComboId=' + optionComboId;
+	$( '#minLimit' ).val( '' );
+	$( '#maxLimit' ).val( '' );
+	
+	var url = 'removeMinMaxLimits.action?organisationUnitId=' + currentOrganisationUnitId + '&dataElementId=' + currentDataElementId + '&optionComboId=' + currentOptionComboId;
 	
 	$.get( url, refreshWindow );
 }
 
-function saveMinMaxLimit( organisationUnitId, dataElementId, optionComboId )
+function saveMinMaxLimit()
 {
 	var minValue = $( '#minLimit' ).val();
 	var maxValue = $( '#maxLimit' ).val();
@@ -160,15 +162,17 @@
 		$( '#maxSpan' ).html( '' );
 	}
 	
-    var url = 'saveMinMaxLimits.action?organisationUnitId=' + organisationUnitId + '&dataElementId=' + dataElementId + 
-    	'&optionComboId=' + optionComboId + '&minLimit=' + minValue + '&maxLimit=' + maxValue;
+    var url = 'saveMinMaxLimits.action?organisationUnitId=' + currentOrganisationUnitId + '&dataElementId=' + currentDataElementId + 
+    	'&optionComboId=' + currentOptionComboId + '&minLimit=' + minValue + '&maxLimit=' + maxValue;
     
     $.get( url, refreshWindow );
 }
 
 function refreshWindow()
 {
-    window.location.reload();
+	var source = 'getHistoryChart.action?dataElementId=' + currentDataElementId + '&categoryOptionComboId=' + currentOptionComboId + '&r=' + Math.random();
+	
+	$( '#historyChart' ).attr( 'src', source );
 }
 
 function markValueForFollowup( dataElementId, periodId, sourceId, categoryOptionComboId )