Fix for CRM-15729
authorWeb Access <rohan.katkar@webaccessglobal.com>
Tue, 3 Mar 2015 15:36:43 +0000 (21:06 +0530)
committerWeb Access <rohan.katkar@webaccessglobal.com>
Wed, 4 Mar 2015 06:52:49 +0000 (12:22 +0530)
CRM/Contact/Form/Edit/TagsAndGroups.php
CRM/Tag/Form/Tag.php
css/civicrm.css
templates/CRM/Contact/Form/Edit/TagsAndGroups.tpl
templates/CRM/Tag/Form/Tag.tpl

index cb25376b68f47724935bf15e1a4bf59c3aafca2e..3e87594de9f4b0a64382087813e870cc3c68c47b 100644 (file)
@@ -148,11 +148,6 @@ class CRM_Contact_Form_Edit_TagsAndGroups {
     }
 
     if ($type & self::TAG) {
-      // CODE FROM CRM/Tag/Form/Tag.php //
-      CRM_Core_Resources::singleton()
-        ->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)
-        ->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header');
-
       $fName = 'tag';
       if ($fieldName) {
         $fName = $fieldName;
@@ -162,6 +157,16 @@ class CRM_Contact_Form_Edit_TagsAndGroups {
       // get the list of all the categories
       $tags = new CRM_Core_BAO_Tag();
       $tree = $tags->getTree('civicrm_contact', TRUE);
+      // let's not load jstree if there are not children. This also fixes blank
+      // display at the beginning of checkboxes
+      $form->assign('loadjsTree', FALSE);
+      if (!empty(CRM_Utils_Array::retrieveValueRecursive($tree, 'children'))) {
+        // CODE FROM CRM/Tag/Form/Tag.php //
+        CRM_Core_Resources::singleton()
+          ->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)
+          ->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header');
+        $form->assign('loadjsTree', TRUE);
+      }
 
       $elements = array();
       self::climbtree($form, $tree, $elements);
index dc89fe3e74778c6fe0b56a961549563d03943a29..6c6ecfce2e542911cb45cf2ae374423d7551d6b8 100644 (file)
@@ -71,9 +71,6 @@ class CRM_Tag_Form_Tag extends CRM_Core_Form {
    * @return void
    */
   public function buildQuickForm() {
-    CRM_Core_Resources::singleton()
-      ->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)
-      ->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header');
     // get categories for the contact id
     $entityTag = CRM_Core_BAO_EntityTag::getTag($this->_entityID, $this->_entityTable);
     $this->assign('tagged', $entityTag);
@@ -102,6 +99,16 @@ class CRM_Tag_Form_Tag extends CRM_Core_Form {
 
     $tags = new CRM_Core_BAO_Tag();
     $tree = $tags->getTree($this->_entityTable, TRUE);
+
+    // let's not load jstree if there are not children. This also fixes blank
+    // display at the beginning of checkboxes
+    $this->assign('loadjsTree', FALSE);
+    if (!empty(CRM_Utils_Array::retrieveValueRecursive($tree, 'children'))) {
+      CRM_Core_Resources::singleton()
+        ->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)
+        ->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header');
+      $this->assign('loadjsTree', TRUE);
+    }
     $this->assign('tree', $tree);
 
     $this->assign('tag', $allTag);
index c67998883243029181c923eaf29aa187f845ced1..dac9ffd0711ded0d69c68405a8be5a10b0447744 100644 (file)
@@ -3312,6 +3312,13 @@ div.m ul#civicrm-menu,
   background: none repeat scroll 0 0 transparent;
 }
 
+/* unset the styling for the li in jstree */
+#tagtree ul {
+  list-style: none;
+  margin: 0px;
+  padding: 0px;
+}
+
 /* Class for successful upgrade */
 .crm-container .upgrade-success {
   background-color: #00CC00;
index f108208f4762ed17ca718cc866c15b3c942d70f9..5368a8816af4dcb4afd441d8022d22a47febcab5 100644 (file)
         highlightSelected();
       });
 
-      //load js tree.
-      $("#tagtree").jstree({
-        plugins : ["themes", "html_data"],
-        themes: {
-          "theme": 'classic',
-          "dots": false,
-          "icons": false,
-          "url": CRM.config.resourceBase + 'packages/jquery/plugins/jstree/themes/classic/style.css'
-        }
-      });
-
+      var childTag = {/literal}{$loadjsTree}{literal};
+      if (childTag) {
+        //load js tree.
+        $("#tagtree").jstree({
+          plugins : ["themes", "html_data"],
+          themes: {
+            "theme": 'classic',
+            "dots": false,
+            "icons": false,
+            "url": CRM.config.resourceBase + 'packages/jquery/plugins/jstree/themes/classic/style.css'
+          }
+        });
+      }
          {/literal}
       {if !empty($permission) && $permission neq 'edit'}
         {literal}
             {$form.group.html}
           </td>
         {/if}
+        {if !$type || $type eq 'tag'}
+          <td width="70%">{if $title}<span class="label">{$form.tag.label}</span>{/if}
+            <div id="tagtree">
+              {include file="CRM/Contact/Form/Edit/Tagtree.tpl" level=1}
+            </div>
+          </td>
+          <tr><td>{include file="CRM/common/Tagset.tpl"}</td></tr>
+        {/if}
       </tr>
-
-    {if !$type || $type eq 'tag'}
-      <tr>
-        <td width="70%"><span class="label">{if $title}{$form.$key.label}{/if}</span>
-          <div id="tagtree">
-            {include file="CRM/Contact/Form/Edit/Tagtree.tpl" level=1}
-          </div>
-        </td>
-      </tr>
-      <tr><td>{include file="CRM/common/Tagset.tpl"}</td></tr>
-    {/if}
-  </table>
+    </table>
 {if $title}
   </div>
 </div><!-- /.crm-accordion-wrapper -->
index fca248caa2490759b1e10540c6f5eceada144838..c616426250ed8542c2d4dd57c746e99ebf968ce8 100644 (file)
         highlightSelected();
         CRM.updateContactSummaryTags();
       });
-
-      //load js tree.
-      $("#tagtree").jstree({
-        plugins : ["themes", "html_data"],
-        themes: {
-          "theme": 'classic',
-          "dots": false,
-          "icons": false,
-          "url": CRM.config.resourceBase + 'packages/jquery/plugins/jstree/themes/classic/style.css'
-        }
-      });
-
+      var childTag = {/literal}{$loadjsTree}{literal};
+      if (childTag) {
+        //load js tree.
+        $("#tagtree").jstree({
+          plugins : ["themes", "html_data"],
+          themes: {
+            "theme": 'classic',
+            "dots": false,
+            "icons": false,
+            "url": CRM.config.resourceBase + 'packages/jquery/plugins/jstree/themes/classic/style.css'
+          }
+        });
+      }
       {/literal}
       {if $permission neq 'edit'}
         {literal}