dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21025
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9849: removed need for anonymous report to get program association for every ou click. also disabled id...
------------------------------------------------------------
revno: 9849
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-02-20 15:03:09 +0700
message:
removed need for anonymous report to get program association for every ou click. also disabled idb adapter for now, still needs work.
modified:
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm
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/jsonProgramMetaData.vm
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.dom.js
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.idb.js
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.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/anonymousRegistration.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm 2013-02-18 03:46:13 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm 2013-02-20 08:03:09 +0000
@@ -1,10 +1,10 @@
<script type="text/javascript">
- jQuery(document).ready( function(){
- datePickerInRange( 'startDate' , 'endDate', false, false );
- disableCriteriaDiv();
- });
+ jQuery( document ).ready( function () {
+ datePickerInRange( 'startDate', 'endDate', false, false );
+ disableCriteriaDiv();
+ } );
</script>
-
+
<h3>$i18n.getString( "anonymous_events_management" ) #openHelp('single_event_without_registration')</h3>
<h4 id='programName' name='programName'></h4>
=== 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-01-29 14:45:08 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js 2013-02-20 08:03:09 +0000
@@ -1,3 +1,31 @@
+var DAO = DAO || {};
+
+$( document ).ready( function () {
+ $.ajaxSetup( {
+ type: 'POST',
+ cache: false
+ } );
+
+ jQuery.getJSON( "getProgramMetaData.action", {}, function ( data ) {
+ DAO.programs = new dhis2.storage.Store( {name: 'programs'}, function ( store ) {
+ var keys = _.keys( data.metaData.programs );
+ var objs = _.values( data.metaData.programs );
+
+ store.addAll( keys, objs, function ( store ) {
+ } );
+ } );
+
+ DAO.programAssociations = new dhis2.storage.Store( {name: 'programAssociations'}, function ( store ) {
+ var keys = _.keys( data.metaData.programAssociations );
+ var objs = _.values( data.metaData.programAssociations );
+
+ store.addAll( keys, objs, function ( store ) {
+ // wait until the stores have been populated until the listener is set
+ selection.setListenerFunction( organisationUnitSelected );
+ } );
+ } );
+ } );
+} );
function organisationUnitSelected( orgUnits, orgUnitNames )
{
@@ -12,30 +40,32 @@
setFieldValue("startDate", '');
setFieldValue("endDate", '');
jQuery('#advancedSearchTB [name=searchText]').val('');
- jQuery.getJSON( "anonymousPrograms.action",{},
- function( json )
- {
- jQuery('#searchingAttributeIdTD [id=searchObjectId] option').remove();
- jQuery('#advancedSearchTB [id=searchObjectId] option').remove();
- clearListById('displayInReports');
- clearListById('programId');
-
- jQuery( '#programId').append( '<option value="" psid="" reportDateDes="' + i18n_report_date + '">[' + i18n_please_select + ']</option>' );
- for ( i in json.programs ) {
- jQuery( '#programId').append( '<option value="' + json.programs[i].id +'" psid="' + json.programs[i].programStageId + '" reportDateDes="' + json.programs[i].reportDateDescription + '">' + json.programs[i].name + '</option>' );
- }
- disableCriteriaDiv();
- showById('selectDiv');
- });
-
- setFieldValue( 'orgunitId', orgUnits[0] );
+
+ setFieldValue( 'orgunitId', orgUnits[0] );
setFieldValue( 'orgunitName', orgUnitNames[0] );
hideById('listDiv');
hideById('dataEntryInfor');
+
+ DAO.programAssociations.fetch( orgUnits[0], function ( store, arr ) {
+ DAO.programs.fetch( arr, function ( store, arr ) {
+ jQuery( '#searchingAttributeIdTD [id=searchObjectId] option' ).remove();
+ jQuery( '#advancedSearchTB [id=searchObjectId] option' ).remove();
+ clearListById( 'displayInReports' );
+ clearListById( 'programId' );
+
+ jQuery( '#programId' ).append( '<option value="" psid="" reportDateDes="' + i18n_report_date + '">[' + i18n_please_select + ']</option>' );
+
+ for ( var i = 0; i < arr.length; i++ ) {
+ jQuery( '#programId' ).append( '<option value="' + arr[i].key + '" psid="' + arr[i].programStages[0].id + '" reportDateDes="' +
+ arr[i].programStages[0].reportDateDescription + '">' + arr[i].name + '</option>' );
+ }
+
+ disableCriteriaDiv();
+ showById( 'selectDiv' );
+ } );
+ } );
}
-selection.setListenerFunction( organisationUnitSelected );
-
function disableCriteriaDiv()
{
disable('listBtn');
@@ -68,7 +98,7 @@
setFieldValue('programStageId', programStageId );
setInnerHTML('reportDateDescriptionField', jQuery('#programId option:selected').attr('reportDateDes'));
setInnerHTML('reportDateDescriptionField2', jQuery('#programId option:selected').attr('reportDateDes'));
-
+
if( programStageId == '')
{
removeAllAttributeOption();
@@ -79,19 +109,19 @@
setFieldValue('searchText');
return;
}
-
+
jQuery.getJSON( "getProgramStageDataElementList.action",
{
programStageId: getFieldValue('programStageId')
- },
- function( json )
- {
+ },
+ function( json )
+ {
jQuery('#advancedSearchTB [name=searchText]').val('');
jQuery('.stage-object-selected').attr('psid', jQuery('#programId option:selected').attr("psid"));
-
+
clearListById('searchObjectId');
clearListById('displayInReports');
-
+
jQuery( '[name=searchObjectId]').append( '<option value="" >[' + i18n_please_select + ']</option>' );
for ( i in json.programStageDataElements ) {
jQuery( '[name=searchObjectId]').append( '<option value="' + json.programStageDataElements[i].id + '" type="' + json.programStageDataElements[i].type +'">' + json.programStageDataElements[i].name + '</option>' );
@@ -99,7 +129,7 @@
jQuery( '#displayInReports').append( '<option value="' + json.programStageDataElements[i].id + '"></option>');
}
}
-
+
enableCriteriaDiv();
validateSearchEvents( true );
});
@@ -110,7 +140,7 @@
var container = jQuery(this_).parent().parent().attr('id');
var element = jQuery('#' + container + ' [id=searchText]');
var valueType = jQuery('#' + container+ ' [id=searchObjectId] option:selected').attr('type');
-
+
if( valueType == 'date' ){
element.replaceWith( getDateField( container ) );
datePickerValid( 'searchText_' + container );
@@ -120,7 +150,7 @@
{
$( '#searchText_' + container ).datepicker("destroy");
$('#' + container + ' [id=dateOperator]').replaceWith("");
-
+
if( valueType == 'bool' ){
element.replaceWith( getTrueFalseBox() );
}
@@ -165,18 +195,18 @@
}
})
.addClass( "ui-widget" );
-
+
input.data( "autocomplete" )._renderItem = function( ul, item ) {
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a>" + item.label + "</a>" )
.appendTo( ul );
};
-
+
var wrapper = this.wrapper = $( "<span style='width:200px'>" )
.addClass( "ui-combobox" )
.insertAfter( input );
-
+
var button = $( "<a style='width:20px; margin-bottom:-5px;height:20px;'>" )
.attr( "tabIndex", -1 )
.attr( "title", i18n_show_all_items )
@@ -204,7 +234,7 @@
var input = jQuery( "#" + idField );
input.parent().width( input.width() + 200 );
var dataElementId = input.attr('id').split('-')[1];
-
+
input.autocomplete({
delay: 0,
minLength: 0,
@@ -226,13 +256,13 @@
minLength: 0,
select: function( event, ui ) {
var fieldValue = ui.item.value;
-
+
if ( !dhis2.trigger.invoke( "caseentry-value-selected", [dataElementId, fieldValue] ) ) {
input.val( "" );
return false;
}
-
- input.val( fieldValue );
+
+ input.val( fieldValue );
if ( !unSave ) {
saveVal( dataElementId );
}
@@ -253,18 +283,18 @@
}
})
.addClass( "ui-widget" );
-
+
input.data( "autocomplete" )._renderItem = function( ul, item ) {
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a>" + item.label + "</a>" )
.appendTo( ul );
};
-
+
var wrapper = this.wrapper = $( "<span style='width:200px'>" )
.addClass( "ui-combobox" )
.insertAfter( input );
-
+
var button = $( "<a style='width:20px; margin-bottom:-5px;height:20px;'>" )
.attr( "tabIndex", -1 )
.attr( "title", i18n_show_all_items )
@@ -298,10 +328,10 @@
}
function validateSearchEvents( listAll )
-{
+{
listAll = eval(listAll);
setFieldValue('listAll', listAll );
-
+
var flag = true;
if( !listAll )
{
@@ -309,7 +339,7 @@
showWarningMessage( i18n_specify_a_date );
flag = false;
}
-
+
if(flag && !listAll && jQuery('#filterBtn').attr("disabled")=="disabled" )
{
jQuery( '#advancedSearchTB tr' ).each( function( index, row ){
@@ -326,7 +356,7 @@
});
}
}
-
+
if(flag){
searchEvents( listAll );
}
@@ -336,14 +366,14 @@
{
hideById('dataEntryInfor');
hideById('listDiv');
-
+
var params = '';
jQuery( '#displayInReports option' ).each( function( i, item ){
var input = jQuery( item );
params += '&searchingValues=de_' + input.val() + '_false_';
});
-
- if(listAll){
+
+ if(listAll){
params += '&startDate=';
params += '&endDate=';
}
@@ -370,7 +400,7 @@
}
}
});
-
+
if( value !=''){
searchingValue += getValueFormula(value);
}
@@ -380,16 +410,16 @@
}
})
}
-
+
params += '&facilityLB=selected';
params += '&level=0';
params += '&orgunitIds=' + getFieldValue('orgunitId');
params += '&programStageId=' + jQuery('#programId option:selected').attr('psid');
params += '&orderByOrgunitAsc=false';
-
+
contentDiv = 'listDiv';
showLoader();
-
+
$.ajax({
type: "POST",
url: 'searchProgramStageInstances.action',
@@ -397,10 +427,10 @@
success: function( html ){
hideById('dataEntryInfor');
setInnerHTML( 'listDiv', html );
-
+
var searchInfor = (listAll) ? i18n_list_all_events : i18n_search_events_by_dataelements;
setInnerHTML( 'searchInforTD', searchInfor);
-
+
if(!listAll && jQuery('#filterBtn').attr("disabled")=="disabled")
{
showById('minimized-advanced-search');
@@ -412,7 +442,7 @@
hideById('advanced-search');
showById('filterBtn');
}
-
+
showById('listDiv');
hideById('loaderDiv');
}
@@ -428,7 +458,7 @@
// if key is [xyz] && [=xyz]
if( value.indexOf("'")==-1 ){
var flag = value.match(/[>|>=|<|<=|=|!=]+[ ]*/);
-
+
if( flag == null )
{
value = "='"+ value + "'";
@@ -444,19 +474,19 @@
else
{
var flag = value.match(/[>|>=|<|<=|=|!=]+[ ]*/);
-
+
if( flag == null )
{
value = "="+ value;
}
}
-
+
return value;
}
function removeEvent( programStageId )
-{
- removeItem( programStageId, '', i18n_comfirm_delete_event, 'removeCurrentEncounter.action' );
+{
+ removeItem( programStageId, '', i18n_comfirm_delete_event, 'removeCurrentEncounter.action' );
}
function showUpdateEvent( programStageInstanceId )
@@ -471,8 +501,8 @@
setInnerHTML('dataEntryFormDiv','');
showLoader();
- $( '#dataEntryFormDiv' ).load( "dataentryform.action",
- {
+ $( '#dataEntryFormDiv' ).load( "dataentryform.action",
+ {
programStageInstanceId: programStageInstanceId
},function()
{
@@ -494,9 +524,9 @@
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' ))
{
@@ -548,9 +578,9 @@
programStageInstanceId:programStageInstanceId,
programId:programId,
executionDate:executionDate
- },
- function( json )
- {
+ },
+ function( json )
+ {
if(json.response=='success')
{
jQuery("#executionDate").css('background-color', SUCCESS_COLOR);
@@ -573,17 +603,17 @@
}
function removeEmptyEvents()
-{
+{
var result = window.confirm( i18n_confirm_remove_empty_events );
-
+
if ( result )
{
jQuery.getJSON( "removeEmptyEvents.action",
{
programStageId: jQuery('#selectDiv [id=programId] option:selected').attr('psid')
- },
- function( json )
- {
+ },
+ function( json )
+ {
if(json.response=='success')
{
showSuccessMessage( i18n_remove_empty_events_success );
@@ -594,23 +624,23 @@
}
function removeCurrentEvent()
-{
+{
var result = window.confirm( i18n_comfirm_delete_event );
if ( result )
{
$.postJSON(
"removeCurrentEncounter.action",
{
- "id": getFieldValue('programStageInstanceId')
+ "id": getFieldValue('programStageInstanceId')
},
function( json )
- {
+ {
if ( json.response == "success" )
{
backEventList();
}
else if ( json.response == "error" )
- {
+ {
showWarningMessage( json.message );
}
});
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramMetaData.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramMetaData.vm 2013-02-19 04:01:58 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramMetaData.vm 2013-02-20 08:03:09 +0000
@@ -2,8 +2,18 @@
"programs": {
#set( $psize = $programs.size() )
#foreach( $program in $programs )
-"${program.id}":{"name":"$encoder.jsonEncode( ${program.displayName} )"}
-#if( $velocityCount < $psize ),#end
+"${program.id}":{
+"name":"$encoder.jsonEncode( ${program.displayName} )",
+"description":"$encoder.jsonEncode( ${program.description} )",
+"enrollmentDescription":"$encoder.jsonEncode( ${program.dateOfEnrollmentDescription} )",
+"incidentDescription":"$encoder.jsonEncode( ${program.dateOfIncidentDescription} )",
+"programStages":[
+#set( $pssize = $program.programStages.size() )
+#foreach( $ps in $program.programStages )
+{ "id": "${ps.id}", "name": "$encoder.jsonEncode( ${ps.displayName} )", "reportDateDescription": "$encoder.jsonEncode( ${ps.reportDateDescription} )" }#if( $velocityCount < $pssize ),#end
+#end
+]
+}#if( $velocityCount < $psize ),#end
#end },
"programAssociations": {
#set( $psize = $programAssociations.size() )
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.dom.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.dom.js 2013-02-17 04:06:34 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.dom.js 2013-02-20 08:03:09 +0000
@@ -65,6 +65,22 @@
return this;
},
+ addAll: function ( keys, objs, callback ) {
+ var that = this;
+
+ if ( keys.length == 0 || objs.length == 0 ) {
+ if ( callback ) callback.call( that, that );
+ return;
+ }
+
+ var key = keys.pop();
+ var obj = objs.pop();
+
+ this.add( key, obj, function ( store ) {
+ that.addAll( keys, objs, callback );
+ } );
+ },
+
remove: function ( key, callback ) {
var key = this.dbname + '.' + this.name + '.' + key;
this.indexer.remove( key );
@@ -94,23 +110,33 @@
},
fetch: function ( key, callback ) {
- var key = this.dbname + '.' + this.name + '.' + key;
- var obj = storage.getItem( key );
-
- if ( obj ) {
- obj = JSON.parse( obj );
- if ( callback ) callback.call( this, this, obj );
+ var arr = [];
+ var keys = $.isArray( key ) ? key : [ key ];
+
+ for ( var k = 0; k < keys.length; k++ ) {
+ var storage_key = this.dbname + '.' + this.name + '.' + keys[k];
+ var obj = storage.getItem( storage_key );
+
+ if ( obj ) {
+ obj = JSON.parse( obj );
+ obj.key = keys[k];
+ arr.push( obj );
+ }
}
+ if ( callback ) callback.call( this, this, arr );
+
return this;
},
fetchAll: function ( callback ) {
+ var arr = [];
var idx = this.indexer.all();
- var arr = [];
for ( var k = 0; k < idx.length; k++ ) {
- arr.push( JSON.parse( storage.getItem( idx[k] ) ) );
+ var obj = JSON.parse( storage.getItem( idx[k] ) );
+ obj.key = idx[k].replace( that.dbname + '.' + that.name + '.', '' );
+ arr.push( obj );
}
if ( callback ) callback.call( this, this, arr );
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.idb.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.idb.js 2013-02-17 04:06:34 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.idb.js 2013-02-20 08:03:09 +0000
@@ -22,9 +22,18 @@
return getTransaction( IDB.TransactionModes.READ_WRITE ).objectStore( IDB.options.name );
}
+ function defaultErrorHandler() {
+ console.log( "error:", e );
+ }
+
+ function defaultBlockingHandler() {
+ console.log( "blocked:", e );
+ }
+
return {
valid: function () {
- return !!(window.indexedDB && window.IDBTransaction && window.IDBKeyRange);
+ return false;
+ // return !!(window.indexedDB && window.IDBTransaction && window.IDBKeyRange);
},
init: function ( options, callback ) {
@@ -47,13 +56,8 @@
if ( callback ) callback.call( that, that );
};
- request.onerror = function ( e ) {
- console.log( "error:", e );
- };
-
- request.onblocked = function ( e ) {
- console.log( "blocked:", e );
- };
+ request.onerror = defaultErrorHandler;
+ request.onblocked = defaultBlockingHandler;
},
add: function ( key, obj, callback ) {
@@ -63,6 +67,25 @@
request.onsuccess = function ( e ) {
if ( callback ) callback.call( that, that, obj );
};
+
+ request.onerror = defaultErrorHandler;
+ request.onblocked = defaultBlockingHandler;
+ },
+
+ addAll: function ( keys, objs, callback ) {
+ var that = this;
+
+ if ( keys.length == 0 || objs.length == 0 ) {
+ if ( callback ) callback.call( that, that );
+ return;
+ }
+
+ var key = keys.pop();
+ var obj = objs.pop();
+
+ this.add( key, obj, function ( store ) {
+ that.addAll( keys, objs, callback );
+ } );
},
remove: function ( key, callback ) {
@@ -72,6 +95,9 @@
request.onsuccess = function ( e ) {
if ( callback ) callback.call( that, that );
};
+
+ request.onerror = defaultErrorHandler;
+ request.onblocked = defaultBlockingHandler;
},
exists: function ( key, callback ) {
@@ -81,6 +107,9 @@
request.onsuccess = function ( e ) {
if ( callback ) callback.call( that, that, e.target.result != null );
};
+
+ request.onerror = defaultErrorHandler;
+ request.onblocked = defaultBlockingHandler;
},
fetch: function ( key, callback ) {
@@ -90,6 +119,9 @@
request.onsuccess = function ( e ) {
if ( callback ) callback.call( that, that, e.target.result );
};
+
+ request.onerror = defaultErrorHandler;
+ request.onblocked = defaultBlockingHandler;
},
fetchAll: function ( callback ) {
@@ -107,6 +139,9 @@
if ( callback ) callback.call( that, that, records );
}
};
+
+ request.onerror = defaultErrorHandler;
+ request.onblocked = defaultBlockingHandler;
},
destroy: function ( callback ) {
@@ -117,6 +152,9 @@
request.onsuccess = function ( e ) {
if ( callback ) callback.call( that, that );
}
+
+ request.onerror = defaultErrorHandler;
+ request.onblocked = defaultBlockingHandler;
}
};
})() );
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.js 2013-02-17 04:06:34 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.js 2013-02-20 08:03:09 +0000
@@ -53,7 +53,7 @@
dhis2.storage.Store.adapter = function ( id, obj ) {
var Store = dhis2.storage.Store;
- var adapter_interface = "init add remove exists fetch fetchAll destroy".split( ' ' );
+ var adapter_interface = "init add addAll remove exists fetch fetchAll destroy".split( ' ' );
var missing_functions = [];
// verify adapter