From b77309d242eb334236ee2d62c8adae5ce318e5e5 Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Sun, 28 May 2017 15:38:03 +0530 Subject: [PATCH 1/3] CRM-20622: contact edit: tags and groups panel layout/styling --- .../CRM/Contact/Form/Edit/TagsAndGroups.tpl | 59 ++++++++++--------- templates/CRM/common/Tagset.tpl | 4 +- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/templates/CRM/Contact/Form/Edit/TagsAndGroups.tpl b/templates/CRM/Contact/Form/Edit/TagsAndGroups.tpl index df271f19d194..9e2da5f8f6ea 100644 --- a/templates/CRM/Contact/Form/Edit/TagsAndGroups.tpl +++ b/templates/CRM/Contact/Form/Edit/TagsAndGroups.tpl @@ -87,35 +87,38 @@
{$title}
{/if} - - - {if !$type || $type eq 'group'} - - {/if} - {if (!$type || $type eq 'tag') && $tree} - - - {/if} - -
- {if $groupElementType eq 'select'} - {if $title}{$form.group.label}{/if} - {$form.group.html} - {else} - {foreach key=key item=item from=$tagGroup.group} -
- {$form.group.$key.html} - {if $item.description} -
{$item.description}
- {/if} -
- {/foreach} +
+ {if !$type || $type eq 'group'} +
+ {if $title} +
{$form.group.label}
+ {/if} + {if $groupElementType eq 'select'} +
{$form.group.html}
+ {else} + {foreach key=key item=item from=$tagGroup.group} +
+ {$form.group.$key.html} + {if $item.description} + {$item.description} {/if} -
{if $title}{$form.tag.label}{/if} -
- {include file="CRM/Contact/Form/Edit/Tagtree.tpl" level=1} -
-
{include file="CRM/common/Tagset.tpl"}
+
+ {/foreach} + {/if} + + {/if} + {if (!$type || $type eq 'tag') && $tree} +
+ {if $title} +
{$form.tag.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/common/Tagset.tpl b/templates/CRM/common/Tagset.tpl index 930ed4433768..94da2ab0ac22 100644 --- a/templates/CRM/common/Tagset.tpl +++ b/templates/CRM/common/Tagset.tpl @@ -41,8 +41,8 @@ {else}
- {$form.$elemName.$parID.label} - {$form.$elemName.$parID.html} +
{$form.$elemName.$parID.label}
+
{$form.$elemName.$parID.html}
{/if} From a52a8469b5c1c71ceb391480354d7101016367b1 Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Thu, 15 Jun 2017 01:39:46 +0530 Subject: [PATCH 2/3] CRM-20673: Tag and group edit form: implement Select2 for tags --- CRM/Contact/Form/Contact.php | 1 + CRM/Contact/Form/Edit/TagsAndGroups.php | 84 +++---------------- .../CRM/Contact/Form/Edit/TagsAndGroups.tpl | 58 +++++++------ templates/CRM/common/Tagset.tpl | 4 +- 4 files changed, 41 insertions(+), 106 deletions(-) diff --git a/CRM/Contact/Form/Contact.php b/CRM/Contact/Form/Contact.php index 0a1c077b62c1..0c9eb8fbc842 100644 --- a/CRM/Contact/Form/Contact.php +++ b/CRM/Contact/Form/Contact.php @@ -992,6 +992,7 @@ public function postProcess() { if (array_key_exists('TagsAndGroups', $this->_editOptions)) { //add contact to tags + $params['tag'] = array_flip(explode(',', $params['tag'])); CRM_Core_BAO_EntityTag::create($params['tag'], 'civicrm_contact', $params['contact_id']); //save free tags diff --git a/CRM/Contact/Form/Edit/TagsAndGroups.php b/CRM/Contact/Form/Edit/TagsAndGroups.php index def736d726e8..87b5d418917d 100644 --- a/CRM/Contact/Form/Edit/TagsAndGroups.php +++ b/CRM/Contact/Form/Edit/TagsAndGroups.php @@ -128,7 +128,7 @@ public static function buildQuickForm( if ($groupElementType == 'select' && !empty($groupsOptions)) { $form->add('select', $fName, $groupName, $groupsOptions, FALSE, - array('id' => $fName, 'multiple' => 'multiple', 'class' => 'crm-select2') + array('id' => $fName, 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 310px') ); $form->assign('groupCount', count($groupsOptions)); } @@ -145,72 +145,17 @@ public static function buildQuickForm( } if ($type & self::TAG) { - $fName = 'tag'; - if ($fieldName) { - $fName = $fieldName; - } - $form->_tagGroup[$fName] = 1; - - // 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 - $loadJsTree = CRM_Utils_Array::retrieveValueRecursive($tree, 'children'); - $form->assign('loadjsTree', FALSE); - if (!empty($loadJsTree)) { - // 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->addGroup($elements, $fName, $tagName, '
'); - $form->assign('tagCount', count($elements)); - $form->assign('tree', $tree); - $form->assign('tag', $tree); - $form->assign('entityID', $contactId); - $form->assign('entityTable', 'civicrm_contact'); - $form->assign('allTags', CRM_Core_BAO_Tag::getTagsUsedFor('civicrm_contact', FALSE)); + $tags = CRM_Core_BAO_Tag::getColorTags('civicrm_contact'); - if ($isRequired) { - $form->addRule($fName, ts('%1 is a required field.', array(1 => $tagName)), 'required'); + if (!empty($tags)) { + $form->add('select2', 'tag', ts('Tag(s)'), $tags, FALSE, array('class' => 'huge', 'placeholder' => ts('- select -'), 'multiple' => TRUE)); } - - // build tag widget - $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact'); - CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', $contactId, FALSE, TRUE); } - $form->assign('tagGroup', $form->_tagGroup); - } - /** - * 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}", - ); - - $elements[$tagID] = $form->createElement('checkbox', $tagID, '', $varValue['name'], $tagAttribute); - - if (array_key_exists('children', $varValue)) { - self::climbtree($form, $varValue['children'], $elements); - } - } - return $elements; + // build tag widget + $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact'); + CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', $contactId, FALSE, TRUE); + $form->assign('tagGroup', $form->_tagGroup); } /** @@ -249,17 +194,8 @@ public static function setDefaults($id, &$defaults, $type = self::ALL, $fieldNam } if ($type & self::TAG) { - $fName = 'tag'; - if ($fieldName) { - $fName = $fieldName; - } - - $contactTag = CRM_Core_BAO_EntityTag::getTag($id); - if ($contactTag) { - foreach ($contactTag as $tag) { - $defaults[$fName . '[' . $tag . ']'] = 1; - } - } + $defaults['tag'] = implode(',', CRM_Core_BAO_EntityTag::getTag($id, 'civicrm_contact')); + CRM_Core_Error::debug_var('tag', $defaults['tag']); } } diff --git a/templates/CRM/Contact/Form/Edit/TagsAndGroups.tpl b/templates/CRM/Contact/Form/Edit/TagsAndGroups.tpl index 9e2da5f8f6ea..2c14b4ef981a 100644 --- a/templates/CRM/Contact/Form/Edit/TagsAndGroups.tpl +++ b/templates/CRM/Contact/Form/Edit/TagsAndGroups.tpl @@ -87,38 +87,36 @@
{$title}
{/if} -
- {if !$type || $type eq 'group'} -
- {if $title} -
{$form.group.label}
- {/if} - {if $groupElementType eq 'select'} -
{$form.group.html}
- {else} - {foreach key=key item=item from=$tagGroup.group} -
- {$form.group.$key.html} - {if $item.description} - {$item.description} + + + {if !$type || $type eq 'tag'} + + {/if} + {if !$type || $type eq 'group'} + + {/if} + + {if !$type || $type eq 'tag'} + {/if} -
- {include file="CRM/Contact/Form/Edit/Tagtree.tpl" level=1} -
- - {include file="CRM/common/Tagset.tpl"} - {/if} - +
+ {if $title}{$form.tag.label}{/if}
+ {$form.tag.html} +
+ {if $groupElementType eq 'select'} + {if $title}{$form.group.label}{/if} + {$form.group.html} + {else} + {foreach key=key item=item from=$tagGroup.group} +
+ {$form.group.$key.html} + {if $item.description} +
{$item.description}
+ {/if} +
+ {/foreach} {/if} - - {/foreach} - {/if} - - {/if} - {if (!$type || $type eq 'tag') && $tree} -
- {if $title} -
{$form.tag.label}
+
{include file="CRM/common/Tagset.tpl"}
{if $title}
diff --git a/templates/CRM/common/Tagset.tpl b/templates/CRM/common/Tagset.tpl index 94da2ab0ac22..930ed4433768 100644 --- a/templates/CRM/common/Tagset.tpl +++ b/templates/CRM/common/Tagset.tpl @@ -41,8 +41,8 @@ {else}
-
{$form.$elemName.$parID.label}
-
{$form.$elemName.$parID.html}
+ {$form.$elemName.$parID.label} + {$form.$elemName.$parID.html}
{/if} From d8d2f9e10641523d0d4cfd676b4af2b26ceefeae Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Sun, 18 Jun 2017 01:54:13 +0530 Subject: [PATCH 3/3] QA fixes --- CRM/Contact/Form/Contact.php | 6 +- CRM/Contact/Form/Edit/TagsAndGroups.php | 11 ++- .../CRM/Contact/Form/Edit/TagsAndGroups.tpl | 75 +++---------------- templates/CRM/Profile/Form/Dynamic.tpl | 2 +- 4 files changed, 20 insertions(+), 74 deletions(-) diff --git a/CRM/Contact/Form/Contact.php b/CRM/Contact/Form/Contact.php index 0c9eb8fbc842..7102c404d9c3 100644 --- a/CRM/Contact/Form/Contact.php +++ b/CRM/Contact/Form/Contact.php @@ -992,8 +992,10 @@ public function postProcess() { if (array_key_exists('TagsAndGroups', $this->_editOptions)) { //add contact to tags - $params['tag'] = array_flip(explode(',', $params['tag'])); - CRM_Core_BAO_EntityTag::create($params['tag'], 'civicrm_contact', $params['contact_id']); + if (isset($params['tag']) && !empty($params['tag'])) { + $params['tag'] = array_flip(explode(',', $params['tag'])); + CRM_Core_BAO_EntityTag::create($params['tag'], 'civicrm_contact', $params['contact_id']); + } //save free tags if (isset($params['contact_taglist']) && !empty($params['contact_taglist'])) { diff --git a/CRM/Contact/Form/Edit/TagsAndGroups.php b/CRM/Contact/Form/Edit/TagsAndGroups.php index 87b5d418917d..1518c2a119e0 100644 --- a/CRM/Contact/Form/Edit/TagsAndGroups.php +++ b/CRM/Contact/Form/Edit/TagsAndGroups.php @@ -128,7 +128,7 @@ public static function buildQuickForm( if ($groupElementType == 'select' && !empty($groupsOptions)) { $form->add('select', $fName, $groupName, $groupsOptions, FALSE, - array('id' => $fName, 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 310px') + array('id' => $fName, 'multiple' => 'multiple', 'class' => 'crm-select2 twenty') ); $form->assign('groupCount', count($groupsOptions)); } @@ -150,11 +150,11 @@ public static function buildQuickForm( if (!empty($tags)) { $form->add('select2', 'tag', ts('Tag(s)'), $tags, FALSE, array('class' => 'huge', 'placeholder' => ts('- select -'), 'multiple' => TRUE)); } - } - // build tag widget - $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact'); - CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', $contactId, FALSE, TRUE); + // build tag widget + $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact'); + CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', $contactId, FALSE, TRUE); + } $form->assign('tagGroup', $form->_tagGroup); } @@ -195,7 +195,6 @@ public static function setDefaults($id, &$defaults, $type = self::ALL, $fieldNam if ($type & self::TAG) { $defaults['tag'] = implode(',', CRM_Core_BAO_EntityTag::getTag($id, 'civicrm_contact')); - CRM_Core_Error::debug_var('tag', $defaults['tag']); } } diff --git a/templates/CRM/Contact/Form/Edit/TagsAndGroups.tpl b/templates/CRM/Contact/Form/Edit/TagsAndGroups.tpl index 2c14b4ef981a..e13c4c50d23f 100644 --- a/templates/CRM/Contact/Form/Edit/TagsAndGroups.tpl +++ b/templates/CRM/Contact/Form/Edit/TagsAndGroups.tpl @@ -23,65 +23,6 @@ | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ *} -{literal} - - - {if $title}