From 6ae71908f276116a3cafcc1286bb63b011145f7e Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 24 Jan 2019 10:21:43 -0500 Subject: [PATCH] Fix shortcode button when popup setting is disabled --- CRM/Core/Form/ShortCode.php | 3 -- js/crm.insert-shortcode.js | 96 ++++++++++++++++++++----------------- 2 files changed, 52 insertions(+), 47 deletions(-) diff --git a/CRM/Core/Form/ShortCode.php b/CRM/Core/Form/ShortCode.php index dd1567f386..559ef97fe3 100644 --- a/CRM/Core/Form/ShortCode.php +++ b/CRM/Core/Form/ShortCode.php @@ -171,9 +171,6 @@ class CRM_Core_Form_ShortCode extends CRM_Core_Form { * Build form elements based on the above metadata. */ public function buildQuickForm() { - CRM_Core_Resources::singleton() - ->addScriptFile('civicrm', 'js/crm.insert-shortcode.js'); - $components = CRM_Utils_Array::collect('label', $this->components); $data = CRM_Utils_Array::collect('select', $this->components); diff --git a/js/crm.insert-shortcode.js b/js/crm.insert-shortcode.js index af285dd5b6..dc17fd1c45 100644 --- a/js/crm.insert-shortcode.js +++ b/js/crm.insert-shortcode.js @@ -1,52 +1,60 @@ // https://civicrm.org/licensing CRM.$(function($) { - var $form = $('form.CRM_Core_Form_ShortCode'); - - function changeComponent() { - var component = $(this).val(), - entities = $(this).data('entities'); - - $('.shortcode-param[data-components]', $form).each(function() { - $(this).toggle($.inArray(component, $(this).data('components')) > -1); - - if (entities[component]) { - $('input[name=entity]') - .val('') - .data('key', entities[component].key) - .data('select-params', null) - .data('api-params', null) - .crmEntityRef(entities[component]); - } - }); - } + $('.crm-shortcode-button').click(function(e) { + e.preventDefault(); + CRM.loadPage($(this).attr('href'), {dialog: {width: '50%', height: '50%'}}).on('crmLoad', loadForm); + }); + + function loadForm() { + var $form = $('form.CRM_Core_Form_ShortCode'); + + function changeComponent() { + var component = $(this).val(), + entities = $(this).data('entities'); + + $('.shortcode-param[data-components]', $form).each(function() { + $(this).toggle($.inArray(component, $(this).data('components')) > -1); + + if (entities[component]) { + $('input[name=entity]') + .val('') + .data('key', entities[component].key) + .data('select-params', null) + .data('api-params', null) + .crmEntityRef(entities[component]); + } + }); + } - function close() { - $form.closest('.ui-dialog-content').dialog('close'); - } + function close() { + $form.closest('.ui-dialog-content').dialog('close'); + } - function insert() { - var code = '[civicrm'; - $('.shortcode-param:visible', $form).each(function() { - var $el = $('input:checked, select, input.crm-form-entityref', this); - code += ' ' + $el.data('key') + '="' + $el.val() + '"'; - }); - window.send_to_editor(code + ']'); - close(); + function insert() { + var code = '[civicrm'; + $('.shortcode-param:visible', $form).each(function() { + var $el = $('input:checked, select, input.crm-form-entityref', this); + code += ' ' + $el.data('key') + '="' + $el.val() + '"'; + }); + window.send_to_editor(code + ']'); + close(); + } + + $('select[name=component]', $form).each(changeComponent).change(changeComponent); + + $(this).dialog('option', 'buttons', [ + { + text: ts("Insert"), + icons: {primary: "fa-check"}, + click: insert + }, + { + text: ts("Cancel"), + icons: {primary: "fa-times"}, + click: close + } + ]); } - $('select[name=component]', $form).each(changeComponent).change(changeComponent); - - $form.closest('.ui-dialog-content').dialog('option', 'buttons', [ - { - text: ts("Insert"), - icons: {primary: "fa-check"}, - click: insert - }, - { - text: ts("Cancel"), - icons: {primary: "fa-times"}, - click: close - } - ]); }); -- 2.25.1