← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20072: validate options for optionsets based on optionset.valuetype

 

------------------------------------------------------------
revno: 20072
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-09-10 15:53:43 +0700
message:
  validate options for optionsets based on optionset.valuetype
modified:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addOptionForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateOptionForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateOptionSetForm.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-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addOptionForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addOptionForm.vm	2014-08-29 13:07:57 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addOptionForm.vm	2015-09-10 08:53:43 +0000
@@ -1,13 +1,26 @@
 <script type="text/javascript">
-	jQuery(document).ready(	function() {
-		validation( 'addOptionForm', function(form){
-			form.submit();
-		});
-
-		checkValueIsExist( "name", "validateOption.action",{optionSetId:getFieldValue('optionSetId')});	
-		checkValueIsExist( "code", "validateOption.action",{optionSetId:getFieldValue('optionSetId')});	
-	});
-
+  var i18n_value_must_integer = '$encoder.jsEscape( $i18n.getString( "value_must_integer" ) , "'")';
+  var i18n_value_must_number = '$encoder.jsEscape( $i18n.getString( "value_must_number" ) , "'")';
+  var i18n_value_must_positive_integer = '$encoder.jsEscape( $i18n.getString( "value_must_positive_integer" ) , "'")';
+  var i18n_value_must_zero_or_positive_integer = '$encoder.jsEscape( $i18n.getString( "value_must_zero_or_positive_integer" ) , "'")';
+  var i18n_value_must_negative_integer = '$encoder.jsEscape( $i18n.getString( "value_must_negative_integer" ) , "'")';
+  var i18n_value_must_unit_interval = '$encoder.jsEscape( $i18n.getString( "value_must_unit_interval" ) , "'")';
+  var i18n_value_must_percentage = '$encoder.jsEscape( $i18n.getString( "value_must_percentage" ) , "'")';
+
+  jQuery(document).ready(function() {
+    validation('addOptionForm', function(form) {
+      var codeEl = document.getElementById('code');
+      var value = codeEl.value;
+      var valueType = '$optionSet.valueType';
+
+      if( dhis2.validation.isValidValueType(value, valueType) ) {
+        form.submit();
+      }
+    });
+
+    checkValueIsExist("name", "validateOption.action", { optionSetId: getFieldValue('optionSetId') });
+    checkValueIsExist("code", "validateOption.action", { optionSetId: getFieldValue('optionSetId') });
+  });
 </script>
 
 <h3>$i18n.getString( "add_option" )</h3>
@@ -16,27 +29,27 @@
   <input id='optionSetId' name='optionSetId' value='$optionSet.id' type='hidden'>
   <table>
     <colgroup>
-        <col width="50px" />
-        <col width="150px"/>
-        <col width="50px"/>
+      <col width="50px"/>
+      <col width="150px"/>
+      <col width="50px"/>
     </colgroup>
     <tr>
