dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #23142
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11254: refactored section-rendering into macro, now used by both section and default forms
------------------------------------------------------------
revno: 11254
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-06-24 14:16:54 +0700
message:
refactored section-rendering into macro, now used by both section and default forms
modified:
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/macros.vm
dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadFormAction.java
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/defaultForm.vm
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.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/macros.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/macros.vm 2013-03-17 14:36:26 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/macros.vm 2013-06-24 07:16:54 +0000
@@ -368,3 +368,91 @@
#end
</div>
#end
+
+##################################################################################################
+## Data Entry Macros
+##################################################################################################
+
+#*
+ @param $categoryComboId
+ @param $dataElements Data Elements to be rendered in your section
+ @param $args.title Include if you want a title rendered in your section
+*#
+#macro( renderSection $categoryComboId $dataElements $args )
+<table class="formSection" style="margin-bottom: 20px;">
+#if( $!args.title )
+<tr>
+ <td>
+ <div class="cent"><h3>$encoder.htmlEncode( $args.title )</h3></div>
+ </td>
+</tr>
+#end
+<tr>
+ <td>
+ <div>
+ <table cellspacing="0">
+ #set( $colCount = $numberOfTotalColumns.get( $categoryComboId ) )
+ #set( $categories = $orderedCategories.get( $categoryComboId ) )
+ #set( $optionsMap = $orderedOptionsMap.get( $categoryComboId ) )
+ #set( $colRepeat = $catColRepeat.get( $categoryComboId ) )
+ #set( $hasFilterInSection = false )
+
+ #foreach( $category in $categories )
+ #set( $categoryOptions = $optionsMap.get( $category.id ) )
+ #set( $colCount = $colCount / $categoryOptions.size() )
+ <tr colspan="$colCount">
+ <td>#if( $hasFilterInSection == false )<input type="text" class="sectionFilter" placeholder="$encoder.jsEscape( $i18n.getString( "filter_in_section" ) , "'")" onkeyup="filterInSection($(this));">#set( $hasFilterInSection = true )#end</td>
+ #set( $cols = $colRepeat.get( $category.id ) )
+ #foreach( $col in $cols )
+ #foreach( $categoryOption in $categoryOptions )
+ <th colspan="$colCount"><span align="center">#if( $categoryOption.isDefault() )${i18n.getString( "value" )}#else ${encoder.htmlEncode( $categoryOption.displayName )}#end</span></th>
+ #end
+ #end
+ </tr>
+ #end
+
+ #set( $count = 0 )
+ #set( $mark = 0 )
+ #set( $optionCombos = $orderedCategoryOptionCombos.get( $categoryComboId ) )
+ #foreach( $optionCombo in $optionCombos )<span id="${optionCombo.uid}-optioncombo" class="hidden">${encoder.htmlEncode( $optionCombo.displayName )}</span>
+ #end
+ #foreach( $dataElement in $dataElements )
+ #if( $mark == 1 )
+ #set( $mark = 0 )
+ #else
+ #set( $mark = 1 )
+ #end
+ #set( $count = $count + 1 )
+ <tr>
+ <td id="${dataElement.uid}-cell" #if( $mark == 1 )class="alt"#else class="reg"#end><span id="${dataElement.uid}-dataelement">${encoder.htmlEncode( $dataElement.getFormNameFallback() )}</span></td>
+ #foreach( $optionCombo in $optionCombos )
+ #set( $dataEntryId = "${dataElement.uid}-${optionCombo.uid}-val" )
+ #set( $commentId = "${dataElement.uid}-${optionCombo.uid}-comment" )
+ #set( $greyedField = false )
+ #set( $greyedField = $greyedFields.get( "${dataElement.uid}:${optionCombo.uid}" ) )
+ #if( $dataElement.type == "bool" )
+ <td><select name="entryselect" id="$dataEntryId" tabindex="$tabIndex"#if( $greyedField || !$hasAccess ) disabled="disabled"#end>
+ <option value="">[$i18n.getString( "no_value" )]</option>
+ <option value="true">$i18n.getString( "yes" )</option>
+ <option value="false">$i18n.getString( "no" )</option>
+ </select><img name="commentlink" id="${commentId}"></td>
+ #elseif( $dataElement.type == "trueOnly" )
+ <td><input name="entrytrueonly" id="${dataEntryId}" type="checkbox" tabindex="${tabIndex}"#if( $greyedField || !$hasAccess ) disabled="disabled"#end></td>
+ #else
+ #if( $dataElement.optionSet )
+ <td><input name="entryoptionset" id="${dataEntryId}" type="text" tabindex="${tabIndex}"#if( $greyedField || !$hasAccess ) disabled="disabled"#end></td>
+ #else
+ <td><input name="entryfield" id="${dataEntryId}" type="text" tabindex="${tabIndex}"#if( $greyedField || !$hasAccess ) disabled="disabled"#end></td>
+ #end
+ #end
+ </td>
+ #set( $tabIndex = $tabIndex + 1 )
+ #end
+ </tr>
+ #end
+ </table>
+ </div>
+ </td>
+ </tr>
+</table>
+#end
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadFormAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadFormAction.java 2013-06-24 05:33:13 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadFormAction.java 2013-06-24 07:16:54 +0000
@@ -29,7 +29,13 @@
import com.opensymphony.xwork2.Action;
import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
-import org.hisp.dhis.dataelement.*;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategory;
+import org.hisp.dhis.dataelement.DataElementCategoryCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryOption;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementOperand;
+import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.dataentryform.DataEntryForm;
import org.hisp.dhis.dataentryform.DataEntryFormService;
import org.hisp.dhis.dataset.DataSet;
@@ -40,7 +46,12 @@
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
/**
* @author Torgeir Lorange Ostby
@@ -299,8 +310,8 @@
// ---------------------------------------------------------------------
// For multi-org unit we only support custom forms
// ---------------------------------------------------------------------
-
- if ( multiOrganisationUnit != null && multiOrganisationUnit != 0 )
+
+ if ( multiOrganisationUnit != null && multiOrganisationUnit != 0 )
{
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( multiOrganisationUnit );
List<OrganisationUnit> organisationUnitChildren = new ArrayList<OrganisationUnit>();
@@ -323,7 +334,7 @@
organisationUnits.addAll( organisationUnitChildren );
getSectionForm( dataElements, dataSet );
-
+
displayMode = DataSet.TYPE_SECTION_MULTIORG;
}
if ( displayMode.equals( DataSet.TYPE_SECTION ) )
@@ -381,7 +392,7 @@
Collections.sort( dataElementsNotInForm, IdentifiableObjectNameComparator.INSTANCE );
}
- List<DataElement> des = new ArrayList<DataElement>();
+ List<DataElement> des;
for ( DataElementCategoryCombo categoryCombo : orderedCategoryCombos )
{
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/defaultForm.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/defaultForm.vm 2013-06-24 05:33:13 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/defaultForm.vm 2013-06-24 07:16:54 +0000
@@ -1,67 +1,8 @@
+
#set( $tabIndex = 1 )
#set( $hasAccess = $auth.hasAccess( "dhis-web-dataentry", "saveValue" ) )
#foreach( $categoryCombo in $orderedCategoryCombos )
-<table class="formSection" cellspacing="0">
- #set( $colCount = $numberOfTotalColumns.get( $categoryCombo.id ) )
- #set( $categories = $orderedCategories.get( $categoryCombo.id ) )
- #set( $optionsMap = $orderedOptionsMap.get( $categoryCombo.id ) )
- #set( $colRepeat = $catColRepeat.get( $categoryCombo.id ) )
-
- #foreach( $category in $categories )
- #set( $categoryOptions = $optionsMap.get( $category.id ) )
- #set( $colCount = $colCount / $categoryOptions.size() )
- <tr colspan="$colCount">
- <td></td>
- #set( $cols = $colRepeat.get( $category.id ) )
- #foreach( $col in $cols )
- #foreach( $categoryOption in $categoryOptions )
- <th colspan="$colCount"><span align="center">#if( $categoryOption.isDefault() )${i18n.getString( "value" )}#else ${encoder.htmlEncode( $categoryOption.displayName )}#end</span></th>
- #end
- #end
- </tr>
- #end
-
- #set( $count = 0 )
- #set( $dataElements = $orderedDataElements.get( $categoryCombo ) )
- #set( $optionCombos = $orderedCategoryOptionCombos.get( $categoryCombo.id ) )
- #set( $mark = 0 )
- #foreach( $optionCombo in $optionCombos )<span id="${optionCombo.uid}-optioncombo" class="hidden">${encoder.htmlEncode( $optionCombo.displayName )}</span>
- #end
- #foreach( $dataElement in $dataElements )
- #if( $mark == 1 )
- #set( $mark = 0 )
- #else
- #set( $mark = 1 )
- #end
- #set( $count = $count + 1 )
- <tr>
- <td id="${dataElement.uid}-cell" #if( $mark == 1 )class="alt"#else class="reg"#end><span id="${dataElement.uid}-dataelement">${encoder.htmlEncode( $dataElement.getFormNameFallback() )}</span></td>
- #foreach( $optionCombo in $optionCombos )
- #set( $dataEntryId = "${dataElement.uid}-${optionCombo.uid}-val" )
- #set( $commentId = "${dataElement.uid}-${optionCombo.uid}-comment" )
- #if( $dataElement.type == "bool" )
- <td><select name="entryselect" id="${dataEntryId}"#if( !$hasAccess ) disabled="disabled"#end tabindex="${tabIndex}">
- <option value="">[$i18n.getString( "no_value" )]</option>
- <option value="true">$i18n.getString( "yes" )</option>
- <option value="false">$i18n.getString( "no" )</option>
- </select>
- <img name="commentlink" id="${commentId}"></td>
- #elseif( $dataElement.type == 'trueOnly' )
- <td><input name="entrytrueonly" id="${dataEntryId}" maxlength="255" type="checkbox"#if( !$hasAccess ) disabled="disabled"#end tabindex="$tabIndex"></td>
- #else
- #if( $dataElement.optionSet )
- <td><input name="entryoptionset" id="${dataEntryId}" maxlength="255" type="text"#if( !$hasAccess ) disabled="disabled"#end tabindex="$tabIndex"></td>
- #else
- <td><input name="entryfield" id="${dataEntryId}" maxlength="255" type="text"#if( !$hasAccess ) disabled="disabled"#end tabindex="$tabIndex"></td>
- #end
- #end
- </td>
- #set( $tabIndex = $tabIndex + 1 )
- #end
- </tr>
- #end
-</table>
-<br>
-<br>
+ #set( $dataElements = $orderedDataElements.get( $categoryCombo ) )
+ #renderSection( $categoryCombo.id $dataElements )
#end
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm 2013-06-24 06:01:18 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/sectionForm.vm 2013-06-24 07:16:54 +0000
@@ -1,90 +1,8 @@
+
#set( $tabIndex = 1 )
#set( $hasAccess = $auth.hasAccess( "dhis-web-dataentry", "saveValue" ) )
#foreach( $section in $sections )
#set( $categoryComboId = $sectionCombos.get( $section.id ) )
- #set( $title = $section.displayName )
-
- #renderSection($categoryComboId, {"title": $title })
-#end
-
-#macro( renderSection $categoryComboId $args )
-#if( $!args.title )
-<table class="formSection" style="margin-bottom: 20px;">
-<tr>
- <td>
- <div class="cent"><h3>$encoder.htmlEncode( $args.title )</h3></div>
- </td>
-</tr>
-#else
-<table class="formSection">
-#end
-<tr>
- <td>
- <div>
- <table cellspacing="0">
- #set( $colCount = $numberOfTotalColumns.get( $categoryComboId ) )
- #set( $categories = $orderedCategories.get( $categoryComboId ) )
- #set( $optionsMap = $orderedOptionsMap.get( $categoryComboId ) )
- #set( $colRepeat = $catColRepeat.get( $categoryComboId ) )
- #set( $hasFilterInSection = false )
-
- #foreach( $category in $categories )
- #set( $categoryOptions = $optionsMap.get( $category.id ) )
- #set( $colCount = $colCount / $categoryOptions.size() )
- <tr colspan="$colCount">
- <td>#if( $hasFilterInSection == false )<input type="text" class="sectionFilter" placeholder="$encoder.jsEscape( $i18n.getString( "filter_in_section" ) , "'")" onkeyup="filterInSection($(this));">#set( $hasFilterInSection = true )#end</td>
- #set( $cols = $colRepeat.get( $category.id ) )
- #foreach( $col in $cols )
- #foreach( $categoryOption in $categoryOptions )
- <th colspan="$colCount"><span align="center">#if( $categoryOption.isDefault() )${i18n.getString( "value" )}#else ${encoder.htmlEncode( $categoryOption.displayName )}#end</span></th>
- #end
- #end
- </tr>
- #end
-
- #set( $count = 0 )
- #set( $mark = 0 )
- #set( $optionCombos = $orderedCategoryOptionCombos.get( $categoryComboId ) )
- #foreach( $optionCombo in $optionCombos )<span id="${optionCombo.uid}-optioncombo" class="hidden">${encoder.htmlEncode( $optionCombo.displayName )}</span>
- #end
- #foreach( $dataElement in $section.dataElements )
- #if( $mark == 1 )
- #set( $mark = 0 )
- #else
- #set( $mark = 1 )
- #end
- #set( $count = $count + 1 )
- <tr>
- <td id="${dataElement.uid}-cell" #if( $mark == 1 )class="alt"#else class="reg"#end><span id="${dataElement.uid}-dataelement">${encoder.htmlEncode( $dataElement.getFormNameFallback() )}</span></td>
- #foreach( $optionCombo in $optionCombos )
- #set( $dataEntryId = "${dataElement.uid}-${optionCombo.uid}-val" )
- #set( $commentId = "${dataElement.uid}-${optionCombo.uid}-comment" )
- #set( $greyedField = false )
- #set( $greyedField = $greyedFields.get( "${dataElement.uid}:${optionCombo.uid}" ) )
- #if( $dataElement.type == "bool" )
- <td><select name="entryselect" id="$dataEntryId" tabindex="$tabIndex"#if( $greyedField || !$hasAccess ) disabled="disabled"#end>
- <option value="">[$i18n.getString( "no_value" )]</option>
- <option value="true">$i18n.getString( "yes" )</option>
- <option value="false">$i18n.getString( "no" )</option>
- </select><img name="commentlink" id="${commentId}"></td>
- #elseif( $dataElement.type == "trueOnly" )
- <td><input name="entrytrueonly" id="${dataEntryId}" type="checkbox" tabindex="${tabIndex}"#if( $greyedField || !$hasAccess ) disabled="disabled"#end></td>
- #else
- #if( $dataElement.optionSet )
- <td><input name="entryoptionset" id="${dataEntryId}" type="text" tabindex="${tabIndex}"#if( $greyedField || !$hasAccess ) disabled="disabled"#end></td>
- #else
- <td><input name="entryfield" id="${dataEntryId}" type="text" tabindex="${tabIndex}"#if( $greyedField || !$hasAccess ) disabled="disabled"#end></td>
- #end
- #end
- </td>
- #set( $tabIndex = $tabIndex + 1 )
- #end
- </tr>
- #end
- </table>
- </div>
- </td>
- </tr>
-</table>
+ #renderSection( $categoryComboId, $section.dataElements, {"title": $section.displayName } )
#end