=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetMetaDataAction.java' --- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetMetaDataAction.java 2012-02-16 19:58:55 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetMetaDataAction.java 2013-05-21 06:03:05 +0000 @@ -38,6 +38,7 @@ import org.hisp.dhis.organisationunit.OrganisationUnitDataSetAssociationSet; import org.hisp.dhis.organisationunit.OrganisationUnitService; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; @@ -106,6 +107,13 @@ return dataElements; } + private List dataElementsWithOptionSet = new ArrayList(); + + public List getDataElementsWithOptionSet() + { + return dataElementsWithOptionSet; + } + private Collection indicators; public Collection getIndicators() @@ -144,6 +152,14 @@ dataElements = dataElementService.getDataElementsWithDataSets(); + for ( DataElement dataElement : dataElements ) + { + if ( dataElement.getOptionSet() != null ) + { + dataElementsWithOptionSet.add( dataElement ); + } + } + indicators = indicatorService.getIndicatorsWithDataSets(); expressionService.explodeAndSubstituteExpressions( indicators, null ); === 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 2013-04-19 13:42:19 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js 2013-05-21 06:03:05 +0000 @@ -127,14 +127,14 @@ function saveVal( dataElementId, optionComboId, fieldId ) { var fieldIds = fieldId.split( "-" ); - + if ( fieldIds.length > 3 ) { currentOrganisationUnitId = fieldIds[0]; } fieldId = '#' + fieldId; - + var dataElementName = getDataElementName( dataElementId ); var value = $( fieldId ).val(); var type = getDataElementType( dataElementId ); === 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-05-18 04:54:10 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2013-05-21 06:03:05 +0000 @@ -11,6 +11,9 @@ // Array with associative arrays for each data set, populated in select.vm var dataSets = []; +// Maps input field to optionSet +var optionSets = {}; + // Associative array with identifier and array of assigned data sets var dataSetAssociationSets = []; @@ -70,6 +73,16 @@ var EVENT_FORM_LOADED = "dhis-web-dataentry-form-loaded"; +var MAX_DROPDOWN_DISPLAYED = 30; + +var DAO = DAO || {}; + +DAO.store = new dhis2.storage.Store( { + name: 'dhis2', + adapters: [ dhis2.storage.DomSessionStorageAdapter, dhis2.storage.InMemoryAdapter ], + objectStores: [ 'optionSets' ] +} ); + ( function( $ ) { $.safeEach = function( arr, fn ) { @@ -187,6 +200,7 @@ dataElements = metaData.dataElements; indicatorFormulas = metaData.indicatorFormulas; dataSets = metaData.dataSets; + optionSets = metaData.optionSets; dataSetAssociationSets = metaData.dataSetAssociationSets; organisationUnitAssociationSetMap = metaData.organisationUnitAssociationSetMap; @@ -371,7 +385,7 @@ if ( type == 'date' ) { - $( this ).css( 'width', '80%' ); + $( this ).css( 'width', '100%' ); datePicker( id ); } } ); @@ -396,7 +410,7 @@ saveBoolean( dataElementId, optionComboId, id ); } ); - $( this ).css( 'width', '100%' ); + $( this ).css( 'width', '90%' ); } ); $( '[name="commentlink"]' ).each( function( i ) @@ -507,6 +521,7 @@ } loadDataValues(); + insertOptionSets(); } else { @@ -531,7 +546,8 @@ $( '#currentOrganisationUnit' ).html( i18n_no_organisationunit_selected ); } - loadDataValues() + loadDataValues(); + insertOptionSets(); } ); } } @@ -1613,6 +1629,10 @@ purgeLocalForms(); updateExistingLocalForms(); downloadRemoteForms(); + + DAO.store.open().done(function() { + loadOptionSets(); + }); } function purgeLocalForms() @@ -2171,3 +2191,142 @@ return true; }; } + +// ----------------------------------------------------------------------------- +// OptionSet +// ----------------------------------------------------------------------------- + +function searchOptionSet( uid, query, success ) { + if(window.DAO !== undefined && window.DAO.store !== undefined ) { + DAO.store.get( 'optionSets', uid ).done( function ( obj ) { + if(obj) { + var options = []; + + if(query == null || query == "") { + options = obj.optionSet.options.slice(0, MAX_DROPDOWN_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: '../api/optionSets/' + uid + '.json?links=false&q=' + query, + dataType: "json", + cache: false, + type: 'GET', + success: function ( data ) { + success( $.map( data.options, function ( item ) { + return { + label: item, + id: item + }; + } ) ); + } + } ); +} + +function loadOptionSets() { + var optionSetUids = _.values( optionSets ); + optionSetUids = _.union(optionSetUids); + + var deferred = $.Deferred(); + var promise = deferred.promise(); + + _.each( optionSetUids, function ( item, idx ) { + promise = promise.then( function () { + return $.ajax( { + url: '../api/optionSets/' + item + '.json?links=false', + type: 'GET', + cache: false + } ).done( function ( data ) { + log( 'Successfully stored optionSet: ' + item ); + + var obj = {}; + obj.id = item; + obj.optionSet = data; + DAO.store.set( 'optionSets', obj ); + } ); + } ); + } ); + + promise = promise.then( function () { + } ); + + deferred.resolve(); +} + +function insertOptionSets() { + $.each( _.keys(optionSets), function(idx, item) { + autocompleteOptionSetField( item + '-val', optionSets[item] ); + }); +} + +function autocompleteOptionSetField( idField, optionSetUid ) { + var input = jQuery( "#" + idField ); + input.css( "width", "85%" ); + input.autocomplete( { + delay: 0, + minLength: 0, + source: function ( request, response ) { + searchOptionSet( optionSetUid, input.val(), response ); + }, + select: function ( event, ui ) { + input.val( ui.item.value ); + input.autocomplete( "close" ); + input.change(); + } + } ).addClass( "ui-widget" ); + + input.data( "autocomplete" )._renderItem = function ( ul, item ) { + return $( "
  • " ) + .data( "item.autocomplete", item ) + .append( "" + item.label + "" ) + .appendTo( ul ); + }; + + var wrapper = this.wrapper = $( "" ) + .addClass( "ui-combobox" ) + .insertAfter( input ); + + var button = $( "" ) + .attr( "tabIndex", -1 ) + .attr( "title", 'i18n_show_all_items' ) + .appendTo( wrapper ) + .button( { + icons: { + primary: "ui-icon-triangle-1-s" + }, + text: false + } ) + .addClass( 'small-button' ) + .click( function () { + if ( input.autocomplete( "widget" ).is( ":visible" ) ) { + input.autocomplete( "close" ); + return; + } + $( this ).blur(); + input.autocomplete( "search", "" ); + input.focus(); + } ); +} === 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-01-16 10:42:27 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/responseMetaData.vm 2013-05-21 06:03:05 +0000 @@ -13,6 +13,13 @@ #if( $velocityCount < $size ),#end #end }, +"optionSets": { +#set( $size = $dataElementsWithOptionSet.size() ) +#foreach( $dataElement in $dataElementsWithOptionSet ) +"${dataElement.uid}-${dataElement.categoryCombo.getSortedOptionCombos().get(0).uid}":"$encoder.jsonEncode( ${dataElement.optionSet.uid} )" +#if( $velocityCount < $size ),#end +#end }, + "indicatorFormulas": { #set( $size = $indicators.size() ) #foreach( $indicator in $indicators )