$defaults['assignee_contact_id'] = CRM_Utils_Array::value('assignee_contact', $defaults);
// set default tags if exists
- $defaults['tag'] = CRM_Core_BAO_EntityTag::getTag($this->_activityId, 'civicrm_activity');
+ $defaults['tag'] = implode(',', CRM_Core_BAO_EntityTag::getTag($this->_activityId, 'civicrm_activity'));
}
else {
// if it's a new activity, we need to set default values for associated contact fields
$this->assign('customDataSubType', $this->_activityTypeId);
$this->assign('entityID', $this->_activityId);
- CRM_Core_BAO_Tag::getTags('civicrm_activity', $tags, NULL,
- ' ', TRUE);
+ $tags = CRM_Core_BAO_Tag::getColorTags('civicrm_activity');
if (!empty($tags)) {
- $this->add('select', 'tag', ts('Tags'), $tags, FALSE,
- array('id' => 'tags', 'multiple' => 'multiple', 'class' => 'crm-select2 huge')
- );
+ $this->add('select2', 'tag', ts('Tags'), $tags, FALSE, array('class' => 'huge', 'placeholder' => ts('- select -'), 'multiple' => TRUE));
}
// we need to hide activity tagset for special activities
// add tags if exists
$tagParams = array();
if (!empty($params['tag'])) {
+ if (!is_array($params['tag'])) {
+ $params['tag'] = explode(',', $params['tag']);
+ }
foreach ($params['tag'] as $tag) {
$tagParams[$tag] = 1;
}
)), TRUE
);
- CRM_Core_BAO_Tag::getTags('civicrm_case', $tags, NULL,
- ' ', TRUE);
+ $tags = CRM_Core_BAO_Tag::getColorTags('civicrm_case');
if (!empty($tags)) {
- $this->add('select', 'tag', ts('Select Tags'), $tags, FALSE,
- array('id' => 'tags', 'multiple' => 'multiple', 'class' => 'crm-select2')
+ $this->add('select2', 'tag', ts('Tags'), $tags, FALSE,
+ array('class' => 'huge', 'multiple' => 'multiple')
);
}
$tagParams = array();
if (!empty($params['tag'])) {
$tagParams = array();
+ if (!is_array($params['tag'])) {
+ $params['tag'] = explode(',', $params['tag']);
+ }
foreach ($params['tag'] as $tag) {
$tagParams[$tag] = 1;
}
$this->assign('hookCaseSummary', $hookCaseSummary);
}
- CRM_Core_BAO_Tag::getTags('civicrm_case', $allTags, NULL,
- ' ', TRUE);
+ $allTags = CRM_Core_BAO_Tag::getColorTags('civicrm_case');
if (!empty($allTags)) {
- $this->add('select', 'case_tag', ts('Tags'), $allTags, FALSE,
- array('id' => 'tags', 'multiple' => 'multiple', 'class' => 'crm-select2')
+ $this->add('select2', 'case_tag', ts('Tags'), $allTags, FALSE,
+ array('id' => 'tags', 'multiple' => 'multiple')
);
$tags = CRM_Core_BAO_EntityTag::getTag($this->_caseID, 'civicrm_case');
- $this->setDefaults(array('case_tag' => $tags));
-
foreach ($tags as $tid) {
- if (isset($allTags[$tid])) {
- $tags[$tid] = $allTags[$tid];
+ $tagInfo = CRM_Utils_Array::findInTree($tid, $allTags);
+ if ($tagInfo) {
+ $tags[$tid] = $tagInfo;
}
else {
unset($tags[$tid]);
}
}
- $this->assign('tags', implode(', ', array_filter($tags)));
+ $this->setDefaults(array('case_tag' => implode(',', array_keys($tags))));
+
+ $this->assign('tags', $tags);
$this->assign('showTags', TRUE);
}
else {
return $tags;
}
+ /**
+ * @param string $usedFor
+ * @param bool $allowSelectingNonSelectable
+ * @param null $exclude
+ * @return array
+ * @throws \CiviCRM_API3_Exception
+ */
+ public static function getColorTags($usedFor = NULL, $allowSelectingNonSelectable = FALSE, $exclude = NULL) {
+ $params = array(
+ 'options' => array('limit' => 0),
+ 'is_tagset' => 0,
+ 'return' => array('name', 'description', 'parent_id', 'color', 'is_selectable', 'used_for'),
+ );
+ if ($usedFor) {
+ $params['used_for'] = array('LIKE' => "%$usedFor%");
+ }
+ if ($exclude) {
+ $params['id'] = array('!=' => $exclude);
+ }
+ $allTags = array();
+ foreach (CRM_Utils_Array::value('values', civicrm_api3('Tag', 'get', $params)) as $id => $tag) {
+ $allTags[$id] = array(
+ 'text' => $tag['name'],
+ 'id' => $id,
+ 'description' => CRM_Utils_Array::value('description', $tag),
+ 'parent_id' => CRM_Utils_Array::value('parent_id', $tag),
+ 'used_for' => CRM_Utils_Array::value('used_for', $tag),
+ 'color' => CRM_Utils_Array::value('color', $tag),
+ );
+ if (!$allowSelectingNonSelectable && empty($tag['is_selectable'])) {
+ $allTags[$id]['disabled'] = TRUE;
+ }
+ }
+ return CRM_Utils_Array::buildTree($allTags);
+ }
+
/**
* Delete the tag.
*
}
$type = $type == 'wysiwyg' ? 'textarea' : 'text';
}
+ // Like select but accepts rich array data (with nesting, colors, icons, etc) as option list.
+ if ($inputType == 'select2') {
+ $type = 'text';
+ $options = $attributes;
+ $attributes = $attributes = ($extra ? $extra : array()) + array('class' => '');
+ $attributes['class'] = ltrim($attributes['class'] . " crm-select2 crm-form-select2");
+ $attributes['data-select-params'] = json_encode(array('data' => $options, 'multiple' => !empty($attributes['multiple'])));
+ unset($attributes['multiple']);
+ $extra = NULL;
+ }
// @see http://wiki.civicrm.org/confluence/display/CRMDOC/crmDatepicker
if ($type == 'datepicker') {
$attributes = ($attributes ? $attributes : array());
if ($element->getAttribute('data-api-entity') && $element->getAttribute('data-entity-value')) {
$this->renderFrozenEntityRef($el, $element);
}
+ elseif ($element->getAttribute('type') == 'text' && $element->getAttribute('data-select-params')) {
+ $this->renderFrozenSelect2($el, $element);
+ }
elseif ($element->getAttribute('type') == 'text' && $element->getAttribute('formatType')) {
list($date, $time) = CRM_Utils_Date::setDateDefaults($element->getValue(), $element->getAttribute('formatType'), $element->getAttribute('format'), $element->getAttribute('timeformat'));
$date .= ($element->getAttribute('timeformat')) ? " $time" : '';
$field->setValue(implode(',', $val));
}
+ /**
+ * Render select2 as text.
+ *
+ * @param array $el
+ * @param HTML_QuickForm_element $field
+ */
+ public function renderFrozenSelect2(&$el, $field) {
+ $params = json_decode($field->getAttribute('data-select-params'), TRUE);
+ $val = $field->getValue();
+ if ($val && !empty($params['data'])) {
+ $display = array();
+ foreach (explode(',', $val) as $item) {
+ $match = CRM_Utils_Array::findInTree($item, $params['data']);
+ if (isset($match['text']) && strlen($match['text'])) {
+ $display[] = $match['text'];
+ }
+ }
+ $el['html'] = implode('; ', $display) . '<input type="hidden" value="' . $field->getValue() . '" name="' . $field->getAttribute('name') . '">';
+ }
+ }
+
/**
* Render entity references as text.
* If user has permission, format as link (for now limited to contacts).
$this->_isTagSet = TRUE;
}
- $allTag = array('' => ts('- select -')) + CRM_Core_BAO_Tag::getTagsNotInTagset();
-
- if ($this->_id) {
- unset($allTag[$this->_id]);
- }
-
if (!$this->_isTagSet) {
- $this->add('select', 'parent_id', ts('Parent Tag'), $allTag, FALSE, array('class' => 'crm-select2'));
+ $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?'));
return $array;
}
+ public static function buildTree($elements, $parentId = NULL) {
+ $branch = array();
+
+ foreach ($elements as $element) {
+ if ($element['parent_id'] == $parentId) {
+ $children = self::buildTree($elements, $element['id']);
+ if ($children) {
+ $element['children'] = $children;
+ }
+ $branch[] = $element;
+ }
+ }
+
+ return $branch;
+ }
+
+ public static function findInTree($search, $tree, $field = 'id') {
+ foreach ($tree as $item) {
+ if ($item[$field] == $search) {
+ return $item;
+ }
+ if (!empty($item['children'])) {
+ $found = self::findInTree($search, $item['children']);
+ if ($found) {
+ return $found;
+ }
+ }
+ }
+ return NULL;
+ }
+
}
}
.crm-container .select2-results li,
.crm-container .select2-results .crm-select2-row,
-.crm-container .select2-results .crm-select2-row .crm-select2-row-description p {
+.crm-container .select2-results .crm-select2-row-description p {
padding: 0;
margin: 0;
}
.crm-container .select2-results .crm-select2-row .crm-select2-row-label {
font-size: 1.1em;
}
-.crm-container .select2-results .crm-select2-row .crm-select2-row-description p {
+.crm-container .select2-results .crm-select2-row-description p {
font-size: 0.8em;
line-height: 1.5em;
color: #696969;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
+ font-weight: normal;
}
-.crm-container .select2-results .select2-highlighted .crm-select2-row .crm-select2-row-description p {
+.crm-container .select2-results .select2-highlighted > .select2-result-label .crm-select2-row-description p {
color: #f0f0f0;
}
+.select2-container .crm-select2-row-description {
+ display: none;
+}
.crm-container .select2-results .crm-select2-icon {
width: 20px;
height: 100%;
box-sizing: border-box;
}
+span.crm-select-item-color {
+ display: inline-block;
+ width: .8em;
+ height: .7em;
+ border-radius: 2px;
+ border: 1px solid grey;
+}
+
/* jQuery UI styles */
.crm-container .ui-progressbar-value {
background-image: url("../packages/jquery/css/images/pbar-ani.gif");
.crm-container .crm-grip {
cursor: move;
}
+
+.crm-tag-item {
+ display: inline-block;
+ padding: 1px 5px;
+ border-radius: 3px;
+ border: 1px solid grey;
+}
\ No newline at end of file
color: #000;
}
-.crm-tag-item {
- display: inline-block;
- padding: 1px 5px;
- border-radius: 3px;
- border: 1px solid grey;
-}
};
function formatCrmSelect2(row) {
- var icon = $(row.element).data('icon');
- return (icon ? '<i class="crm-i ' + icon + '"></i> ' : '') + _.escape(row.text);
+ var icon = row.icon || $(row.element).data('icon'),
+ color = row.color || $(row.element).data('color'),
+ description = row.description || $(row.element).data('description'),
+ ret = '';
+ if (icon) {
+ ret += '<i class="crm-i ' + icon + '"></i> ';
+ }
+ if (color) {
+ ret += '<span class="crm-select-item-color" style="background-color: ' + color + '"></span> ';
+ }
+ return ret + _.escape(row.text) + (description ? '<div class="crm-select2-row-description"><p>' + _.escape(description) + '</p></div>' : '');
}
/**
var miniForms = {
'#manageTagsDialog': {
post: function(data) {
- var tagsChecked = $("#tags", this) ? $("#tags", this).select2('val').join(',') : '',
+ var tagsChecked = $("#tags", this) ? $("#tags", this).val() : '',
tagList = {},
url = CRM.url('civicrm/case/ajax/processtags');
$("input[name^=case_taglist]", this).each(function() {
</div><!-- /.crm-accordion-header -->
<div class="crm-accordion-body">
{if $tags}
- <p class="crm-block crm-content-block crm-case-caseview-display-tags"> {$tags}</p>
+ <p class="crm-block crm-content-block crm-case-caseview-display-tags">
+
+ {foreach from=$tags item='tag'}
+ <span class="crm-tag-item" {if !empty($tag.color)}style="background-color: {$tag.color}; color: {$tag.color|colorContrast};"{/if}>
+ {$tag.text}
+ </span>
+ {/foreach}
+ </p>
{/if}
{foreach from=$tagSetTags item=displayTagset}