Merge pull request #2753 from fuzionnz/CRM-14394
[civicrm-core.git] / templates / CRM / Tag / Form / Tag.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.4 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2013 |
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 $(function() {
39 $("#tagtree ul input:checked").each (function(){
40 $(this).closest("li").addClass('highlighted');
41 });
42
43 $("#tagtree input").change(function(){
44 var tagid = this.id.replace("check_", "");
45 var op = (this.checked) ? 'create' : 'delete';
46 var api = CRM.api3('entity_tag', op, {entity_table: entityTable, entity_id: entityID, tag_id: tagid}, true);
47 $(this).closest("li").toggleClass('highlighted');
48 CRM.updateContactSummaryTags();
49 });
50
51 //load js tree.
52 $("#tagtree").jstree({
53 "plugins" : ["themes", "html_data"],
54 "themes": {"url": CRM.config.resourceBase + 'packages/jquery/plugins/jstree/themes/default/style.css'}
55 });
56
57 {/literal}
58 {if $permission neq 'edit'}
59 {literal}
60 $("#tagtree input").prop('disabled', true);
61 {/literal}
62 {/if}
63 {literal}
64 });
65
66 CRM.updateContactSummaryTags = function() {
67 var tags = [];
68 $('.tag-section .token-input-token-facebook p, #tagtree input:checkbox:checked+label').each(function() {
69 tags.push($(this).text());
70 });
71 // contact summary tabs and search forms both listen for this event
72 $('#Tag').closest('.crm-ajax-container').trigger('crmFormSuccess', {tabCount: tags.length});
73 // update summary tab
74 $("#contact-summary #tags").html(tags.join(', '));
75 };
76 })(cj);
77 {/literal}
78 </script>
79 <div id="Tag" class="view-content">
80 <h3>{if !$hideContext}{ts}Tags{/ts}{/if}</h3>
81 <div id="tagtree">
82 <ul class="tree">
83 {foreach from=$tree item="node" key="id"}
84 <li id="tag_{$id}">
85 {if ! $node.children}<input name="tagList[{$id}]" id="check_{$id}" type="checkbox" {if $tagged[$id]}checked="checked"{/if}/>{/if}
86 {if $node.children}<input name="tagList[{$id}]" id="check_{$id}" type="checkbox" {if $tagged[$id]}checked="checked"{/if}/>{/if}
87 {if $node.children} <span class="hit"></span> {/if} <label for="check_{$id}" id="tagLabel_{$id}">{$node.name}</label>
88 {if $node.children}
89 <ul>
90 {foreach from=$node.children item="subnode" key="subid"}
91 <li id="tag_{$subid}">
92 <input id="check_{$subid}" name="tagList[{$subid}]" type="checkbox" {if $tagged[$subid]}checked="checked"{/if}/>
93 {if $subnode.children} <span class="hit"></span> {/if} <label for="check_{$subid}" id="tagLabel_{$subid}">{$subnode.name}</label>
94 {if $subnode.children}
95 <ul>
96 {foreach from=$subnode.children item="subsubnode" key="subsubid"}
97 <li id="tag_{$subsubid}">
98 <input id="check_{$subsubid}" name="tagList[{$subsubid}]" type="checkbox" {if $tagged[$subsubid]}checked="checked"{/if}/>
99 <label for="check_{$subsubid}" id="tagLabel_{$subsubid}">{$subsubnode.name}</label>
100 </li>
101 {/foreach}
102 </ul>
103 {/if}
104 </li>
105 {/foreach}
106 </ul>
107 {/if}
108 </li>
109 {/foreach}
110 </ul>
111 </div>
112 <br />
113 {include file="CRM/common/Tag.tpl" context="contactTab"}
114 </div>