From 6bed696401e2b6af841e029525fb52e8426f3aaa Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 24 Dec 2016 00:14:31 -0500 Subject: [PATCH] Manage tags screen UI improvements --- CRM/Tag/Form/Edit.php | 24 +-- CRM/Tag/Page/Tag.php | 14 +- templates/CRM/Tag/Form/Edit.tpl | 14 ++ templates/CRM/Tag/Page/Tag.tpl | 268 +++++++++++++++++++------------- 4 files changed, 196 insertions(+), 124 deletions(-) diff --git a/CRM/Tag/Form/Edit.php b/CRM/Tag/Form/Edit.php index 8d6d94ff678f..6def792c3428 100644 --- a/CRM/Tag/Form/Edit.php +++ b/CRM/Tag/Form/Edit.php @@ -58,6 +58,9 @@ public function buildQuickForm() { } } else { + $parentId = NULL; + $isTagsetChild = FALSE; + $this->_isTagSet = CRM_Utils_Request::retrieve('tagset', 'Positive', $this); if (!$this->_isTagSet && @@ -67,9 +70,16 @@ public function buildQuickForm() { $this->_isTagSet = TRUE; } + if ($this->_id) { + $parentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $this->_id, 'parent_id'); + $isTagSetChild = $parentId ? CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $parentId, 'is_tagset') : FALSE; + } + if (!$this->_isTagSet) { - $colorTags = CRM_Core_BAO_Tag::getColorTags(NULL, TRUE, $this->_id); - $this->add('select2', 'parent_id', ts('Parent Tag'), $colorTags, FALSE, array('placeholder' => ts('- select -'))); + if (!$isTagSetChild) { + $colorTags = CRM_Core_BAO_Tag::getColorTags(NULL, TRUE, $this->_id); + $this->add('select2', 'parent_id', ts('Parent Tag'), $colorTags, FALSE, array('placeholder' => ts('- select -'))); + } // Tagsets are not selectable by definition so only include the selectable field if NOT a tagset. $selectable = $this->add('checkbox', 'is_selectable', ts('Selectable?')); @@ -99,13 +109,7 @@ public function buildQuickForm() { $isReserved = $this->add('checkbox', 'is_reserved', ts('Reserved?')); - $usedFor = $this->addSelect('used_for', array('multiple' => TRUE, 'option_url' => NULL)); - - if ($this->_id && - CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $this->_id, 'parent_id') - ) { - $usedFor->freeze(); - } + $this->addSelect('used_for', array('multiple' => TRUE, 'option_url' => NULL)); $adminTagset = TRUE; if (!CRM_Core_Permission::check('administer Tagsets')) { @@ -129,7 +133,7 @@ public function setDefaultValues() { if (empty($this->_id) || !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $this->_id, 'color')) { $defaults['color'] = '#ffffff'; } - if (empty($this->_id) && $this->_isTagSet) { + if (empty($this->_id)) { $defaults['used_for'] = 'civicrm_contact'; } return $defaults; diff --git a/CRM/Tag/Page/Tag.php b/CRM/Tag/Page/Tag.php index cd02704792fb..42327a960bcd 100644 --- a/CRM/Tag/Page/Tag.php +++ b/CRM/Tag/Page/Tag.php @@ -164,10 +164,12 @@ public function browse($action = NULL, $sort = NULL) { $usedFor = CRM_Core_OptionGroup::values('tag_used_for'); - $query = "SELECT t1.name, t1.id, t2.name as parent, t1.description, t1.used_for, t1.is_tagset, - t1.is_reserved, t1.parent_id, t1.used_for, t1.color - FROM civicrm_tag t1 LEFT JOIN civicrm_tag t2 ON t1.parent_id = t2.id - GROUP BY t1.parent_id, t1.id"; + $query = " SELECT t1.name, t1.id, t2.name as parent, t1.description, t1.used_for, t1.is_tagset as is_tagset, + t1.is_reserved, t1.parent_id, t1.used_for, t1.color, t2.is_tagset as is_tagset_child, t2.parent_id as grandparent_id + FROM civicrm_tag t1 + LEFT JOIN civicrm_tag t2 ON t1.parent_id = t2.id + LEFT JOIN civicrm_tag t3 ON t2.parent_id = t3.id + ORDER BY CONCAT(IFNULL(t3.name, ''), IFNULL(t2.name, ''), t1.name)"; $tag = CRM_Core_DAO::executeQuery($query); $values = array(); @@ -186,9 +188,7 @@ public function browse($action = NULL, $sort = NULL) { } } - if (!empty($used)) { - $values[$tag->id]['used_for'] = implode(", ", $used); - } + $values[$tag->id]['used_for'] = implode(", ", $used); $newAction = $action; if ($values[$tag->id]['is_reserved']) { diff --git a/templates/CRM/Tag/Form/Edit.tpl b/templates/CRM/Tag/Form/Edit.tpl index 4d982a765e48..46dc9725cdca 100644 --- a/templates/CRM/Tag/Form/Edit.tpl +++ b/templates/CRM/Tag/Form/Edit.tpl @@ -85,3 +85,17 @@ {/if}
{include file="CRM/common/formButtons.tpl" location="bottom"}
+{literal} + +{/literal} \ No newline at end of file diff --git a/templates/CRM/Tag/Page/Tag.tpl b/templates/CRM/Tag/Page/Tag.tpl index 5eb43910a10d..c0f418b394b4 100644 --- a/templates/CRM/Tag/Page/Tag.tpl +++ b/templates/CRM/Tag/Page/Tag.tpl @@ -27,146 +27,200 @@ {capture assign=docLink}{docURL page="user/organising-your-data/groups-and-tags"}{/capture} {if $action eq 1 or $action eq 2 or $action eq 8} - {include file="CRM/Tag/Form/Edit.tpl"} + {include file="CRM/Tag/Form/Edit.tpl"} {else} -
+
- {ts 1=$docLink}Tags can be assigned to any contact record, and are a convenient way to find contacts. You can create as many tags as needed to organize and segment your records.{/ts} {$docLink} + {ts 1=$docLink}Tags can be assigned to any contact record, and are a convenient way to find contacts. You can create as many tags as needed to organize and segment your records.{/ts} {$docLink}
{if $rows} - {if !($action eq 1 and $action eq 2)} +
+ +
+ {if !($action eq 1 and $action eq 2)}
+ {crmButton q="action=add&reset=1" id="newTag" icon="plus-circle"}{ts}Add Tag{/ts}{/crmButton} +
- {/if} - - {include file="CRM/common/jsortable.tpl"} -
-
- {strip} - + {/if} + {strip} +
- - - - - - - - - - - - {foreach from=$rows item=row key=id } - + + + + + + + + + + + {foreach from=$rows item=row key=id } + {if !$row.is_tagset && !$row.is_tagset_child} + - - + - - {/foreach} + + {/if} + {/foreach}
{ts}Tag{/ts}{ts}ID{/ts}{ts}Description{/ts}{ts}Parent (ID){/ts}{ts}Used For{/ts}{ts}Tag set?{/ts}{ts}Reserved?{/ts}
{ts}Tag{/ts}{ts}ID{/ts}{ts}Description{/ts}{ts}Parent (ID){/ts}{ts}Used For{/ts}{ts}Reserved?{/ts}
{$row.name} {$row.id} {$row.description} {$row.parent}{if $row.parent_id} ({$row.parent_id}){/if}{$row.used_for}{if $row.is_tagset}{ts}Tag Set{/ts}{/if}{$row.used_for} {if $row.is_reserved}{ts}Reserved{/ts}{/if} {$row.action|replace:'xx':$row.id}
- {/strip} + {/strip}
- {if !($action eq 1 and $action eq 2)} +
+ {if !($action eq 1 and $action eq 2) && $adminTagSet}
- +
- {/if} + {/if} + {strip} + + + + + + + + + + + + + {foreach from=$rows item=row key=id} + {if $row.is_tagset || $row.is_tagset_child} + + + + + + + + + + {/if} + {/foreach} +
{ts}Tag{/ts}{ts}ID{/ts}{ts}Description{/ts}{ts}Parent (ID){/ts}{ts}Used For{/ts}{ts}Reserved?{/ts}
+ {$row.name} + {$row.id}{$row.description} {$row.parent}{if $row.parent_id} ({$row.parent_id}){/if}{$row.used_for}{if $row.is_reserved}{ts}Reserved{/ts}{/if}{$row.action|replace:'xx':$row.id}
+ {/strip} +
+
+ {if !($action eq 1 and $action eq 2)} +
+ +
+ {/if} +
+ {include file="CRM/common/jsortable.tpl"} {else} -
+
  - {capture assign=crmURL}{crmURL p='civicrm/tag' q="action=add&reset=1"}{/capture} - {ts 1=$crmURL}There are no Tags present. You can add one.{/ts} -
+ {capture assign=crmURL}{crmURL p='civicrm/tag' q="action=add&reset=1"}{/capture} + {ts 1=$crmURL}There are no Tags present. You can add one.{/ts} +
{/if} -
+
{literal} - + }); + + {/literal} {/if}