CRM-17620 - Cleanup and abstract expandRow js
authorColeman Watts <coleman@civicrm.org>
Thu, 3 Dec 2015 01:34:21 +0000 (20:34 -0500)
committerColeman Watts <coleman@civicrm.org>
Thu, 3 Dec 2015 01:34:21 +0000 (20:34 -0500)
css/civicrm.css
js/crm.expandRow.js [new file with mode: 0644]
templates/CRM/Contribute/Form/Selector.tpl
templates/CRM/common/expandRow.tpl [deleted file]

index 98389b4af7dbdd8223eb86c9436c1724b4166cc0..3b2e1b254b9529b89f9f57ae6c1a234e3b64c2d9 100644 (file)
@@ -2245,9 +2245,17 @@ div.crm-master-accordion-header a.helpicon {
   display: none;
 }
 
+.crm-container .crm-expand-row {
+  width: 16px;
+  height: 16px;
+  display: inline-block;
+  background-image: url("../i/TreePlus.gif");
+}
+
 .crm-container .crm-accordion-inner .crm-accordion-header,
 .crm-container .crm-accordion-wrapper .crm-master-accordion-header,
-.crm-container .crm-collapsible .collapsible-title {
+.crm-container .crm-collapsible .collapsible-title,
+.crm-container .crm-expand-row.expanded {
   background-image: url("../i/TreeMinus.gif");
   background-color: transparent;
   color: #3E3E3E;
diff --git a/js/crm.expandRow.js b/js/crm.expandRow.js
new file mode 100644 (file)
index 0000000..de0f410
--- /dev/null
@@ -0,0 +1,18 @@
+// http://civicrm.org/licensing
+CRM.$(function($) {
+  $('body')
+    .off('.crmExpandRow')
+    .on('click.crmExpandRow', 'a.crm-expand-row', function(e) {
+      var $row = $(this).closest('tr');
+      if ($(this).hasClass('expanded')) {
+        $row.next('.crm-child-row').remove();
+      } else {
+        var count = $('td', $row).length,
+          $newRow = $('<tr class="crm-child-row"><td colspan="' + count + '"></td></tr>')
+            .insertAfter($row);
+        CRM.loadPage(this.href, {target: $('td', $newRow.animate({height: '3em'}, 'fast'))});
+      }
+      $(this).toggleClass('expanded');
+      e.preventDefault();
+    });
+});
index f7dddb6c18ea2b29167b9aa75ba12a4e6f5778cc..02642415042a288a452a45caf30c6c4831fb2cf9 100644 (file)
@@ -65,8 +65,9 @@
     <td>{$row.contact_type}</td>
       <td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contact_id`"}">{$row.sort_name}</a></td>
     {/if}
-    {assign var="targetRowID" value="paymentDetails"|cat:$row.contribution_id}
-    {include file='CRM/common/expandRow.tpl' rowEntityID=$row.contribution_id rowEntity='contribution' targetRowID=$targetRowID baseUrl='payment'}
+    <td>
+      <a class="crm-expand-row" href="{crmURL p='civicrm/payment' q="view=transaction&component=contribution&action=browse&cid=`$row.contact_id`&id=`$row.contribution_id`&selector=1"}"></a>
+    </td>
     {if $row.contribution_soft_credit_amount}
       <td class="right bold crm-contribution-amount">&nbsp;</td>
     {else}
     {/if}
     <td>{$row.action|replace:'xx':$row.contribution_id}</td>
   </tr>
-    <tr id="{$targetRowID}_row" class='{$rowClass} hiddenElement'>
-      <td style="border-right: none;"></td>
-      <td colspan= {if $context EQ 'Search'} "10" {else} "8" {/if} class="enclosingNested" id="{$targetRowID}">&nbsp;</td>
-    </tr>
   {/foreach}
 
 </table>
 {/strip}
 
 {include file="CRM/common/pager.tpl" location="bottom"}
+{crmScript ext='civicrm' file='js/crm.expandRow.js'}
 
diff --git a/templates/CRM/common/expandRow.tpl b/templates/CRM/common/expandRow.tpl
deleted file mode 100644 (file)
index e352bfc..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
- <td>
-    <span id="icon_{$targetRowID}_show" title="{ts}Show payments{/ts}">
-      <a href="#" data-entity_id='{$rowEntityID}' data-base_url="{$baseUrl}"
-         data-contact_id='{$row.contact_id}' data-entity='{$rowEntity}' data-target_row='{$targetRowID}'
-         onclick="subDetails(this);
-          showSubDetails(this);
-          return false;">
-        <img src="{$config->resourceBase}i/TreePlus.gif" class="action-icon" alt="{ts}open section{/ts}"/>
-      </a>
-    </span>
-    <span id="icon_{$targetRowID}_hide" class="hiddenElement">
-        <a data-entity_id='{$rowEntityID}' href="#"  data-contact_id='{$row.contact_id}' data-entity='{$rowEntity}' data-target_row='{$targetRowID}'
-           href="#" onclick="hideSubDetails(this);
-          return false;"><img src="{$config->resourceBase}i/TreeMinus.gif" class="action-icon" alt="{ts}open section{/ts}"/>
-        </a>
-    </span>
-  </td>
-
-  {literal}
-  <script type="text/javascript">
-      function subDetails(element) {
-        var entityId = cj(element).data('entity_id');
-        var targetRow = cj(element).data('target_row');
-        var rowElement = cj('#' + targetRow);
-        var contactId = cj(element).data('contact_id');
-        var entity = cj(element).data('entity');
-        var baseURL = 'civicrm/' + cj(element).data('base_url');
-        var dataUrl = CRM.url(baseURL, {
-          'view': 'transaction',
-          'component': entity,
-          'action': 'browse',
-          'cid': contactId,
-          'id': entityId,
-          'selector' : 1,
-        });
-        CRM.loadPage(dataUrl, {'target': rowElement});
-      }
-
-      function showSubDetails(element) {
-        var targetRow = cj(element).data('target_row');
-        cj('#' + targetRow + '_row').show();
-        cj('#icon_' + targetRow + '_show').hide();
-        cj('#icon_' + targetRow + '_hide').show();
-      }
-
-      function hideSubDetails(element) {
-        var targetRow = cj(element).data('target_row');
-        cj('#' + targetRow + '_row').hide();
-        cj('#icon_' + targetRow + '_show').show();
-        cj('#icon_' + targetRow + '_hide').hide();
-      }
-
-  </script>
-{/literal}