=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/ValidateDataElementCategoryOptionAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/ValidateDataElementCategoryOptionAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/ValidateDataElementCategoryOptionAction.java 2009-11-03 08:29:16 +0000 @@ -0,0 +1,107 @@ +package org.hisp.dhis.dd.action.category; + +/* + * Copyright (c) 2004-2007, 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. + */ + +import org.hisp.dhis.dataelement.DataElementCategoryService; +import org.hisp.dhis.i18n.I18n; + +import com.opensymphony.xwork2.Action; + +/** + * @author Abyot Asalefew + * @version $Id$ + */ +public class ValidateDataElementCategoryOptionAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private DataElementCategoryService dataElementCategoryService; + + public void setDataElementCategoryService( DataElementCategoryService dataElementCategoryService ) + { + this.dataElementCategoryService = dataElementCategoryService; + } + + private I18n i18n; + + public void setI18n( I18n i18n ) + { + this.i18n = i18n; + } + + // ------------------------------------------------------------------------- + // Input + // ------------------------------------------------------------------------- + + private String name; + + public void setName( String name ) + { + this.name = name; + } + + // ------------------------------------------------------------------------- + // Output + // ------------------------------------------------------------------------- + + private String message; + + public String getMessage() + { + return message; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + { + if ( (name == null) || (name.trim().equals( "" )) ) + { + message = i18n.getString( "specify_name" ); + + return INPUT; + } + else + { + if (dataElementCategoryService.getDataElementCategoryOptionByName( name ) != null) + { + message = i18n.getString( "name_in_use" ); + + return INPUT; + } + } + message = "ok"; + + return SUCCESS; + } +} === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/META-INF/dhis/beans.xml 2009-10-30 07:06:12 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/META-INF/dhis/beans.xml 2009-11-03 08:29:16 +0000 @@ -18,6 +18,9 @@ + + + + + + + + + + + + === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml 2009-11-02 18:13:58 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml 2009-11-03 08:29:16 +0000 @@ -991,7 +991,17 @@ 10240 - + + + + + + /dhis-web-maintenance-datadictionary/responseSuccess.vm + + /dhis-web-maintenance-datadictionary/responseInput.vm + + === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/category.js' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/category.js 2009-10-20 12:49:32 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/category.js 2009-11-03 08:29:16 +0000 @@ -53,24 +53,18 @@ } } -function addCategoryOptionToCategory() +function addCategoryOptionToCategory( categoryName ) { - var categoryName = document.getElementById( 'categoryOptionName' ).value; - - if ( categoryName == "" ) - { - setMessage( i18n_specify_category_option_name ); - } - else if ( listContainsById( 'categoryOptionNames', categoryName ) ) + if ( listContainsById( 'categoryOptionNames', categoryName ) ) { setMessage( i18n_category_option_name_already_exists ); } else { - addOption( 'categoryOptionNames', categoryName, categoryName ); + addOption( 'categoryOptionNames', categoryName, categoryName ); + document.getElementById( 'categoryOptionName' ).value = ""; + } - document.getElementById( 'categoryOptionName' ).value = ""; - } } // ---------------------------------------------------------------------- @@ -145,3 +139,26 @@ setMessage( message ); } } + + +function validateCategoryOptionJQuery() { + + var categoryName = $("#categoryOptionName").val(); + + $.post("validateDataElementCategoryOption.action", { + name:categoryName + }, function ( xmlObject ) { + + xmlObject = xmlObject.getElementsByTagName("message")[0]; + var type = xmlObject.getAttribute("type"); + + if ( type == "input" ) { + + setMessage(xmlObject.firstChild.nodeValue); + } + else { + addCategoryOptionToCategory( categoryName ); + } + }, "xml"); +} + === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/addDataElementCategoryForm.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/addDataElementCategoryForm.vm 2009-10-20 12:49:32 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/addDataElementCategoryForm.vm 2009-11-03 08:29:16 +0000 @@ -27,7 +27,7 @@ - +