169 lines
5.2 KiB
JavaScript
169 lines
5.2 KiB
JavaScript
"use strict";
|
|
/*
|
|
* Author: Srinivas R
|
|
*/
|
|
function ActionVO() {
|
|
this.resource = '';
|
|
this.actionType = 'client';
|
|
this.actionName = '';
|
|
this.supportedPlatforms = [
|
|
'web'
|
|
];
|
|
this.url = '';
|
|
this.labels = {
|
|
default: ''
|
|
};
|
|
this.sequenceNo = 0;
|
|
this.scope = {};
|
|
this.subActions;
|
|
this.target = 'new';
|
|
this.mode = 'both';
|
|
this.isOpen = false;
|
|
this.delete = false;
|
|
this.screenId = '';
|
|
this.templateId = '';
|
|
this.actionOrder = '';
|
|
this.mappings = [];
|
|
this.isExpression = false;
|
|
this.expressions = null; // TODO will be [] array
|
|
this.mappedFields = [];
|
|
this.entryId = null;
|
|
this.formName = null;
|
|
this.isSynchronous = false;
|
|
}
|
|
/**
|
|
* Setup inheritance chain.
|
|
*/
|
|
ActionVO.prototype = Object.create(BaseVO.prototype);
|
|
ActionVO.prototype.constructor = ActionVO;
|
|
/**
|
|
* @override
|
|
* @return {Array}
|
|
*/
|
|
ActionVO.prototype.getProps = function () {
|
|
return BaseVO.prototype.getProps().concat('resource', 'actionType', 'actionName', 'supportedPlatforms', 'url', 'labels', 'sequenceNo', 'scope', 'target', 'subActions', 'entryId', 'templateId', 'mappings', 'formName', 'isSynchronous', 'expressions', 'mappedFields', 'mode', 'screenId');
|
|
};
|
|
ActionVO.prototype.openItem = function () {
|
|
this.isOpen = true;
|
|
};
|
|
ActionVO.prototype.closeItem = function () {
|
|
this.isOpen = false;
|
|
delete this.isOpen;
|
|
};
|
|
ActionVO.prototype.deleteItem = function () {
|
|
this.delete = true;
|
|
};
|
|
ActionVO.prototype.isSupported = function (type) {
|
|
for (var i = 0; i < this.supportedPlatforms.length; i++) {
|
|
if (this.supportedPlatforms[i] === type) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
ActionVO.prototype.setResource = function (resourceType) {
|
|
this.resource = resourceType;
|
|
};
|
|
ActionVO.prototype.setAssetScope = function () {
|
|
this.scope = {
|
|
assetClass: {
|
|
"ALL": true
|
|
}
|
|
};
|
|
this.subActions = [];
|
|
};
|
|
ActionVO.prototype.removeLabel = function (label) {
|
|
delete this.labels[label];
|
|
};
|
|
ActionVO.prototype.getFirstLabel = function () {
|
|
var label = '';
|
|
for (var key in this.labels) {
|
|
if (this.labels.hasOwnProperty(key)) {
|
|
label = this.labels[key];
|
|
break;
|
|
}
|
|
}
|
|
return label;
|
|
};
|
|
ActionVO.prototype.isLabelEmpty = function () {
|
|
for (var key in this.labels) {
|
|
if (this.labels.hasOwnProperty(key)) {
|
|
if (!this.labels[key]) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
ActionVO.prototype.isAssetClassChecked = function (assetClass, subClass) {
|
|
if (assetClass === 'ALL') {
|
|
return !!this.scope.assetClass.ALL;
|
|
}
|
|
else if (subClass) {
|
|
return this.scope.assetClass[assetClass] && (this.scope.assetClass[assetClass].indexOf(subClass) > -1);
|
|
}
|
|
else {
|
|
return this.scope.assetClass[assetClass] && (this.scope.assetClass[assetClass].indexOf("ALL") > -1);
|
|
}
|
|
};
|
|
ActionVO.prototype.isUserInputChecked = function (userAction) {
|
|
var subAction = _.find(this.subActions, { 'name': userAction });
|
|
return subAction ? true : false;
|
|
};
|
|
ActionVO.prototype.isAssetFieldChecked = function (field) {
|
|
var subAction = _.find(this.subActions, { name: 'assetUpdate' });
|
|
return (subAction.fields.indexOf(field) > -1) ? true : false;
|
|
};
|
|
ActionVO.prototype.setMapping = function (fieldArr) {
|
|
var addMapping = function (field, obj) {
|
|
obj.mappings.push(field);
|
|
};
|
|
for (var i in fieldArr) {
|
|
addMapping(fieldArr[i], this);
|
|
}
|
|
};
|
|
ActionVO.prototype.parseItem = function (screenObj) {
|
|
this.closeItem();
|
|
if (this.mappings.length > 0) {
|
|
this.actionOrder = 'custom';
|
|
this.screenId = screenObj.id;
|
|
delete this.scope;
|
|
if (this.mode && this.mode.value) {
|
|
this.mode = this.mode.value;
|
|
}
|
|
for (var i in this.mappings) {
|
|
if ((!this.mappings[i].mappedSource || this.mappings[i].mappedSource.value) && !this.delete) {
|
|
if (!this.mappings[i].mappedFieldValue) {
|
|
this.mappings[i].mappedFieldValue = '';
|
|
}
|
|
if (this.mappings[i].mappedSource && this.mappings[i].type !== 'output') {
|
|
this.mappings[i].type = 'input-' + this.mappings[i].mappedSource.value;
|
|
}
|
|
}
|
|
delete this.mappings[i].mappedField;
|
|
//delete this.mappings[i].dataType;
|
|
delete this.mappings[i].mappingOptions;
|
|
delete this.mappings[i].defaultValue;
|
|
delete this.mappings[i].mappedSource;
|
|
delete this.mappings[i].sequence;
|
|
delete this.mappings[i].mappedFieldName;
|
|
}
|
|
}
|
|
};
|
|
ActionVO.prototype.convertToOldVO = function () {
|
|
delete this.mappings;
|
|
delete this.isSynchronous;
|
|
delete this.isExpression;
|
|
delete this.expressions;
|
|
delete this.templateId;
|
|
delete this.entryId;
|
|
delete this.actionOrder;
|
|
delete this.mappedFields;
|
|
delete this.formName;
|
|
delete this.mode;
|
|
delete this.screenId;
|
|
};
|
|
ActionVO.prototype.isV3ProviderAction = function () {
|
|
return (this.resource === EntityVO.TYPE_INCIDENT || this.resource === EntityVO.TYPE_CHANGE || this.resource === EntityVO.TYPE_WORKORDER || this.resource === EntityVO.TYPE_TASK);
|
|
};
|