=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionService.java 2012-02-06 02:56:02 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionService.java 2012-06-15 04:41:31 +0000 @@ -28,6 +28,7 @@ */ import java.util.Collection; +import java.util.List; /** * @author Lars Helge Overland @@ -49,4 +50,6 @@ void deleteOptionSet( OptionSet optionSet ); Collection getAllOptionSets(); + + List getOptions( OptionSet optionSet, String key ); } === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionStore.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionStore.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionStore.java 2012-06-15 04:41:31 +0000 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2004-2012, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.option; + +import java.util.List; + +import org.hisp.dhis.common.GenericIdentifiableObjectStore; + +/** + * @author Chau Thu Tran + * + * @version $OptionStore.java Jun 15, 2012 9:45:00 AM$ + */ +public interface OptionStore extends GenericIdentifiableObjectStore +{ + List getOptions( OptionSet optionSet, String key ); +} === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java 2012-02-06 02:56:02 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java 2012-06-15 04:41:31 +0000 @@ -28,8 +28,8 @@ */ import java.util.Collection; +import java.util.List; -import org.hisp.dhis.common.GenericIdentifiableObjectStore; import org.springframework.transaction.annotation.Transactional; /** @@ -39,45 +39,50 @@ public class DefaultOptionService implements OptionService { - private GenericIdentifiableObjectStore optionSetStore; + private OptionStore optionStore; - public void setOptionSetStore( GenericIdentifiableObjectStore optionSetStore ) + public void setOptionStore( OptionStore optionStore ) { - this.optionSetStore = optionSetStore; + this.optionStore = optionStore; } public int saveOptionSet( OptionSet optionSet ) { - return optionSetStore.save( optionSet ); + return optionStore.save( optionSet ); } public void updateOptionSet( OptionSet optionSet ) { - optionSetStore.update( optionSet ); + optionStore.update( optionSet ); } public OptionSet getOptionSet( int id ) { - return optionSetStore.get( id ); + return optionStore.get( id ); } public OptionSet getOptionSet( String uid ) { - return optionSetStore.getByUid( uid ); + return optionStore.getByUid( uid ); } public OptionSet getOptionSetByName( String name ) { - return optionSetStore.getByName( name ); + return optionStore.getByName( name ); } public void deleteOptionSet( OptionSet optionSet ) { - optionSetStore.delete( optionSet ); + optionStore.delete( optionSet ); } public Collection getAllOptionSets() { - return optionSetStore.getAll(); + return optionStore.getAll(); + } + + public List getOptions( OptionSet optionSet, String key ) + { + return optionStore.getOptions( optionSet, key ); } } === added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/HibernateOptionStore.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/HibernateOptionStore.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/HibernateOptionStore.java 2012-06-15 04:41:31 +0000 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2004-2012, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.option; + +import java.util.List; + +import org.hibernate.Query; +import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore; + +/** + * @author Chau Thu Tran + * + * @version $HibernateOptionStore.java Jun 15, 2012 9:45:48 AM$ + */ +public class HibernateOptionStore + extends HibernateIdentifiableObjectStore + implements OptionStore +{ + + @SuppressWarnings("unchecked") + @Override + public List getOptions( OptionSet optionSet, String key ) + { + String hql = "select option from OptionSet as optionset inner join optionset.options as option where optionset.id = :optionSetId and lower(option) like lower('%" + key + "%') "; + + Query query = getQuery( hql ); + query.setInteger( "optionSetId", optionSet.getId() ); + + return query.list(); + } + +} === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2012-06-13 08:44:07 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2012-06-15 04:41:31 +0000 @@ -275,10 +275,9 @@ - + - @@ -506,7 +505,7 @@ - + === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java 2012-06-04 10:03:56 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java 2012-06-15 04:41:31 +0000 @@ -555,8 +555,7 @@ // Inline Javascript to add to HTML before outputting // --------------------------------------------------------------------- - final String jsCodeForInputs = " $DISABLED onchange=\"saveVal( $DATAELEMENTID )\" data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME', deType:'$DATAELEMENTTYPE'}\" onkeypress=\"return keyPress(event, this)\" style=\" text-align:center;\" "; - final String jsCodeForOptions = " $DISABLED options='$OPTIONS' dataElementId=\"$DATAELEMENTID\" data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME', deType:'$DATAELEMENTTYPE'}\" onkeypress=\"return keyPress(event, this)\" style=\" text-align:center;\" "; + final String jsCodeForInputs = " $DISABLED onchange=\"saveVal( $DATAELEMENTID )\" data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME', deType:'$DATAELEMENTTYPE'}\" onkeypress=\"return keyPress(event, this)\" options='$OPTIONS' style=\" text-align:center;\" "; StringBuffer sb = new StringBuffer(); @@ -700,16 +699,10 @@ appendCode += "value=\"" + dataElementValue + "\""; } - if ( dataElement.getOptionSet() != null ) - { - appendCode += jsCodeForOptions; - - appendCode = appendCode.replace( "$OPTIONS", dataElement.getOptionSet().getOptions().toString() ); - } - else - { - appendCode += jsCodeForInputs; - } + appendCode += jsCodeForInputs; + + Boolean hasOptionSet = ( dataElement.getOptionSet() != null ); + appendCode = appendCode.replace( "$OPTIONS", hasOptionSet.toString() ); appendCode += " />"; === added file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetOptionsByDataElementAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetOptionsByDataElementAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetOptionsByDataElementAction.java 2012-06-15 04:41:31 +0000 @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2004-2012, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.caseentry.action.caseentry; + +import java.util.List; + +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementService; +import org.hisp.dhis.option.OptionService; + +import com.opensymphony.xwork2.Action; + +/** + * @author Chau Thu Tran + * + * @version $GetOptionsByDataElementAction.java Jun 15, 2012 10:36:29 AM$ + */ +public class GetOptionsByDataElementAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private DataElementService dataElementService; + + public void setDataElementService( DataElementService dataElementService ) + { + this.dataElementService = dataElementService; + } + + private OptionService optionService; + + public void setOptionService( OptionService optionService ) + { + this.optionService = optionService; + } + + // ------------------------------------------------------------------------- + // Input + // ------------------------------------------------------------------------- + + private Integer id; + + public void setId( Integer id ) + { + this.id = id; + } + + private String key; + + public void setKey( String key ) + { + this.key = key; + } + + // ------------------------------------------------------------------------- + // Output + // ------------------------------------------------------------------------- + + private List options; + + public List getOptions() + { + return options; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + { + DataElement dataElement = dataElementService.getDataElement( id ); + + options = optionService.getOptions( dataElement.getOptionSet(), key ); + + return SUCCESS; + } +} === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2012-06-14 13:07:22 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2012-06-15 04:41:31 +0000 @@ -136,6 +136,16 @@ + + + + + === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml 2012-06-07 13:09:16 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml 2012-06-15 04:41:31 +0000 @@ -148,6 +148,10 @@ /dhis-web-caseentry/validationResult.vm + + /dhis-web-caseentry/jsonOptions.vm + + #set( $id = $programStageDataElement.programStage.id + '-' + $programStageDataElement.dataElement.id + '-val' ) #if( $!programStageDataElement.dataElement.optionSet ) - #set( $optionId = $id + '-options') - - #elseif( $programStageDataElement.dataElement.type == "bool" ) + #set( $hasOptionSet = 'true') + #else + #set( $hasOptionSet = 'true') + #end + + #if( $programStageDataElement.dataElement.type == "bool" ) + #end === 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 2012-06-13 08:22:35 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js 2012-06-15 04:41:31 +0000 @@ -824,71 +824,30 @@ { var input = jQuery( "#" + idField ) var dataElementId = input.attr( 'dataElementId' ); - var options = new Array(); - options = input.attr('options').replace('[', '').replace(']', '').split(', '); - options.push(" "); - + input.autocomplete({ delay: 0, minLength: 0, - source: options, + source: function( request, response ){ + $.ajax({ + url: "getOptions.action?id=" + dataElementId + "&key=" + input.val(), + dataType: "json", + success: function(data) { + response($.map(data.options, function(item) { + return { + label: item, + id: item + }; + })); + } + }); + }, + minLength: 2, select: function( event, ui ) { input.val(ui.item.value); saveVal( dataElementId ); input.autocomplete( "close" ); - }, - change: function( event, ui ) { - if ( !ui.item ) { - var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ), - valid = false; - for (var i = 0; i < options.length; i++) - { - if (options[i].match( matcher ) ) { - this.selected = valid = true; - break; - } - } - if ( !valid ) { - // remove invalid value, as it didn't match anything - $( this ).val( "" ); - input.data( "autocomplete" ).term = ""; - return false; - } - } - saveVal( dataElementId ); } }) .addClass( "ui-widget" ); - - this.button = $( "" ) - .attr( "tabIndex", -1 ) - .attr( "title", i18n_show_all_items ) - .insertAfter( input ) - .button({ - icons: { - primary: "ui-icon-triangle-1-s" - }, - text: false - }) - .addClass( "optionset-small-button" ) - .click(function() { - // close if already visible - if ( input.autocomplete( "widget" ).is( ":visible" ) ) { - input.autocomplete( "close" ); - return; - } - - // work around a bug (likely same cause as #5265) - $( this ).blur(); - - // pass empty string as value to search for, displaying all results - input.autocomplete( "search", "" ); - input.focus(); - }); } - -/* function hexToR(h) { - return parseInt((cutHex(h)).substring(0,2),16) + - parseInt((cutHex(h)).substring(2,4),16); - parseInt((cutHex(h)).substring(2,4),16); -} */ === added file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonOptions.vm' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonOptions.vm 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonOptions.vm 2012-06-15 04:41:31 +0000 @@ -0,0 +1,7 @@ +{ "options": [ + #foreach( $option in $options ) + "$option", + #end + "" + ] +} \ No newline at end of file