dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #13844
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4549: finished ui for adding/updating attributes
------------------------------------------------------------
revno: 4549
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-09-08 21:22:56 +0200
message:
finished ui for adding/updating attributes
added:
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/attribute.js
modified:
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/validationRules.js
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/attribute/AddAttributeAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/attribute/UpdateAttributeAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addAttributeForm.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateAttributeForm.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateAttributeOptionForm.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/validationRules.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/validationRules.js 2011-09-08 15:28:20 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/validationRules.js 2011-09-08 19:22:56 +0000
@@ -380,22 +380,36 @@
"chartGroup" : {
"name" : {
"required" : true,
- "rangelength" : [ 3, 230 ],
+ "rangelength" : [ 3, 230 ],
"alphanumericwithbasicpuncspaces" : true
- }
+ }
},
"reportGroup" : {
"name" : {
"required" : true,
- "rangelength" : [ 3, 230 ],
+ "rangelength" : [ 3, 230 ],
"alphanumericwithbasicpuncspaces" : true
- }
+ }
},
"reportTableGroup" : {
"name" : {
"required" : true,
- "rangelength" : [ 3, 230 ],
- "alphanumericwithbasicpuncspaces" : true
- }
+ "rangelength" : [ 3, 230 ],
+ "alphanumericwithbasicpuncspaces" : true
+ }
+ },
+ "attribute" : {
+ "name" : {
+ "required" : true,
+ "rangelength" : [ 3, 230 ],
+ "alphanumericwithbasicpuncspaces" : true
+ }
+ },
+ "attributeOption" : {
+ "name" : {
+ "required" : true,
+ "rangelength" : [ 3, 230 ],
+ "alphanumericwithbasicpuncspaces" : true
+ }
}
};
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/attribute/AddAttributeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/attribute/AddAttributeAction.java 2011-09-08 10:38:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/attribute/AddAttributeAction.java 2011-09-08 19:22:56 +0000
@@ -120,18 +120,18 @@
attribute.setIndicator( indicator );
attribute.setOrganisationUnit( organisationUnit );
+ Set<AttributeOption> attributeOptions = new HashSet<AttributeOption>();
+
if ( valueType.compareTo( "multiple_choice" ) == 0 )
{
- Set<AttributeOption> attributeOptions = new HashSet<AttributeOption>();
-
for ( Integer id : selectedAttributeOptions )
{
attributeOptions.add( attributeService.getAttributeOption( id ) );
}
-
- attribute.setAttributeOptions( attributeOptions );
}
+ attribute.setAttributeOptions( attributeOptions );
+
attributeService.addAttribute( attribute );
return SUCCESS;
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/attribute/UpdateAttributeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/attribute/UpdateAttributeAction.java 2011-09-08 10:38:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/attribute/UpdateAttributeAction.java 2011-09-08 19:22:56 +0000
@@ -27,7 +27,13 @@
package org.hisp.dhis.dataadmin.action.attribute;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
import org.hisp.dhis.attribute.Attribute;
+import org.hisp.dhis.attribute.AttributeOption;
import org.hisp.dhis.attribute.AttributeService;
import com.opensymphony.xwork2.Action;
@@ -67,6 +73,48 @@
this.name = name;
}
+ private String valueType;
+
+ public void setValueType( String valueType )
+ {
+ this.valueType = valueType;
+ }
+
+ private Boolean mandatory = false;
+
+ public void setMandatory( Boolean mandatory )
+ {
+ this.mandatory = mandatory;
+ }
+
+ private Boolean dataElement = false;
+
+ public void setDataElement( Boolean dataElement )
+ {
+ this.dataElement = dataElement;
+ }
+
+ private Boolean indicator = false;
+
+ public void setIndicator( Boolean indicator )
+ {
+ this.indicator = indicator;
+ }
+
+ private Boolean organisationUnit = false;
+
+ public void setOrganisationUnit( Boolean organisationUnit )
+ {
+ this.organisationUnit = organisationUnit;
+ }
+
+ private List<Integer> selectedAttributeOptions = new ArrayList<Integer>();
+
+ public void setSelectedAttributeOptions( List<Integer> selectedAttributeOptions )
+ {
+ this.selectedAttributeOptions = selectedAttributeOptions;
+ }
+
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@@ -79,6 +127,23 @@
if ( attribute != null )
{
attribute.setName( name );
+ attribute.setValueType( valueType );
+ attribute.setMandatory( mandatory );
+ attribute.setDataElement( dataElement );
+ attribute.setIndicator( indicator );
+ attribute.setOrganisationUnit( organisationUnit );
+
+ Set<AttributeOption> attributeOptions = new HashSet<AttributeOption>();
+
+ if ( valueType.compareTo( "multiple_choice" ) == 0 )
+ {
+ for ( Integer id : selectedAttributeOptions )
+ {
+ attributeOptions.add( attributeService.getAttributeOption( id ) );
+ }
+ }
+
+ attribute.setAttributeOptions( attributeOptions );
attributeService.updateAttribute( attribute );
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addAttributeForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addAttributeForm.vm 2011-09-08 10:38:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addAttributeForm.vm 2011-09-08 19:22:56 +0000
@@ -1,26 +1,22 @@
+<script type="text/javascript" src="javascript/attribute.js"></script>
<script type="text/javascript">
- function onValueTypeChange(e) {
- var val = $(this).find(":selected").val();
-
- if(val == "multiple_choice") {
- $("#multipleChoice").show();
- } else {
- $("#multipleChoice").hide();
- }
- }
-
jQuery(document).ready( function()
{
+ validation2( 'addAttributeForm', function( form ) {
+ $("#selectedAttributeOptions").children().attr("selected", "selected");
+ form.submit();
+ }, {
+ 'beforeValidateHandler' : function()
+ {
+ listValidator( 'memberValidator', 'selectedAttributeOptions' );
+ },
+ 'rules': getValidationRules("attribute")
+ });
+
+ checkValueIsExist( "name", "validateAttribute.action" );
+
$("#valueType").bind("change", onValueTypeChange);
-
- var rules = getValidationRules("attribute");
-
- validation2( 'addAttributeForm', function( form ){ form.submit(); },
- {
- 'rules': rules
- });
-
- checkValueIsExist( "name", "validateAttribute.action" );
+ $("#valueType").change();
jQuery("#availableAttributeOptions").dhisAjaxSelect({
source: "../dhis-web-commons-ajax-json/getAttributeOptions.action",
@@ -74,13 +70,18 @@
<select id="valueType" name="valueType" style="width:20em">
<option value="string">$i18n.getString( "text" )</option>
<option value="bool">$i18n.getString( "yes_no" )</option>
+ <option value="date">$i18n.getString( "date" )</option>
+ <option value="number">$i18n.getString( "number" )</option>
+ <option value="int" >$i18n.getString( "int" )</option>
+ <option value="positiveNumber">$i18n.getString( "positiveNumber" )</option>
+ <option value="negativeNumber">$i18n.getString( "negativeNumber" )</option>
<option value="multiple_choice">$i18n.getString( "multiple_choice" )</option>
</select>
</td>
</tr>
- <tr>
- <td colspan="3" id="multipleChoice" style="display: none;">
+ <tr id="multipleChoice" style="display: none;">
+ <td colspan="3">
<table>
<col style="width: 300px"/>
@@ -101,10 +102,10 @@
</td>
<td style="text-align:center">
- <input type="button" value=">" title="$i18n.getString( 'move_selected' )" style="width:50px" onclick="dhisAjaxSelect_moveAllSelected( 'availableUsersList' );"/><br/>
- <input type="button" value="<" title="$i18n.getString( 'remove_selected' )" style="width:50px" onclick="dhisAjaxSelect_moveAllSelected( 'groupMembersList' );"/><br/>
- <input type="button" value=">>" title="$i18n.getString('move_all')" style="width:50px" onclick="dhisAjaxSelect_moveAll( 'availableUsersList' );"/><br/>
- <input type="button" value="<<" title="$i18n.getString('remove_all')" style="width:50px" onclick="dhisAjaxSelect_moveAll( 'groupMembersList' );"/>
+ <input type="button" value=">" title="$i18n.getString( 'move_selected' )" style="width:50px" onclick="dhisAjaxSelect_moveAllSelected( 'availableAttributeOptions' );"/><br/>
+ <input type="button" value="<" title="$i18n.getString( 'remove_selected' )" style="width:50px" onclick="dhisAjaxSelect_moveAllSelected( 'selectedAttributeOptions' );"/><br/>
+ <input type="button" value=">>" title="$i18n.getString('move_all')" style="width:50px" onclick="dhisAjaxSelect_moveAll( 'availableAttributeOptions' );"/><br/>
+ <input type="button" value="<<" title="$i18n.getString('remove_all')" style="width:50px" onclick="dhisAjaxSelect_moveAll( 'selectedAttributeOptions' );"/>
</td>
<td>
=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/attribute.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/attribute.js 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/attribute.js 2011-09-08 19:22:56 +0000
@@ -0,0 +1,15 @@
+function onValueTypeChange( e )
+{
+ var val = $( this ).find( ":selected" ).val();
+
+ if ( val == "multiple_choice" )
+ {
+ $( "#memberValidator" ).addClass( "required" );
+ $( "#multipleChoice" ).show();
+ }
+ else
+ {
+ $( "#memberValidator" ).removeClass( "required" );
+ $( "#multipleChoice" ).hide();
+ }
+};
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateAttributeForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateAttributeForm.vm 2011-09-07 13:42:12 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateAttributeForm.vm 2011-09-08 19:22:56 +0000
@@ -1,1 +1,134 @@
-updateAttribute
\ No newline at end of file
+<script type="text/javascript" src="javascript/attribute.js"></script>
+<script type="text/javascript">
+ jQuery(document).ready( function()
+ {
+ validation2( 'updateAttributeForm', function( form ) {
+ $("#selectedAttributeOptions").children().attr("selected", "selected");
+ form.submit();
+ }, {
+ 'beforeValidateHandler' : function()
+ {
+ listValidator( 'memberValidator', 'selectedAttributeOptions' );
+ },
+ 'rules': getValidationRules("attribute")
+ });
+
+ checkValueIsExist( "name", "validateAttribute.action", {id: $attribute.id} );
+
+ $("#valueType").bind("change", onValueTypeChange);
+ $("#valueType").change();
+
+ jQuery("#availableAttributeOptions").dhisAjaxSelect({
+ source: "../dhis-web-commons-ajax-json/getAttributeOptions.action",
+ iterator: "attributeOptions",
+ connectedTo: 'selectedAttributeOptions',
+ handler: function(item) {
+ var option = jQuery("<option />");
+ option.text( item.name );
+ option.attr( "value", item.id );
+
+ return option;
+ }
+ });
+ });
+</script>
+
+<h3>$i18n.getString( "edit_attribute" )</h3>
+
+<form id="updateAttributeForm" action="updateAttribute.action" method="post" >
+<input type="hidden" id="id" name="id" value="$!attribute.id"/>
+
+<table>
+ <col style="width: 100px"/>
+ <col/>
+
+ <tr>
+ <th colspan="2">$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" style="width:20em" value="$encoder.htmlEncode( $!attribute.name )"/></td>
+ </tr>
+
+ <tr>
+ <td><label for="mandatory">$i18n.getString( "mandatory" )</td>
+ <td><input type="checkbox" id="mandatory" name="mandatory" value="true" #if( $attribute.mandatory ) checked="checked" #end /></td>
+ </tr>
+
+ <tr>
+ <td style="vertical-align: text-top;">$i18n.getString( "assigned_to" )</td>
+ <td>
+ <input type="checkbox" id="dataElement" name="dataElement" value="true" #if( $attribute.dataElement ) checked="checked" #end /><label for="dataElement">$i18n.getString( 'data_element' )</label> <br />
+ <input type="checkbox" id="indicator" name="indicator" value="true" #if( $attribute.indicator ) checked="checked" #end /><label for="indicator">$i18n.getString( 'indicator' )</label> <br />
+ <input type="checkbox" id="organisationUnit" name="organisationUnit" value="true" #if( $attribute.organisationUnit ) checked="checked" #end /><label for="organisationUnit">$i18n.getString( 'organisation_unit' )</label> <br />
+ </td>
+ </tr>
+
+ <tr>
+ <td><label for="valueType">$i18n.getString( "value_type" )</td>
+ <td>
+ <select id="valueType" name="valueType" style="width:20em">
+ <option value="string" #if( $attribute.valueType == 'string') selected="selected" #end>$i18n.getString( "text" )</option>
+ <option value="bool" #if( $attribute.valueType == 'bool') selected="selected" #end>$i18n.getString( "yes_no" )</option>
+ <option value="date" #if( $attribute.valueType == 'date') selected="selected" #end>$i18n.getString( "date" )</option>
+ <option value="number" #if( $attribute.valueType == 'number') selected="selected" #end>$i18n.getString( "number" )</option>
+ <option value="int" #if( $attribute.valueType == 'int') selected="selected" #end>$i18n.getString( "int" )</option>
+ <option value="positiveNumber" #if( $attribute.valueType == 'positiveNumber') selected="selected" #end>$i18n.getString( "positiveNumber" )</option>
+ <option value="negativeNumber" #if( $attribute.valueType == 'negativeNumber') selected="selected" #end>$i18n.getString( "negativeNumber" )</option>
+ <option value="multiple_choice" #if( $attribute.valueType == 'multiple_choice') selected="selected" #end>$i18n.getString( "multiple_choice" )</option>
+ </select>
+ </td>
+ </tr>
+
+ <tr>
+ <td colspan="3" id="multipleChoice" style="display: none;">
+ <br />
+ <table>
+
+ <col style="width: 300px"/>
+ <col/>
+ <col style="width: 300px"/>
+
+ <tr>
+ <th>$i18n.getString( "available_attribute_options" )</th>
+ <th></th>
+ <th>$i18n.getString( "selected_attribute_options" )
+ <select id="memberValidator" multiple="multiple" style="display:none"/>
+ </th>
+ </tr>
+
+ <tr>
+ <td>
+ <select id="availableAttributeOptions" name="availableAttributeOptions" multiple="multiple" style="height: 200px; width: 100%;"></select>
+ </td>
+
+ <td style="text-align:center">
+ <input type="button" value=">" title="$i18n.getString( 'move_selected' )" style="width:50px" onclick="dhisAjaxSelect_moveAllSelected( 'availableAttributeOptions' );"/><br/>
+ <input type="button" value="<" title="$i18n.getString( 'remove_selected' )" style="width:50px" onclick="dhisAjaxSelect_moveAllSelected( 'selectedAttributeOptions' );"/><br/>
+ <input type="button" value=">>" title="$i18n.getString('move_all')" style="width:50px" onclick="dhisAjaxSelect_moveAll( 'availableAttributeOptions' );"/><br/>
+ <input type="button" value="<<" title="$i18n.getString('remove_all')" style="width:50px" onclick="dhisAjaxSelect_moveAll( 'selectedAttributeOptions' );"/>
+ </td>
+
+ <td>
+ <select id="selectedAttributeOptions" name="selectedAttributeOptions" multiple="multiple" style="height: 200px; width: 100%; margin-top: 22px;">
+ #foreach( $attributeOption in $attribute.attributeOptions )
+ <option value="$attributeOption.id">$encoder.htmlEncode( $attributeOption.name )</option>
+ #end
+ </select>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+
+ <tr>
+ <td colspan="2">
+ <br/>
+ <input type="submit" value="$i18n.getString( 'save' )" style="width:10em"/>
+ <input type="button" value="$i18n.getString( 'cancel' )" onclick="window.location.href='attribute.action'" style="width:10em"/>
+ </td>
+ </tr>
+</table>
+
+</form>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateAttributeOptionForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateAttributeOptionForm.vm 2011-09-07 13:42:12 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/updateAttributeOptionForm.vm 2011-09-08 19:22:56 +0000
@@ -8,7 +8,7 @@
'rules': rules
});
- checkValueIsExist( "name", "validateAttributeOption.action" );
+ checkValueIsExist( "name", "validateAttributeOption.action", {id: $attributeOption.id} );
});
</script>