Skip to content
Snippets Groups Projects
Commit 397c32e4 authored by Satish's avatar Satish
Browse files

Show picklist color as background color for picklist value in Edit / Create view

parent 62b81786
No related branches found
No related tags found
No related merge requests found
{*<!--
/*********************************************************************************
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
*
********************************************************************************/
-->*}
{*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
*************************************************************************************}
{strip}
{assign var="FIELD_INFO" value=$FIELD_MODEL->getFieldInfo()}
{assign var=PICKLIST_VALUES value=$FIELD_MODEL->getPicklistValues()}
{assign var="SPECIAL_VALIDATOR" value=$FIELD_MODEL->getValidator()}
{assign var=PICKLIST_COLORS value=$FIELD_MODEL->getPicklistColors()}
<select data-fieldname="{$FIELD_MODEL->getFieldName()}" data-fieldtype="picklist" class="inputElement select2 {if $OCCUPY_COMPLETE_WIDTH} row {/if}" type="picklist" name="{$FIELD_MODEL->getFieldName()}" {if !empty($SPECIAL_VALIDATOR)}data-validator='{Zend_Json::encode($SPECIAL_VALIDATOR)}'{/if} data-selected-value='{$FIELD_MODEL->get('fieldvalue')}'
{if $FIELD_INFO["mandatory"] eq true} data-rule-required="true" {/if}
{if count($FIELD_INFO['validator'])}
data-specific-rules='{ZEND_JSON::encode($FIELD_INFO["validator"])}'
{/if}
>
{if $FIELD_MODEL->isEmptyPicklistOptionAllowed()}<option value="">{vtranslate('LBL_SELECT_OPTION','Vtiger')}</option>{/if}
{if $FIELD_INFO["mandatory"] eq true} data-rule-required="true" {/if}
{if count($FIELD_INFO['validator'])}
data-specific-rules='{ZEND_JSON::encode($FIELD_INFO["validator"])}'
{/if}
>
{if $FIELD_MODEL->isEmptyPicklistOptionAllowed()}<option value="">{vtranslate('LBL_SELECT_OPTION','Vtiger')}</option>{/if}
{foreach item=PICKLIST_VALUE key=PICKLIST_NAME from=$PICKLIST_VALUES}
<option value="{Vtiger_Util_Helper::toSafeHTML($PICKLIST_NAME)}" {if trim(decode_html($FIELD_MODEL->get('fieldvalue'))) eq trim($PICKLIST_NAME)} selected {/if}>{$PICKLIST_VALUE}</option>
{/foreach}
{assign var=CLASS_NAME value="picklistColor_{$FIELD_MODEL->getFieldName()}_{$PICKLIST_NAME|replace:' ':'_'}"}
<option value="{Vtiger_Util_Helper::toSafeHTML($PICKLIST_NAME)}" {if $PICKLIST_COLORS[$PICKLIST_NAME]}class="{$CLASS_NAME}"{/if} {if trim(decode_html($FIELD_MODEL->get('fieldvalue'))) eq trim($PICKLIST_NAME)} selected {/if}>{$PICKLIST_VALUE}</option>
{/foreach}
</select>
<style type="text/css">
{foreach item=PICKLIST_VALUE key=PICKLIST_NAME from=$PICKLIST_VALUES}
{assign var=CLASS_NAME value="{$FIELD_MODEL->getFieldName()}_{$PICKLIST_NAME|replace:' ':'_'}"}
.picklistColor_{$CLASS_NAME} {
background-color: {$PICKLIST_COLORS[$PICKLIST_NAME]} !important;
}
{/foreach}
</style>
{/strip}
......@@ -1306,4 +1306,30 @@ class Vtiger_Field_Model extends Vtiger_Field {
return ($this->get('headerfield')) ? true : false;
}
}
\ No newline at end of file
public function getPicklistColors() {
$picklistColors = array();
$fieldDataType = $this->getFieldDataType();
if (in_array($fieldDataType, array('picklist', 'multipicklist'))) {
$fieldName = $this->getName();
preg_match('/(\w+) ; \((\w+)\) (\w+)/', $fieldName, $matches);
if (count($matches) > 0) {
list($full, $referenceParentField, $referenceModule, $referenceFieldName) = $matches;
$fieldName = $referenceFieldName;
}
if (!in_array($fieldName, array('hdnTaxType', 'region_id'))) {
$db = PearDatabase::getInstance();
$picklistValues = $this->getPicklistValues();
if (is_array($picklistValues)) {
$result = $db->pquery("SELECT $fieldName, color FROM vtiger_$fieldName WHERE $fieldName IN (".generateQuestionMarks($picklistValues).")", array_keys($picklistValues));
while ($row = $db->fetch_row($result)) {
$picklistColors[$row[$fieldName]] = $row['color'];
}
}
}
}
return $picklistColors;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment