Merge pull request #3041 from freeform/CRM-14470
[civicrm-core.git] / templates / CRM / Tag / Form / Tag.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 {* this template is used for adding/editing tags *}
27 {literal}
28 <style>
29 #tagtree .highlighted > label {
30 background-color: #FEFD7B;
31 }
32 </style>
33 <script type="text/javascript">
34 (function($, _){{/literal}
35 var entityID={$entityID};
36 var entityTable='{$entityTable}';
37 {literal}
38 CRM.updateContactSummaryTags = function() {
39 var tags = [];
40 $('#tagtree input:checkbox:checked+label').each(function() {
41 tags.push($(this).text());
42 });
43 $('input.crm-contact-tagset').each(function() {
44 var setTags = _.pluck($(this).select2('data'), 'label');
45 tags = tags.concat(setTags);
46 });
47 // contact summary tabs and search forms both listen for this event
48 $('#Tag').closest('.crm-ajax-container').trigger('crmFormSuccess', {tabCount: tags.length});
49 // update summary tab
50 $("#contact-summary #tags").html(tags.join(', '));
51 };
52
53 $(function() {
54 $("#tagtree ul input:checked").each (function(){
55 $(this).closest("li").addClass('highlighted');
56 });
57
58 $("#tagtree input").change(function(){
59 var tagid = this.id.replace("check_", "");
60 var op = (this.checked) ? 'create' : 'delete';
61 var api = CRM.api3('entity_tag', op, {entity_table: entityTable, entity_id: entityID, tag_id: tagid}, true);
62 $(this).closest("li").toggleClass('highlighted');
63 CRM.updateContactSummaryTags();
64 });
65
66 //load js tree.
67 $("#tagtree").jstree({
68 "plugins" : ["themes", "html_data"],
69 "themes": {"url": CRM.config.resourceBase + 'packages/jquery/plugins/jstree/themes/default/style.css'}
70 });
71
72 {/literal}
73 {if $permission neq 'edit'}
74 {literal}
75 $("#tagtree input").prop('disabled', true);
76 {/literal}
77 {/if}
78 {literal}
79
80 $(document).on('change', 'input.crm-contact-tagset', CRM.updateContactSummaryTags);
81 });
82 })(CRM.$, CRM._);
83 {/literal}
84 </script>
85 <div id="Tag" class="view-content">
86 <h3>{if !$hideContext}{ts}Tags{/ts}{/if}</h3>
87 <div id="tagtree">
88 <ul class="tree">
89 {foreach from=$tree item="node" key="id"}
90 <li id="tag_{$id}">
91 {if ! $node.children}<input name="tagList[{$id}]" id="check_{$id}" type="checkbox" {if $tagged[$id]}checked="checked"{/if}/>{/if}
92 {if $node.children}<input name="tagList[{$id}]" id="check_{$id}" type="checkbox" {if $tagged[$id]}checked="checked"{/if}/>{/if}
93 {if $node.children} <span class="hit"></span> {/if} <label for="check_{$id}" id="tagLabel_{$id}">{$node.name}</label>
94 {if $node.children}
95 <ul>
96 {foreach from=$node.children item="subnode" key="subid"}
97 <li id="tag_{$subid}">
98 <input id="check_{$subid}" name="tagList[{$subid}]" type="checkbox" {if $tagged[$subid]}checked="checked"{/if}/>
99 {if $subnode.children} <span class="hit"></span> {/if} <label for="check_{$subid}" id="tagLabel_{$subid}">{$subnode.name}</label>
100 {if $subnode.children}
101 <ul>
102 {foreach from=$subnode.children item="subsubnode" key="subsubid"}
103 <li id="tag_{$subsubid}">
104 <input id="check_{$subsubid}" name="tagList[{$subsubid}]" type="checkbox" {if $tagged[$subsubid]}checked="checked"{/if}/>
105 <label for="check_{$subsubid}" id="tagLabel_{$subsubid}">{$subsubnode.name}</label>
106 </li>
107 {/foreach}
108 </ul>
109 {/if}
110 </li>
111 {/foreach}
112 </ul>
113 {/if}
114 </li>
115 {/foreach}
116 </ul>
117 </div>
118 <br />
119 {include file="CRM/common/Tagset.tpl"}
120 </div>