X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2Fcrm.insert-shortcode.js;h=dc17fd1c451244bd27a46a1b01216b5f1df67d54;hb=bea5230b23b02701ac9ba3259ffe7232bb11c62a;hp=af285dd5b692b9fc12fad64523a4f48e09a60817;hpb=07f36380385fd50f98f69fb08db3f9188fb77667;p=civicrm-core.git 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 - } - ]); });