dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21937
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10499: using js module pattern to encapsulate possible offline ajax actions
------------------------------------------------------------
revno: 10499
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-04-08 17:13:58 +0700
message:
using js module pattern to encapsulate possible offline ajax actions
modified:
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.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-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js 2013-04-08 05:53:22 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js 2013-04-08 10:13:58 +0000
@@ -536,40 +536,7 @@
setInnerHTML( 'dataEntryFormDiv', '' );
showLoader();
- $( '#dataEntryFormDiv' ).load( "dataentryform.action",
- {
- programStageInstanceId: programStageInstanceId
- }, function () {
- jQuery( '#inputCriteriaDiv' ).remove();
- showById( 'programName' );
- showById( 'actionDiv' );
- var programName = jQuery( '#programId option:selected' ).text();
- var programStageId = jQuery( '#programId option:selected' ).attr( 'psid' );
- jQuery( '.stage-object-selected' ).attr( 'psid', programStageId );
- setInnerHTML( 'programName', programName );
- jQuery('#executionDate').css('width',430);
- jQuery('#executionDate').css('margin-right',30);
-
- if ( getFieldValue( 'completed' ) == 'true' ) {
- disable( "completeBtn" );
- enable( "uncompleteBtn" );
- }
- else {
- enable( "completeBtn" );
- disable( "uncompleteBtn" );
- }
- hideById( 'loaderDiv' );
- showById( 'dataEntryInfor' );
- showById( 'entryFormContainer' );
-
- jQuery( "#entryForm :input" ).each( function () {
- if ( ( jQuery( this ).attr( 'options' ) != null && jQuery( this ).attr( 'options' ) == 'true' )
- || ( jQuery( this ).attr( 'username' ) != null && jQuery( this ).attr( 'username' ) == 'true' ) ) {
- var input = jQuery( this );
- input.parent().width( input.width() + 200 );
- }
- } );
- } );
+ service.loadDataEntryForm( programStageInstanceId, getFieldValue( 'orgunitId' ) );
}
function backEventList() {
@@ -608,26 +575,7 @@
jQuery( "#executionDate" ).css( 'background-color', SAVING_COLOR );
- jQuery.postJSON( "saveExecutionDate.action",
- {
- programStageInstanceId: programStageInstanceId,
- programId: programId,
- executionDate: executionDate,
- organisationUnitId: orgunitId
- },
- function ( json ) {
- if ( json.response == 'success' ) {
- jQuery( "#executionDate" ).css( 'background-color', SUCCESS_COLOR );
- setFieldValue( 'programStageInstanceId', json.message );
- if ( programStageInstanceId != json.message ) {
- showUpdateEvent( json.message );
- }
- }
- else {
- jQuery( "#executionDate" ).css( 'background-color', ERROR_COLOR );
- showWarningMessage( json.message );
- }
- } );
+ service.saveExecutionDate( programId, programStageInstanceId, executionDate, orgunitId );
}
function completedAndAddNewEvent() {
@@ -696,3 +644,68 @@
jQuery( '#searchText' ).val( "" );
searchEvents( eval( getFieldValue( "listAll" ) ) );
}
+
+// execution date module
+var service = (function () {
+ return {
+ saveExecutionDate: function( programId, programStageInstanceId, executionDate, organisationUnitId ) {
+ jQuery.postJSON( "saveExecutionDate.action", {
+ programId: programId,
+ programStageInstanceId: programStageInstanceId,
+ executionDate: executionDate,
+ organisationUnitId: organisationUnitId
+ },
+ function ( json ) {
+ if ( json.response == 'success' ) {
+ jQuery( "#executionDate" ).css( 'background-color', SUCCESS_COLOR );
+ setFieldValue( 'programStageInstanceId', json.message );
+ if ( programStageInstanceId != json.message ) {
+ showUpdateEvent( json.message );
+ }
+ }
+ else {
+ jQuery( "#executionDate" ).css( 'background-color', ERROR_COLOR );
+ showWarningMessage( json.message );
+ }
+ } );
+ },
+
+ loadDataEntryForm: function( programStageInstanceId, organisationUnitId ) {
+ $( '#dataEntryFormDiv' ).load( "dataentryform.action", {
+ programStageInstanceId: programStageInstanceId,
+ organisationUnitId: organisationUnitId
+ }, function () {
+ jQuery( '#inputCriteriaDiv' ).remove();
+ showById( 'programName' );
+ showById( 'actionDiv' );
+ var programName = jQuery( '#programId option:selected' ).text();
+ var programStageId = jQuery( '#programId option:selected' ).attr( 'psid' );
+ jQuery( '.stage-object-selected' ).attr( 'psid', programStageId );
+ setInnerHTML( 'programName', programName );
+ jQuery('#executionDate').css('width',430);
+ jQuery('#executionDate').css('margin-right',30);
+
+ if ( getFieldValue( 'completed' ) == 'true' ) {
+ disable( "completeBtn" );
+ enable( "uncompleteBtn" );
+ }
+ else {
+ enable( "completeBtn" );
+ disable( "uncompleteBtn" );
+ }
+ hideById( 'loaderDiv' );
+ showById( 'dataEntryInfor' );
+ showById( 'entryFormContainer' );
+
+ jQuery( "#entryForm :input" ).each( function () {
+ if ( ( jQuery( this ).attr( 'options' ) != null && jQuery( this ).attr( 'options' ) == 'true' )
+ || ( jQuery( this ).attr( 'username' ) != null && jQuery( this ).attr( 'username' ) == 'true' ) ) {
+ var input = jQuery( this );
+ input.parent().width( input.width() + 200 );
+ }
+ } );
+ } );
+
+ }
+ }
+})();