Commit | Line | Data |
---|---|---|
15f842bd CW |
1 | // https://civicrm.org/licensing |
2 | ||
3 | CRM.$(function($) { | |
6ae71908 CW |
4 | $('.crm-shortcode-button').click(function(e) { |
5 | e.preventDefault(); | |
6 | CRM.loadPage($(this).attr('href'), {dialog: {width: '50%', height: '50%'}}).on('crmLoad', loadForm); | |
7 | }); | |
8 | ||
9 | function loadForm() { | |
10 | var $form = $('form.CRM_Core_Form_ShortCode'); | |
11 | ||
12 | function changeComponent() { | |
13 | var component = $(this).val(), | |
14 | entities = $(this).data('entities'); | |
15 | ||
16 | $('.shortcode-param[data-components]', $form).each(function() { | |
17 | $(this).toggle($.inArray(component, $(this).data('components')) > -1); | |
18 | ||
19 | if (entities[component]) { | |
20 | $('input[name=entity]') | |
21 | .val('') | |
22 | .data('key', entities[component].key) | |
23 | .data('select-params', null) | |
24 | .data('api-params', null) | |
25 | .crmEntityRef(entities[component]); | |
26 | } | |
27 | }); | |
28 | } | |
15f842bd | 29 | |
6ae71908 CW |
30 | function close() { |
31 | $form.closest('.ui-dialog-content').dialog('close'); | |
32 | } | |
15f842bd | 33 | |
6ae71908 CW |
34 | function insert() { |
35 | var code = '[civicrm'; | |
36 | $('.shortcode-param:visible', $form).each(function() { | |
37 | var $el = $('input:checked, select, input.crm-form-entityref', this); | |
38 | code += ' ' + $el.data('key') + '="' + $el.val() + '"'; | |
39 | }); | |
40 | window.send_to_editor(code + ']'); | |
41 | close(); | |
42 | } | |
43 | ||
44 | $('select[name=component]', $form).each(changeComponent).change(changeComponent); | |
45 | ||
46 | $(this).dialog('option', 'buttons', [ | |
47 | { | |
48 | text: ts("Insert"), | |
49 | icons: {primary: "fa-check"}, | |
50 | click: insert | |
51 | }, | |
52 | { | |
53 | text: ts("Cancel"), | |
54 | icons: {primary: "fa-times"}, | |
55 | click: close | |
56 | } | |
57 | ]); | |
15f842bd CW |
58 | } |
59 | ||
972bd897 | 60 | }); |