<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
-*/
+ */
/**
*
class CRM_Contact_Form_Edit_TagsAndGroups {
/**
- * Constant to determine which forms we are generating
+ * Constant to determine which forms we are generating.
*
* Used by both profile and edit contact
*/
- CONST GROUP = 1, TAG = 2, ALL = 3;
+ const GROUP = 1, TAG = 2, ALL = 3;
/**
- * This function is to build form elements
+ * build form elements.
* params object $form object of the form
*
- * @param CRM_Core_Form $form the form object that we are operating on
- * @param int $contactId contact id
- * @param int $type what components are we interested in
- * @param boolean $visibility visibility of the field
+ * @param CRM_Core_Form $form
+ * The form object that we are operating on.
+ * @param int $contactId
+ * Contact id.
+ * @param int $type
+ * What components are we interested in.
+ * @param bool $visibility
+ * Visibility of the field.
* @param null $isRequired
- * @param string $groupName if used for building group block
- * @param string $tagName if used for building tag block
- * @param string $fieldName this is used in batch profile(i.e to build multiple blocks)
+ * @param string $groupName
+ * If used for building group block.
+ * @param string $tagName
+ * If used for building tag block.
+ * @param string $fieldName
+ * This is used in batch profile(i.e to build multiple blocks).
*
* @param string $groupElementType
*
- * @static
- * @access public
*/
- static function buildQuickForm(&$form,
+ public static function buildQuickForm(
+ &$form,
$contactId = 0,
$type = self::ALL,
$visibility = FALSE,
}
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;
// 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);
$form->assign('tagGroup', $form->_tagGroup);
}
- static function climbtree($form, $tree, &$elements) {
+ /**
+ * Climb tree.
+ *
+ * @param $form
+ * @param $tree
+ * @param $elements
+ *
+ * @return mixed
+ */
+ public static function climbtree($form, $tree, &$elements) {
foreach ($tree as $tagID => $varValue) {
$tagAttribute = array(
- 'onclick' => "return changeRowColor(\"rowidtag_$tagID\")",
- 'id' => "tag_{$tagID}",
+ 'onclick' => "return changeRowColor(\"rowidtag_$tagID\")",
+ 'id' => "tag_{$tagID}",
);
$elements[$tagID] = $form->createElement('checkbox', $tagID, '', '', $tagAttribute);
self::climbtree($form, $varValue['children'], $elements);
}
}
- return $elements;
+ return $elements;
}
/**
- * Set defaults for relevant form elements
+ * Set defaults for relevant form elements.
*
- * @param int $id the contact id
- * @param array $defaults the defaults array to store the values in
- * @param int $type what components are we interested in
- * @param string $fieldName this is used in batch profile(i.e to build multiple blocks)
+ * @param int $id
+ * The contact id.
+ * @param array $defaults
+ * The defaults array to store the values in.
+ * @param int $type
+ * What components are we interested in.
+ * @param string $fieldName
+ * This is used in batch profile(i.e to build multiple blocks).
*
* @param string $groupElementType
*
* @return void
- * @access public
- * @static
*/
- static function setDefaults($id, &$defaults, $type = self::ALL, $fieldName = NULL, $groupElementType = 'checkbox') {
+ public static function setDefaults($id, &$defaults, $type = self::ALL, $fieldName = NULL, $groupElementType = 'checkbox') {
$type = (int ) $type;
if ($type & self::GROUP) {
$fName = 'group';
* Set default values for the form. Note that in edit/view mode
* the default values are retrieved from the database
*
- * @access public
*
* @param CRM_Core_Form $form
* @param $defaults
}
}
}
+
}