From 8c01223211821aa94056d5e6c26a154af3492d20 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 14 Mar 2014 13:23:28 -0400 Subject: [PATCH] CRM-13863 - Add crmPopup method to centralize settings --- CRM/Activity/Form/Search.php | 1 + CRM/Campaign/Form/Search.php | 1 + CRM/Case/Form/Search.php | 1 + CRM/Contact/Form/Search.php | 1 + CRM/Contribute/Form/Search.php | 1 + CRM/Event/Form/Search.php | 1 + CRM/Grant/Form/Search.php | 1 + CRM/Member/Form/Search.php | 1 + CRM/Pledge/Form/Search.php | 1 + js/Common.js | 55 ++++++++++++++++++------- js/crm.livePage.js | 14 +++---- js/crm.searchForm.js | 21 ---------- js/view/crm.designer.js | 7 +--- templates/CRM/Admin/Page/Navigation.tpl | 11 ++--- templates/CRM/Group/Form/Search.tpl | 8 ++-- templates/CRM/Group/Page/Group.tpl | 4 +- templates/CRM/common/TabHeader.js | 16 +++---- 17 files changed, 74 insertions(+), 71 deletions(-) diff --git a/CRM/Activity/Form/Search.php b/CRM/Activity/Form/Search.php index d6b9d2502e..315a14aaec 100644 --- a/CRM/Activity/Form/Search.php +++ b/CRM/Activity/Form/Search.php @@ -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, diff --git a/CRM/Campaign/Form/Search.php b/CRM/Campaign/Form/Search.php index 6388660a4b..c00be64fff 100755 --- a/CRM/Campaign/Form/Search.php +++ b/CRM/Campaign/Form/Search.php @@ -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')); diff --git a/CRM/Case/Form/Search.php b/CRM/Case/Form/Search.php index e637bb5efe..73f15a8d7c 100644 --- a/CRM/Case/Form/Search.php +++ b/CRM/Case/Form/Search.php @@ -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', diff --git a/CRM/Contact/Form/Search.php b/CRM/Contact/Form/Search.php index e6c0cd768e..ae34675f61 100644 --- a/CRM/Contact/Form/Search.php +++ b/CRM/Contact/Form/Search.php @@ -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) diff --git a/CRM/Contribute/Form/Search.php b/CRM/Contribute/Form/Search.php index 5cafd0f2eb..9af148eb67 100644 --- a/CRM/Contribute/Form/Search.php +++ b/CRM/Contribute/Form/Search.php @@ -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', diff --git a/CRM/Event/Form/Search.php b/CRM/Event/Form/Search.php index eeffc5875d..bd707d7498 100644 --- a/CRM/Event/Form/Search.php +++ b/CRM/Event/Form/Search.php @@ -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) { diff --git a/CRM/Grant/Form/Search.php b/CRM/Grant/Form/Search.php index 2f03146217..ec286c1516 100644 --- a/CRM/Grant/Form/Search.php +++ b/CRM/Grant/Form/Search.php @@ -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')); diff --git a/CRM/Member/Form/Search.php b/CRM/Member/Form/Search.php index e78d43a2e4..f4c6e9638a 100644 --- a/CRM/Member/Form/Search.php +++ b/CRM/Member/Form/Search.php @@ -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')); diff --git a/CRM/Pledge/Form/Search.php b/CRM/Pledge/Form/Search.php index 55b94e9736..3986a57963 100644 --- a/CRM/Pledge/Form/Search.php +++ b/CRM/Pledge/Form/Search.php @@ -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')); diff --git a/js/Common.js b/js/Common.js index 2f79c8e104..479eb80992 100644 --- a/js/Common.js +++ b/js/Common.js @@ -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); + } $('
' + ts('Loading') + '...
').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() { diff --git a/js/crm.livePage.js b/js/crm.livePage.js index ea355ffb5c..a47145cb41 100644 --- a/js/crm.livePage.js +++ b/js/crm.livePage.js @@ -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; }); }); diff --git a/js/crm.searchForm.js b/js/crm.searchForm.js index 181a204549..7e3a53b22b 100644 --- a/js/crm.searchForm.js +++ b/js/crm.searchForm.js @@ -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; diff --git a/js/view/crm.designer.js b/js/view/crm.designer.js index de2e88ab04..01e75f26bd 100644 --- a/js/view/crm.designer.js +++ b/js/view/crm.designer.js @@ -676,15 +676,12 @@ 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); } diff --git a/templates/CRM/Admin/Page/Navigation.tpl b/templates/CRM/Admin/Page/Navigation.tpl index 3210863ac3..dd55bdcd66 100644 --- a/templates/CRM/Admin/Page/Navigation.tpl +++ b/templates/CRM/Admin/Page/Navigation.tpl @@ -157,12 +157,13 @@ }); }); 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; - }) + }); }); {/literal} diff --git a/templates/CRM/Group/Form/Search.tpl b/templates/CRM/Group/Form/Search.tpl index ea9b6edfe7..44f857e24e 100644 --- a/templates/CRM/Group/Form/Search.tpl +++ b/templates/CRM/Group/Form/Search.tpl @@ -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; + } + }); }); }); diff --git a/templates/CRM/Group/Page/Group.tpl b/templates/CRM/Group/Page/Group.tpl index 855266f988..d25bbc16da 100644 --- a/templates/CRM/Group/Page/Group.tpl +++ b/templates/CRM/Group/Page/Group.tpl @@ -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}
-
{ts}Add Group{/ts}

+
{ts}Add Group{/ts}

{/if} {* action ne add or edit *}
@@ -47,7 +47,7 @@ {if $action ne 1 and $action ne 2 and $action ne 8 and $groupPermission eq 1} {/if} {* action ne add or edit *}
diff --git a/templates/CRM/common/TabHeader.js b/templates/CRM/common/TabHeader.js index 93c40692d8..104ead9a0f 100644 --- a/templates/CRM/common/TabHeader.js +++ b/templates/CRM/common/TabHeader.js @@ -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 -- 2.25.1