From d768b78088640f977dc6a40cc425c037b1649673 Mon Sep 17 00:00:00 2001 From: Web Access Date: Tue, 3 Mar 2015 21:06:43 +0530 Subject: [PATCH] Fix for CRM-15729 --- CRM/Contact/Form/Edit/TagsAndGroups.php | 15 ++++--- CRM/Tag/Form/Tag.php | 13 ++++-- css/civicrm.css | 7 +++ .../CRM/Contact/Form/Edit/TagsAndGroups.tpl | 45 +++++++++---------- templates/CRM/Tag/Form/Tag.tpl | 25 ++++++----- 5 files changed, 62 insertions(+), 43 deletions(-) diff --git a/CRM/Contact/Form/Edit/TagsAndGroups.php b/CRM/Contact/Form/Edit/TagsAndGroups.php index cb25376b68..3e87594de9 100644 --- a/CRM/Contact/Form/Edit/TagsAndGroups.php +++ b/CRM/Contact/Form/Edit/TagsAndGroups.php @@ -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); diff --git a/CRM/Tag/Form/Tag.php b/CRM/Tag/Form/Tag.php index dc89fe3e74..6c6ecfce2e 100644 --- a/CRM/Tag/Form/Tag.php +++ b/CRM/Tag/Form/Tag.php @@ -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); diff --git a/css/civicrm.css b/css/civicrm.css index c679988832..dac9ffd071 100644 --- a/css/civicrm.css +++ b/css/civicrm.css @@ -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; diff --git a/templates/CRM/Contact/Form/Edit/TagsAndGroups.tpl b/templates/CRM/Contact/Form/Edit/TagsAndGroups.tpl index f108208f47..5368a8816a 100644 --- a/templates/CRM/Contact/Form/Edit/TagsAndGroups.tpl +++ b/templates/CRM/Contact/Form/Edit/TagsAndGroups.tpl @@ -57,17 +57,19 @@ 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} @@ -95,19 +97,16 @@ {$form.group.html} {/if} + {if !$type || $type eq 'tag'} + {if $title}{$form.tag.label}{/if} +
+ {include file="CRM/Contact/Form/Edit/Tagtree.tpl" level=1} +
+ + {include file="CRM/common/Tagset.tpl"} + {/if} - - {if !$type || $type eq 'tag'} - - {if $title}{$form.$key.label}{/if} -
- {include file="CRM/Contact/Form/Edit/Tagtree.tpl" level=1} -
- - - {include file="CRM/common/Tagset.tpl"} - {/if} - + {if $title} diff --git a/templates/CRM/Tag/Form/Tag.tpl b/templates/CRM/Tag/Form/Tag.tpl index fca248caa2..c616426250 100644 --- a/templates/CRM/Tag/Form/Tag.tpl +++ b/templates/CRM/Tag/Form/Tag.tpl @@ -75,18 +75,19 @@ 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} -- 2.25.1