Commit | Line | Data |
---|---|---|
6d538af3 CW |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
1188c7a8 | 3 | | Copyright CiviCRM LLC. All rights reserved. | |
6d538af3 | 4 | | | |
1188c7a8 TO |
5 | | This work is published under the GNU AGPLv3 license with some | |
6 | | permitted exceptions and without any warranty. For full license | | |
7 | | and copyright information, see https://civicrm.org/licensing | | |
6d538af3 CW |
8 | +--------------------------------------------------------------------+ |
9 | *} | |
10 | {if empty($tagsetType)} | |
4fd1cd0b | 11 | {assign var="tagsetType" value="contact"} |
6d538af3 | 12 | {/if} |
f2be88e7 MD |
13 | {if $tableLayout} |
14 | <td colspan="2" class="crm-content-block"> | |
15 | <table> | |
16 | {/if} | |
17 | {foreach from=$tagsetInfo.$tagsetType item=tagset} | |
18 | {assign var="elemName" value=$tagset.tagsetElementName} | |
19 | {if empty($tagsetElementName) or $tagsetElementName eq $elemName} | |
20 | {assign var="parID" value=$tagset.parentID} | |
21 | {assign var="skipEntityAction" value=$tagset.skipEntityAction} | |
22 | {if $tableLayout} | |
23 | <tr> | |
24 | <td class="label"> | |
25 | {$form.$elemName.$parID.label} | |
26 | </td> | |
27 | <td class="{$tagsetType}-tagset {$tagsetType}-tagset-{$tagset.parentID}-section"> | |
28 | {$form.$elemName.$parID.html} | |
29 | </td> | |
30 | </tr> | |
31 | {else} | |
32 | <div class="crm-section tag-section {$tagsetType}-tagset {$tagsetType}-tagset-{$tagset.parentID}-section"> | |
33 | <div class="crm-clearfix"> | |
34 | {$form.$elemName.$parID.label} | |
35 | {$form.$elemName.$parID.html} | |
36 | </div> | |
37 | </div> | |
38 | {/if} | |
39 | {/if} | |
40 | {/foreach} | |
41 | {if $tableLayout} | |
42 | </table> | |
43 | </td> | |
44 | {/if} | |
c087eb82 CW |
45 | |
46 | {if !$skipEntityAction and empty($form.frozen)} | |
47 | <script type="text/javascript"> | |
48 | {* Add/remove entity tags via ajax api *} | |
49 | {literal} | |
50 | (function($, _) { | |
51 | var $el = $('.{/literal}{$tagsetType}-tagset{literal} input.crm-form-entityref'); | |
52 | // select2 provides "added" and "removed" properties in the event | |
53 | $el.on('change', function(e) { | |
54 | var tags, | |
55 | data = _.pick($(this).data(), 'entity_id', 'entity_table'), | |
56 | apiCall = []; | |
57 | if (e.added) { | |
58 | tags = $.isArray(e.added) ? e.added : [e.added]; | |
59 | _.each(tags, function(tag) { | |
60 | if (tag.id && tag.id != '0') { | |
61 | apiCall.push(['entity_tag', 'create', $.extend({tag_id: tag.id}, data)]); | |
e4f4dc22 | 62 | } |
c087eb82 CW |
63 | }); |
64 | } | |
65 | if (e.removed) { | |
66 | tags = $.isArray(e.removed) ? e.removed : [e.removed]; | |
67 | _.each(tags, function(tag) { | |
68 | if (tag.id && tag.id != '0') { | |
69 | apiCall.push(['entity_tag', 'delete', $.extend({tag_id: tag.id}, data)]); | |
e4f4dc22 CW |
70 | } |
71 | }); | |
c087eb82 CW |
72 | } |
73 | if (apiCall.length) { | |
74 | CRM.api3(apiCall, true); | |
75 | } | |
76 | }); | |
77 | }(CRM.$, CRM._)); | |
78 | {/literal} | |
79 | </script> | |
80 | {/if} |