dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #29810
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15125: Fixed bug - Error when to remove program-instance of single program.
------------------------------------------------------------
revno: 15125
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-04-30 20:57:22 +0800
message:
Fixed bug - Error when to remove program-instance of single program.
added:
dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RemoveSingleEventAction.java
modified:
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/struts.xml
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/form.js
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/singleEvent.js
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/singleEventSelect.vm
--
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
=== added file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RemoveSingleEventAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RemoveSingleEventAction.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RemoveSingleEventAction.java 2014-04-30 12:57:22 +0000
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2004-2013, 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.Collection;
+
+import org.hisp.dhis.common.DeleteNotAllowedException;
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramInstance;
+import org.hisp.dhis.program.ProgramInstanceService;
+import org.hisp.dhis.program.ProgramService;
+import org.hisp.dhis.program.ProgramStageInstanceService;
+import org.hisp.dhis.trackedentity.TrackedEntityInstance;
+import org.hisp.dhis.trackedentity.TrackedEntityInstanceService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ *
+ * @version $ RemoveSingleEventAction.java Apr 30, 2014 5:56:25 PM $
+ */
+public class RemoveSingleEventAction
+ implements Action
+{
+ // -------------------------------------------------------------------------
+ // Dependency
+ // -------------------------------------------------------------------------
+ @Autowired
+ private TrackedEntityInstanceService entityInstanceService;
+
+ @Autowired
+ private ProgramService programService;
+
+ @Autowired
+ private ProgramInstanceService programInstanceService;
+
+ @Autowired
+ private ProgramStageInstanceService programStageInstanceService;
+
+ private I18n i18n;
+
+ public void setI18n( I18n i18n )
+ {
+ this.i18n = i18n;
+ }
+
+ // -------------------------------------------------------------------------
+ // Getter && Setter
+ // -------------------------------------------------------------------------
+
+ private String entityInstanceId;
+
+ public void setEntityInstanceId( String entityInstanceId )
+ {
+ this.entityInstanceId = entityInstanceId;
+ }
+
+ private String programId;
+
+ public void setProgramId( String programId )
+ {
+ this.programId = programId;
+ }
+
+ // -------------------------------------------------------------------------
+ // Output
+ // -------------------------------------------------------------------------
+
+ private String message;
+
+ public String getMessage()
+ {
+ return message;
+ }
+
+ // -------------------------------------------------------------------------
+ // Action Implementation
+ // -------------------------------------------------------------------------
+
+ @Override
+ public String execute()
+ throws Exception
+ {
+ try
+ {
+ TrackedEntityInstance entityInstance = entityInstanceService.getTrackedEntityInstance( entityInstanceId );
+
+ Program program = programService.getProgram( programId );
+
+ Collection<ProgramInstance> programInstances = programInstanceService.getProgramInstances( entityInstance,
+ program );
+ if ( programInstances != null )
+ {
+ ProgramInstance programInstance = programInstances.iterator().next();
+
+ programStageInstanceService.deleteProgramStageInstance( programInstance.getProgramStageInstances()
+ .iterator().next() );
+ programInstanceService.deleteProgramInstance( programInstance );
+ }
+ }
+ catch ( DeleteNotAllowedException ex )
+ {
+ if ( ex.getErrorCode().equals( DeleteNotAllowedException.ERROR_ASSOCIATED_BY_OTHER_OBJECTS ) )
+ {
+ message = i18n.getString( "object_not_deleted_associated_by_objects" ) + " " + ex.getMessage();
+
+ return ERROR;
+ }
+ }
+ 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 2014-04-24 16:30:48 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2014-04-30 12:57:22 +0000
@@ -751,6 +751,12 @@
scope="prototype">
<property name="programInstanceService" ref="org.hisp.dhis.program.ProgramInstanceService" />
</bean>
+
+ <bean
+ id="org.hisp.dhis.caseentry.action.caseentry.RemoveSingleEventAction"
+ class="org.hisp.dhis.caseentry.action.caseentry.RemoveSingleEventAction"
+ scope="prototype">
+ </bean>
<!-- Comment && Message -->
=== 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 2014-04-26 13:20:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml 2014-04-30 12:57:22 +0000
@@ -842,7 +842,7 @@
<param name="stylesheets">style/style.css</param>
<param name="requiredAuthorities">F_TRACKED_ENTITY_INSTANCE_DASHBOARD</param>
</action>
-
+
<action name="removeProgramInstance"
class="org.hisp.dhis.caseentry.action.caseentry.RemoveProgramInstanceAction">
<result name="success" type="velocity-json">
@@ -854,6 +854,17 @@
<param name="requiredAuthorities">F_PROGRAM_INSTANCE_DELETE</param>
</action>
+ <action name="removeSingleEvent"
+ class="org.hisp.dhis.caseentry.action.caseentry.RemoveSingleEventAction">
+ <result name="success" type="velocity-json">
+ /dhis-web-commons/ajax/jsonResponseSuccess.vm
+ </result>
+ <result name="error" type="velocity-json">
+ /dhis-web-commons/ajax/jsonResponseError.vm
+ </result>
+ <param name="requiredAuthorities">F_PROGRAM_INSTANCE_DELETE</param>
+ </action>
+
<!-- Comment && Message -->
<action name="saveTrackedEntityInstanceComment"
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/form.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/form.js 2014-04-24 16:30:48 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/form.js 2014-04-30 12:57:22 +0000
@@ -5,6 +5,7 @@
setInnerHTML( 'contentDiv', '' );
setFieldValue( 'orgunitName', orgUnitNames[0] );
+ hideById('programNameDiv');
hideById('singleDataEntryFormDiv');
showById('searchDiv');
@@ -22,6 +23,7 @@
setInnerHTML('singleDataEntryFormDiv', '');
showById('executionDateTB');
showById('singleDataEntryFormDiv');
+ showById('programNameDiv');
setFieldValue( 'dueDate', '' );
setFieldValue( 'executionDate', '' );
disableCompletedButton(true);
@@ -32,10 +34,10 @@
$( '#singleDataEntryFormDiv' ).load( "dataentryform.action",
{
programStageInstanceId: programStageInstanceId
- },function( html )
+ },function()
{
var programName = $('#program option:selected').text();
- setInnerHTML( 'singleDataEntryFormDiv', '<h3>' + programName + '</h3><br>' + html);
+ setInnerHTML( 'programNameDiv', '<h3>' + programName + '</h3>');
var completed = jQuery('#entryFormContainer input[id=completed]').val();
var irregular = jQuery('#entryFormContainer input[id=irregular]').val();
showById('inputCriteriaDiv');
@@ -51,6 +53,7 @@
function showSearchForm()
{
+ hideById('programNameDiv');
hideById('singleDataEntryFormDiv');
hideById('addNewDiv');
showById('searchDiv');
@@ -140,6 +143,7 @@
hideById('enrollmentDiv');
hideById('listRelationshipDiv');
hideById('addRelationshipDiv');
+ hideById('programNameDiv');
hideById('singleDataEntryFormDiv');
hideById('migrationEntityInstanceDiv');
setInnerHTML('entityInstanceDashboard', '');
@@ -251,24 +255,23 @@
colVal = (colVal=='true')? i18n_yes : i18n_no;
}
- table += "<td onclick=\"javascript:isDashboard=true;showTrackedEntityInstanceDashboardForm( '"
+ table += "<td onclick=\"javascript:isDashboard=true;showUpdateEventForm( '"
+ uid
+ "' )\" title='"
- + i18n_dashboard
- + "'>" + colVal + "</td>";
+ + i18n_data_entry
+ + "'><a>" + colVal + "</a></td>";
}
// Operations column
table += "<td>";
- table += "<a href=\"javascript:isDashboard=false;showUpdateTrackedEntityInstanceForm( '"
+ table += "<a href=\"javascript:isDashboard=false;showUpdateEventForm( '"
+ uid
+ "' )\" title='"
+ i18n_data_entry
+ "'><img src= '../images/edit.png' alt='"
+ i18n_data_entry
+ "'></a>";
- table += "<a href=\"javascript:removeTrackedEntityInstance( '" + uid
- + "', '', '" + i18n_confirm_delete_tracked_entity_instance
+ table += "<a href=\"javascript:removeSingleEvent( '" + uid
+ "' )\" title='" + i18n_remove
+ "'><img src='../images/delete.png' alt='" + i18n_remove
+ "'></a>";
@@ -357,3 +360,34 @@
loadDataEntry( json.activeProgramStageInstanceId );
});
};
+
+function removeSingleEvent(uid)
+{
+ var result = window.confirm( i18n_comfirm_delete_event );
+
+ if ( result )
+ {
+ jQuery.getJSON( "removeSingleEvent.action",
+ {
+ entityInstanceId: uid,
+ programId: getFieldValue('program')
+ },
+ function( json )
+ {
+ if ( json.response == "success" )
+ {
+ $( "tr#tr" + uid ).remove();
+
+ $( "table.listTable tbody tr" ).removeClass( "listRow listAlternateRow" );
+ $( "table.listTable tbody tr:odd" ).addClass( "listAlternateRow" );
+ $( "table.listTable tbody tr:even" ).addClass( "listRow" );
+ $( "table.listTable tbody" ).trigger("update");
+ showSuccessMessage( i18n_delete_success );
+ }
+ else if ( json.response == "error" )
+ {
+ showWarningMessage( json.message );
+ }
+ });
+ }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/singleEvent.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/singleEvent.js 2014-04-26 13:20:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/singleEvent.js 2014-04-30 12:57:22 +0000
@@ -62,10 +62,11 @@
});
}
-function showUpdateTrackedEntityInstanceForm( entityInstanceId )
+function showUpdateEventForm( entityInstanceId )
{
showLoader();
hideById('searchDiv');
+ hideById('programNameDiv');
hideById('singleDataEntryFormDiv');
hideById('dataEntryMenu');
showById('eventActionMenu');
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/singleEventSelect.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/singleEventSelect.vm 2014-04-24 16:30:48 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/singleEventSelect.vm 2014-04-30 12:57:22 +0000
@@ -50,6 +50,7 @@
<div id='listEntityInstanceDiv'></div>
<div id='addNewDiv'></div>
<div id='entityInstanceDashboard'></div> <!-- TrackedEntityInstance dashboard -->
+<div id='programNameDiv'></div>
<div id='singleDataEntryFormDiv'></div>
<div id='editEntityInstanceDiv'></div> <!-- Add TrackedEntityInstance Form -->
<div id='resultSearchDiv' style='font-size:13px'></div> <!-- List searching entityInstances -->