worked on CRM-12202, added new form for changing activity status and used it for...
authorKurund Jalmi <kurund@civicrm.org>
Wed, 27 Mar 2013 10:17:44 +0000 (15:47 +0530)
committerKurund Jalmi <kurund@civicrm.org>
Wed, 27 Mar 2013 10:17:44 +0000 (15:47 +0530)
CRM/Case/BAO/Case.php
CRM/Case/Form/ActivityChangeStatus.php [new file with mode: 0644]
CRM/Case/Form/CaseView.php
CRM/Case/Page/DashBoard.php
CRM/Case/xml/Menu/Case.xml
templates/CRM/Case/Form/ActivityChangeStatus.js [new file with mode: 0644]
templates/CRM/Case/Form/ActivityChangeStatus.tpl
templates/CRM/Case/Form/CaseView.tpl

index 30764eac00e7ea0d6c4dd77b5c9204a41a40100a..3ccbff8aa21d6c10f0de4c45dd4d60c0b4e04060 100644 (file)
@@ -1287,7 +1287,7 @@ SELECT case_status.label AS case_status, status_id, case_type.label AS case_type
       }
 
       if ($allowEdit) {
-        $values[$dao->id]['status'] = '<a class="crm-activity-status crm-activity-status-' . $dao->id . ' ' . $values[$dao->id]['class'] . '" href="javascript:changeActivityStatus(' . $dao->id . ',' . $contactID . ',' . $dao->status . ');" title=\'' . $statusTitle . '\'>' . $values[$dao->id]['status'] . '</a>';
+        $values[$dao->id]['status'] = '<a class="crm-activity-status crm-activity-status-' . $dao->id . ' ' . $values[$dao->id]['class'] . '" href="javascript:changeActivityStatus(' . $dao->id . ',' . $contactID . ',' . $dao->status . ', ' . $caseID . ');" title=\'' . $statusTitle . '\'>' . $values[$dao->id]['status'] . '</a>';
       }
     }
     $dao->free();
diff --git a/CRM/Case/Form/ActivityChangeStatus.php b/CRM/Case/Form/ActivityChangeStatus.php
new file mode 100644 (file)
index 0000000..1f67162
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.3                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*/
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2013
+ * $Id$
+ *
+ */
+
+/**
+ * This class generates form components for building changing activity status interface in a case
+ *
+ */
+class CRM_Case_Form_ActivityChangeStatus extends CRM_Core_Form {
+
+  /**
+   * Function to build the form
+   *
+   * @return None
+   * @access public
+   */
+  public function buildQuickForm() {
+    $activityStatus = CRM_Core_PseudoConstant::activityStatus();
+    $this->add('select', 'activity_change_status', ts('New Status'), $activityStatus);
+  }
+}
+
index 7ddad8384c691fbcb9e9410e959c482174874aa3..615f7dee2a8d6b8ed72399530a0dd8495a573509 100644 (file)
@@ -51,8 +51,10 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form {
    * @access public
    */
   public function preProcess() {
-    $this->_showRelatedCases = CRM_Utils_Array::value('relatedCases', $_GET);
+    // js for changing activity status
+    CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Case/Form/ActivityChangeStatus.js');
 
+    $this->_showRelatedCases = CRM_Utils_Array::value('relatedCases', $_GET);
 
     $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process();
     $isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients();
@@ -330,7 +332,6 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form {
 
     $activityStatus = CRM_Core_PseudoConstant::activityStatus();
     $this->add('select', 'status_id', ts('Status'), array("" => ts(' - any status - ')) + $activityStatus);
-    $this->add('select', 'activity_change_status', ts('New Status'), $activityStatus);
 
     // activity dates
     $this->addDate('activity_date_low', ts('Activity Dates - From'), FALSE, array('formatType' => 'searchDate'));
index 9f3a4a33e633facf09f11b6db6ac6a60dc51398b..083e781a48af576cc2beeedae985561d238c768f 100644 (file)
@@ -47,6 +47,9 @@ class CRM_Case_Page_DashBoard extends CRM_Core_Page {
    *
    */
   function preProcess() {
+    // js for changing activity status
+    CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Case/Form/ActivityChangeStatus.js');
+
     //check for civicase access.
     if (!CRM_Case_BAO_Case::accessCiviCase()) {
       CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
index 5d5e622429a31c97d59ffbb4a2a5a60dc7decb31..af47eb036ac6cdc232399e43bb0ef8b6b727c430 100644 (file)
     <path>civicrm/ajax/delcaserole</path>
     <page_callback>CRM_Case_Page_AJAX::deleteCaseRoles</page_callback>
   </item>
+  <item>
+    <path>civicrm/case/changeactivitystatus</path>
+    <title>Change Activity Status</title>
+    <page_callback>CRM_Case_Form_ActivityChangeStatus</page_callback>
+  </item>
 </menu>
diff --git a/templates/CRM/Case/Form/ActivityChangeStatus.js b/templates/CRM/Case/Form/ActivityChangeStatus.js
new file mode 100644 (file)
index 0000000..2c2dce7
--- /dev/null
@@ -0,0 +1,59 @@
+// http://civicrm.org/licensing
+function changeActivityStatus(activityId, contactId, current_status_id, caseId) {
+  var data = 'snippet=1&reset=1';
+  cj('<div>')
+    .load(CRM.url('civicrm/case/changeactivitystatus'), data, function() {
+      cj("#activity_change_status").val(current_status_id);
+    })
+    .dialog({
+      modal: true,
+      title: ts('Change Activity Status'),
+      buttons: {
+        "Ok" : function() {
+          // update the status
+          var status_id = cj("#activity_change_status").val( );
+
+          if (status_id === current_status_id) {
+            return false;
+          }
+
+          var dataUrl = CRM.url('civicrm/ajax/rest');
+          var data = 'json=1&version=3&entity=Activity&action=update&id=' + activityId + '&status_id=' + status_id
+            + '&case_id=' + caseId;
+          cj.ajax({
+            type     : "POST",
+            dataType : "json",
+            url      : dataUrl,
+            data     : data,
+            success  : function( values ) {
+              if ( values.is_error ) {
+                // seems to be some discrepancy as to which spelling it should be
+                var err_msg = values.error_msg ? values.error_msg : values.error_message;
+                CRM.alert(err_msg, ts('Unable to change status'), 'error');
+                return false;
+              }
+              else {
+                // just reload the page on success
+                window.location.reload();
+              }
+            },
+            error    : function( jqXHR, textStatus ) {
+              CRM.alert(jqXHR.responseText, jqXHR.statusText, 'error');
+              return false;
+            }
+          });
+
+          cj(this).dialog('close').remove();
+        },
+        "Cancel": function() {
+          cj(this).dialog('close').remove();
+        }
+      },
+      beforeClose: function() {
+        cj(this).dialog("destroy");
+      }
+    }
+  );
+}
+
+
index 9b6068bc05b600f4b9e8b143580fa872e8e12f9d..c32650b09f53229d13f10c91d508404c3146fe3b 100644 (file)
  +--------------------------------------------------------------------+
 *}
 {* CiviCase - change activity status inline *}
-<div id="changeStatusDialog">
 <div class="crm-block crm-form-block crm-case-activitychangestatus-form-block">
-<table class="form-layout">
-     <tr class="crm-case-activitychangestatus-form-block-status">
+  <table class="form-layout">
+    <tr class="crm-case-activitychangestatus-form-block-status">
       <td class="label">{$form.activity_change_status.label}</td>
-       <td>{$form.activity_change_status.html}</td>
-     </tr>
-</table>
-</div>
-</div>
-
-{literal}
-<script type="text/javascript">
-cj( "#changeStatusDialog" ).hide( );
-function changeActivityStatus( activityID, contactId, current_status_id ) {
-
-    cj("#changeStatusDialog").show();
-    cj("#changeStatusDialog").dialog({
-        title       : "Change Activity Status",
-        modal       : true,
-        bgiframe    : true,
-        width       : 400,
-        height      : 170,
-        close       : function( event, ui ) { },
-        overlay     : { opacity: 0.5, background: "black" },
-        beforeclose : function( event, ui ) {
-            cj(this).dialog("destroy");
-        },
-        open        : function() {
-            cj("#activity_change_status").val( current_status_id );
-        },
-
-        buttons : {
-      "Ok": function() {
-                var status_id = cj("#activity_change_status").val( );
-
-                cj(this).dialog("destroy");
-
-                if ( status_id == current_status_id  ) {
-                    return false;
-                }
-
-                var dataUrl = {/literal}"{crmURL p='civicrm/ajax/rest' h=0 }"{literal};
-                var data = 'json=1&version=3&entity=Activity&action=update&id=' + activityID + '&status_id=' + status_id + '&case_id=' + {/literal}{$caseId}{literal};
-                cj.ajax({   type     : "POST",
-                            dataType : "json",
-                            url      : dataUrl,
-                            data     : data,
-                            success  : function( values ) {
-                                if ( values.is_error ) {
-                                    // seems to be some discrepancy as to which spelling it should be
-                                    var err_msg = values.error_msg ? values.error_msg : values.error_message;
-                                    CRM.alert(err_msg, '{/literal}{ts escape="js"}Unable to change status{/ts}{literal}', 'error');
-                                    return false;
-                                } else {
-                                    // Hmm, actually several links inside the row have to change to use the new activity id
-                                    // and also the row class might change with the new status. So either we duplicate code here,
-                                    // do a reload which defeats the purpose of ajax, or rewrite the way this table works.
-                                    //cj( "a.crm-activity-status-" + activityID ).html(
-                                    //    cj("#activity_change_status option[value='" + status_id + "']").text()
-                                    //);
-                                    window.location.reload();
-                                }
-                            },
-                            error    : function( jqXHR, textStatus, errorThrown ) {
-                                CRM.alert(jqXHR.responseText, jqXHR.statusText, 'error');
-                                return false;
-                            }
-                });
-            },
-
-            "Cancel": function() {
-                cj(this).dialog("close");
-                cj(this).dialog("destroy");
-            }
-        }
-    });
-}
-</script>
-{/literal}
+      <td>{$form.activity_change_status.html}</td>
+    </tr>
+  </table>
+</div>
\ No newline at end of file
index 4321d24a54643b544c8c8549aa00c1e3c7556ba6..955c03b06e592b7c349c19707720ec669ec2bc78 100644 (file)
@@ -766,7 +766,6 @@ function addRole() {
 </script>
 {/literal}
 {include file="CRM/Case/Form/ActivityToCase.tpl"}
-{include file="CRM/Case/Form/ActivityChangeStatus.tpl"}
 
 {* pane to display / edit regular tags or tagsets for cases *}
 {if $showTags OR $showTagsets}