dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #14049
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4621: wip, ui for adding/removing dynamic attributes on data element
------------------------------------------------------------
revno: 4621
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-09-20 16:48:24 +0200
message:
wip, ui for adding/removing dynamic attributes on data element
removed:
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/addDataElementForm.js
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/updateDataElementForm.js
modified:
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.validate.ext.js
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/macros.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/AddDataElementAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/ShowUpdateDataElementFormAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/UpdateDataElementAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addDataElementForm.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/updateDataElementForm.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-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.validate.ext.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.validate.ext.js 2011-09-19 07:44:36 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.validate.ext.js 2011-09-20 14:48:24 +0000
@@ -339,19 +339,19 @@
});
jQuery.validator.addMethod("number", function(value, element, param) {
- return isRealNumber(value);
+ return this.optional(element) || isRealNumber(value);
});
jQuery.validator.addMethod("integer", function(value, element, param) {
- return isInt(value);
+ return this.optional(element) || isInt(value);
});
jQuery.validator.addMethod("positive_integer", function(value, element, param) {
- return isPositiveInt(value);
+ return this.optional(element) || isPositiveInt(value);
});
jQuery.validator.addMethod("negative_integer", function(value, element, param) {
- return isNegativeInt(value);
+ return this.optional(element) || isNegativeInt(value);
});
// Support method for date
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/macros.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/macros.vm 2011-09-19 07:44:36 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/macros.vm 2011-09-20 14:48:24 +0000
@@ -347,26 +347,70 @@
</tr>
#end
-#macro( tblDynamicAttributes $attributes )
+#macro( tblDynamicAttributesJavascript )
+var attributes = jQuery("form").find(":input[name*='attribute_']");
+var jqAttributeValues= jQuery("#attributeValues");
+jqAttributeValues.children().remove();
+
+jQuery.each(attributes, function(i, item) {
+ var jqItem = jQuery(item);
+ var json = {};
+
+ json.id = jqItem.attr("id").split("_")[1];
+
+ if( jqItem.is("input[type='text']") )
+ {
+ json.value = jqItem.val();
+ }
+ else if( jqItem.is("select") )
+ {
+ json.value = jqItem.find(":selected").val();
+ }
+
+ json = JSON.stringify(json);
+
+ jQuery("<option />")
+ .attr("value", json)
+ .attr("selected", "selected")
+ .text(json)
+ .appendTo(jqAttributeValues);
+});
+#end
+
+#****************************************************
+ Required args:
+ attributes
+ Optional args:
+ attributeValues
+*****************************************************#
+#macro( tblDynamicAttributes $args )
+
+<select multiple="multiple" id="attributeValues" name="attributeValues" style="display: none;"></select>
+
<div id="dynamicAttributesContainer" style="margin-top: 20px;">
<table>
#trHeader( "Dynamic Attributes" )
- #foreach( $attribute in $attributes )
+ #foreach( $attribute in $args.attributes )
+ #set( $text = $attribute.name )
+ #set( $id = $attribute.id )
+ #set( $mandatory = $attribute.mandatory )
+ #set( $value = $!args.attributeValues.get( $attribute.id ) )
+
#if( $attribute.valueType == "string" )
- #trTextInput( { "text": $attribute.name, "id": "textAttribute$attribute.id", "mandatory": $attribute.mandatory } )
+ #trTextInput( { "text": $text, "id": "attribute_$id", "mandatory": $mandatory, "value": $value } )
#elseif( $attribute.valueType == "bool" )
- #trBooleanSelectInput( { "text": $attribute.name, "id": "booleanAttribute$attribute.id", "mandatory": $attribute.mandatory } )
+ #trBooleanSelectInput( { "text": $text, "id": "attribute_$id", "mandatory": $mandatory, "value": $value } )
#elseif( $attribute.valueType == "date" )
- #trDateInput( { "text": $attribute.name, "id": "dateAttribute$attribute.id", "mandatory": $attribute.mandatory } )
+ #trDateInput( { "text": $text, "id": "attribute_$id", "mandatory": $mandatory, "value": $value } )
#elseif( $attribute.valueType == "number" )
- #trNumberInput( { "text": $attribute.name, "id": "numberAttribute$attribute.id", "mandatory": $attribute.mandatory } )
+ #trNumberInput( { "text": $text, "id": "attribute_$id", "mandatory": $mandatory, "value": $value } )
#elseif( $attribute.valueType == "integer" )
- #trIntegerInput( { "text": $attribute.name, "id": "integerAttribute$attribute.id", "mandatory": $attribute.mandatory } )
+ #trIntegerInput( { "text": $text, "id": "attribute_$id", "mandatory": $mandatory, "value": $value } )
#elseif( $attribute.valueType == "positive_integer" )
- #trPositiveIntegerInput( { "text": $attribute.name, "id": "positiveIntegerAttribute$attribute.id", "mandatory": $attribute.mandatory } )
+ #trPositiveIntegerInput( { "text": $text, "id": "attribute_$id", "mandatory": $mandatory, "value": $value } )
#elseif( $attribute.valueType == "negative_integer" )
- #trNegativeIntegerInput( { "text": $attribute.name, "id": "negativeIntegerAttribute$attribute.id", "mandatory": $attribute.mandatory } )
+ #trNegativeIntegerInput( { "text": $text, "id": "attribute_$id", "mandatory": $mandatory, "value": $value } )
#elseif( $attribute.valueType == "multiple_choice" )
#set( $attributeOptions = [] )
@@ -374,7 +418,7 @@
#set( $return = $attributeOptions.add( $attributeOption.name ) )
#end
- #trMultipleChoiceInput( { "text": $attribute.name, "id": "multipleChoiceAttribute$attribute.id", "mandatory": $attribute.mandatory, "choices": $attributeOptions } )
+ #trMultipleChoiceInput( { "text": $text, "id": "attribute_$id", "mandatory": $mandatory, "choices": $attributeOptions, "value": $value } )
#end
#end
</table>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/AddDataElementAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/AddDataElementAction.java 2011-09-08 15:28:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/AddDataElementAction.java 2011-09-20 14:48:24 +0000
@@ -29,6 +29,7 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryCombo;
@@ -100,7 +101,7 @@
{
this.description = description;
}
-
+
private String formName;
public void setFormName( String formName )
@@ -164,6 +165,13 @@
this.zeroIsSignificant = zeroIsSignificant;
}
+ private List<String> attributeValues;
+
+ public void setAttributeValues( List<String> attributeValues )
+ {
+ this.attributeValues = attributeValues;
+ }
+
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@@ -213,11 +221,16 @@
dataElement.setCategoryCombo( categoryCombo );
dataElement.setAggregationLevels( new ArrayList<Integer>( ConversionUtils
.getIntegerCollection( aggregationLevels ) ) );
-
+
dataElement.setZeroIsSignificant( zeroIsSignificant );
dataElementService.addDataElement( dataElement );
+ for ( String attributeValue : attributeValues )
+ {
+ System.out.println( attributeValue );
+ }
+
return SUCCESS;
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/ShowUpdateDataElementFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/ShowUpdateDataElementFormAction.java 2011-09-14 10:14:11 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/ShowUpdateDataElementFormAction.java 2011-09-20 14:48:24 +0000
@@ -141,11 +141,18 @@
return defaultCategoryCombo;
}
- public Map<Attribute, AttributeValue> attributeMap = new HashMap<Attribute, AttributeValue>();
-
- public Map<Attribute, AttributeValue> getAttributeMap()
- {
- return attributeMap;
+ private List<Attribute> attributes;
+
+ public List<Attribute> getAttributes()
+ {
+ return attributes;
+ }
+
+ public Map<Integer, String> attributeValues = new HashMap<Integer, String>();
+
+ public Map<Integer, String> getAttributeValues()
+ {
+ return attributeValues;
}
// -------------------------------------------------------------------------
@@ -175,27 +182,16 @@
organisationUnitLevels.removeAll( aggregationLevels );
+ attributes = new ArrayList<Attribute>( attributeService.getDataElementAttributes() );
+
+ Collections.sort( attributes, new AttributeNameComparator() );
+
List<AttributeValue> dataElementAttributeValues = new ArrayList<AttributeValue>(
dataElement.getAttributeValues() );
- List<Attribute> attributes = new ArrayList<Attribute>( attributeService.getDataElementAttributes() );
-
- Collections.sort( attributes, new AttributeNameComparator() );
-
- // TODO fix this.. quite ugly and slow
- for ( Attribute key : attributes )
+ for ( AttributeValue attributeValue : dataElementAttributeValues )
{
- AttributeValue value = null;
-
- for ( AttributeValue av : dataElementAttributeValues )
- {
- if ( value.getAttribute().equals( key ) )
- {
- value = av;
- }
- }
-
- attributeMap.put( key, value );
+ attributeValues.put( attributeValue.getId(), attributeValue.getValue() );
}
return SUCCESS;
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/UpdateDataElementAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/UpdateDataElementAction.java 2011-09-14 10:14:11 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/UpdateDataElementAction.java 2011-09-20 14:48:24 +0000
@@ -29,6 +29,7 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
import java.util.Set;
import org.hisp.dhis.dataelement.DataElement;
@@ -188,6 +189,13 @@
this.zeroIsSignificant = zeroIsSignificant;
}
+ private List<String> attributeValues;
+
+ public void setAttributeValues( List<String> attributeValues )
+ {
+ this.attributeValues = attributeValues;
+ }
+
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@@ -256,6 +264,11 @@
dataElementService.updateDataElement( dataElement );
+ for ( String attributeValue : attributeValues )
+ {
+ System.out.println( attributeValue );
+ }
+
return SUCCESS;
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addDataElementForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addDataElementForm.vm 2011-09-16 15:55:47 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/addDataElementForm.vm 2011-09-20 14:48:24 +0000
@@ -1,5 +1,25 @@
-<script type="text/javascript" src="javascript/addDataElementForm.js"></script>
<script type="text/javascript">
+ jQuery( document ).ready( function()
+ {
+ validation2( 'addDataElementForm', function( form )
+ {
+ dhis2.select.selectAll( jQuery( '#aggregationLevels' ) );
+ form.submit();
+ }, {
+ 'beforeValidateHandler' : function()
+ {
+ setFieldValue( 'submitCategoryComboId', getFieldValue( 'selectedCategoryComboId' ) );
+ setFieldValue( 'submitValueType', getFieldValue( 'valueType' ) );
+ #tblDynamicAttributesJavascript()
+ },
+ 'rules' : getValidationRules( "dataElement" )
+ } );
+
+ checkValueIsExist( "name", "validateDataElement.action" );
+ checkValueIsExist( "shortName", "validateDataElement.action" );
+ checkValueIsExist( "alternativeName", "validateDataElement.action" );
+ } );
+
var previousName = '';
</script>
@@ -144,7 +164,7 @@
</div>
-#tblDynamicAttributes( $attributes )
+#tblDynamicAttributes( { "attributes": $attributes } )
<p>
<input type="submit" value="$i18n.getString( 'add' )" style="width:10em"/>
=== removed file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/addDataElementForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/addDataElementForm.js 2011-06-01 08:15:30 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/addDataElementForm.js 1970-01-01 00:00:00 +0000
@@ -1,19 +0,0 @@
-jQuery( document ).ready( function()
-{
- validation2( 'addDataElementForm', function( form )
- {
- dhis2.select.selectAll( $( '#aggregationLevels' ) );
- form.submit();
- }, {
- 'beforeValidateHandler' : function()
- {
- setFieldValue( 'submitCategoryComboId', getFieldValue( 'selectedCategoryComboId' ) );
- setFieldValue( 'submitValueType', getFieldValue( 'valueType' ) );
- },
- 'rules' : getValidationRules( "dataElement" )
- } );
-
- checkValueIsExist( "name", "validateDataElement.action" );
- checkValueIsExist( "shortName", "validateDataElement.action" );
- checkValueIsExist( "alternativeName", "validateDataElement.action" );
-} );
=== removed file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/updateDataElementForm.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/updateDataElementForm.js 2011-06-01 08:15:30 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/updateDataElementForm.js 1970-01-01 00:00:00 +0000
@@ -1,15 +0,0 @@
-jQuery( document ).ready( function()
-{
- validation2( 'updateDataElementForm', function( form )
- {
- dhis2.select.selectAll( $( '#aggregationLevels' ) );
- form.submit();
- }, {
- 'beforeValidateHandler' : function()
- {
- setFieldValue( 'submitCategoryComboId', getFieldValue( 'selectedCategoryComboId' ) );
- setFieldValue( 'submitValueType', getFieldValue( 'valueType' ) );
- },
- 'rules' : getValidationRules( "dataElement" )
- } );
-} );
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/updateDataElementForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/updateDataElementForm.vm 2011-09-08 15:28:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/updateDataElementForm.vm 2011-09-20 14:48:24 +0000
@@ -1,6 +1,19 @@
-<script type="text/javascript" src="javascript/updateDataElementForm.js"></script>
<script type="text/javascript">
jQuery(document).ready( function() {
+ validation2( 'updateDataElementForm', function( form )
+ {
+ dhis2.select.selectAll( jQuery( '#aggregationLevels' ) );
+ form.submit();
+ }, {
+ 'beforeValidateHandler' : function()
+ {
+ setFieldValue( 'submitCategoryComboId', getFieldValue( 'selectedCategoryComboId' ) );
+ setFieldValue( 'submitValueType', getFieldValue( 'valueType' ) );
+ #tblDynamicAttributesJavascript()
+ },
+ 'rules' : getValidationRules( "dataElement" )
+ } );
+
checkValueIsExist( "name", "validateDataElement.action", {id:getFieldValue('id')});
checkValueIsExist( "shortName", "validateDataElement.action", {id:getFieldValue('id')});
checkValueIsExist( "alternativeName", "validateDataElement.action", {id:getFieldValue('id')});
@@ -178,6 +191,11 @@
</div>
-<p><input type="submit" value="$i18n.getString( 'save' )" style="width:10em"/><input type="button" value="$i18n.getString( 'cancel' )" onclick="window.location.href='dataElement.action'" style="width:10em"/></p>
+#tblDynamicAttributes( { "attributes": $attributes, "attributeValues": $attributeValues } )
+
+<p>
+ <input type="submit" value="$i18n.getString( 'save' )" style="width:10em" />
+ <input type="button" value="$i18n.getString( 'cancel' )" onclick="window.location.href='dataElement.action'" style="width:10em" />
+</p>
</form>