Merge pull request #4520 from jitendrapurohit/CRM-15545
[civicrm-core.git] / templates / CRM / Tag / Form / Tag.tpl
index 61c9d30efab80bbdb2eb7376da91e5eb17d5a425..3051d4ec68860fd40bcd4fc62deb4e7513b13c91 100644 (file)
@@ -1,8 +1,8 @@
 {*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
 {* this template is used for adding/editing tags  *}
 {literal}
 <style>
-  #tagtree .highlighted > label {
-    background-color: #FEFD7B;
+  #tagtree .highlighted > span {
+    background-color: #fefca6;
+  }
+  #tagtree .helpicon ins {
+    display: none;
+  }
+  #tagtree ins.jstree-icon {
+    cursor: pointer;
   }
 </style>
 <script type="text/javascript">
-  (function($){{/literal}
-    var entityID={$entityID};
-    var entityTable='{$entityTable}';
+  (function($, _){{/literal}
+    var entityID={$entityID},
+      entityTable='{$entityTable}',
+      $form = $('form.{$form.formClass}');
     {literal}
-    $(function() {
-      $("#tagtree ul input:checked").each (function(){
-        $(this).closest("li").addClass('highlighted');
+    CRM.updateContactSummaryTags = function() {
+      var tags = [];
+      $('#tagtree input:checkbox:checked+span label').each(function() {
+        tags.push($(this).text());
       });
+      $('input.crm-contact-tagset').each(function() {
+        var setTags = _.pluck($(this).select2('data'), 'label');
+        tags = tags.concat(setTags);
+      });
+      // contact summary tabs and search forms both listen for this event
+      $($form).closest('.crm-ajax-container').trigger('crmFormSuccess', {tabCount: tags.length});
+      // update summary tab
+      $("#contact-summary #tags").html(tags.join(', '));
+    };
+
+    $(function() {
+      function highlightSelected() {
+        $("ul input:not(:checked)", '#tagtree').each(function () {
+          $(this).closest("li").removeClass('highlighted');
+        });
+        $("ul input:checked", '#tagtree').each(function () {
+          $(this).parents("li[id^=tag]").addClass('highlighted');
+        });
+      }
+      highlightSelected();
 
       $("#tagtree input").change(function(){
         var tagid = this.id.replace("check_", "");
         var op = (this.checked) ? 'create' : 'delete';
         var api = CRM.api3('entity_tag', op, {entity_table: entityTable, entity_id: entityID, tag_id: tagid}, true);
-        $(this).closest("li").toggleClass('highlighted');
+        highlightSelected();
         CRM.updateContactSummaryTags();
       });
 
       //load js tree.
       $("#tagtree").jstree({
-        "plugins" : ["themes", "html_data"],
-        "themes": {"url": CRM.config.resourceBase + 'packages/jquery/plugins/jstree/themes/default/style.css'}
+        plugins : ["themes", "html_data"],
+        themes: {
+          "theme": 'classic',
+          "dots": false,
+          "icons": false,
+          "url": CRM.config.resourceBase + 'packages/jquery/plugins/jstree/themes/classic/style.css'
+        }
       });
 
       {/literal}
         {/literal}
       {/if}
       {literal}
-    });
 
-    CRM.updateContactSummaryTags = function() {
-      var tags = [];
-      $('.tag-section .token-input-token-facebook p, #tagtree input:checkbox:checked+label').each(function() {
-        tags.push($(this).text());
-      });
-      // contact summary tabs and search forms both listen for this event
-      $('#Tag').closest('.crm-ajax-container').trigger('crmFormSuccess', {tabCount: tags.length});
-      // update summary tab
-      $("#contact-summary #tags").html(tags.join(', '));
-    };
-  })(cj);
+      $(document).on('change', 'input.crm-contact-tagset', CRM.updateContactSummaryTags);
+    });
+  })(CRM.$, CRM._);
   {/literal}
 </script>
 <div id="Tag" class="view-content">
   <h3>{if !$hideContext}{ts}Tags{/ts}{/if}</h3>
   <div id="tagtree">
-    <ul class="tree">
-    {foreach from=$tree item="node" key="id"}
-      <li id="tag_{$id}">
-        {if ! $node.children}<input name="tagList[{$id}]" id="check_{$id}" type="checkbox" {if $tagged[$id]}checked="checked"{/if}/>{/if}
-        {if $node.children}<input name="tagList[{$id}]" id="check_{$id}" type="checkbox" {if $tagged[$id]}checked="checked"{/if}/>{/if}
-        {if $node.children} <span class="hit"></span> {/if} <label for="check_{$id}" id="tagLabel_{$id}">{$node.name}</label>
-        {if $node.children}
-          <ul>
-            {foreach from=$node.children item="subnode" key="subid"}
-              <li id="tag_{$subid}">
-                <input id="check_{$subid}" name="tagList[{$subid}]" type="checkbox" {if $tagged[$subid]}checked="checked"{/if}/>
-                {if $subnode.children} <span class="hit"></span> {/if} <label for="check_{$subid}" id="tagLabel_{$subid}">{$subnode.name}</label>
-                {if $subnode.children}
-                  <ul>
-                    {foreach from=$subnode.children item="subsubnode" key="subsubid"}
-                      <li id="tag_{$subsubid}">
-                        <input id="check_{$subsubid}" name="tagList[{$subsubid}]" type="checkbox" {if $tagged[$subsubid]}checked="checked"{/if}/>
-                        <label for="check_{$subsubid}" id="tagLabel_{$subsubid}">{$subsubnode.name}</label>
-                      </li>
-                    {/foreach}
-                  </ul>
-                {/if}
-              </li>
-            {/foreach}
-          </ul>
-        {/if}
-      </li>
-    {/foreach}
-    </ul>
+    {include file="CRM/Tag/Form/Tagtree.tpl" level=1}
   </div>
   <br />
-{include file="CRM/common/Tag.tpl" context="contactTab"}
+{include file="CRM/common/Tagset.tpl"}
 </div>