CRM-15759 - Use crmEditable for changing case activity status
authorColeman Watts <coleman@civicrm.org>
Mon, 26 Jan 2015 18:38:31 +0000 (13:38 -0500)
committerColeman Watts <coleman@civicrm.org>
Mon, 26 Jan 2015 19:43:38 +0000 (14:43 -0500)
Also cleanup js in ActivityTab.tpl

13 files changed:
CRM/Case/BAO/Case.php
CRM/Case/Form/ActivityChangeStatus.php [deleted file]
CRM/Case/xml/Menu/Case.xml
api/v3/Activity.php
templates/CRM/Case/Form/ActivityChangeStatus.tpl [deleted file]
templates/CRM/Case/Form/ActivityChangeStatusJs.tpl [deleted file]
templates/CRM/Case/Form/ActivityTab.tpl
templates/CRM/Case/Form/CaseView.tpl
templates/CRM/Case/Form/Search.tpl
templates/CRM/Case/Page/CaseDetails.tpl
templates/CRM/Case/Page/DashBoard.tpl
templates/CRM/Case/Page/DashboardSelector.tpl
templates/CRM/Case/Page/Tab.tpl

index a714634a0c8ab77edfc38b5c67608d42d3a2c043..7df56b3dc3ed493b59e6f98c6574d96cabf2af15 100644 (file)
@@ -1349,7 +1349,7 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c
       }
 
       if ($allowEdit) {
-        $values[$dao->id]['status'] = '<a class="crm-activity-status crm-activity-status-' . $dao->id . ' ' . $values[$dao->id]['class'] . ' crm-activity-change-status crm-editable-enabled" activity_id=' . $dao->id . ' current_status=' . $dao->status . ' case_id=' . $caseID . ' href="#" title=\'' . $statusTitle . '\'>' . $values[$dao->id]['status'] . '</a>';
+        $values[$dao->id]['status'] = '<div class="crmf-status_id crm-activity-status-' . $dao->id . ' ' . $values[$dao->id]['class'] . ' crm-editable" data-type="select" data-action="create" data-refresh="true">' . $values[$dao->id]['status'] . '</div>';
       }
     }
     $dao->free();
