Merge pull request #3524 from atif-shaikh/CRM-14816
[civicrm-core.git] / templates / CRM / common / Tagset.tpl
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)}
27 {assign var="tagsetType" value="contact"}contact{/capture}
28 {/if}
29 {foreach from=$tagsetInfo.$tagsetType item=tagset}
30 {assign var="elemName" value=$tagset.tagsetElementName}
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">
36 {$form.$elemName.$parID.label}
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>
47 </div>
48 {/if}
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)]);
68 }
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)]);
76 }
77 });
78 }
79 if (apiCall.length) {
80 CRM.api3(apiCall, true);
81 }
82 });
83 }(CRM.$, CRM._));
84 {/literal}
85 </script>
86 {/if}