CRM-14015 CRM-13863 - Fix enable/disable and crmEditable to work with groups datatable
authorColeman Watts <coleman@civicrm.org>
Tue, 24 Dec 2013 23:56:37 +0000 (15:56 -0800)
committerColeman Watts <coleman@civicrm.org>
Mon, 6 Jan 2014 19:10:41 +0000 (11:10 -0800)
CRM/Contact/BAO/Group.php
css/civicrm.css
js/jquery/jquery.crmeditable.js
templates/CRM/Admin/Page/ContactType.tpl
templates/CRM/Admin/Page/Options.tpl
templates/CRM/Badge/Page/Layout.tpl
templates/CRM/Financial/Page/FinancialAccount.tpl
templates/CRM/Financial/Page/FinancialType.tpl
templates/CRM/Group/Form/Search.tpl
templates/CRM/common/enableDisableApi.tpl

index da200837d4bfae24b09221a5d2c16d1dc8662c98..5fd0259a8923868a413a4b93c1493511c544b385 100644 (file)
@@ -701,7 +701,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
       foreach ($groups as $id => $value) {
         $groupList[$id]['group_id'] = $value['id'];
         $groupList[$id]['group_name'] = $value['title'];
-        $groupList[$id]['class'] = $value['class'];
+        $groupList[$id]['class'] = implode(' ', $value['class']);
 
         // append parent names if in search mode
         if ( !CRM_Utils_Array::value('parent_id', $params) &&
@@ -712,7 +712,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
             $title[] = $allGroups[$gId];
           }
           $groupList[$id]['group_name'] .= '<div class="crm-row-parent-name"><em>'.ts('Child of').'</em>: ' . implode(', ', $title) . '</div>';
-          $groupList[$id]['class'] = '';
+          $groupList[$id]['class'] = in_array('disabled', $value['class']) ? 'disabled' : '';
         }
 
         $groupList[$id]['group_description'] = CRM_Utils_Array::value('description', $value);
@@ -813,7 +813,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
 
       if ($permission) {
         $newLinks = $links;
-        $values[$object->id] = array();
+        $values[$object->id] = array('class' => array());
         CRM_Core_DAO::storeValues($object, $values[$object->id]);
         if ($object->saved_search_id) {
           $values[$object->id]['title'] .= ' (' . ts('Smart Group') . ')';
@@ -842,13 +842,12 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
           }
         }
 