diff --git a/CRM/Case/Form/ActivityChangeStatus.php b/CRM/Case/Form/ActivityChangeStatus.php
deleted file mode 100644 (file)
index 8c51e5f..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-<?php
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.6                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
- +--------------------------------------------------------------------+
- | 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-2014
- * $Id$
- *
- */
-
-/**
- * This class generates form components for building changing activity status interface in a case
- *
- */
-class CRM_Case_Form_ActivityChangeStatus extends CRM_Core_Form {
-
-  /**
-   * Build the form object
-   *
-   * @return void
-   */
-  public function buildQuickForm() {
-    $activityStatus = CRM_Core_PseudoConstant::activityStatus();
-    $this->add('select', 'activity_change_status', ts('New Status'), $activityStatus);
-  }
-
-}
index 2fe5462c100579121ebfa3d2235d94d764d7cbb6..61bd8f28515e46c567e927c60453d9df10566908 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>
index 9ebad65d5a548d708abc3547632acc87715b270a..2d006ce781e392143cf94bd32a5f207b8dc3619d 100644 (file)
@@ -97,6 +97,10 @@ function civicrm_api3_activity_create($params) {
   $case_id = '';
   $createRevision = FALSE;
   $oldActivityValues = array();
+  // Lookup case id if not supplied
+  if (!isset($params['case_id']) && !empty($params['id'])) {
+    $params['case_id'] = CRM_Core_DAO::singleValueQuery("SELECT case_id FROM civicrm_case_activity WHERE activity_id = " . (int) $params['id']);
+  }
   if (!empty($params['case_id'])) {
     $case_id = $params['case_id'];
     if (!empty($params['id'])) {
diff --git a/templates/CRM/Case/Form/ActivityChangeStatus.tpl b/templates/CRM/Case/Form/ActivityChangeStatus.tpl
deleted file mode 100644 (file)
index b129b1f..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-{*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.6                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*}
-{* CiviCase - change activity status inline *}
-<div class="crm-block crm-form-block crm-case-activitychangestatus-form-block">
-  <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>
diff --git a/templates/CRM/Case/Form/ActivityChangeStatusJs.tpl b/templates/CRM/Case/Form/ActivityChangeStatusJs.tpl
deleted file mode 100644 (file)
index d1d57d9..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-{*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.6                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
-*}
-{* CiviCase - change activity status inline *}
-{literal}
-  <script type="text/javascript">
-    CRM.$(function($) {
-      // Elements are sometimes in a jQuery dialog box which is outside crm-container,
-      // So gotta attach this handler to the whole body - sorry.
-      $('body').off('click.changeActivityStatus');
-      $('body').on('click.changeActivityStatus', 'a.crm-activity-change-status', function() {
-        var link = $(this),
-          activityId = $(this).attr('activity_id'),
-          current_status_id = $(this).attr('current_status'),
-          caseId = $(this).attr('case_id'),
-          data = 'snippet=1&reset=1',
-          $el = $('<div class="crm-activity_change_status"></div>');
-        $el.block();
-
-        $el.load(CRM.url('civicrm/case/changeactivitystatus'), data, function() {
-          $el.unblock().trigger('crmLoad');
-          $("#activity_change_status").val(current_status_id);
-        });
-
-        CRM.confirm({
-          title: {/literal}'{ts escape='js'}Change Activity Status{/ts}'{literal},
-          message: $el
-        })
-          .on('crmConfirm:yes', function() {
-            // update the status
-            var status_id = $("#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;
-            var request = $.ajax({
-              type     : 'POST',
-              dataType : 'json',
-              url      : dataUrl,
-              data     : data,
-              success  : function(values) {
-                if (values.is_error) {
-                  CRM.alert(values.error_message, {/literal}'{ts escape='js'}Unable to change status{/ts}'{literal}, 'error');
-                  return false;
-                }
-                else {
-                  CRM.refreshParent(link);
-                }
-              },
-              error : function(jqXHR) {
-                CRM.alert(jqXHR.responseText, jqXHR.statusText, 'error');
-                return false;
-              }
-            });
-            CRM.status({}, request);
-          });
-        return false;
-      });
-    });
-  </script>
-{/literal}
index 90c8089b656a50ad6827abb0808872ae6d2df209..c77fc37177504d06f02045987db6dc73c72bad09 100644 (file)
@@ -31,7 +31,7 @@
   <div id="activities" class="crm-accordion-body">
     <div class="crm-accordion-wrapper crm-accordion-inner crm-search_filters-accordion collapsed">
       <div class="crm-accordion-header">
-        {ts}Search Filters{/ts}</a>
+        {ts}Search Filters{/ts}
       </div><!-- /.crm-accordion-header -->
       <div class="crm-accordion-body">
         <table class="no-border form-layout-compressed" id="searchOptions">
             </td>
             <td style="vertical-align: bottom;">
               {assign var=caseid value=$caseID}
-              <span class="crm-button"><input class="crm-form-submit default" name="_qf_Basic_refresh" value="Search" type="button" onclick="buildCaseActivities( true,{$caseid} )"; /></span>
+              <span class="crm-button crm-icon-button">
+                <span class="crm-button-icon ui-icon-check"></span>
+                <input class="crm-form-submit default" name="_qf_Basic_refresh" value="{ts}Search{/ts}" type="button" data-case-id="{$caseid}" />
+              </span>
             </td>
           </tr>
           <tr>
 {literal}
 <script type="text/javascript">
 CRM.$(function($) {
-  buildCaseActivities(false,{/literal}{$caseID}{literal});
-});
-
-function buildCaseActivities(filterSearch , CaseId) {
-  if (filterSearch) {
-    oTable.fnDestroy();
-  }
-  var count   = 0;
-  var columns = '';
-  var sourceUrl = {/literal}"{crmURL p='civicrm/ajax/activity' h=0 q='snippet=4&caseID='}"{literal}+CaseId;
-  sourceUrl = sourceUrl + '&cid={/literal}{$contactID}{literal}';
-  sourceUrl = sourceUrl + '&userID={/literal}{$userID}{literal}';
+  var CaseId = {/literal}{$caseID}{literal};
+  buildCaseActivities(false);
+  $('input.crm-form-submit[data-case-id=' + CaseId + ']').click(buildCaseActivities);
 
-  CRM.$('#case_id_'+CaseId+' th').each(function( ) {
-    if (CRM.$(this).attr('id') != 'nosort') {
-      columns += '{"sClass": "' + CRM.$(this).attr('class') +'"},';
-    }
-    else {
-      columns += '{ "bSortable": false },';
+  function buildCaseActivities(filterSearch) {
+    if (filterSearch) {
+      oTable.fnDestroy();
     }
-    count++;
-  });
+    var count = 0;
+    var columns = '';
+    var sourceUrl = {/literal}"{crmURL p='civicrm/ajax/activity' h=0 q='snippet=4&caseID='}"{literal}+CaseId;
+    sourceUrl = sourceUrl + '&cid={/literal}{$contactID}{literal}';
+    sourceUrl = sourceUrl + '&userID={/literal}{$userID}{literal}';
 
-  columns    = columns.substring(0, columns.length - 1 );
-  eval('columns =[' + columns + ']');
+    $('#case_id_'+CaseId+' th').each(function( ) {
+      if ($(this).attr('id') != 'nosort') {
+        columns += '{"sClass": "' + $(this).attr('class') +'"},';
+      }
+      else {
+        columns += '{ "bSortable": false },';
+      }
+      count++;
+    });
 
-  oTable = CRM.$('#case_id_'+CaseId).dataTable({
-    "bFilter"    : false,
-    "bAutoWidth" : false,
-    "aaSorting"  : [],
-    "aoColumns"  : columns,
-    "bProcessing": true,
-    "bJQueryUI": true,
-    "asStripClasses" : [ "odd-row", "even-row" ],
-    "sPaginationType": "full_numbers",
-    "sDom"       : '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>',
-    "bServerSide": true,
-    "sAjaxSource": sourceUrl,
-    "iDisplayLength": 10,
-    "bDestroy": true,
-    "fnDrawCallback": function() { setSelectorClass(CaseId); },
-    "fnServerData": function ( sSource, aoData, fnCallback ) {
+    columns = columns.substring(0, columns.length - 1 );
+    eval('columns =[' + columns + ']');
 
-      if ( filterSearch ) {
-        var activity_deleted = 0;
-        if ( CRM.$("#activity_deleted_"+CaseId+":checked").val() == 1 ) {
-          activity_deleted = 1;
+    oTable = $('#case_id_'+CaseId).dataTable({
+      "bFilter"    : false,
+      "bAutoWidth" : false,
+      "aaSorting"  : [],
+      "aoColumns"  : columns,
+      "bProcessing": true,
+      "bJQueryUI": true,
+      "asStripClasses" : [ "odd-row", "even-row" ],
+      "sPaginationType": "full_numbers",
+      "sDom"       : '<"crm-datatable-pager-top"lfp>rt<"crm-datatable-pager-bottom"ip>',
+      "bServerSide": true,
+      "sAjaxSource": sourceUrl,
+      "iDisplayLength": 10,
+      "bDestroy": true,
+      "fnDrawCallback": function() {
+        setSelectorClass();
+        setRowIds();
+        // FIXME: trigger crmLoad and crmEditable would happen automatically
+        $('.crm-editable', '#case_id_'+CaseId).crmEditable();
+      },
+      "fnServerData": function ( sSource, aoData, fnCallback ) {
+
+        if ( filterSearch ) {
+          var activity_deleted = 0;
+          if ( $("#activity_deleted_"+CaseId+":checked").val() == 1 ) {
+            activity_deleted = 1;
+          }
+          aoData.push(
+            {name:'status_id', value: $("select#status_id_"+CaseId).val()},
+            {name:'reporter_id', value: $("select#reporter_id_"+CaseId).val()},
+            {name:'activity_type_id', value: $("select#activity_type_filter_id_"+CaseId).val()},
+            {name:'activity_date_low', value: $("#activity_date_low_"+CaseId).val()},
+            {name:'activity_date_high', value: $("#activity_date_high_"+CaseId).val() },
+            {name:'activity_deleted', value: activity_deleted }
+          );
         }
-        aoData.push(
-          {name:'status_id', value: CRM.$("select#status_id_"+CaseId).val()},
-          {name:'reporter_id', value: CRM.$("select#reporter_id_"+CaseId).val()},
-          {name:'activity_type_id', value: CRM.$("select#activity_type_filter_id_"+CaseId).val()},
-          {name:'activity_date_low', value: CRM.$("#activity_date_low_"+CaseId).val()},
-          {name:'activity_date_high', value: CRM.$("#activity_date_high_"+CaseId).val() },
-          {name:'activity_deleted', value: activity_deleted }
-        );
+        $.ajax( {
+          "dataType": 'json',
+          "type": "POST",
+          "url": sSource,
+          "data": aoData,
+          "success": fnCallback
+        } );
       }
-      CRM.$.ajax( {
-        "dataType": 'json',
-        "type": "POST",
-        "url": sSource,
-        "data": aoData,
-        "success": fnCallback
-      } );
-    }
-  });
-}
+    });
+  }
 
-function setSelectorClass(CaseId) {
-  CRM.$("#case_id_"+CaseId+" td:last-child").each( function( ) {
-    CRM.$(this).parent().addClass(CRM.$(this).text() );
-  });
-}
+  function setRowIds() {
+    $("#case_id_"+CaseId+" tbody tr").each(function() {
+      var link, id;
+      link = $('a.action-item', this).attr('href');
+      if (link) {
+        id = link.match(/&id=(\d+)/);
+      }
+      if (id) {
+        $(this)
+          .addClass('crm-entity')
+          .data('entity', 'activity')
+          .data('id', id[1]);
+      }
+    });
+  }
+
+  function setSelectorClass() {
+    $("#case_id_"+CaseId+" td:last-child").each(function() {
+      $(this).parent().addClass($(this).text());
+    });
+  }
+});
 </script>
 {/literal}
index 48add0ae57d6d18840868f051f1401420a72dad8..78d72865fd805f3b4ace1db5f88c966c0ceba326 100644 (file)
 {include file="CRM/Case/Form/ActivityTab.tpl"}
 
 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
-
-  {include file="CRM/Case/Form/ActivityChangeStatusJs.tpl"}
 {/if} {* view related cases if end *}
 </div>
 
index 5adf01ca2163a2476dc3b60e3797bcd764e0d1b0..aa1161a8eb734539cad56b1409c4b2ba15c42569 100644 (file)
@@ -81,5 +81,3 @@
 </div>
 {/if}
 {/if}
-
-{include file="CRM/Case/Form/ActivityChangeStatusJs.tpl"}
index 9af31c0b7deb697e90408d17448702912625f921..89a6ec9bb46aba939c9b5e009571228e8a9bdc1e 100644 (file)
@@ -38,7 +38,7 @@
 
     {counter start=0 skip=1 print=false}
     {foreach from=$rows item=row}
-    <tr class="{$row.class}">
+    <tr class="crm-entity {$row.class}" data-entity="activity" data-id="{$row.id}">
       <td class="crm-case-display_date">{$row.display_date}</td>
       <td class="crm-case-subject">{$row.subject}</td>
       <td class="crm-case-type">{$row.type}</td>
index 42f8d5326a0b285d287029b21ca5875570974b2a..1893c2ed593ecd7c3b5220c792cb082d3d107678 100644 (file)
     {/if}
 {/if}
 </div>
-
-{include file="CRM/Case/Form/ActivityChangeStatusJs.tpl"}
index 3dddbdd597210c732d06fa82310834b66ed4e0ae..3b4329e4650cc9a7328761dbac528a4654002557 100644 (file)
 <script type="text/javascript">
 function {/literal}{$context}{$list}{literal}CaseDetails( caseId, contactId, type, context )
 {
-    var dataUrl = {/literal}"{crmURL p='civicrm/case/details' h=0 q='snippet=4&caseId='}{literal}" + caseId +'&cid=' + contactId + '&type=' + type;
-    cj.ajax({
-            url     : dataUrl,
-            dataType: "html",
-            timeout : 5000, //Time in milliseconds
-            success : function( data ){
-                  cj( '#'+ context + '-' + type +'-casedetails-' + caseId ).html( data );
-                      },
-            error   : function( XMLHttpRequest, textStatus, errorThrown ) {
-                        CRM.console('error', 'Error: ', textStatus);
-                      }
-         });
+    var dataUrl = CRM.url('civicrm/case/details', {caseId: caseId, cid: contactId, type: type});
+    CRM.loadPage(dataUrl, {target: '#'+ context + '-' + type +'-casedetails-' + caseId});
 }
 
 function showCaseActivities( caseId, type, context ) {
@@ -146,5 +136,3 @@ function hideCaseActivities( caseId , type, context ) {
 
 </script>
 {/literal}
-
-{include file="CRM/Case/Form/ActivityChangeStatusJs.tpl"}
index 91ed78ca9836034443fcbd601cfdcf0e0529ed6a..d3bd158ef1099f9c9b99d91b953593b159dcad5f 100644 (file)
@@ -66,7 +66,6 @@
 
     {if $rows}
           {include file="CRM/Case/Form/Selector.tpl"}
-          {include file="CRM/Case/Form/ActivityChangeStatusJs.tpl"}
     {else}
        <div class="messages status no-popup">
           <div class="icon inform-icon"></div>