Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;
- (() => {
- if(!Object.keys(input).length) return
- const record = getRecord(input.tableName, input.recordId);
- if (input.action === 'INIT') {
- const CLOSED_STATE = 10;
- const COMPLETED_STATE = 7;
- const tableNames = ['itsm_incident', 'itsm_request', ...getChildTableName('itsm_request')];
- if (!tableNames.includes(input.tableName)) {
- return;
- }
- if (!record) {
- return;
- }
- if ([CLOSED_STATE, COMPLETED_STATE].includes(record.state)) {
- return;
- }
- }
- data.isShowUrgency = true;
- data.translations = getTranslations();
- const warningAttributes = getAttributes();
- data.toggleHint = false;
- data.userCanNotSave = true;
- data.urgencyChoices = getChoices(ss.getUser().getDisplayValue('language_id'));
- setWidgetUrgencyValue(record.urgency);
- data.currentChoice = data.argencyValueServer.display_value;
- data.infoWarningBox = warningAttributes.isShowWarning.includes(data.argencyValueServer.database_value);
- data.isShowWarning = warningAttributes.isShowWarning;
- data.warningPhone = warningAttributes.warningPhone;
- data.warningInfo = warningAttributes.warningInfo;
- if (input.action === 'CHANGE_URGENCY') {
- saveUrgency(data.translations.message);
- data.urgencyValueForm = data.urgencyChoices[ Number(input.setUrgency) - 1 ];
- data.infoWarningBox = warningAttributes.isShowWarning.includes( (input.setUrgency) );
- data.action = '';
- }
- })();
- function getTranslations() {
- const sm = new SimpleMessage();
- return {
- change: sm.getMessage('Change'),
- cancel: sm.getMessage('Cancel'),
- save: sm.getMessage('Save'),
- annotationValue: sm.getMessage('Urgency impacts the priority of the ticket processing'),
- title: sm.getMessage('Ticket urgency'),
- hintInfoBold: sm.getMessage('Urgency '),
- hintInfoRegular: sm.getMessage('is a measure defining how soon an issue affects a business'),
- message: `${sm.getMessage('Urgency is set to')} "${input.urgencyValueForm.display_value}"`,
- urgencyNotSet: sm.getMessage('Urgency not set'),
- defaultMessage: sm.getMessage('Contact us in any available way to confirm the information'),
- customMessage: getCustomMessages('Custom warning message for urgency widget'),
- }
- }
- function clientNotReady() {
- return !Object.keys(input).length;
- }
- function getChildTableName(tableObj) {
- const request = new SimpleTable(tableObj);
- const childTables = [];
- request.getChildTables().forEach((item) => { childTables.push(item.name) })
- return childTables;
- }
- function setWidgetUrgencyValue(ARGENCY_VALUE_SERVER) {
- const sm = new SimpleMessage();
- if(ARGENCY_VALUE_SERVER) {
- data.argencyValueServer = data.urgencyChoices[ARGENCY_VALUE_SERVER - 1];
- data.urgencyValueForm = data.argencyValueServer;
- } else {
- data.argencyValueServer = {"database_value": '-1000',"display_value": data.translations.urgencyNotSet}
- data.urgencyValueForm = {"database_value": '-1000',"display_value": data.translations.urgencyNotSet}
- }
- }
- function getCustomMessages(sourceMessagesWarning) {
- const source_message = new SimpleRecord('source_message');
- source_message.get('message', sourceMessagesWarning);
- const message = new SimpleRecord('message');
- message.addQuery('source_message_id', source_message.sys_id);
- message.addQuery('language', getLanguage());
- message.query();
- message.next();
- return message.translation;
- }
- function getAttributes() {
- const warningAttributes = {};
- const sm = new SimpleMessage();
- const defaultMessage = data.translations.defaultMessage;
- const customMessage = data.translations.customMessage;
- if (isShowWarning(warningAttributes, defaultMessage)) {
- setAttributesWarning(warningAttributes, defaultMessage, customMessage);
- }
- return warningAttributes;
- function isShowWarning(warningAttributes, defaultMessage) {
- const isShowWarning = `${options.isShowWarning}`;
- warningAttributes.isShowWarning = [];
- if (isShowWarning === 'true' && defaultMessage != '') return true;
- return false;
- }
- function setAttributesWarning(warningAttributes, defaultMessage, customMessage) {
- warningAttributes.warningPhone = '';
- const propertyPhone = ss.getProperty('itsm.notification.contact.phone');
- const optionText = `${options.sourceMessage}`;
- const optionPhone = `${options.phone}`;
- warningAttributes.isShowWarning = ['4'];
- if (optionPhone == 'true') {
- warningAttributes.warningPhone = propertyPhone;
- }
- if (optionText != 'Custom warning message for urgency widget' || customMessage == '') {
- warningAttributes.warningInfo = defaultMessage;
- return true;
- }
- warningAttributes.warningInfo = customMessage;
- }
- }
- function getLanguage() {
- const user = new SimpleRecord('user');
- user.get(`${ss.getUser()}`);
- return user.getDisplayValue('language_id') === 'English' ? 'en' : 'ru';
- }
- function getChoices(language) {
- const TASK_TABLE_ID = '155931135900000083';
- const URGENCY_COLUMN_ID = '155931135900001088';
- language = language === 'English' ? 'en' : 'ru';
- const options = [];
- const choice = new SimpleRecord('sys_choice')
- choice.addQuery('column_id', URGENCY_COLUMN_ID);
- choice.addQuery('table_id', TASK_TABLE_ID);
- choice.addQuery('language', language);
- choice.orderBy('order');
- choice.selectAttributes(['value', 'title'])
- choice.query();
- while (choice.next()) {
- options.push({
- database_value: choice.getValue('value'),
- display_value: choice.getValue('title'),
- })
- }
- return options;
- }
- function saveUrgency(message) {
- const record = new SimpleRecord(input.tableName);
- record.get(input.recordId);
- record.urgency = input.setUrgency;
- const save = record.update();
- if (save != 0) {
- ss.addSuccessMessage(message)
- data.argencyValueServer = data.urgencyChoices[ Number(input.setUrgency) - 1 ];
- data.currentChoice = data.argencyValueServer.display_value;
- }
- }
- function getRecord(tableName, recordId) {
- const record = new SimpleRecord(tableName);
- record.get(recordId);
- return record;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement