dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #22124
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10617: check and use offline optionsets if they exist
------------------------------------------------------------
revno: 10617
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-04-18 17:56:03 +0700
message:
check and use offline optionsets if they exist
modified:
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.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/entry.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js 2013-04-18 08:47:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js 2013-04-18 10:56:03 +0000
@@ -295,6 +295,12 @@
var key = dataElementUid;
DAO.offlineData.fetch( dataValueKey, function ( store, arr ) {
+ if ( arr.length == 0 ) {
+ markValue( ERROR );
+ window.alert( i18n_saving_value_failed_error_code + '\n\n' + errorCode );
+ return;
+ }
+
var obj = arr[0];
if ( !obj.values ) {
@@ -815,20 +821,56 @@
});
}
+var MAX_OPTIONS_DISPLAYED = 30;
+
function searchOptionSet( uid, query, success ) {
- $.ajax({
+ if(window.DAO !== undefined && window.DAO.optionSets !== undefined ) {
+ DAO.optionSets.fetch(uid, function(store, arr) {
+ if ( arr.length > 0 ) {
+ var obj = arr[0];
+ var options = [];
+
+ if(query == null || query == "") {
+ options = obj.optionSet.options.slice(0, MAX_OPTIONS_DISPLAYED-1);
+ } else {
+ query = query.toLowerCase();
+
+ _.each(obj.optionSet.options, function(item, idx) {
+ if ( item.toLowerCase().indexOf( query ) != -1 ) {
+ options.push(item);
+ }
+ });
+ }
+
+ success( $.map( options, function ( item ) {
+ return {
+ label: item,
+ id: item
+ };
+ } ) );
+ } else {
+ getOptions( uid, query, success );
+ }
+ } );
+ } else {
+ getOptions( uid, query, success );
+ }
+}
+
+function getOptions( uid, query, success ) {
+ $.ajax( {
url: "getOptions.action?id=" + uid + "&query=" + query,
dataType: "json",
cache: true,
- success: function(data) {
- success($.map(data.options, function(item) {
+ success: function ( data ) {
+ success( $.map( data.options, function ( item ) {
return {
label: item.o,
id: item.o
};
- }));
+ } ) );
}
- });
+ } );
}
function autocompletedField( idField )