-        $values[$object->id]['class'] = '';
         if (array_key_exists('is_active', $object)) {
           if ($object->is_active) {
             $action -= CRM_Core_Action::ENABLE;
           }
           else {
-            $values[$object->id]['class'] = 'disabled';
+            $values[$object->id]['class'][] = 'disabled';
             $action -= CRM_Core_Action::VIEW;
             $action -= CRM_Core_Action::DISABLE;
           }
@@ -885,18 +884,13 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
         // If group has children, add class for link to view children
         $values[$object->id]['is_parent'] = false;
         if (array_key_exists('children', $values[$object->id])) {
-          $values[$object->id]['class'] = "crm-group-parent";
+          $values[$object->id]['class'][] = "crm-group-parent";
           $values[$object->id]['is_parent'] = true;
         }
 
         // If group is a child, add child class
         if (array_key_exists('parents', $values[$object->id])) {
-          $values[$object->id]['class'] = "crm-group-child";
-        }
-
-        if (array_key_exists('children', $values[$object->id])
-        && array_key_exists('parents', $values[$object->id])) {
-          $values[$object->id]['class'] = "crm-group-child crm-group-parent";
+          $values[$object->id]['class'][] = "crm-group-child";
         }
 
         if ($groupOrg) {
index 58bc42cb18ed9446153f116fc100d5a7b50c4c50..e2381bf1557675f51fe60717b28df9303296ab05 100644 (file)
@@ -4017,19 +4017,30 @@ div.m ul#civicrm-menu,
 }
 
 /* in place edit  */
-.crm-container .crm-editable-enabled,
-.crm-container .crm-editable-textarea-enabled {
+.crm-container .crm-editable-enabled {
   white-space: nowrap;
-  display: block;
+  padding-left: 2px;
+  border: 2px dashed transparent;
+}
+.crm-container .crm-editable-textarea-enabled {
   padding-left: 2px;
   border: 2px dashed transparent;
 }
 
-.crm-container .crm-editable-enabled:hover {
+.crm-container .crm-editable-enabled:hover,
+.crm-container .crm-editable-textarea-enabled:hover {
   border: 2px dashed lightgrey;
   cursor: pointer;
 }
 
+.crm-container span.crm-editable-textarea-enabled {
+  display: inline-block !important;
+  width: 96%;
+}
+.crm-container span.crm-editable-enabled {
+  display: inline-block !important;
+}
+
 .crm-container .crm-editable-placeholder {
   background: url("../i/icons/jquery-ui-2786C2.png") -66px -114px no-repeat;
   text-indent: -10000px;
@@ -4051,9 +4062,8 @@ div.m ul#civicrm-menu,
 .crm-container h2.crm-editable-enabled input {
   min-height: 1.4em;
 }
-
-.crm-container td.crm-editable {
-  display: table-cell !important;
+.crm-container .crm-editable-textarea-enabled textarea {
+  min-height: 5em;
 }
 
 /*crm-10345*/
@@ -4081,6 +4091,9 @@ div.m ul#civicrm-menu,
   padding-left: 60px;
   text-indent: -20px;
 }
+#crm-container .crm-group-name span.crm-editable-enabled {
+  text-indent: 0;
+}
 
 #crm-container div.crm-row-parent-name {
   padding: 3px 0px 0px .5em;
index 1c37cbd592617ac39bdd5717922125ab5d33c2af..3c1bf0fb1faf4afbdef288fc41793552a380b083 100644 (file)
       el = this[0],
       ret = {},
       $row = this.first().closest('.crm-entity');
-    ret.entity = $row.data('entity');
-    ret.id = $row.data('id');
-    if (!ret.entity || !ret.id) {
-      ret.entity = $row[0].id.split('-')[0];
-      ret.id = $row[0].id.split('-')[1];
-    }
+    ret.entity = $row.data('entity') || $row[0].id.split('-')[0];
+    ret.id = $row.data('id') || $row[0].id.split('-')[1];
     if (!ret.entity || !ret.id) {
       return false;
     }
index 322034284327f6a087e1099bd932ed8e7012c4c5..79c5284a9a9aaa3f4d6c23fceb99289816cbc0cc 100644 (file)
@@ -51,7 +51,7 @@
       <tr id="contact_type-{$row.id}" class="{cycle values="odd-row,even-row"} {$row.class} crm-contactType crm-entity {if NOT $row.is_active} disabled{/if}">
         <td class="crm-contactType-label crm-editable" data-field="label">{ts}{$row.label}{/ts}</td>
         <td class="crm-contactType-parent">{if $row.parent}{ts}{$row.parent_label}{/ts}{else}{ts}(built-in){/ts}{/if}</td>
-        <td class="crm-contactType-description crm-editable" data-field="description">{$row.description}</td>
+        <td class="crm-contactType-description crm-editable" data-field="description" data-type="textarea">{$row.description}</td>
         <td>{$row.action|replace:'xx':$row.id}</td>
     </tr>
     {/foreach}
index e15baf77850f3867877a5bc758582029a2331d61..8deb1527350f73bacedd36a726b661167a4feb48 100644 (file)
               <td class="yes-no crm-admin-options-filter">{if $row.filter eq 1}<img src="{$config->resourceBase}i/check.gif" alt="{ts}Counted{/ts}" />{/if}</td>
             {/if}
             {if $showVisibility}<td class="crm-admin-visibility_label">{$row.visibility_label}</td>{/if}
-            <td class="crm-admin-options-description crm-editable" data-field="description" data-action="create">{$row.description}</td>
+            <td class="crm-admin-options-description crm-editable" data-field="description" data-type="textarea">{$row.description}</td>
             <td class="nowrap crm-admin-options-order">{$row.order}</td>
             {if $showIsDefault}
               <td class="crm-admin-options-is_default" align="center">{if $row.is_default eq 1}<img src="{$config->resourceBase}i/check.gif" alt="{ts}Default{/ts}" />{/if}&nbsp;</td>
index c1e56484993b0116953f2e9e337ba7f69a7dcf9f..4aaaa99f1e82c7ab6d9e444bcf20f7de9101feee 100644 (file)
@@ -51,7 +51,7 @@
           {foreach from=$rows item=row}
             <tr id="print_label-{$row.id}" class="crm-entity {cycle values="odd-row,even-row"} {$row.class} crm-badge-layout {if NOT $row.is_active} disabled{/if}">
               <td class="crm-badge-layout-title crm-editable" data-field="title">{$row.title}</td>
-              <td class="crm-badge-layout-description crm-editable" data-field="description">{$row.description}</td>
+              <td class="crm-badge-layout-description crm-editable" data-field="description" data-type="textarea">{$row.description}</td>
               <td id="row_{$row.id}_status" class="crm-badge-layout-is_active">
                 {if $row.is_active eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}
               </td>
index 421130bd806ef7df3f6007571fa9f00453fb139b..22d60f19258398c6f29534727d2e32659bf30208 100644 (file)
@@ -62,7 +62,7 @@
         {foreach from=$rows item=row}
         <tr id="financial_account-{$row.id}" class="crm-entity {cycle values="odd-row,even-row"} {$row.class}{if NOT $row.is_active} disabled{/if}">
         <td class="crm-editable" data-field="name">{$row.name}</td>
-        <td class="crm-editable" data-field="description">{$row.description}</td>
+        <td class="crm-editable" data-field="description" data-type="textarea">{$row.description}</td>
         <td class="crm-editable" data-field="accounting_code">{$row.accounting_code}</td>
         <td>{$row.financial_account_type_id}{if $row.account_type_code} ({$row.account_type_code}){/if}</td>
         <td>{if $row.is_deductible eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}</td>
index 64879a4da6d532215a1e381479b2d88c51c16d25..a8232871f7f92a7af836e4df9055f63df7675a5c 100644 (file)
@@ -55,7 +55,7 @@
          {foreach from=$rows item=row}
         <tr id="financial_type-{$row.id}" class="crm-entity {cycle values="odd-row,even-row"} {$row.class}{if NOT $row.is_active} disabled{/if}">
           <td class="crm-editable" data-field="name">{$row.name}</td>
-          <td class="crm-editable" data-field="description">{$row.description}</td>
+          <td class="crm-editable" data-field="description" data-type="textarea">{$row.description}</td>
      <td>{$row.financial_account}</td>
           <td>{if $row.is_deductible eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}</td>
           <td>{if $row.is_reserved eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if}</td>
index af6a6e6b532639ebd27e670e79fd5eb7f2deb025..1bd20864837c931681c923af6ff5a66979fe5a63 100644 (file)
 
 {literal}
 <script type="text/javascript">
-cj( function() {
+cj(function($) {
   // for CRM-11310 and CRM-10635 : processing just parent groups on initial display
   // passing '1' for parentsOnlyArg to show parent child heirarchy structure display
   // on initial load of manage group page and
   // also to handle search filtering for initial load of same page.
   buildGroupSelector(true, 1);
-  cj('#_qf_Search_refresh').click( function() {
+  $('#_qf_Search_refresh').click( function() {
     buildGroupSelector( true );
   });
+  // Add livePage functionality
+  $('#crm-container').on('click', 'a.button, a.action-item[href*="action=update"], a.action-item[href*="action=delete"]', function() {
+    CRM.loadForm($(this).attr('href'), {
+      openInline: 'a:not([href="#"])'
+    }).on('crmFormSuccess', function(e, data) {
+        // Refresh datatable when form completes
+        $('#crm-group-selector').dataTable().fnDraw();
+      });
+    return false;
+  });
 });
 
 function buildGroupSelector( filterSearch, parentsOnlyArg ) {
@@ -162,7 +172,17 @@ function buildGroupSelector( filterSearch, parentsOnlyArg ) {
                             "sLast":     {/literal}"{ts escape='js'}Last{/ts}"{literal}
                         }
                     },
-        "fnDrawCallback": function() { setSelectorClass( parentsOnly, showOrgInfo ); },
+        "fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
+          var id = cj('td:eq(1)', nRow).text();
+          cj(nRow).addClass('crm-entity').attr('data-entity', 'group').attr('data-id', id);
+          cj('td:eq(0)', nRow).wrapInner('<span class="crm-editable crmf-name" />');
+          cj('td:eq(3)', nRow).wrapInner('<span class="crm-editable crmf-description" data-type="textarea" />');
+          return nRow;
+        },
+        "fnDrawCallback": function() {
+          setSelectorClass( parentsOnly, showOrgInfo );
+          cj('.crm-editable').crmEditable();
+        },
         "fnServerData": function ( sSource, aoData, fnCallback ) {
             aoData.push( {name:'showOrgInfo', value: showOrgInfo },
                          {name:'parentsOnly', value: parentsOnly }
@@ -274,26 +294,23 @@ function showChildren( parent_id, showOrgInfo, group_id, levelClass) {
         "success": function(response){
           var appendHTML = '';
           cj.each( response, function( i, val ) {
-            appendHTML += '<tr id="row_'+ val.group_id +'_'+parent_id+'" class="parent_is_' + parent_id + ' crm-row-child ' + val.class + '">';
+            appendHTML += '<tr id="row_'+ val.group_id +'_'+parent_id+'" data-entity="group" data-id="'+ val.group_id +'" class="crm-entity parent_is_' + parent_id + ' crm-row-child ' + val.class + '">';
             if ( val.is_parent ) {
-              appendHTML += '<td class="crm-group-name ' + levelClass + '">' + '{/literal}<span class="collapsed show-children" title="{ts}show child groups{/ts}"/></span>{literal}' + val.group_name + '</td>';
+              appendHTML += '<td class="crm-group-name ' + levelClass + '">' + '{/literal}<span class="collapsed show-children" title="{ts}show child groups{/ts}"/></span>{literal}<span class="crm-editable crmf-name">' + val.group_name + '</span></td>';
             }
             else {
-              appendHTML += '<td class="crm-group-name ' + levelClass + '"><span class="crm-no-children"></span>' + val.group_name + '</td>';
+              appendHTML += '<td class="crm-group-name ' + levelClass + '"><span class="crm-no-children"></span><span class="crm-editable crmf-name">' + val.group_name + '</span></td>';
             }
             appendHTML += "<td>" + val.group_id + "</td>";
             appendHTML += "<td>" + val.created_by + "</td>";
-            if (val.group_description) {
-              appendHTML += "<td>" + val.group_description + "</td>";
-            } else {
-              appendHTML += "<td>&nbsp;</td>";
-            }
+            appendHTML += '<td><span class="crm-editable crmf-description" data-type="textarea">' + (val.group_description || '') + "</span></td>";
             appendHTML += "<td>" + val.group_type + "</td>";
             appendHTML += "<td>" + val.visibility + "</td>";
             appendHTML += "<td>" + val.links + "</td>";
             appendHTML += "</tr>";
           });
           cj( rowID ).after( appendHTML );
+          cj('.crm-editable').crmEditable();
         }
     } );
   }
index 63e355d523a7cabae376d879b4e1083437e76c9b..63beb1fdcc9cdfeebabb7b3367402d0f9e74e8e1 100644 (file)
     var $row, $table, info, enabled, fieldLabel;
 
     function refresh() {
-      if (false && $.fn.DataTable.fnIsDataTable($table[0])) { // fixme why doesn't this work?
-        $table.dataTable().fnDraw();
-      } else {
-        // Refresh an existing ajax container or create a new one
+      // Call native refresh method on ajax datatables
+      if ($.fn.DataTable.fnIsDataTable($table[0]) && $table.dataTable().fnSettings().sAjaxSource) {
+        $table.unblock().dataTable().fnDraw();
+      }
+      // Otherwise refresh the content area using crmSnippet
+      else {
         $row.closest('.crm-ajax-container, #crm-main-content-wrapper').crmSnippet().crmSnippet('refresh');
       }
       {/literal} {* client-side variable substitutions in smarty are AWKWARD! *}