Remove unnecessary id attribute.
[civicrm-core.git] / templates / CRM / common / Tagset.tpl
CommitLineData
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}
8a76e0df 13{if !empty($tableLayout)}
f2be88e7
MD
14 <td colspan="2" class="crm-content-block">
15 <table>
16{/if}
8a76e0df 17 {if !empty($tagsetInfo)}
f2be88e7
MD
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}
5f4b1c1d 23 {if !empty($tableLayout)}
f2be88e7
MD
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}
8a76e0df
SL
42 {/if}
43{if !empty($tableLayout)}
f2be88e7
MD
44 </table>
45 </td>
46{/if}
c087eb82 47
8a76e0df 48{if empty($skipEntityAction) and empty($form.frozen)}
c087eb82
CW
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)]);
e4f4dc22 64 }
c087eb82
CW
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)]);
e4f4dc22
CW
72 }
73 });
c087eb82
CW
74 }
75 if (apiCall.length) {
76 CRM.api3(apiCall, true);
77 }
78 });
79 }(CRM.$, CRM._));
80 {/literal}
81 </script>
82{/if}