-      <th colspan='3'>$i18n.getString( "details" )</th>      
+      <th colspan='3'>$i18n.getString( "details" )</th>
     </tr>
     <tr>
       <td><label for='name'>$i18n.getString( "name" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
-      <td ><input type="text" id="name" name="name" class="{validate:{required:true,minlength:2}}" /></td>
-    </tr>      
-	<tr>
+      <td><input type="text" id="name" name="name" class="{validate:{required:true,minlength:2}}"/></td>
+    </tr>
+    <tr>
       <td><label for='code'>$i18n.getString( "code" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
-      <td ><input type="text" id="code" name="code" class="{validate:{required:true}}" /></td>
+      <td><input type="text" id="code" name="code" class="{validate:{required:true}}"/></td>
     </tr>
-	<tr>
-	  <td></td>
-	  <td colspan="2">
-		<input type="submit"  value="$i18n.getString( 'add' )" style="width:10em">
-		<input type="button" onclick="window.location.href='option.action?optionSetId=$optionSet.id'" value="$i18n.getString( 'cancel' )" style="width:10em"/></p>
+    <tr>
+      <td></td>
+      <td colspan="2">
+        <input type="submit" value="$i18n.getString( 'add' )" style="width:10em">
+        <input type="button" onclick="window.location.href='option.action?optionSetId=$optionSet.id'" value="$i18n.getString( 'cancel' )" style="width:10em"/></p>
       </td>
-	</tr>
+    </tr>
   </table>
 </form>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateOptionForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateOptionForm.vm	2014-09-28 20:26:12 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateOptionForm.vm	2015-09-10 08:53:43 +0000
@@ -1,12 +1,18 @@
 <script type="text/javascript">
-	jQuery(document).ready(	function() {
-		validation( 'updateOptionForm', function(form){
-			form.submit();
-		});
-
-		checkValueIsExist( "name", "validateOption.action",{optionSetId:getFieldValue('optionSetId'), id: getFieldValue('optionId')});	
-		checkValueIsExist( "code", "validateOption.action",{optionSetId:getFieldValue('optionSetId'), id: getFieldValue('optionId')});	
-	});
+  jQuery(document).ready(function() {
+    validation('updateOptionForm', function(form) {
+      var codeEl = document.getElementById('code');
+      var value = codeEl.value;
+      var valueType = '$optionSet.valueType';
+
+      if( dhis2.validation.isValidValueType(value, valueType) ) {
+        form.submit();
+      }
+    });
+
+    checkValueIsExist("name", "validateOption.action", { optionSetId: getFieldValue('optionSetId'), id: getFieldValue('optionId') });
+    checkValueIsExist("code", "validateOption.action", { optionSetId: getFieldValue('optionSetId'), id: getFieldValue('optionId') });
+  });
 
 </script>
 
@@ -17,27 +23,27 @@
   <input id='optionId' name='optionId' value='$option.id' type='hidden'>
   <table>
     <colgroup>
-        <col width="50px" />
-        <col width="150px"/>
-        <col width="50px"/>
+      <col width="50px"/>
+      <col width="150px"/>
+      <col width="50px"/>
     </colgroup>
     <tr>
-      <th colspan='3'>$i18n.getString( "details" )</th>      
+      <th colspan='3'>$i18n.getString( "details" )</th>
     </tr>
     <tr>
       <td><label for='name'>$i18n.getString( "name" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
-      <td ><input type="text" id="name" name="name" value='$option.name' class="{validate:{required:true,minlength:2}}" /></td>
-    </tr>      
-	<tr>
+      <td><input type="text" id="name" name="name" value='$option.name' class="{validate:{required:true,minlength:2}}"/></td>
+    </tr>
+    <tr>
       <td><label for='code'>$i18n.getString( "code" ) <em title="$i18n.getString( 'required' )" class="required">*</em></label></td>
-      <td ><input type="text" id="code" name="code" readonly disabled value='$option.code' class="{validate:{required:true}}" /></td>
+      <td><input type="text" id="code" name="code" style="background-color: lightgrey;" readonly disabled value='$option.code' class="{validate:{required:true}}"/></td>
     </tr>
-	<tr>
-	  <td></td>
-	  <td colspan="2">
-		<input type="submit"  value="$i18n.getString( 'update' )" style="width:10em">
-		<input type="button" onclick="window.location.href='option.action?optionSetId=$optionSet.id'" value="$i18n.getString( 'cancel' )" style="width:10em"/></p>
+    <tr>
+      <td></td>
+      <td colspan="2">
+        <input type="submit" value="$i18n.getString( 'update' )" style="width:10em">
+        <input type="button" onclick="window.location.href='option.action?optionSetId=$optionSet.id'" value="$i18n.getString( 'cancel' )" style="width:10em"/></p>
       </td>
-	</tr>
+    </tr>
   </table>
 </form>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateOptionSetForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateOptionSetForm.vm	2015-09-10 07:57:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateOptionSetForm.vm	2015-09-10 08:53:43 +0000
@@ -37,7 +37,7 @@
            <option value="INTEGER_POSITIVE" #if( $!optionSet.valueType == 'INTEGER_POSITIVE' ) selected="selected" #end >$i18n.getString( "positive_integer" )</option>
            <option value="INTEGER_NEGATIVE" #if( $!optionSet.valueType == 'INTEGER_NEGATIVE' ) selected="selected" #end >$i18n.getString( "negative_integer" )</option>
            <option value="INTEGER_ZERO_OR_POSITIVE" #if( $!optionSet.valueType == 'INTEGER_ZERO_OR_POSITIVE' ) selected="selected" #end >$i18n.getString( "zero_positive_int" )</option>
-           <option value="NUMBER" #if( $!optionSet.optionSet == 'NUMBER' ) selected="selected" #end >$i18n.getString( "number" )</option>
+           <option value="NUMBER" #if( $!optionSet.valueType == 'NUMBER' ) selected="selected" #end >$i18n.getString( "number" )</option>
            <option value="UNIT_INTERVAL" #if( $!optionSet.valueType == 'UNIT_INTERVAL' ) selected="selected" #end >$i18n.getString( "unit_interval" )</option>
            <option value="PERCENTAGE" #if( $!optionSet.valueType == 'PERCENTAGE' ) selected="selected" #end >$i18n.getString( "percentage" )</option>
            <option value="TEXT" #if( $!optionSet.valueType == 'TEXT' ) selected="selected" #end >$i18n.getString( "text" )</option>