Merge pull request #4520 from jitendrapurohit/CRM-15545
[civicrm-core.git] / templates / CRM / Tag / Form / Tag.tpl
index 9dca5a9c279cc8df363617082d1479ceafe3dd90..3051d4ec68860fd40bcd4fc62deb4e7513b13c91 100644 (file)
@@ -26,8 +26,8 @@
 {* 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;
 </style>
 <script type="text/javascript">
   (function($, _){{/literal}
-    var entityID={$entityID};
-    var entityTable='{$entityTable}';
+    var entityID={$entityID},
+      entityTable='{$entityTable}',
+      $form = $('form.{$form.formClass}');
     {literal}
     CRM.updateContactSummaryTags = function() {
       var tags = [];
-      $('#tagtree input:checkbox:checked+label').each(function() {
+      $('#tagtree input:checkbox:checked+span label').each(function() {
         tags.push($(this).text());
       });
       $('input.crm-contact-tagset').each(function() {
         tags = tags.concat(setTags);
       });
       // contact summary tabs and search forms both listen for this event
-      $('#Tag').closest('.crm-ajax-container').trigger('crmFormSuccess', {tabCount: tags.length});
+      $($form).closest('.crm-ajax-container').trigger('crmFormSuccess', {tabCount: tags.length});
       // update summary tab
       $("#contact-summary #tags").html(tags.join(', '));
     };
 
     $(function() {
-      $("#tagtree ul input:checked").each (function(){
-        $(this).closest("li").addClass('highlighted');
-      });
+      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();
       });
 
 <div id="Tag" class="view-content">
   <h3>{if !$hideContext}{ts}Tags{/ts}{/if}</h3>
   <div id="tagtree">
-    {include file="CRM/Tag/Form/Tagtree.tpl"}
+    {include file="CRM/Tag/Form/Tagtree.tpl" level=1}
   </div>
   <br />
 {include file="CRM/common/Tagset.tpl"}