Improve tagTree and fix tag formatting on contact summary
authorColeman Watts <coleman@civicrm.org>
Wed, 20 Aug 2014 21:08:04 +0000 (22:08 +0100)
committerColeman Watts <coleman@civicrm.org>
Wed, 20 Aug 2014 21:08:04 +0000 (22:08 +0100)
templates/CRM/Tag/Form/Tag.tpl
templates/CRM/Tag/Form/Tagtree.tpl

index 52af9c8d3f3d9e35f324afaf4f1b034e6dd952c9..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;
@@ -44,7 +44,7 @@
     {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() {
     };
 
     $(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"}
index 3c017cdba02c4b5dceb8ac71a3a3c123027b99a9..14fc903449ab155452e5e2bae97748b6095b1412 100644 (file)
  +--------------------------------------------------------------------+
 *}
 {* This tpl runs recursively to build each level of the tag tree *}
-<ul>
+<ul class="tree-level-{$level}">
   {foreach from=$tree item="node" key="id"}
     <li id="tag_{$id}">
       <input name="tagList[{$id}]" id="check_{$id}" type="checkbox" {if $tagged[$id]}checked="checked"{/if}/>
-      <label for="check_{$id}" id="tagLabel_{$id}">
-        {$node.name}
+      <span>
+        <label for="check_{$id}" id="tagLabel_{$id}">{$node.name}</label>
         {if $node.description}{help id=$id title=$node.name file="CRM/Tag/Form/Tagtree"}{/if}
-      </label>
+      </span>
       {if $node.children}
         {* Recurse... *}
-        {include file="CRM/Tag/Form/Tagtree.tpl" tree=$node.children}
+        {include file="CRM/Tag/Form/Tagtree.tpl" tree=$node.children level=$level+1}
       {/if}
     </li>
   {/foreach}