Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-20622 , CRM-20673 : tags and groups panel layout/styling #10429

Merged
merged 3 commits into from
Jun 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CRM/Contact/Form/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,10 @@ public function postProcess() {

if (array_key_exists('TagsAndGroups', $this->_editOptions)) {
//add contact to tags
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'])) {
Expand Down
75 changes: 5 additions & 70 deletions CRM/Contact/Form/Edit/TagsAndGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 twenty')
);
$form->assign('groupCount', count($groupsOptions));
}
Expand All @@ -145,40 +145,10 @@ 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);
$tags = CRM_Core_BAO_Tag::getColorTags('civicrm_contact');

$form->addGroup($elements, $fName, $tagName, '<br />');
$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));

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
Expand All @@ -188,31 +158,6 @@ public static function buildQuickForm(
$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;
}

/**
* Set defaults for relevant form elements.
*
Expand Down Expand Up @@ -249,17 +194,7 @@ 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'));
}
}

Expand Down
82 changes: 14 additions & 68 deletions templates/CRM/Contact/Form/Edit/TagsAndGroups.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,77 +23,31 @@
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*}
{literal}
<style>
#tagtree .highlighted > span {
background-color: #fefca6;
}
#tagtree .helpicon ins {
display: none;
}
#tagtree ins.jstree-icon {
cursor: pointer;
}
</style>
<script type="text/javascript">
(function($, _){{/literal}
var entityID='{$entityID}',
entityTable='{$entityTable}',
$form = $('form.{$form.formClass}');
{literal}

$(function() {
function highlightSelected() {
$("ul input:not(:checked)", '#tagtree').each(function () {
$(this).closest("li").removeClass('highlighted');
});
$("ul input:checked", '#tagtree').each(function () {
$(this).parents("li[id^=tag]").addClass('highlighted');
});
}
highlightSelected();

$("#tagtree input").change(function(){
highlightSelected();
});

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}
$("#tagtree input").prop('disabled', true);
{/literal}
{/if}
{literal}
});
})(CRM.$, CRM._);
{/literal}
</script>

{if $title}
<div class="crm-accordion-wrapper crm-tagGroup-accordion collapsed">
<div class="crm-accordion-header">{$title}</div>
<div class="crm-accordion-body" id="tagGroup">
{/if}
<table class="form-layout-compressed{if $context EQ 'profile'} crm-profile-tagsandgroups{/if}">
<tr>
{if !$type || $type eq 'tag'}
<td>
<div class="crm-section tag-section">
{if $title}{$form.tag.label}{/if}
{$form.tag.html}
</div>
{if $context NEQ 'profile'}
{include file="CRM/common/Tagset.tpl"}
{/if}
</td>
{/if}
{if !$type || $type eq 'group'}
<td>
{if $groupElementType eq 'select'}
<span class="label">{if $title}{$form.group.label}{/if}</span>
<div class="crm-section group-section">
{if $title}{$form.group.label}{/if}
{$form.group.html}
</div>
{else}
{foreach key=key item=item from=$tagGroup.group}
<div class="group-wrapper">
Expand All @@ -106,14 +60,6 @@
{/if}
</td>
{/if}
{if (!$type || $type eq 'tag') && $tree}
<td width="70%">{if $title}<span class="label">{$form.tag.label}</span>{/if}
<div id="tagtree">
{include file="CRM/Contact/Form/Edit/Tagtree.tpl" level=1}
</div>
</td>
<tr><td>{include file="CRM/common/Tagset.tpl"}</td></tr>
{/if}
</tr>
</table>
{if $title}
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Profile/Form/Dynamic.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
{if $n eq 'email_greeting' or $n eq 'postal_greeting' or $n eq 'addressee'}
{include file="CRM/Profile/Form/GreetingType.tpl"}
{elseif ( $n eq 'group' && $form.group ) || ( $n eq 'tag' && $form.tag )}
{include file="CRM/Contact/Form/Edit/TagsAndGroups.tpl" type=$n context="profile"}
{include file="CRM/Contact/Form/Edit/TagsAndGroups.tpl" type=$n context="profile" tableLayout=1}
{elseif ( $form.$n.name eq 'image_URL' )}
{$form.$n.html}
{if !empty($imageURL)}
Expand Down