CRM-13863 - Add crmPopup method to centralize settings
authorColeman Watts <coleman@civicrm.org>
Fri, 14 Mar 2014 17:23:28 +0000 (13:23 -0400)
committerColeman Watts <coleman@civicrm.org>
Sat, 15 Mar 2014 20:49:59 +0000 (16:49 -0400)
17 files changed:
CRM/Activity/Form/Search.php
CRM/Campaign/Form/Search.php
CRM/Case/Form/Search.php
CRM/Contact/Form/Search.php
CRM/Contribute/Form/Search.php
CRM/Event/Form/Search.php
CRM/Grant/Form/Search.php
CRM/Member/Form/Search.php
CRM/Pledge/Form/Search.php
js/Common.js
js/crm.livePage.js
js/crm.searchForm.js
js/view/crm.designer.js
templates/CRM/Admin/Page/Navigation.tpl
templates/CRM/Group/Form/Search.tpl
templates/CRM/Group/Page/Group.tpl
templates/CRM/common/TabHeader.js

index d6b9d2502ef3fbd0163f643f61d2f69a3de3806e..315a14aaecfdcfd08dd0a00b5e01feeaf0efcd6d 100644 (file)
@@ -234,6 +234,7 @@ class CRM_Activity_Form_Search extends CRM_Core_Form {
 
     $rows = $this->get('rows');
     if (is_array($rows)) {
+      CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
       CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.searchForm.js');
       if (!$this->_single) {
         $this->addElement('checkbox', 'toggleSelect', NULL, NULL,
index 6388660a4b4a6223f5b7cb86552b14564c8b432f..c00be64fffe2bfe5546fd280e12d07a111e6eeb7 100755 (executable)
@@ -260,6 +260,7 @@ class CRM_Campaign_Form_Search extends CRM_Core_Form {
 
     $rows = $this->get('rows');
     if (is_array($rows)) {
+      CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
       CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.searchForm.js');
       if (!$this->_single) {
         $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('onclick' => "toggleTaskAction( true );", 'class' => 'select-rows'));
index e637bb5efe7f32e42af3944ee8445f33e851468e..73f15a8d7c50085defd1014662f290e4a26665ae 100644 (file)
@@ -244,6 +244,7 @@ class CRM_Case_Form_Search extends CRM_Core_Form {
      */
     $rows = $this->get('rows');
     if (is_array($rows)) {
+      CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
       CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.searchForm.js');
       if (!$this->_single) {
         $this->addElement('checkbox',
index e6c0cd768e73330da08009595b8ae45a9cab4e6a..ae34675f611747cb7e4ae09cb8c6e56ca1d5be9b 100644 (file)
@@ -372,6 +372,7 @@ class CRM_Contact_Form_Search extends CRM_Core_Form {
    */
   function buildQuickForm() {
     CRM_Core_Resources::singleton()
+      ->addScriptFile('civicrm', 'js/crm.livePage.js')
       ->addScriptFile('civicrm', 'js/crm.searchForm.js')
       // jsTree is needed for tags popup
       ->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)
index 5cafd0f2ebed9f09b2b782e7e53587a5064b6758..9af148eb673ebfb4de893cf16c50b78e7e1c4a58 100644 (file)
@@ -265,6 +265,7 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form {
 
     $rows = $this->get('rows');
     if (is_array($rows)) {
+      CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
       CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.searchForm.js');
       if (!$this->_single) {
         $this->addElement('checkbox',
index eeffc5875df56f0d3061a397a651fe24099fe04e..bd707d7498f266a16aee7c163eb1bd10db7438cf 100644 (file)
@@ -234,6 +234,7 @@ class CRM_Event_Form_Search extends CRM_Core_Form {
      */
     $rows = $this->get('rows');
     if (is_array($rows)) {
+      CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
       CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.searchForm.js');
       $lineItems = $eventIds = array();
       if (!$this->_single) {
index 2f03146217712d9af516b1636f740579930e3d3f..ec286c1516b4971c71af73a06690c375a48f0882 100644 (file)
@@ -228,6 +228,7 @@ class CRM_Grant_Form_Search extends CRM_Core_Form {
 
     $rows = $this->get('rows');
     if (is_array($rows)) {
+      CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
       CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.searchForm.js');
       if (!$this->_single) {
         $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('onchange' => "toggleTaskAction( true );", 'class' => 'select-rows'));
index e78d43a2e465b37c2cbf387c9df9816aa5bba97c..f4c6e9638a8e295978ee4c4ff55e36126308be4d 100644 (file)
@@ -224,6 +224,7 @@ class CRM_Member_Form_Search extends CRM_Core_Form {
 
     $rows = $this->get('rows');
     if (is_array($rows)) {
+      CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
       CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.searchForm.js');
       if (!$this->_single) {
         $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('onclick' => "toggleTaskAction( true );", 'class' => 'select-rows'));
index 55b94e9736c6d6eb3471e3535a8cf875d6e69b6c..3986a579638a3dccd08d0ae7f86e1199e088c88e 100644 (file)
@@ -222,6 +222,7 @@ class CRM_Pledge_Form_Search extends CRM_Core_Form {
      */
     $rows = $this->get('rows');
     if (is_array($rows)) {
+      CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
       CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.searchForm.js');
       if (!$this->_single) {
         $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('onclick' => "toggleTaskAction( true );", 'class' => 'select-rows'));
index 2f79c8e10499ef16f56ca54b9462b91694ded2f1..479eb80992baaf546d6119eef35950293cba89d4 100644 (file)
@@ -874,13 +874,17 @@ CRM.validate = CRM.validate || {
       settings.dialog = {
         modal: true,
         width: '65%',
-        height: parseInt($(window).height() * .75)
+        height: '75%'
       };
     }
     options && $.extend(true, settings, options);
     settings.url = url;
     // Create new dialog
     if (settings.dialog) {
+      // HACK: jQuery UI doesn't support relative height
+      if (settings.dialog.height && settings.dialog.height.indexOf('%') > 0) {
+        settings.dialog.height = parseInt($(window).height() * (parseFloat(settings.dialog.height)/100), 10);
+      }
       $('<div id="'+ settings.target.substring(1) +'"><div class="crm-loading-element">' + ts('Loading') + '...</div></div>').dialog(settings.dialog);
       $(settings.target).on('dialogclose', function() {
         $(this).crmSnippet('destroy').dialog('destroy').remove();
@@ -920,13 +924,6 @@ CRM.validate = CRM.validate || {
         }
       }
     };
-    // Hack to make delete dialogs smaller
-    if (url.indexOf('/delete') > 0 || url.indexOf('action=delete') > 0) {
-      settings.dialog = {
-        width: 400,
-        height: 300
-      };
-    }
     // Move options that belong to crmForm. Others will be passed through to crmSnippet
     options && $.each(options, function(key, value) {
       if (typeof(settings.crmForm[key]) !== 'undefined') {
@@ -1005,6 +1002,36 @@ CRM.validate = CRM.validate || {
     });
     return widget;
   };
+  /**
+   * @see https://wiki.civicrm.org/confluence/display/CRMDOC/Ajax+Pages+and+Forms
+   */
+  $.fn.crmPopup = function(listeners) {
+    var $el = this.first(),
+      url = $el.attr('href'),
+      popup = $el.data('popup-type') === 'page' ? CRM.loadPage : CRM.loadForm,
+      settings = $el.data('popup-settings') || {};
+    settings.dialog = settings.dialog || {};
+    if (!CRM.ajax_popups_enabled || !url || url.charAt(0) === '#' || $el.attr('onclick') || $el.hasClass('no-popup')) {
+      return false;
+    }
+    // Hack to make delete dialogs smaller
+    if ($el.hasClass('small-popup') || url.indexOf('/delete') > 0 || url.indexOf('action=delete') > 0) {
+      settings.dialog.width = 400;
+      settings.dialog.height = 300;
+    }
+    else if ($el.hasClass('medium-popup')) {
+      settings.dialog.width = '50%';
+      settings.dialog.height = '50%';
+    }
+    else if ($el.hasClass('huge-popup')) {
+      settings.dialog.height = '95%';
+    }
+    var dialog = popup(url, settings);
+    $.each(listeners || {}, function(k, v) {
+      dialog.on(k, v);
+    });
+    return dialog;
+  };
 
   // Preprocess all cj ajax calls to display messages
   $(document).ajaxSuccess(function(event, xhr, settings) {
@@ -1064,11 +1091,11 @@ CRM.validate = CRM.validate || {
         var
           link = $(this),
           optionsChanged = false;
-        CRM.loadForm(this.href, {openInline: 'a:not("[href=#], .no-popup")'})
-          .on('crmFormSuccess', function() {
+        return !link.crmPopup({
+          crmFormSuccess: function() {
             optionsChanged = true;
-          })
-          .on('dialogclose', function() {
+          },
+          dialogclose: function() {
             if (optionsChanged) {
               link.trigger('crmOptionsEdited');
               var $elects = $('select[data-option-edit-path="' + link.data('option-edit-path') + '"]');
@@ -1079,8 +1106,8 @@ CRM.validate = CRM.validate || {
                   });
               }
             }
-          });
-        return false;
+          }
+        });
       })
       // Handle clear button for form elements
       .on('click', 'a.crm-clear-link', function() {
index ea355ffb5c991440f2d74d925212fdc4492d7545..a47145cb41b037909d7d4cd203962f252f5864c1 100644 (file)
@@ -7,15 +7,11 @@ cj(function($) {
     // Open action links in a popup
     .off('click.crmLivePage')
     .on('click.crmLivePage', 'a.button, a.action-item', function() {
-      var url = $(this).attr('href');
-      // only follow real links not javascript buttons
-      if (url === '#' || $(this).attr('onclick') || $(this).hasClass('no-popup')) {
-        return;
-      }
-      CRM.loadForm(url).on('crmFormSuccess', function(e, data) {
-        // Refresh page when form completes
-        $('#crm-main-content-wrapper').crmSnippet('refresh');
+      return !$(this).crmPopup({
+        crmFormSuccess: function() {
+          // Refresh page when form completes
+          $('#crm-main-content-wrapper').crmSnippet('refresh');
+        }
       });
-      return false;
     });
 });
index 181a204549dd1a4ae7f7670c8630a50104d7302b..7e3a53b22bddf5addca734236ebec2bababb3fb2 100644 (file)
@@ -1,25 +1,4 @@
 // http://civicrm.org/licensing
-// Controls search form action links and refreshes
-cj(function($) {
-  $('#crm-main-content-wrapper').crmSnippet();
-  if (CRM.config.ajax_popups_enabled) {
-    $('#crm-main-content-wrapper')
-      // Open action links in a popup
-      .off('click.crmLivePage')
-      .on('click.crmLivePage', 'a.button, a.action-item', function () {
-        var url = $(this).attr('href');
-        // only follow real links not javascript buttons
-        if (url === '#' || $(this).attr('onclick') || $(this).hasClass('no-popup')) {
-          return;
-        }
-        CRM.loadForm(url).on('crmFormSuccess', function (e, data) {
-          // Refresh page when form completes
-          $('#crm-main-content-wrapper').crmSnippet('refresh');
-        });
-        return false;
-      });
-  }
-});
 
 function countSelectedCheckboxes(fldPrefix, form) {
   fieldCount = 0;
index de2e88ab04ec10c95d8b2f9fa7ab3f8a8b574a75..01e75f26bdb068f59dd6f0c0c53c539755998740 100644 (file)
             var buttons = {};
             buttons[$link.text()] = function() {
               var form2 = CRM.loadForm($link.attr('href'), {
-                cancelButton: '.cancel.form-submit, #done',
                 openInline: 'a.action-item:not([href="#"])',
                 dialog: {
                   width: '60%',
-                  height: parseInt($(window).height() * .8)
+                  height: '70%'
                 }
-              }).on('crmLoad', function() {
-                  $('#done', this).removeAttr('onclick');
-                });
+              });
             }
             $(this).dialog('option', 'buttons', buttons);
           }
index 3210863ac3b2f0a3c3b3faacef07ca05003c455f..dd55bdcd66af35d3169e255f0c0b55f44b93740e 100644 (file)
       });
     });
     cj('#new-menu-item a.button').click(function() {
-      CRM.loadForm(this.href).on('crmFormSuccess', function() {
-        cj("#navigation-tree").jstree('refresh');
-        cj("#reset-menu").show( );
+      return !$(this).crmPopup({
+        crmFormSuccess: function() {
+          cj("#navigation-tree").jstree('refresh');
+          cj("#reset-menu").show( );
+        }
       });
-      return false;
-    })
+    });
   });
 </script>
 {/literal}
index ea9b6edfe75992c85e2acc67644d219af96f5b49..44f857e24e6afb358354ea671b9e80b52cfdabb7 100644 (file)
@@ -102,12 +102,12 @@ cj(function($) {
   });
   // 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'))
-      .on('crmFormSuccess', function(e, data) {
+    return !$(this).crmPopup({
+      crmFormSuccess: function() {
         // Refresh datatable when form completes
         $('#crm-group-selector').dataTable().fnDraw();
-      });
-    return false;
+      }
+    });
   });
 });
 
index 855266f988116b256d6d9387a8cb32aac3d6d850..d25bbc16da50d978f1dfe02e2b56aef37c5b8abb 100644 (file)
@@ -26,7 +26,7 @@
 {* Actions: 1=add, 2=edit, browse=16, delete=8 *}
 {if $action ne 1 and $action ne 2 and $action ne 8 and $groupPermission eq 1}
 <div class="crm-submit-buttons">
-    <a accesskey="N" href="{crmURL p='civicrm/group/add' q='reset=1'}" id="newGroup" class="button"><span><div class="icon add-icon"></div>{ts}Add Group{/ts}</span></a><br/>
+    <a accesskey="N" href="{crmURL p='civicrm/group/add' q='reset=1'}" data-popup-type="page" class="newGroup button"><span><div class="icon add-icon"></div>{ts}Add Group{/ts}</span></a><br/>
 </div>
 {/if} {* action ne add or edit *}
 <div class="crm-block crm-content-block">
@@ -47,7 +47,7 @@
 
 {if $action ne 1 and $action ne 2 and $action ne 8 and $groupPermission eq 1}
 <div class="crm-submit-buttons">
-        <a accesskey="N" href="{crmURL p='civicrm/group/add' q='reset=1'}" id="newGroup" class="button"><span><div class="icon add-icon"></div>{ts}Add Group{/ts}</span></a><br/>
+        <a accesskey="N" href="{crmURL p='civicrm/group/add' q='reset=1'}" data-popup-type="page" class="newGroup button"><span><div class="icon add-icon"></div>{ts}Add Group{/ts}</span></a><br/>
 </div>
 {/if} {* action ne add or edit *}
 </div>
index 93c40692d851c5662559176a0b85f085da5052ab..104ead9a0f7196f8e4d516ad4a45038a6361fba4 100644 (file)
@@ -33,18 +33,12 @@ cj(function($) {
           ui.panel
             .off('click.crmLivePage')
             .on('click.crmLivePage', 'a.button, a.action-item', function() {
-              var url = $(this).attr('href');
-              // only follow real links not javascript buttons
-              if (url === '#' || $(this).attr('onclick') || $(this).hasClass('no-popup')) {
-                return;
-              }
-              CRM.loadForm(url, {
-                openInline: 'a:not("[href=#], .no-popup")'
-              }).on('crmFormSuccess', function(e, data) {
-                  // Refresh when form completes
+              return !$(this).crmPopup({
+                crmFormSuccess: function() {
+                  // Refresh panel when form completes
                   ui.panel.crmSnippet('refresh');
-                });
-              return false;
+                }
+              });
             });
         }
         ui.panel