CRM-12872 - Fine-tune popup links on search forms
authorColeman Watts <coleman@civicrm.org>
Thu, 9 Jan 2014 02:16:42 +0000 (18:16 -0800)
committerColeman Watts <coleman@civicrm.org>
Thu, 9 Jan 2014 02:18:13 +0000 (18:18 -0800)
CRM/Contact/BAO/Contact.php
CRM/Contact/Form/Search.php
CRM/Contact/Selector.php
js/crm.livePage.js
templates/CRM/Activity/Form/ActivityLinks.tpl
templates/CRM/Contact/Page/Inline/Actions.tpl
templates/CRM/Contact/Page/View/Summary.js
templates/CRM/Tag/Form/Tag.tpl
templates/CRM/common/TabHeader.js

index 18f240f80ffd98ce69389b1f4fac67ddd5c8de79..f34b6e378d260211575bd789fc522d80e015366c 100644 (file)
@@ -2707,28 +2707,35 @@ AND       civicrm_openid.is_primary = 1";
    */
   static function contextMenu($contactId = NULL) {
     $menu = array(
-      'view' => array('title' => ts('View Contact'),
+      'view' => array(
+        'title' => ts('View Contact'),
         'weight' => 0,
         'ref' => 'view-contact',
+        'class' => 'no-popup',
         'key' => 'view',
         'permissions' => array('view all contacts'),
       ),
-      'add' => array('title' => ts('Edit Contact'),
+      'add' => array(
+        'title' => ts('Edit Contact'),
         'weight' => 0,
         'ref' => 'edit-contact',
+        'class' => 'no-popup',
         'key' => 'add',
         'permissions' => array('edit all contacts'),
       ),
-      'delete' => array('title' => ts('Delete Contact'),
+      'delete' => array(
+        'title' => ts('Delete Contact'),
         'weight' => 0,
         'ref' => 'delete-contact',
         'key' => 'delete',
         'permissions' => array('access deleted contacts', 'delete contacts'),
       ),
-      'contribute' => array('title' => ts('Add Contribution'),
+      'contribution' => array(
+        'title' => ts('Add Contribution'),
         'weight' => 5,
         'ref' => 'new-contribution',
-        'key' => 'contribute',
+        'key' => 'contribution',
+        'tab' => 'contribute',
         'component' => 'CiviContribute',
         'href' => CRM_Utils_System::url('civicrm/contact/view/contribution',
           'reset=1&action=add&context=contribution'
@@ -2738,10 +2745,12 @@ AND       civicrm_openid.is_primary = 1";
           'edit contributions',
         ),
       ),
-      'participant' => array('title' => ts('Register for Event'),
+      'participant' => array(
+        'title' => ts('Register for Event'),
         'weight' => 10,
         'ref' => 'new-participant',
         'key' => 'participant',
+        'tab' => 'participant',
         'component' => 'CiviEvent',
         'href' => CRM_Utils_System::url('civicrm/contact/view/participant', 'reset=1&action=add&context=participant'),
         'permissions' => array(
@@ -2749,16 +2758,20 @@ AND       civicrm_openid.is_primary = 1";
           'edit event participants',
         ),
       ),
-      'activity' => array('title' => ts('Record Activity'),
+      'activity' => array(
+        'title' => ts('Record Activity'),
         'weight' => 35,
         'ref' => 'new-activity',
         'key' => 'activity',
+        'tab' => 'activity',
         'permissions' => array('edit all contacts'),
       ),
-      'pledge' => array('title' => ts('Add Pledge'),
+      'pledge' => array(
+        'title' => ts('Add Pledge'),
         'weight' => 15,
         'ref' => 'new-pledge',
         'key' => 'pledge',
+        'tab' => 'pledge',
         'href' => CRM_Utils_System::url('civicrm/contact/view/pledge',
           'reset=1&action=add&context=pledge'
         ),
@@ -2768,10 +2781,12 @@ AND       civicrm_openid.is_primary = 1";
           'edit pledges',
         ),
       ),
-      'member' => array('title' => ts('Add Membership'),
+      'membership' => array(
+        'title' => ts('Add Membership'),
         'weight' => 20,
         'ref' => 'new-membership',
-        'key' => 'member',
+        'key' => 'membership',
+        'tab' => 'member',
         'component' => 'CiviMember',
         'href' => CRM_Utils_System::url('civicrm/contact/view/membership',
           'reset=1&action=add&context=membership'
@@ -2781,58 +2796,71 @@ AND       civicrm_openid.is_primary = 1";
           'edit memberships',
         ),
       ),
-      'case' => array('title' => ts('Add Case'),
+      'case' => array(
+        'title' => ts('Add Case'),
         'weight' => 25,
         'ref' => 'new-case',
         'key' => 'case',
+        'tab' => 'case',
         'component' => 'CiviCase',
         'href' => CRM_Utils_System::url('civicrm/case/add', 'reset=1&action=add&context=case'),
         'permissions' => array('add cases'),
       ),
-      'grant' => array('title' => ts('Add Grant'),
+      'grant' => array(
+        'title' => ts('Add Grant'),
         'weight' => 26,
         'ref' => 'new-grant',
         'key' => 'grant',
+        'tab' => 'grant',
         'component' => 'CiviGrant',
         'href' => CRM_Utils_System::url('civicrm/contact/view/grant',
           'reset=1&action=add&context=grant'
         ),
         'permissions' => array('edit grants'),
       ),
-      'rel' => array('title' => ts('Add Relationship'),
+      'rel' => array(
+        'title' => ts('Add Relationship'),
         'weight' => 30,
         'ref' => 'new-relationship',
         'key' => 'rel',
+        'tab' => 'rel',
         'href' => CRM_Utils_System::url('civicrm/contact/view/rel',
           'reset=1&action=add'
         ),
         'permissions' => array('edit all contacts'),
       ),
-      'note' => array('title' => ts('Add Note'),
+      'note' => array(
+        'title' => ts('Add Note'),
         'weight' => 40,
         'ref' => 'new-note',
         'key' => 'note',
+        'tab' => 'note',
         'href' => CRM_Utils_System::url('civicrm/contact/view/note',
           'reset=1&action=add'
         ),
         'permissions' => array('edit all contacts'),
       ),
-      'email' => array('title' => ts('Send an Email'),
+      'email' => array(
+        'title' => ts('Send an Email'),
         'weight' => 45,
         'ref' => 'new-email',
         'key' => 'email',
         'permissions' => array('view all contacts'),
       ),
-      'group' => array('title' => ts('Add to Group'),
+      'group' => array(
+        'title' => ts('Add to Group'),
         'weight' => 50,
         'ref' => 'group-add-contact',
         'key' => 'group',
+        'tab' => 'group',
         'permissions' => array('edit groups'),
       ),
-      'tag' => array('title' => ts('Tag'),
+      'tag' => array(
+        'title' => ts('Tag Contact'),
         'weight' => 55,
         'ref' => 'tag-contact',
         'key' => 'tag',
+        'tab' => 'tag',
         'permissions' => array('edit all contacts'),
       ),
     );
@@ -2907,6 +2935,7 @@ AND       civicrm_openid.is_primary = 1";
         $contextMenu['primaryActions'][$key] = array(
           'title' => $values['title'],
           'ref' => $values['ref'],
+          'class' => CRM_Utils_Array::value('class', $values),
           'key' => $values['key'],
         );
         continue;
@@ -2917,6 +2946,8 @@ AND       civicrm_openid.is_primary = 1";
         'title' => $values['title'],
         'ref' => $values['ref'],
         'href' => CRM_Utils_Array::value('href', $values),
+        'tab' => CRM_Utils_Array::value('tab', $values),
+        'class' => CRM_Utils_Array::value('class', $values),
         'key' => $values['key'],
       );
     }
index 43d2de41a473e39c412ee439d468fa7a54223ac6..c0f2839b31899fca181e19a6ce0845ccd56ee0dd 100644 (file)
@@ -379,7 +379,11 @@ class CRM_Contact_Form_Search extends CRM_Core_Form {
    * @return void
    */
   function buildQuickForm() {
-    CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
+    CRM_Core_Resources::singleton()
+      ->addScriptFile('civicrm', 'js/crm.livePage.js')
+      // jsTree is needed for tags popup
+      ->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)
+      ->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header');
     $permission = CRM_Core_Permission::getPermission();
     // some tasks.. what do we want to do with the selected contacts ?
     $tasks = array('' => ts('- actions -'));
index f3523ffe92f274c56801d5e2fee429ec09efd18f..af660d03a508dc8843c428e894011b271ad49267 100644 (file)
@@ -236,6 +236,7 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se
         CRM_Core_Action::VIEW => array(
           'name' => ts('View'),
           'url' => 'civicrm/contact/view',
+          'class' => 'no-popup',
           'qs' => "reset=1&cid=%%id%%{$searchContext}{$extraParams}",
           'title' => ts('View Contact Details'),
           'ref' => 'view-contact',
@@ -243,6 +244,7 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se
         CRM_Core_Action::UPDATE => array(
           'name' => ts('Edit'),
           'url' => 'civicrm/contact/add',
+          'class' => 'no-popup',
           'qs' => "reset=1&action=update&cid=%%id%%{$searchContext}{$extraParams}",
           'title' => ts('Edit Contact Details'),
           'ref' => 'edit-contact',
@@ -267,7 +269,6 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se
           if ($value['key'] == 'delete') {
             $contextVal = $searchContext;
           }
-
           $url = "civicrm/contact/view/{$value['key']}";
           $qs = "reset=1&action=add&cid=%%id%%{$contextVal}{$extraParams}";
           if ($value['key'] == 'activity') {
@@ -284,6 +285,7 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se
             'qs' => $qs,
             'title' => $value['title'],
             'ref' => $value['ref'],
+            'class' => CRM_Utils_Array::value('class', $value),
           );
         }
       }
@@ -714,6 +716,7 @@ class CRM_Contact_Selector extends CRM_Core_Selector_Base implements CRM_Core_Se
               'name' => ts('View'),
               'url' => 'civicrm/contact/view',
               'qs' => 'reset=1&cid=%%id%%',
+              'class' => 'no-popup',
               'title' => ts('View Contact Details'),
             ),
             array(
index 4d241ef88e8505ee21dfa7ec0ba88732460fcd18..9ee6d03c4ce5b39c78c79f23948b1699a93ea978 100644 (file)
@@ -7,12 +7,21 @@ cj(function($) {
     // Open action links in a popup
     .off('click.crmLivePage')
     .on('click.crmLivePage', 'a.button, a.action-item', function() {
+      var
+        dialogSettings = {},
+        url = $(this).attr('href');
       // only follow real links not javascript buttons
-      if ($(this).attr('href') === '#' || $(this).attr('onclick') || $(this).hasClass('no-popup')) {
+      if (url === '#' || $(this).attr('onclick') || $(this).hasClass('no-popup')) {
         return;
       }
-      CRM.loadForm($(this).attr('href'), {
-        openInline: 'a:not("[href=#], .no-popup")'
+      // Hack to make delete dialogs smaller
+      if (url.indexOf('/delete') > 0 || url.indexOf('action=delete') > 0) {
+        dialogSettings.width = 400;
+        dialogSettings.height = 300;
+      }
+      CRM.loadForm(url, {
+        openInline: 'a:not("[href=#], .no-popup")',
+        dialog: dialogSettings
       }).on('crmFormSuccess', function(e, data) {
         // Refresh page when form completes
         $('#crm-main-content-wrapper').crmSnippet('refresh');
index d4169814962e838e4826cab4989788295cbb36a6..f48e17b61bb0106df31a73c135edafeb68344cd6 100644 (file)
 {else}
 <ul>
 {foreach from=$activityTypes key=k item=link}
-<li class="crm-activity-type_{$k}"><a href="{$urls.$k}">{$link}</a></li>
+<li class="crm-activity-type_{$k}"><a href="{$urls.$k}" data-tab="activity">{$link}</a></li>
 {/foreach}
 
 {* add hook links if any *}
 {if $hookLinks}
    {foreach from=$hookLinks item=link}
     <li>
-        <a href="{$link.url}"{if $link.title} title="{$link.title}"{/if}>
+        <a href="{$link.url}" data-tab="activity"{if !empty($link.title)} title="{$link.title}"{/if}>
           {if $link.img}
                 <img src="{$link.img}" alt="{$link.title}" />&nbsp;
           {/if}
index 981c0f5c84ca1918b00a0f9eee5d2ef85d5119bb..ede72e28e4d226d321941af93575261916c4a6dd 100644 (file)
@@ -70,9 +70,9 @@
         <div class="crm-contact_actions-list">
         <ul class="contact-actions">
           {foreach from=$actionsMenuList.moreActions item='row'}
-          {if $row.href}
+          {if !empty($row.href) or !empty($row.tab)}
           <li class="crm-action-{$row.ref}">
-            <a href="{$row.href}&cid={$contactId}" title="{$row.title}" data-tab="{$row.key}">{$row.title}</a>
+            <a href="{if !empty($row.href)}{$row.href}&cid={$contactId}{else}#{/if}" title="{$row.title}" data-tab="{$row.tab}">{$row.title}</a>
           </li>
           {/if}
         {/foreach}
index 4b6d48b1d36ea069197396651647eecad48831be..7e9b60f976a101b17d510ced088378506aeccf09 100644 (file)
@@ -93,7 +93,7 @@
         CRM.tabHeader.updateCount('#tab_log', response.changeLog.count);
       }
       $("#crm-record-log").replaceWith(response.changeLog.markup);
-      // Refresh tab contents - Simple
+      // Refresh tab contents - Simple logging
       if (!CRM.reloadChangeLogTab && $('#changeLog').closest('.ui-tabs-panel').data('civiCrmSnippet')) {
         $('#changeLog').closest('.ui-tabs-panel').crmSnippet('destroy');
       }
       })
       // Handle action links in popup
       .on('click', '.crm-contact_actions-list a, .crm-contact_activities-list a', function() {
-        var tabName = $(this).data('tab') || 'activity';
+        var tabName = $(this).data('tab') || 'summary';
         var $tab = $('#tab_' + tabName);
         var $panel = $('#' + $tab.attr('aria-controls'));
-        CRM.loadForm($(this).attr('href'))
-          .on('crmFormSuccess', function() {
-            if ($panel.data('civiCrmSnippet')) {
-              $panel.crmSnippet('refresh');
-            }
-            $('#mainTabContainer').tabs('option', 'active', $tab.prevAll().length);
-          });
+        var url = $(this).attr('href');
+        if (url !== '#') {
+          CRM.loadForm(url)
+            .on('crmFormSuccess', function() {
+              if ($panel.data('civiCrmSnippet')) {
+                $panel.crmSnippet('refresh');
+              }
+              $('#mainTabContainer').tabs('option', 'active', $tab.prevAll().length);
+            });
+        } else {
+          $('#mainTabContainer').tabs('option', 'active', $tab.prevAll().length);
+        }
+        $('#crm-contact-actions-list').hide();
         return false;
       });
     $(document)
         }
         $('#crm-contact-actions-list').hide();
       })
+      // Reload changelog whenever an inline or popup form submits
       .on('crmFormSuccess', function(e) {
         CRM.reloadChangeLogTab && CRM.reloadChangeLogTab();
       });
index 13f53462950d8334ce0065ec7936590eb68a7b48..763c83a815d4f99c419a2c325e1bc983cbea792c 100644 (file)
       $('.tag-section .token-input-token-facebook p, #tagtree input:checkbox:checked+label').each(function() {
         tags.push($(this).text());
       });
-      // showing count of tags in summary tab
-      CRM.tabHeader && CRM.tabHeader.updateCount('#tab_tag', tags.length);
-      CRM.reloadChangeLogTab && CRM.reloadChangeLogTab();
+      // contact summary tabs and search forms both listen for this event
+      $('#Tag').closest('.crm-ajax-container').trigger('crmFormSuccess', {tabCount: tags.length});
       // update summary tab
-      $("#tags").html(tags.join(', '));
+      $("#contact-summary #tags").html(tags.join(', '));
     };
   })(cj);
   {/literal}
index 3f9e5e3798097e049f17a68f73a004aa2cabd2a9..e6e4e1b727da234a7d99049fd71d9696beb90203 100644 (file)
@@ -33,12 +33,21 @@ cj(function($) {
           ui.panel
             .off('click.crmLivePage')
             .on('click.crmLivePage', 'a.button, a.action-item', function() {
+              var
+                dialogSettings = {},
+                url = $(this).attr('href');
               // only follow real links not javascript buttons
-              if ($(this).attr('href') === '#' || $(this).attr('onclick') || $(this).hasClass('no-popup')) {
+              if (url === '#' || $(this).attr('onclick') || $(this).hasClass('no-popup')) {
                 return;
               }
-              CRM.loadForm($(this).attr('href'), {
-                openInline: 'a:not("[href=#], .no-popup")'
+              // Hack to make delete dialogs smaller
+              if (url.indexOf('/delete') > 0 || url.indexOf('action=delete') > 0) {
+                dialogSettings.width = 400;
+                dialogSettings.height = 300;
+              }
+              CRM.loadForm(url, {
+                openInline: 'a:not("[href=#], .no-popup")',
+                dialog: dialogSettings
               }).on('crmFormSuccess', function(e, data) {
                   // Refresh when form completes
                   ui.panel.crmSnippet('refresh');