Skip to content

Commit

Permalink
Merge pull request #9554 from colemanw/CRM-19769
Browse files Browse the repository at this point in the history
CRM-19769 CRM-19779 - Colors for tags and activty statuses
  • Loading branch information
colemanw authored Dec 29, 2016
2 parents 408fbd4 + 6bed696 commit eac1f38
Show file tree
Hide file tree
Showing 38 changed files with 662 additions and 184 deletions.
2 changes: 1 addition & 1 deletion CRM/Activity/BAO/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -2498,7 +2498,7 @@ public static function getContactActivitySelector(&$params) {
$activity = array();
$activity['DT_RowId'] = $activityId;
// Add class to this row if overdue.
$activity['DT_RowClass'] = 'crm-entity';
$activity['DT_RowClass'] = "crm-entity status-id-{$values['status_id']}";
if (CRM_Utils_Date::overdue(CRM_Utils_Array::value('activity_date_time', $values))
&& CRM_Utils_Array::value('status_id', $values) == 1
) {
Expand Down
12 changes: 6 additions & 6 deletions CRM/Activity/Form/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ public function setDefaultValues() {
$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
Expand Down Expand Up @@ -725,13 +725,10 @@ public function buildQuickForm() {
$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
Expand Down Expand Up @@ -1011,6 +1008,9 @@ protected function processActivity(&$params) {
// 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;
}
Expand Down
13 changes: 12 additions & 1 deletion CRM/Admin/Form/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ public function setDefaultValues() {
if ($this->_gName == 'payment_instrument' && $this->_id) {
$defaults['financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($this->_id, 'civicrm_option_value', 'financial_account_id');
}
if (empty($this->_id) || !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'color')) {
$defaults['color'] = '#ffffff';
}
return $defaults;
}

Expand Down Expand Up @@ -174,6 +177,10 @@ public function buildQuickForm() {
$this->add('text', 'icon', ts('Icon'), array('class' => 'crm-icon-picker', 'title' => ts('Choose Icon'), 'allowClear' => TRUE));
}

if ($this->_gName == 'activity_status') {
$this->add('color', 'color', ts('Color'));
}

if (!in_array($this->_gName, array(
'email_greeting',
'postal_greeting',
Expand Down Expand Up @@ -428,7 +435,7 @@ public function postProcess() {
}
}
else {
$params = $ids = array();
$ids = array();
$params = $this->exportValues();

// allow multiple defaults within group.
Expand Down Expand Up @@ -458,6 +465,10 @@ public function postProcess() {
}
}

if (isset($params['color']) && strtolower($params['color']) == '#ffffff') {
$params['color'] = 'null';
}

$groupParams = array('name' => ($this->_gName));
$optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id);

Expand Down
3 changes: 2 additions & 1 deletion CRM/Admin/Page/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public static function mergeTagList() {

// query to list mergable tags
$query = "
SELECT t1.name, t1.id, t1.used_for, t2.name as parent
SELECT t1.name, t1.id, t1.used_for, t1.color, t2.name as parent
FROM civicrm_tag t1
LEFT JOIN civicrm_tag t2 ON t1.parent_id = t2.id
WHERE t1.id <> {$fromId} AND
Expand All @@ -280,6 +280,7 @@ public static function mergeTagList() {
$row = array(
'id' => $dao->id,
'text' => ($dao->parent ? "{$dao->parent} :: " : '') . $dao->name,
'color' => isset($dao->color) ? $dao->color : NULL,
);
// Add warning about used_for types
if (!empty($dao->used_for)) {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Case/BAO/Case.php
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ public static function getCaseActivity($caseID, &$params, $contactID, $context =

$caseActivity['DT_RowId'] = $caseActivityId;
//Add classes to the row, via DataTables syntax
$caseActivity['DT_RowClass'] = "crm-entity";
$caseActivity['DT_RowClass'] = "crm-entity status-id-$dao->status";

if (CRM_Utils_Array::crmInArray($dao->status, $compStatusValues)) {
$caseActivity['DT_RowClass'] .= " status-completed";
Expand Down
10 changes: 6 additions & 4 deletions CRM/Case/Form/Case.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,11 @@ public function buildQuickForm() {
)), TRUE
);

CRM_Core_BAO_Tag::getTags('civicrm_case', $tags, NULL,
'&nbsp;&nbsp;', 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')
);
}

Expand Down Expand Up @@ -371,6 +370,9 @@ public function postProcess() {
$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;
}
Expand Down
18 changes: 9 additions & 9 deletions CRM/Case/Form/CaseView.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,28 +343,28 @@ public function buildQuickForm() {
$this->assign('hookCaseSummary', $hookCaseSummary);
}

CRM_Core_BAO_Tag::getTags('civicrm_case', $allTags, NULL,
'&nbsp;&nbsp;', 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 {
Expand Down
3 changes: 2 additions & 1 deletion CRM/Contact/Page/View/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ public function view() {
$contactTags = CRM_Core_BAO_EntityTag::getContactTags($this->_contactId);

if (!empty($contactTags)) {
$defaults['contactTag'] = implode(', ', $contactTags);
$defaults['contactTag'] = $contactTags;
$defaults['allTags'] = CRM_Core_BAO_Tag::getTagsUsedFor('civicrm_contact', FALSE);
}

$defaults['privacy_values'] = CRM_Core_SelectValues::privacy();
Expand Down
39 changes: 38 additions & 1 deletion CRM/Core/BAO/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public static function getTagsUsedFor(
$tags[$tag->id]['parent_id'] = $tag->parent_id;
$tags[$tag->id]['is_tagset'] = $tag->is_tagset;
$tags[$tag->id]['used_for'] = $tag->used_for;
$tags[$tag->id]['color'] = !empty($tag->color) ? $tag->color : NULL;
}
}
$tag->free();
Expand Down Expand Up @@ -313,6 +314,42 @@ public static function getTags(
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.
*
Expand Down Expand Up @@ -345,7 +382,7 @@ public static function del($id) {
}

/**
* Takes an associative array and creates a contact object.
* Takes an associative array and creates a tag object.
*
* The function extract all the params it needs to initialize the create a
* contact object. the params array could contain additional unused name/value
Expand Down
17 changes: 16 additions & 1 deletion CRM/Core/DAO/OptionValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* Generated from xml/schema/CRM/Core/OptionValue.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:7581126bad606520292d883da2f620ca)
* (GenCodeChecksum:fdf2f62ba69b54da0567362493827448)
*/
require_once 'CRM/Core/DAO.php';
require_once 'CRM/Utils/Type.php';
Expand Down Expand Up @@ -149,6 +149,12 @@ class CRM_Core_DAO_OptionValue extends CRM_Core_DAO {
* @var string
*/
public $icon;
/**
* Hex color value e.g. #ffffff
*
* @var string
*/
public $color;
/**
* class constructor
*
Expand Down Expand Up @@ -335,6 +341,15 @@ static function &fields() {
'size' => CRM_Utils_Type::HUGE,
'default' => 'NULL',
) ,
'color' => array(
'name' => 'color',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Color') ,
'description' => 'Hex color value e.g. #ffffff',
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'default' => 'NULL',
) ,
);
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
Expand Down
17 changes: 16 additions & 1 deletion CRM/Core/DAO/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* Generated from xml/schema/CRM/Core/Tag.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:e62b7ed2ffb1714200328dd2b08cdc9c)
* (GenCodeChecksum:1e6ad1d5a7c05b1a7d300d2a7722ba4d)
*/
require_once 'CRM/Core/DAO.php';
require_once 'CRM/Utils/Type.php';
Expand Down Expand Up @@ -99,6 +99,12 @@ class CRM_Core_DAO_Tag extends CRM_Core_DAO {
* @var int unsigned
*/
public $created_id;
/**
* Hex color value e.g. #ffffff
*
* @var string
*/
public $color;
/**
* Date and time that tag was created.
*
Expand Down Expand Up @@ -208,6 +214,15 @@ static function &fields() {
'description' => 'FK to civicrm_contact, who created this tag',
'FKClassName' => 'CRM_Contact_DAO_Contact',
) ,
'color' => array(
'name' => 'color',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Color') ,
'description' => 'Hex color value e.g. #ffffff',
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'default' => 'NULL',
) ,
'created_date' => array(
'name' => 'created_date',
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
Expand Down
16 changes: 16 additions & 0 deletions CRM/Core/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
'number',
'url',
'email',
'color',
);

/**
Expand Down Expand Up @@ -345,6 +346,7 @@ public function &add(
$attributes = '', $required = FALSE, $extra = NULL
) {
// Fudge some extra types that quickform doesn't support
$inputType = $type;
if ($type == 'wysiwyg' || in_array($type, self::$html5Types)) {
$attributes = ($attributes ? $attributes : array()) + array('class' => '');
$attributes['class'] = ltrim($attributes['class'] . " crm-form-$type");
Expand All @@ -354,6 +356,16 @@ public function &add(
}
$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());
Expand Down Expand Up @@ -384,6 +396,10 @@ public function &add(
CRM_Core_Error::fatal(HTML_QuickForm::errorMessage($element));
}

if ($inputType == 'color') {
$this->addRule($name, ts('%1 must contain a color value e.g. #ffffff.', array(1 => $label)), 'regex', '/#[0-9a-fA-F]{6}/');
}

if ($required) {
if ($type == 'file') {
$error = $this->addRule($name, ts('%1 is a required field.', array(1 => $label)), 'uploadedfile');
Expand Down
Loading

0 comments on commit eac1f38

Please sign in to comment.