Merge pull request #12010 from JMAConsulting/dev-core-70
[civicrm-core.git] / templates / CRM / Tag / Form / Tag.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 5 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2018 |
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 {crmStyle file='bower_components/jstree/dist/themes/default/style.min.css'}
28 {literal}
29 <script type="text/javascript">
30 (function($, _){{/literal}
31 var entityID={$entityID},
32 entityTable='{$entityTable}',
33 $form = $('form.{$form.formClass}');
34 {literal}
35
36 $(function() {
37
38 // Display tags on the contact summary
39 function updateContactSummaryTags() {
40 var tags = [],
41 selected = $("#tagtree").jstree(true).get_selected(true);
42 $.each(selected, function(k, item) {
43 var $tag = $(item.text);
44 tags.push('<span class="crm-tag-item" style="' + $tag.attr('style') + '" title="' + ($.parseHTML($tag.attr('title')) || '') + '">' + $tag.text() + '</span>');
45 });
46 $('input.crm-contact-tagset').each(function() {
47 $.each($(this).select2('data'), function (i, tag) {
48 tags.push('<span class="crm-tag-item" title="' + ($.parseHTML(tag.description.text) || '') + '"' + (tag.color ? 'style="color: ' + CRM.utils.colorContrast(tag.color) + '; background-color: ' + tag.color + ';"' : '') + '>' + tag.label + '</span>');
49 });
50 });
51 // contact summary tabs and search forms both listen for this event
52 $($form).closest('.crm-ajax-container').trigger('crmFormSuccess', {tabCount: tags.length});
53 // update summary tab
54 $("#contact-summary #tags").html(tags.join(' '));
55 }
56
57 // Load js tree.
58 CRM.loadScript(CRM.config.resourceBase + 'bower_components/jstree/dist/jstree.min.js').done(function() {
59 $("#tagtree").jstree({
60 plugins : ['search', 'wholerow', 'checkbox'],
61 core: {
62 animation: 100,
63 themes: {
64 "theme": 'classic',
65 "dots": false,
66 "icons": false
67 }
68 },
69 'search': {
70 'case_insensitive' : true,
71 'show_only_matches': true
72 },
73 checkbox: {
74 three_state: false
75 }
76 })
77 .on('select_node.jstree deselect_node.jstree', function(e, selected) {
78 var id = selected.node.a_attr.id.replace('tag_', ''),
79 op = e.type === 'select_node' ? 'create' : 'delete';
80 CRM.api3('entity_tag', op, {entity_table: entityTable, entity_id: entityID, tag_id: id}, true);
81 updateContactSummaryTags();
82 });
83 });
84
85 $(document).on('change', 'input.crm-contact-tagset', updateContactSummaryTags);
86
87 $('input[name=filter_tag_tree]', '#Tag').on('keyup change', function() {
88 $("#tagtree").jstree(true).search($(this).val());
89 });
90 });
91 })(CRM.$, CRM._);
92 {/literal}
93 </script>
94 <div id="Tag" class="view-content">
95 <table class="">
96 <thead>
97 <tr>
98 <th>{ts}Tag Tree{/ts}</th>
99 {if $tagsetInfo.contact}<th>{ts}Tag Sets{/ts}</th>{/if}
100 </tr>
101 </thead>
102 <tbody>
103 <tr>
104 <td>
105 <input class="crm-form-text big" name="filter_tag_tree" placeholder="{ts}Filter List{/ts}" allowclear="1"/>
106 <a class="crm-hover-button crm-clear-link" style="visibility:hidden;" title="{ts}Clear{/ts}"><i class="crm-i fa-times"></i></a>
107 <div id="tagtree">
108 {include file="CRM/Tag/Form/Tagtree.tpl" level=1}
109 </div>
110 </td>
111 {if $tagsetInfo.contact}
112 <td>
113 {include file="CRM/common/Tagset.tpl"}
114 </td>
115 {/if}
116 </tr>
117 </tbody>
118 </table>
119 </div>