dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #26990
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13378: Data entry, js functionality for displaying attribute select fields
------------------------------------------------------------
revno: 13378
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2013-12-22 00:00:20 +0100
message:
Data entry, js functionality for displaying attribute select fields
modified:
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseMetaData.vm
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/select.vm
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/style/dhis-web-dataentry.css
--
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/javascript/form.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2013-12-21 21:21:51 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2013-12-21 23:00:20 +0000
@@ -52,6 +52,9 @@
// Currently selected data set identifier
dhis2.de.currentDataSetId = null;
+// Array with category objects, null if default category combo / no categories
+dhis2.de.currentCategories = null;
+
// Current offset, next or previous corresponding to increasing or decreasing
// value with one
dhis2.de.currentPeriodOffset = 0;
@@ -935,6 +938,9 @@
var dataSetId = $( '#selectedDataSetId' ).val();
var periodId = $( '#selectedPeriodId' ).val();
+
+ dhis2.de.currentCategories = dhis2.de.getCategories( dataSetId );
+
var periodType = dhis2.de.dataSets[dataSetId].periodType;
var allowFuturePeriods = dhis2.de.dataSets[dataSetId].allowFuturePeriods;
var periods = dhis2.de.periodTypeFactory.get( periodType ).generatePeriods( dhis2.de.currentPeriodOffset );
@@ -949,6 +955,9 @@
{
clearListById( 'selectedPeriodId' );
clearSectionFilters();
+
+ var attributeMarkup = dhis2.de.getAttributesMarkup();
+ $( '#attributeComboDiv' ).html( attributeMarkup );
if ( periods.length > 0 )
{
@@ -1057,6 +1066,124 @@
} );
}
+//------------------------------------------------------------------------------
+// Attributes / Categories
+//------------------------------------------------------------------------------
+
+/**
+* Returns an array of category objects for the given data set identifier. Categories
+* are looked up using the category combo of the data set. Null is returned if
+* the given data set has the default category combo.
+*/
+dhis2.de.getCategories = function( dataSetId )
+{
+ var dataSet = dhis2.de.dataSets[dataSetId];
+
+ if ( !dataSet || !dataSet.categoryCombo || dhis2.de.defaultCategoryCombo === dataSet.categoryCombo ) {
+ return null;
+ }
+
+ var categoryCombo = dhis2.de.categoryCombos[dataSet.categoryCombo];
+
+ var categories = [];
+
+ $.safeEach( categoryCombo.categories, function( idx, cat ) {
+ var category = dhis2.de.categories[cat];
+ categories.push( category );
+ } );
+
+ return categories;
+};
+
+/**
+ * Indicates whether all present categories have been selected. True is returned
+ * if no categories are present. False is returned if less selections have been
+ * made thant here are categories present.
+ */
+dhis2.de.categoriesSelected = function()
+{
+ if ( !dhis2.de.currentCategories || dhis2.de.currentCategories.length == 0 ) {
+ return true; // No categories present which can be selected
+ }
+
+ var options = dhis2.de.getCurrentCategoryOptions();
+
+ if ( !options || options.length < dhis2.de.currentCategories.length ) {
+ return false; // Less selected options than categories present
+ }
+
+ return true;
+};
+
+/**
+* Returns the identifier of the current attribute category combo. Based on the
+* dhis2.de.currentDataSetId global variable. Returns null if there is no
+* current data set or if current data set has the default category combo.
+*/
+dhis2.de.getCurrentCategoryCombo = function()
+{
+ var dataSet = dhis2.de.dataSets[dhis2.de.currentDataSetId];
+
+ if ( !dataSet || !dataSet.categoryCombo || dhis2.de.defaultCategoryCombo === dataSet.categoryCombo ) {
+ return null;
+ }
+
+ return dataSet.categoryCombo.id;
+};
+
+/**
+* Returns an array of the currently selected attribute category options. Based
+* on the dhis2.de.currentCategories global variable. Returns null if there are
+* no current categories.
+*/
+dhis2.de.getCurrentCategoryOptions = function()
+{
+ if ( !dhis2.de.currentCategories || dhis2.de.currentCategories.length == 0 ) {
+ return null;
+ }
+
+ var options = [];
+
+ $.safeEach( dhis2.de.currentCategories, function( idx, category ) {
+ var option = $( '#category-' + category.id ).val();
+
+ if ( option && option != -1 ) {
+ options.push( option );
+ }
+ } );
+
+ return options;
+};
+
+/**
+* Returns markup for drop down boxes to be put in the selection box for the
+* given categories. The empty string is returned if no categories are given.
+*/
+dhis2.de.getAttributesMarkup = function()
+{
+ var html = '';
+
+ if ( !dhis2.de.currentCategories || dhis2.de.currentCategories.length == 0 ) {
+ return html;
+ }
+
+ $.safeEach( dhis2.de.currentCategories, function( idx, category ) {
+ html += '<div class="selectionBoxRow">';
+ html += '<div class="selectionLabel">' + category.name + '</div> ';
+ html += '<select id="category-' + category.id + '" class="selectionBoxSelect">';
+ html += '<option value="-1">[ Please select ]</option>';
+
+ $.safeEach( category.options, function( idx, option ) {
+ html += '<option value="' + option.id + '">' + option.name + '</option>';
+ } );
+
+ html += '</select>';
+ html += '</div>';
+ } );
+
+ return html;
+};
+
// -----------------------------------------------------------------------------
// Form
// -----------------------------------------------------------------------------
@@ -1366,59 +1493,6 @@
$( 'body' ).off( EVENT_FORM_LOADED ).on( EVENT_FORM_LOADED, fn );
}
-/**
- * Returns an array of category objects for the given data set identifier. Categories
- * are looked up using the category combo of the data set. Null is returned if
- * the given data set has the default category combo.
- */
-dhis2.de.getCategories = function( dataSetId )
-{
- var dataSet = dhis2.de.dataSets[dataSetId];
-
- if ( !dataSet || dhis2.de.defaultCategoryCombo === dataSet.categoryCombo ) {
- return null;
- }
-
- var categoryCombo = dhis2.de.categoryCombos[dataSet.categoryCombo];
-
- var categories = [];
-
- $.safeEach( combo.categories, function( idx, cat ) {
- var category = dhis2.de.categories[cat];
- categories.push( category );
- } );
-
- return categories;
-}
-
-/**
- * Returns markup for drop down boxes to be put in the selection box for the
- * given categories. If no categories are given the empty string is returned.
- */
-dhis2.de.getAttributesMarkup = function( categories )
-{
- var html = '';
-
- if ( !categories || categories.length == 0 ) {
- return html;
- }
-
- $.safeEach( categories, function( idx, category ) {
- html += '<div class="selectionBoxRow">';
- html += '<div class="selectionLabel">' + category.name + '</div>';
- html += '<select id="category-' + category.id + '" class="selectionBoxSelect">';
-
- $.safeEach( category.options, function( idx, option ) {
- html += '<option value="' + option.id + '">' + option.name + '</option>';
- } );
-
- html += '</select>';
- html += '</div>';
- } );
-
- return html;
-}
-
// -----------------------------------------------------------------------------
// Data completeness
// -----------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseMetaData.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseMetaData.vm 2013-12-21 21:21:51 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseMetaData.vm 2013-12-21 23:00:20 +0000
@@ -59,8 +59,7 @@
#set( $size = $organisationUnitAssociationSetMap.size() )
#foreach( $orgUnit in $organisationUnitAssociationSetMap.keySet() )
"${orgUnit}":"$organisationUnitAssociationSetMap.get( ${orgUnit} )"#if( $velocityCount < $size ),#end
-#end }
-},
+#end },
"defaultCategoryCombo":"${defaultCategoryCombo.uid}",
@@ -85,5 +84,5 @@
{"id":"${option.uid}","name":"$encoder.jsonEncode( ${option.displayName} )"}#if( $velocityCount < $size2 ),#end
#end
] }#if( $velocityCount < $size1 ),#end
-#end
+#end }
} }
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/select.vm'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/select.vm 2013-12-21 20:44:52 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/select.vm 2013-12-21 23:00:20 +0000
@@ -69,7 +69,7 @@
<input type="button" value="$i18n.getString( 'print_blank_form' )" onclick="printBlankForm()" style="width:120px"/><br> </br>
</div>
-<div id="selectionBox" class="inputCriteria" style="width:534px">
+<div id="selectionBox" class="inputCriteria" style="width:564px">
<div class="selectionBoxRow">
<div class="selectionLabel">$i18n.getString( "organisation_unit" )</div>
<input type="text" id="selectedOrganisationUnit" readonly="readonly" value="[ $i18n.getString( 'select_from_tree' ) ]" style="width: 394px; padding: 3px;">
@@ -79,14 +79,13 @@
<select id="selectedDataSetId" name="selectedDataSetId" class="selectionBoxSelect" onchange="dataSetSelected()" disabled="disabled"></select>
<span id="loaderSpan" style="display:none"><img src='../images/ajax-loader-bar.gif'></span>
</div>
+<div id="attributeComboDiv"></div>
<div class="selectionBoxRow">
<div class="selectionLabel">$i18n.getString( "period" )</div>
<select id="selectedPeriodId" name="selectedPeriodId" style="width:225px" onchange="periodSelected()" disabled="disabled"></select>
<input type="button" id="prevButton" style="width:85px" value="$i18n.getString( 'prev_year' )" title="$i18n.getString('earlier_periods')" onclick="previousPeriodsSelected()" disabled="disabled">
<input type="button" id="nextButton" style="width:85px" value="$i18n.getString( 'next_year' )" title="$i18n.getString('later_periods')" onclick="nextPeriodsSelected()" disabled="disabled">
</div>
-<div id="attributeComboDiv">
-</div>
<div id="filterDataSetSectionDiv" class="selectionBoxRow" style="display:none">
<div class="selectionLabel">$i18n.getString( "filter_on_section" )</div>
<select id="filterDataSetSection" name="filterDataSetSection" class="selectionBoxSelect" onchange="filterOnSection()"></select>
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/style/dhis-web-dataentry.css'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/style/dhis-web-dataentry.css 2013-12-21 20:44:52 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/style/dhis-web-dataentry.css 2013-12-21 23:00:20 +0000
@@ -84,7 +84,7 @@
.selectionLabel
{
display: inline-block;
- width: 100px;
+ width: 130px;
}
.formSection td