From 4171274a5585aacc98d4eb6738ed6d7ff88ef876 Mon Sep 17 00:00:00 2001 From: satish <satish.dvnk@vtiger.com> Date: Tue, 29 Aug 2017 17:54:09 +0530 Subject: [PATCH] Fixes #648 - vt7: Adding a field called "Tasks" breaks the Workflow editor --- .../Workflows/resources/AdvanceFilter.js | 32 +++++++++++++++++ modules/Settings/Workflows/models/Field.php | 23 ++++++------ modules/Settings/Workflows/models/Record.php | 36 +++++++++++++++++-- 3 files changed, 78 insertions(+), 13 deletions(-) diff --git a/layouts/v7/modules/Settings/Workflows/resources/AdvanceFilter.js b/layouts/v7/modules/Settings/Workflows/resources/AdvanceFilter.js index b73f8615..76ed5b4f 100644 --- a/layouts/v7/modules/Settings/Workflows/resources/AdvanceFilter.js +++ b/layouts/v7/modules/Settings/Workflows/resources/AdvanceFilter.js @@ -501,3 +501,35 @@ Vtiger_Picklist_Field_Js('Workflows_Picklist_Field_Js',{},{ return selectContainer; } }); + +Vtiger_Multipicklist_Field_Js('Workflows_Multipicklist_Field_Js', {}, { + + getUi: function () { + var selectedOptions = new Array(); + var selectedRawOption = app.htmlDecode(this.getValue()); + if (selectedRawOption) { + var selectedOptions = selectedRawOption.split(','); + } + var pickListValues = this.getPickListValues(); + + var tagsArray = new Array(); + var pickListValuesArrayFlip = {}; + var selectedOption = ''; + jQuery.map(pickListValues, function (pickListValue, key) { + (jQuery.inArray(key, selectedOptions) !== -1); + if (jQuery.inArray(key, selectedOptions) !== -1) { + selectedOption += pickListValue+','; + } + tagsArray.push(pickListValue); + pickListValuesArrayFlip[pickListValue] = key; + }) + selectedOption = selectedOption.substring(0,selectedOption.lastIndexOf(',')); + + var html = '<input type="hidden" class="col-lg-12 select2" name="'+this.getName()+'[]" id="'+this.getName()+'" data-fieldtype="multipicklist" >'; + var selectContainer = jQuery(html).val(selectedOption); + selectContainer.data('tags', tagsArray).data('picklistvalues', pickListValuesArrayFlip); + selectContainer.data('placeholder', app.vtranslate('JS_PLEASE_SELECT_ATLEAST_ONE_OPTION')).data('closeOnSelect', true); + this.addValidationToElement(selectContainer); + return selectContainer; + } +}); diff --git a/modules/Settings/Workflows/models/Field.php b/modules/Settings/Workflows/models/Field.php index 17ce3c22..89c70081 100644 --- a/modules/Settings/Workflows/models/Field.php +++ b/modules/Settings/Workflows/models/Field.php @@ -61,31 +61,32 @@ class Settings_Workflows_Field_Model extends Vtiger_Field_Model { */ public static function getAdvancedFilterOpsByFieldType() { return array( - 'string' => array('is', 'contains', 'does not contain', 'starts with', 'ends with', 'has changed', 'is empty', 'is not empty'), - 'salutation' => array('is', 'contains', 'does not contain', 'starts with', 'ends with', 'has changed', 'is empty', 'is not empty'), - 'text' => array('is', 'contains', 'does not contain', 'starts with', 'ends with', 'has changed', 'is empty', 'is not empty'), - 'url' => array('is', 'contains', 'does not contain', 'starts with', 'ends with', 'has changed', 'is empty', 'is not empty'), - 'email' => array('is', 'contains', 'does not contain', 'starts with', 'ends with', 'has changed', 'is empty', 'is not empty'), - 'phone' => array('is', 'contains', 'does not contain', 'starts with', 'ends with', 'has changed', 'is empty', 'is not empty'), + 'string' => array('is', 'is not', 'contains', 'does not contain', 'starts with', 'ends with', 'has changed', 'is empty', 'is not empty'), + 'salutation' => array('is', 'is not', 'contains', 'does not contain', 'starts with', 'ends with', 'has changed', 'is empty', 'is not empty'), + 'text' => array('is', 'is not', 'contains', 'does not contain', 'starts with', 'ends with', 'has changed', 'is empty', 'is not empty'), + 'url' => array('is', 'is not', 'contains', 'does not contain', 'starts with', 'ends with', 'has changed', 'is empty', 'is not empty'), + 'email' => array('is', 'is not', 'contains', 'does not contain', 'starts with', 'ends with', 'has changed', 'is empty', 'is not empty'), + 'phone' => array('is', 'is not', 'contains', 'does not contain', 'starts with', 'ends with', 'has changed', 'is empty', 'is not empty'), 'integer' => array('equal to', 'less than', 'greater than', 'does not equal', 'less than or equal to', 'greater than or equal to', 'has changed'), 'double' => array('equal to', 'less than', 'greater than', 'does not equal', 'less than or equal to', 'greater than or equal to', 'has changed'), 'currency' => array('equal to', 'less than', 'greater than', 'does not equal', 'less than or equal to', 'greater than or equal to', 'has changed', 'is not empty'), - 'picklist' => array('is', 'is not', 'has changed', 'has changed to', 'has changed from', 'is empty', 'is not empty'), + 'picklist' => array('is', 'is not', 'starts with', 'ends with', 'contains', 'does not contain', 'has changed', 'has changed to', 'has changed from', 'is empty', 'is not empty'), 'multipicklist' => array('is', 'is not','contains','does not contain', 'has changed', 'has changed to'), 'datetime' => array('is', 'is not', 'has changed', 'before', 'after', 'is today', 'is tomorrow', 'is yesterday', 'less than hours before', 'less than hours later', - 'more than hours before', 'more than hours later', 'less than days ago', 'less than days later', 'more than days ago', 'more than days later', 'days ago', 'days later', 'is empty', 'is not empty'), + 'more than hours before', 'more than hours later', 'less than days ago', 'less than days later', 'more than days ago', 'more than days later', 'days ago', 'days later', 'is empty', 'is not empty'), 'time' => array('is', 'is not', 'has changed', 'is not empty'), 'date' => array('is', 'is not', 'has changed', 'between', 'before', 'after', 'is today', 'is tomorrow', 'is yesterday', 'less than days ago', 'more than days ago', 'less than days later', - 'more than days later', 'in less than', 'in more than', 'days ago', 'days later', 'is empty', 'is not empty'), + 'more than days later', 'in less than', 'in more than', 'days ago', 'days later', 'is empty', 'is not empty'), 'boolean' => array('is', 'is not', 'has changed'), - 'reference' => array('has changed'), - 'multireference'=>array('has changed'), + 'reference' => array('is empty', 'is not empty', 'has changed'), + 'multireference'=>array('has changed'), 'owner' => array('has changed','is','is not'), 'ownergroup' => array('has changed','is','is not'), 'recurrence' => array('is', 'is not', 'has changed'), 'comment' => array('is added'), 'image' => array('is', 'is not', 'contains', 'does not contain', 'starts with', 'ends with', 'is empty', 'is not empty'), 'percentage' => array('equal to', 'less than', 'greater than', 'does not equal', 'less than or equal to', 'greater than or equal to', 'has changed', 'is not empty'), + 'currencyList' => array('is', 'is not', 'has changed', 'has changed to', 'has changed from'), ); } diff --git a/modules/Settings/Workflows/models/Record.php b/modules/Settings/Workflows/models/Record.php index 0f9a741c..4d8344da 100644 --- a/modules/Settings/Workflows/models/Record.php +++ b/modules/Settings/Workflows/models/Record.php @@ -462,12 +462,44 @@ class Settings_Workflows_Record_Model extends Settings_Vtiger_Record_Model { } else { $conditionGroup = 'Any'; } - if($value == 'true:boolean' || ($fieldModel && $fieldModel->getFieldDataType() == 'boolean' && $value == '1')) { + + $fieldDataType = ''; + if ($fieldModel) { + $fieldDataType = $fieldModel->getFieldDataType(); + } + if($value == 'true:boolean' || ($fieldModel && $fieldDataType == 'boolean' && $value == '1')) { $value = 'LBL_ENABLED'; } - if($value == 'false:boolean' || ($fieldModel && $fieldModel->getFieldDataType() == 'boolean' && $value == '0')) { + if($value == 'false:boolean' || ($fieldModel && $fieldDataType == 'boolean' && $value == '0')) { $value = 'LBL_DISABLED'; } + if ($fieldModel && (($fieldModel->column === 'smownerid') || (($fieldModel->column === 'smgroupid')))) { + if (vtws_getOwnerType($value) == 'Users') { + $value = getUserFullName($value); + } else { + $groupNameList = getGroupName($value); + $value = $groupNameList[0]; + } + } + if ($value) { + if ($fieldModel && in_array('Currency', $fieldModel->getReferenceList())) { + $currencyNamewithSymbol = getCurrencyName($value); + $currencyName = explode(':', $currencyNamewithSymbol); + $value = $currencyName[0]; + } + if ($fieldModel && (in_array($fieldDataType, array('picklist', 'multipicklist')))) { + $picklistValues = explode(',', $value); + if (count($picklistValues) > 1) { + $translatedValues = array(); + foreach ($picklistValues as $selectedValue) { + array_push($translatedValues, vtranslate($selectedValue, $moduleName)); + } + $value = implode(',', $translatedValues); + } else { + $value = vtranslate($value, $moduleName); + } + } + } if($fieldLabel == '_VT_add_comment') { $fieldLabel = 'Comment'; } -- GitLab