Commit | Line | Data |
---|---|---|
6d538af3 CW |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
3 | | CiviCRM version 4.5 | | |
4 | +--------------------------------------------------------------------+ | |
5 | | Copyright CiviCRM LLC (c) 2004-2014 | | |
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)} | |
e4f4dc22 | 27 | {assign var="tagsetType" value="contact"}contact{/capture} |
6d538af3 CW |
28 | {/if} |
29 | {foreach from=$tagsetInfo.$tagsetType item=tagset} | |
c087eb82 CW |
30 | {assign var="elemName" value=$tagset.tagsetElementName} |
31 | {assign var="parID" value=$tagset.parentID} | |
32 | {assign var="skipEntityAction" value=$tagset.skipEntityAction} | |
33 | {if $tableLayout} | |
34 | <td class="label"> | |
e4f4dc22 | 35 | {$form.$elemName.$parID.label} |
c087eb82 CW |
36 | </td> |
37 | <td class="{$tagsetType}-tagset {$tagsetType}-tagset-{$tagset.parentID}-section"> | |
38 | {$form.$elemName.$parID.html} | |
39 | </td> | |
40 | {else} | |
41 | <div class="crm-section tag-section {$tagsetType}-tagset {$tagsetType}-tagset-{$tagset.parentID}-section"> | |
42 | <div class="crm-clearfix"> | |
43 | {$form.$elemName.$parID.label} | |
44 | {$form.$elemName.$parID.html} | |
45 | </div> | |
6d538af3 | 46 | </div> |
c087eb82 CW |
47 | {/if} |
48 | {/foreach} | |
49 | ||
50 | {if !$skipEntityAction and empty($form.frozen)} | |
51 | <script type="text/javascript"> | |
52 | {* Add/remove entity tags via ajax api *} | |
53 | {literal} | |
54 | (function($, _) { | |
55 | var $el = $('.{/literal}{$tagsetType}-tagset{literal} input.crm-form-entityref'); | |
56 | // select2 provides "added" and "removed" properties in the event | |
57 | $el.on('change', function(e) { | |
58 | var tags, | |
59 | data = _.pick($(this).data(), 'entity_id', 'entity_table'), | |
60 | apiCall = []; | |
61 | if (e.added) { | |
62 | tags = $.isArray(e.added) ? e.added : [e.added]; | |
63 | _.each(tags, function(tag) { | |
64 | if (tag.id && tag.id != '0') { | |
65 | apiCall.push(['entity_tag', 'create', $.extend({tag_id: tag.id}, data)]); | |
e4f4dc22 | 66 | } |
c087eb82 CW |
67 | }); |
68 | } | |
69 | if (e.removed) { | |
70 | tags = $.isArray(e.removed) ? e.removed : [e.removed]; | |
71 | _.each(tags, function(tag) { | |
72 | if (tag.id && tag.id != '0') { | |
73 | apiCall.push(['entity_tag', 'delete', $.extend({tag_id: tag.id}, data)]); | |
e4f4dc22 CW |
74 | } |
75 | }); | |
c087eb82 CW |
76 | } |
77 | if (apiCall.length) { | |
78 | CRM.api3(apiCall, true); | |
79 | } | |
80 | }); | |
81 | }(CRM.$, CRM._)); | |
82 | {/literal} | |
83 | </script> | |
84 | {/if} |