Simplify Tag.tpl code
authorColeman Watts <coleman@civicrm.org>
Thu, 14 Aug 2014 15:07:28 +0000 (16:07 +0100)
committerColeman Watts <coleman@civicrm.org>
Thu, 14 Aug 2014 15:07:28 +0000 (16:07 +0100)
templates/CRM/Tag/Form/Tag.tpl
templates/CRM/Tag/Form/Tagtree.tpl [new file with mode: 0644]

index 834b586fc84e0b3450d3f93d9e41060896dd06d8..87a98301855fe565866f040574e35745b7c2b801 100644 (file)
 <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"}
   </div>
   <br />
 {include file="CRM/common/Tagset.tpl"}
diff --git a/templates/CRM/Tag/Form/Tagtree.tpl b/templates/CRM/Tag/Form/Tagtree.tpl
new file mode 100644 (file)
index 0000000..cbbf37a
--- /dev/null
@@ -0,0 +1,38 @@
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.5                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*}
+{* This tpl runs recursively to build each level of the tag tree *}
+<ul>
+  {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}</label>
+      {if $node.children}
+        {* Recurse... *}
+        {include file="CRM/Tag/Form/Tagtree.tpl" tree=$node.children}
+      {/if}
+    </li>
+  {/foreach}
+</ul>