------------------------------------------------------------ revno: 11692 committer: Tran Chau <tran.hispviet...@gmail.com> branch nick: dhis2 timestamp: Mon 2013-08-19 10:45:04 +0700 message: Add function for validating name of tabular report. modified: dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientreport/PatientTabularReportService.java dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientreport/DefaultPatientTabularReportService.java dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/ValidateTabularReportAction.java 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/org/hisp/dhis/caseentry/i18n_module.properties dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.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-api/src/main/java/org/hisp/dhis/patientreport/PatientTabularReportService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientreport/PatientTabularReportService.java 2013-04-02 04:33:34 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientreport/PatientTabularReportService.java 2013-08-19 03:45:04 +0000 @@ -41,6 +41,8 @@ void saveOrUpdate( PatientTabularReport patientTabularReport ); PatientTabularReport getPatientTabularReport( int id ); + + PatientTabularReport getPatientTabularReport( String name ); void deletePatientTabularReport( PatientTabularReport patientTabularReport ); === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientreport/DefaultPatientTabularReportService.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientreport/DefaultPatientTabularReportService.java 2013-04-02 04:33:34 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientreport/DefaultPatientTabularReportService.java 2013-08-19 03:45:04 +0000 @@ -73,7 +73,13 @@ { return tabularReportStore.get( id ); } - + + @Override + public PatientTabularReport getPatientTabularReport( String name ) + { + return tabularReportStore.getByName( name ); + } + @Override public Collection<PatientTabularReport> getPatientTabularReports( User user, String query, Integer min, Integer max ) { @@ -85,7 +91,7 @@ { tabularReportStore.save( patientTabularReport ); } - + @Override public int countPatientTabularReportList( User user, String query ) { === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/ValidateTabularReportAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/ValidateTabularReportAction.java 2012-03-12 08:10:06 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/report/ValidateTabularReportAction.java 2013-08-19 03:45:04 +0000 @@ -27,9 +27,9 @@ package org.hisp.dhis.caseentry.action.report; -import org.hisp.dhis.caseentry.state.SelectedStateManager; import org.hisp.dhis.i18n.I18n; -import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.patientreport.PatientTabularReport; +import org.hisp.dhis.patientreport.PatientTabularReportService; import com.opensymphony.xwork2.Action; @@ -45,11 +45,11 @@ // Dependencies // ------------------------------------------------------------------------- - private SelectedStateManager selectedStateManager; + private PatientTabularReportService tabularReportService; - public void setSelectedStateManager( SelectedStateManager selectedStateManager ) + public void setTabularReportService( PatientTabularReportService tabularReportService ) { - this.selectedStateManager = selectedStateManager; + this.tabularReportService = tabularReportService; } private I18n i18n; @@ -62,12 +62,19 @@ // ------------------------------------------------------------------------- // Input && Output // ------------------------------------------------------------------------- - - private String facilityLB; - - public void setFacilityLB( String facilityLB ) - { - this.facilityLB = facilityLB; + + private Integer id; + + public void setId( Integer id ) + { + this.id = id; + } + + private String name; + + public void setName( String name ) + { + this.name = name; } private String message; @@ -84,19 +91,18 @@ public String execute() throws Exception { - OrganisationUnit selectedOrgunit = selectedStateManager.getSelectedOrganisationUnit(); - - if ( selectedOrgunit == null ) - { - message = i18n.getString( "please_specify_an_orgunit" ); - return INPUT; - } - - if ( facilityLB.equals( "childrenOnly" ) && !selectedOrgunit.hasChild() ) - { - message = i18n.getString( "selected_orgunit_no_have_any_child" ); - return INPUT; - } + name = name.trim(); + + PatientTabularReport match = tabularReportService.getPatientTabularReport( name ); + + if ( match != null && (id == null || match.getId() != id.intValue()) ) + { + message = i18n.getString( "name_in_use" ); + + return INPUT; + } + + message = i18n.getString( "everything_is_ok" ); 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 2013-08-12 06:23:01 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2013-08-19 03:45:04 +0000 @@ -933,8 +933,8 @@ id="org.hisp.dhis.caseentry.action.report.ValidateTabularReportAction" class="org.hisp.dhis.caseentry.action.report.ValidateTabularReportAction" scope="prototype"> - <property name="selectedStateManager" - ref="org.hisp.dhis.caseentry.state.SelectedStateManager" /> + <property name="tabularReportService" + ref="org.hisp.dhis.patientreport.PatientTabularReportService" /> </bean> <bean id="org.hisp.dhis.caseentry.action.report.GetTabularReportsAction" === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties 2013-08-12 06:23:01 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties 2013-08-19 03:45:04 +0000 @@ -674,4 +674,6 @@ event_registration = Event registration add_patient_related_the_seleced_event = Add person related to the selected event related_patient = Related person -search_by_user_orgunits = Search by user orgunits \ No newline at end of file +search_by_user_orgunits = Search by user orgunits +show_data = Show data +name_in_use = Name is in use \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js 2013-07-08 06:58:36 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/app/app.js 2013-08-19 03:45:04 +0000 @@ -54,6 +54,7 @@ casebasedfavorite_getall: 'getTabularReports.action', casebasedfavorite_get: 'getTabularReport.action', casebasedfavorite_rename: 'updateTabularReportName.action', + casebasedfavorite_validate: 'validateTabularReport.action', casebasedfavorite_save: 'saveTabularReport.action', casebasedfavorite_delete: 'deleteTabularReport.action', suggested_dataelement_get: 'getOptions.action', @@ -3295,15 +3296,30 @@ p.name = name; Ext.Ajax.request({ - url: TR.conf.finals.ajax.path_root + TR.conf.finals.ajax.casebasedfavorite_save, + url: TR.conf.finals.ajax.path_root + TR.conf.finals.ajax.casebasedfavorite_validate, method: 'POST', - params: p, - success: function() { - TR.store.caseBasedFavorite.loadStore(); - window.destroy(); - TR.util.mask.hideMask(); - } - }); + params: {name:name}, + success: function(r) { + var json = Ext.JSON.decode(r.responseText); + if(json.response=='success'){ + Ext.Ajax.request({ + url: TR.conf.finals.ajax.path_root + TR.conf.finals.ajax.casebasedfavorite_save, + method: 'POST', + params: p, + success: function() { + TR.store.caseBasedFavorite.loadStore(); + window.destroy(); + TR.util.mask.hideMask(); + } + }) + } + else{ + TR.util.notification.error(TR.i18n.error, json.message); + window.destroy(); + TR.util.mask.hideMask(); + } + } + }); } } }); @@ -3314,26 +3330,39 @@ var name = nameTextfield.getValue(); if (id && name) { - if (TR.store.caseBasedFavorite.findExact('name', name) != -1) { - return; + TR.util.mask.showMask(TR.cmp.caseBasedFavorite.window, TR.i18n.renaming + '...'); + + Ext.Ajax.request({ + url: TR.conf.finals.ajax.path_root + TR.conf.finals.ajax.casebasedfavorite_validate, + method: 'POST', + params: {id:id, name:name}, + success: function(r) { + var json = Ext.JSON.decode(r.responseText); + if(json.response=='success'){ + Ext.Ajax.request({ + url: TR.conf.finals.ajax.path_root + TR.conf.finals.ajax.casebasedfavorite_rename, + method: 'POST', + params: {id: id, name: name}, + failure: function(r) { + TR.util.mask.hideMask(); + alert(r.responseText); + }, + success: function() { + TR.store.caseBasedFavorite.loadStore(); + window.destroy(); + TR.util.mask.hideMask(); + } + }); + } + else{ + TR.util.notification.error(TR.i18n.error, json.message); + window.destroy(); + TR.util.mask.hideMask(); + } + } + }); } - TR.util.mask.showMask(TR.cmp.caseBasedFavorite.window, TR.i18n.renaming + '...'); - Ext.Ajax.request({ - url: TR.conf.finals.ajax.path_root + TR.conf.finals.ajax.casebasedfavorite_rename, - method: 'POST', - params: {id: id, name: name}, - failure: function(r) { - TR.util.mask.hideMask(); - alert(r.responseText); - }, - success: function() { - TR.store.caseBasedFavorite.loadStore(); - window.destroy(); - TR.util.mask.hideMask(); - } - }); } - } }); cancelButton = Ext.create('Ext.button.Button', {
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp