Merge pull request #11962 from compucorp/55-hide-adding-option-value-for-locked-groups
[civicrm-core.git] / js / crm.insert-shortcode.js
1 // https://civicrm.org/licensing
2
3 CRM.$(function($) {
4 var $form = $('form.CRM_Core_Form_ShortCode');
5
6 function changeComponent() {
7 var component = $(this).val(),
8 entities = $(this).data('entities');
9
10 $('.shortcode-param[data-components]', $form).each(function() {
11 $(this).toggle($.inArray(component, $(this).data('components')) > -1);
12
13 if (entities[component]) {
14 $('input[name=entity]')
15 .val('')
16 .data('key', entities[component].key)
17 .data('select-params', null)
18 .data('api-params', null)
19 .crmEntityRef(entities[component]);
20 }
21 });
22 }
23
24 function close() {
25 $form.closest('.ui-dialog-content').dialog('close');
26 }
27
28 function insert() {
29 var code = '[civicrm';
30 $('.shortcode-param:visible', $form).each(function() {
31 var $el = $('input:checked, select, input.crm-form-entityref', this);
32 code += ' ' + $el.data('key') + '="' + $el.val() + '"';
33 });
34 window.send_to_editor(code + ']');
35 close();
36 }
37
38 $('select[name=component]', $form).each(changeComponent).change(changeComponent);
39
40 $form.closest('.ui-dialog-content').dialog('option', 'buttons', [
41 {
42 text: ts("Insert"),
43 icons: {primary: "fa-check"},
44 click: insert
45 },
46 {
47 text: ts("Cancel"),
48 icons: {primary: "fa-times"},
49 click: close
50 }
51 ]);
52 });