dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #18984
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8105: WIP dynamic fields
------------------------------------------------------------
revno: 8105
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-09-16 17:21:25 +0200
message:
WIP dynamic fields
modified:
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js
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/history.js
--
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/entry.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js 2012-08-02 13:16:16 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js 2012-09-16 15:21:25 +0000
@@ -113,16 +113,26 @@
return expression;
}
-/**
- * /* Used by default and section forms.
- */
-function saveVal( dataElementId, optionComboId )
+function saveDynamicVal( code, optionComboId, fieldId )
+{
+ var dataElementId = $( '#' + code + '-dynselect option:selected' ).val();
+
+ if ( isDefined( dataElementId ) && dataElementId != '' )
+ {
+ saveVal( dataElementId, optionComboId, fieldId );
+ return;
+ }
+
+ log( 'There is no select list in form or no option selected for code: ' + code );
+}
+
+function saveVal( dataElementId, optionComboId, fieldId )
{
dataElementId = parseInt( dataElementId );
optionComboId = parseInt( optionComboId );
+ fieldId = '#' + fieldId;
var dataElementName = getDataElementName( dataElementId );
- var fieldId = '#' + dataElementId + '-' + optionComboId + '-val';
var value = $( fieldId ).val();
var type = getDataElementType( dataElementId );
@@ -182,7 +192,7 @@
if ( valueNo < min )
{
var valueSaver = new ValueSaver( dataElementId, optionComboId, currentOrganisationUnitId, periodId,
- value, COLOR_ORANGE );
+ value, fieldId, COLOR_ORANGE );
valueSaver.save();
window.alert( i18n_value_of_data_element_less + ': ' + min + '\n\n' + dataElementName );
@@ -192,7 +202,7 @@
if ( valueNo > max )
{
var valueSaver = new ValueSaver( dataElementId, optionComboId, currentOrganisationUnitId, periodId,
- value, COLOR_ORANGE );
+ value, fieldId, COLOR_ORANGE );
valueSaver.save();
window.alert( i18n_value_of_data_element_greater + ': ' + max + '\n\n' + dataElementName );
@@ -203,16 +213,19 @@
}
var valueSaver = new ValueSaver( dataElementId, optionComboId,
- currentOrganisationUnitId, periodId, value, COLOR_GREEN );
+ currentOrganisationUnitId, periodId, value, fieldId, COLOR_GREEN );
valueSaver.save();
updateIndicators(); // Update indicators for custom form
updateDataElementTotals(); // Update data element totals for custom forms
}
-function saveBoolean( dataElementId, optionComboId )
+function saveBoolean( dataElementId, optionComboId, fieldId )
{
- var fieldId = '#' + dataElementId + '-' + optionComboId + '-val';
+ dataElementId = parseInt( dataElementId );
+ optionComboId = parseInt( optionComboId );
+ fieldId = '#' + fieldId;
+
var value = $( fieldId + ' option:selected' ).val();
$( fieldId ).css( 'background-color', COLOR_YELLOW );
@@ -220,7 +233,7 @@
var periodId = $( '#selectedPeriodId' ).val();
var valueSaver = new ValueSaver( dataElementId, optionComboId,
- currentOrganisationUnitId, periodId, value, COLOR_GREEN );
+ currentOrganisationUnitId, periodId, value, fieldId, COLOR_GREEN );
valueSaver.save();
}
@@ -241,18 +254,16 @@
// Saver objects
// -----------------------------------------------------------------------------
-function ValueSaver( dataElementId_, optionComboId_, organisationUnitId_, periodId_, value_, resultColor_ )
+function ValueSaver( dataElementId, optionComboId, organisationUnitId, periodId, value, fieldId, resultColor )
{
var dataValue = {
- 'dataElementId' : dataElementId_,
- 'optionComboId' : optionComboId_,
- 'organisationUnitId' : organisationUnitId_,
- 'periodId' : periodId_,
- 'value' : value_,
+ 'dataElementId' : dataElementId,
+ 'optionComboId' : optionComboId,
+ 'organisationUnitId' : organisationUnitId,
+ 'periodId' : periodId,
+ 'value' : value,
};
- var resultColor = resultColor_;
-
this.save = function()
{
storageManager.saveDataValue( dataValue );
@@ -273,16 +284,16 @@
if ( code == 0 ) // Value successfully saved on server
{
storageManager.clearDataValueJSON( dataValue );
- markValue( resultColor );
+ markValue( fieldId, resultColor );
}
- else if(code == 2)
+ else if ( code == 2 )
{
- markValue( COLOR_RED );
+ markValue( fieldId, COLOR_RED );
window.alert( i18n_saving_value_failed_dataset_is_locked );
}
else // Server error during save
{
- markValue( COLOR_RED );
+ markValue( fieldId, COLOR_RED );
window.alert( i18n_saving_value_failed_status_code + '\n\n' + code );
}
}
@@ -290,11 +301,11 @@
function handleError( jqXHR, textStatus, errorThrown )
{
setHeaderMessage( i18n_offline_notification );
- markValue( resultColor );
+ markValue( fieldId, resultColor );
}
- function markValue( color )
+ function markValue( fieldId, color )
{
- $( '#' + dataValue.dataElementId + '-' + dataValue.optionComboId + '-val' ).css( 'background-color', color );
+ $( fieldId ).css( 'background-color', color );
}
}
=== 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 2012-09-16 14:44:45 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2012-09-16 15:21:25 +0000
@@ -321,7 +321,7 @@
$( this ).change( function()
{
- saveVal( dataElementId, optionComboId );
+ saveVal( dataElementId, optionComboId, id );
} );
$( this ).dblclick( function()
@@ -362,7 +362,7 @@
$( this ).change( function()
{
- saveBoolean( dataElementId, optionComboId );
+ saveBoolean( dataElementId, optionComboId, id );
} );
$( this ).css( 'width', '100%' );
@@ -379,8 +379,7 @@
$( this ).change( function()
{
- var dataElementId = $( '#' + code + '-dynselect option:selected' ).val();
- saveVal( dataElementId, optionComboId );
+ saveDynamicVal( code, optionComboId, id );
} );
$( this ).keyup( function( event )
@@ -484,7 +483,7 @@
var $tbody = $this.parent().parent().parent();
var $trTarget = $tbody.find( 'tr:not([colspan])' );
- if( $this.val() == '' )
+ if ( $this.val() == '' )
{
$trTarget.show();
}
@@ -495,9 +494,9 @@
$trTargetChildren.each( function( idx, item )
{
var text1 = $this.val().toUpperCase();
- var text2 = $(item).find('span').html().toUpperCase();
+ var text2 = $( item ).find( 'span' ).html().toUpperCase();
- if( text2.indexOf( text1 ) >= 0 )
+ if ( text2.indexOf( text1 ) >= 0 )
{
$( item ).parent().show();
}
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/history.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/history.js 2012-08-02 13:16:16 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/history.js 2012-09-16 15:21:25 +0000
@@ -7,7 +7,7 @@
var commentValue = $( '#commentTextArea' ).val();
var periodId = $( '#selectedPeriodId' ).val();
- if( commentValue.length > 360 )
+ if ( commentValue.length > 360 )
{
markComment( COLOR_YELLOW );
window.alert(i18n_value_too_long + " for comment field");