Commit | Line | Data |
---|---|---|
6d538af3 CW |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
fee14197 | 3 | | CiviCRM version 5 | |
6d538af3 | 4 | +--------------------------------------------------------------------+ |
6b83d5bd | 5 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6d538af3 CW |
6 | +--------------------------------------------------------------------+ |
7 | | This file is a part of CiviCRM. | | |
8 | | | | |
9 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
10 | | under the terms of the GNU Affero General Public License | | |
11 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
12 | | | | |
13 | | CiviCRM is distributed in the hope that it will be useful, but | | |
14 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
15 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
16 | | See the GNU Affero General Public License for more details. | | |
17 | | | | |
18 | | You should have received a copy of the GNU Affero General Public | | |
19 | | License and the CiviCRM Licensing Exception along | | |
20 | | with this program; if not, contact CiviCRM LLC | | |
21 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
22 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
24 | +--------------------------------------------------------------------+ | |
25 | *} | |
26 | {if empty($tagsetType)} | |
4fd1cd0b | 27 | {assign var="tagsetType" value="contact"} |
6d538af3 CW |
28 | {/if} |
29 | {foreach from=$tagsetInfo.$tagsetType item=tagset} | |
c087eb82 | 30 | {assign var="elemName" value=$tagset.tagsetElementName} |
310bbbe5 CW |
31 | {if empty($tagsetElementName) or $tagsetElementName eq $elemName} |
32 | {assign var="parID" value=$tagset.parentID} | |
33 | {assign var="skipEntityAction" value=$tagset.skipEntityAction} | |
34 | {if $tableLayout} | |
35 | <td class="label"> | |
c087eb82 | 36 | {$form.$elemName.$parID.label} |
310bbbe5 CW |
37 | </td> |
38 | <td class="{$tagsetType}-tagset {$tagsetType}-tagset-{$tagset.parentID}-section"> | |
39 | {$form.$elemName.$parID.html} | |
40 | </td> | |
41 | {else} | |
42 | <div class="crm-section tag-section {$tagsetType}-tagset {$tagsetType}-tagset-{$tagset.parentID}-section"> | |
43 | <div class="crm-clearfix"> | |
44 | {$form.$elemName.$parID.label} | |
45 | {$form.$elemName.$parID.html} | |
46 | </div> | |
c087eb82 | 47 | </div> |
310bbbe5 | 48 | {/if} |
c087eb82 CW |
49 | {/if} |
50 | {/foreach} | |
51 | ||
52 | {if !$skipEntityAction and empty($form.frozen)} | |
53 | <script type="text/javascript"> | |
54 | {* Add/remove entity tags via ajax api *} | |
55 | {literal} | |
56 | (function($, _) { | |
57 | var $el = $('.{/literal}{$tagsetType}-tagset{literal} input.crm-form-entityref'); | |
58 | // select2 provides "added" and "removed" properties in the event | |
59 | $el.on('change', function(e) { | |
60 | var tags, | |
61 | data = _.pick($(this).data(), 'entity_id', 'entity_table'), | |
62 | apiCall = []; | |
63 | if (e.added) { | |
64 | tags = $.isArray(e.added) ? e.added : [e.added]; | |
65 | _.each(tags, function(tag) { | |
66 | if (tag.id && tag.id != '0') { | |
67 | apiCall.push(['entity_tag', 'create', $.extend({tag_id: tag.id}, data)]); | |
e4f4dc22 | 68 | } |
c087eb82 CW |
69 | }); |
70 | } | |
71 | if (e.removed) { | |
72 | tags = $.isArray(e.removed) ? e.removed : [e.removed]; | |
73 | _.each(tags, function(tag) { | |
74 | if (tag.id && tag.id != '0') { | |
75 | apiCall.push(['entity_tag', 'delete', $.extend({tag_id: tag.id}, data)]); | |
e4f4dc22 CW |
76 | } |
77 | }); | |
c087eb82 CW |
78 | } |
79 | if (apiCall.length) { | |
80 | CRM.api3(apiCall, true); | |
81 | } | |
82 | }); | |
83 | }(CRM.$, CRM._)); | |
84 | {/literal} | |
85 | </script> | |
86 | {/if} |