Merge pull request #22449 from mattwire/phpnotices
[civicrm-core.git] / templates / CRM / common / Tagset.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | Copyright CiviCRM LLC. All rights reserved. |
4 | |
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 |
8 +--------------------------------------------------------------------+
9 *}
10 {if empty($tagsetType)}
11 {assign var="tagsetType" value="contact"}
12 {/if}
13 {if !empty($tableLayout)}
14 <td colspan="2" class="crm-content-block">
15 <table>
16 {/if}
17 {if !empty($tagsetInfo)}
18 {foreach from=$tagsetInfo.$tagsetType item=tagset}
19 {assign var="elemName" value=$tagset.tagsetElementName}
20 {if empty($tagsetElementName) or $tagsetElementName eq $elemName}
21 {assign var="parID" value=$tagset.parentID}
22 {assign var="skipEntityAction" value=$tagset.skipEntityAction}
23 {if !empty($tableLayout)}
24 <tr>
25 <td class="label">
26 {$form.$elemName.$parID.label}
27 </td>
28 <td class="{$tagsetType}-tagset {$tagsetType}-tagset-{$tagset.parentID}-section">
29 {$form.$elemName.$parID.html}
30 </td>
31 </tr>
32 {else}
33 <div class="crm-section tag-section {$tagsetType}-tagset {$tagsetType}-tagset-{$tagset.parentID}-section">
34 <div class="crm-clearfix">
35 {$form.$elemName.$parID.label}
36 {$form.$elemName.$parID.html}
37 </div>
38 </div>
39 {/if}
40 {/if}
41 {/foreach}
42 {/if}
43 {if !empty($tableLayout)}
44 </table>
45 </td>
46 {/if}
47
48 {if empty($skipEntityAction) and empty($form.frozen)}
49 <script type="text/javascript">
50 {* Add/remove entity tags via ajax api *}
51 {literal}
52 (function($, _) {
53 var $el = $('.{/literal}{$tagsetType}-tagset{literal} input.crm-form-entityref');
54 // select2 provides "added" and "removed" properties in the event
55 $el.on('change', function(e) {
56 var tags,
57 data = _.pick($(this).data(), 'entity_id', 'entity_table'),
58 apiCall = [];
59 if (e.added) {
60 tags = $.isArray(e.added) ? e.added : [e.added];
61 _.each(tags, function(tag) {
62 if (tag.id && tag.id != '0') {
63 apiCall.push(['entity_tag', 'create', $.extend({tag_id: tag.id}, data)]);
64 }
65 });
66 }
67 if (e.removed) {
68 tags = $.isArray(e.removed) ? e.removed : [e.removed];
69 _.each(tags, function(tag) {
70 if (tag.id && tag.id != '0') {
71 apiCall.push(['entity_tag', 'delete', $.extend({tag_id: tag.id}, data)]);
72 }
73 });
74 }
75 if (apiCall.length) {
76 CRM.api3(apiCall, true);
77 }
78 });
79 }(CRM.$, CRM._));
80 {/literal}
81 </script>
82 {/if}