Commit | Line | Data |
---|---|---|
15f842bd CW |
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"), | |
972bd897 | 43 | icons: {primary: "fa-check"}, |
15f842bd CW |
44 | click: insert |
45 | }, | |
46 | { | |
47 | text: ts("Cancel"), | |
972bd897 | 48 | icons: {primary: "fa-times"}, |
15f842bd CW |
49 | click: close |
50 | } | |
51 | ]); | |
972bd897 | 52 | }); |