Skip to content

Commit

Permalink
Manage tags screen UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Dec 24, 2016
1 parent fd06599 commit 6bed696
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 124 deletions.
24 changes: 14 additions & 10 deletions CRM/Tag/Form/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public function buildQuickForm() {
}
}
else {
$parentId = NULL;
$isTagsetChild = FALSE;

$this->_isTagSet = CRM_Utils_Request::retrieve('tagset', 'Positive', $this);

if (!$this->_isTagSet &&
Expand All @@ -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?'));
Expand Down Expand Up @@ -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')) {
Expand All @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions CRM/Tag/Page/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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']) {
Expand Down
14 changes: 14 additions & 0 deletions templates/CRM/Tag/Form/Edit.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,17 @@
{/if}
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
</div>
{literal}
<script type="text/javascript">
CRM.$(function($) {
var $form = $('form.{/literal}{$form.formClass}{literal}');
function toggleUsedFor() {
$('.crm-tag-form-block-used_for', $form).toggle(!$(this).val());
if ($(this).val()) {
$('select#used_for', $form).val('').change();
}
}
$('input[name=parent_id]', $form).change(toggleUsedFor).each(toggleUsedFor);
});
</script>
{/literal}
Loading

0 comments on commit 6bed696

Please sign in to comment.