507 lines
29 KiB
JavaScript
507 lines
29 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Created by andey on 25-07-2017.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
angular.module('customWidgetsModule')
|
|
.service('widgetDependencyHandlerService', ['objectValueMapperService', 'categoriesService', 'systemAlertService',
|
|
'i18nService', 'expressionEvaluatorService', 'events', '$rootScope',
|
|
function (objectValueMapperService, categoriesService, systemAlertService, i18nService, expressionEvaluatorService, events, $rootScope) {
|
|
function _handleValueChange(fieldName, action, source) {
|
|
if (fieldName === 'locationCompany' || fieldName === 'serviceType') {
|
|
handleLocationCompanyChange(fieldName);
|
|
}
|
|
else if (fieldName === 'impactedService') {
|
|
handleAffectedServiceChange(fieldName);
|
|
}
|
|
else if (fieldName === 'causalCI') {
|
|
handleAffectedAssetChange(fieldName);
|
|
}
|
|
else if (fieldName === 'customer' || fieldName === 'requestedFor' || fieldName === 'contact') {
|
|
handlePersonNameChange(fieldName, action);
|
|
}
|
|
else if (fieldName === 'changeClass') {
|
|
handleTicketClassChange(fieldName);
|
|
}
|
|
else if (fieldName === 'organization') {
|
|
handleOrganizationChange(fieldName);
|
|
}
|
|
else if (fieldName === 'site') {
|
|
handleCustomerSiteChange();
|
|
}
|
|
else if (fieldName === 'operational') {
|
|
handleOpertaionalCategoryChange();
|
|
}
|
|
else if (fieldName === 'company') {
|
|
handleCompanyValueChange(source);
|
|
}
|
|
else if (fieldName === 'customerCompany') {
|
|
handleCustomerCompanyValueChange();
|
|
}
|
|
}
|
|
function handleCompanyValueChange(source) {
|
|
if (_.isEmpty(objectValueMapperService.getFieldByName('customer')) && objectValueMapperService.getExactValueByFieldName('company')) {
|
|
var menuFieldsList = objectValueMapperService.getFieldsByType('dynamicSelectionField');
|
|
_.forEach(menuFieldsList, function (menuField) {
|
|
if (menuField.readOnlyCondition) {
|
|
menuField.isReadOnly = expressionEvaluatorService.evaluate(menuField.readOnlyCondition);
|
|
return;
|
|
}
|
|
if (menuField.readOnly) {
|
|
return;
|
|
}
|
|
menuField.isReadOnly = false;
|
|
});
|
|
var affectedAssetList = objectValueMapperService.getFieldsByType('affectedAsset');
|
|
_.forEach(affectedAssetList, function (affectedAsset) {
|
|
if (affectedAsset.readOnlyCondition) {
|
|
affectedAsset.isReadOnly = expressionEvaluatorService.evaluate(affectedAsset.readOnlyCondition);
|
|
return;
|
|
}
|
|
if (affectedAsset.readOnly) {
|
|
return;
|
|
}
|
|
affectedAsset.isReadOnly = false;
|
|
});
|
|
var priority = objectValueMapperService.getFieldsByType('priority');
|
|
if (priority && priority[0] && priority[0].members) {
|
|
if (priority[0].readOnlyCondition) {
|
|
var isReadOnly = expressionEvaluatorService.evaluate(priority[0].readOnlyCondition);
|
|
priority[0].isReadOnly = isReadOnly;
|
|
_.forEach(priority[0].members, function (member) {
|
|
member.isReadOnly = isReadOnly;
|
|
});
|
|
return;
|
|
}
|
|
if (priority[0].readOnly) {
|
|
return;
|
|
}
|
|
priority[0].isReadOnly = false;
|
|
_.forEach(priority[0].members, function (member) {
|
|
member.isReadOnly = false;
|
|
});
|
|
}
|
|
var categoriesList = objectValueMapperService.getFieldsByType('category');
|
|
_.forEach(categoriesList, function (categoryField) {
|
|
if (categoryField.readOnlyCondition) {
|
|
categoryField.isReadOnly = expressionEvaluatorService.evaluate(categoryField.readOnlyCondition);
|
|
return;
|
|
}
|
|
if (source !== "fromTicketLoad") {
|
|
categoryField.triggerClear = true;
|
|
}
|
|
if (categoryField.readOnly) {
|
|
return;
|
|
}
|
|
categoryField.isReadOnly = false;
|
|
});
|
|
}
|
|
}
|
|
function handleCustomerCompanyValueChange() {
|
|
if (_.isEmpty(objectValueMapperService.getFieldByName('customer')) && objectValueMapperService.getExactValueByFieldName('customerCompany')) {
|
|
var menuFieldsList = objectValueMapperService.getFieldsByType('dynamicSelectionField');
|
|
_.forEach(menuFieldsList, function (menuField) {
|
|
if (menuField.readOnlyCondition) {
|
|
menuField.isReadOnly = expressionEvaluatorService.evaluate(menuField.readOnlyCondition);
|
|
return;
|
|
}
|
|
if (menuField.readOnly) {
|
|
return;
|
|
}
|
|
menuField.isReadOnly = false;
|
|
});
|
|
var affectedAssetList = objectValueMapperService.getFieldsByType('affectedAsset');
|
|
_.forEach(affectedAssetList, function (affectedAsset) {
|
|
if (affectedAsset.readOnlyCondition) {
|
|
affectedAsset.isReadOnly = expressionEvaluatorService.evaluate(affectedAsset.readOnlyCondition);
|
|
return;
|
|
}
|
|
if (affectedAsset.readOnly) {
|
|
return;
|
|
}
|
|
affectedAsset.isReadOnly = false;
|
|
});
|
|
var categoriesList = objectValueMapperService.getFieldsByType('category');
|
|
_.forEach(categoriesList, function (categoryField) {
|
|
if (categoryField.readOnlyCondition) {
|
|
categoryField.isReadOnly = expressionEvaluatorService.evaluate(categoryField.readOnlyCondition);
|
|
return;
|
|
}
|
|
if (categoryField.readOnly) {
|
|
return;
|
|
}
|
|
categoryField.isReadOnly = false;
|
|
});
|
|
}
|
|
}
|
|
function handleTicketClassChange(fieldName) {
|
|
var fieldValue = objectValueMapperService.getValueByFieldName(fieldName);
|
|
fieldValue = fieldValue.timing.name ? fieldValue.timing.name : fieldValue.timing;
|
|
var actualDates = objectValueMapperService.getFieldByName('actualDates');
|
|
var scheduledDates = objectValueMapperService.getFieldByName('scheduledDates');
|
|
if (actualDates) {
|
|
if (fieldValue === 'Latent') {
|
|
actualDates.isRequired = true;
|
|
}
|
|
else {
|
|
actualDates.isRequired = false;
|
|
}
|
|
}
|
|
if (scheduledDates) {
|
|
if (fieldValue === 'Latent') {
|
|
scheduledDates.isReadOnly = true;
|
|
}
|
|
else {
|
|
scheduledDates.isReadOnly = false;
|
|
}
|
|
}
|
|
}
|
|
function handleLocationCompanyChange(fieldName) {
|
|
var fieldValue = objectValueMapperService.getValueByFieldName(fieldName);
|
|
var categoriesList = objectValueMapperService.getFieldsByType('category');
|
|
_.forEach(categoriesList, function (categoryField) {
|
|
if (categoryField.value) {
|
|
categoryField.value.locationCompany = fieldValue;
|
|
categoryField.triggerClear = true;
|
|
}
|
|
});
|
|
}
|
|
function handleAffectedServiceChange(fieldName) {
|
|
var fieldValue = objectValueMapperService.getValueByFieldName(fieldName);
|
|
var category = objectValueMapperService.getValueByFieldName('product');
|
|
if (category && fieldValue.ci && fieldValue.ci.product && fieldValue.ci.product.categorizations
|
|
&& fieldValue.ci.product.categorizations.length) {
|
|
category.cognitiveFlag = false;
|
|
updateCategoryField(category, fieldValue.ci.product.categorizations[0].tiers);
|
|
}
|
|
}
|
|
function handleOrganizationChange(fieldName) {
|
|
var fieldValue = objectValueMapperService.getValueByFieldName(fieldName);
|
|
var customer = objectValueMapperService.getFieldByName('customer') || objectValueMapperService.getFieldByName('requestedFor');
|
|
customer.organization = fieldValue && fieldValue.organization;
|
|
}
|
|
function handleAffectedAssetChange(fieldName) {
|
|
var fieldValue = objectValueMapperService.getValueByFieldName(fieldName);
|
|
var category = objectValueMapperService.getValueByFieldName('resolutionProduct');
|
|
if (category && fieldValue.ci.product && fieldValue.ci.product.categorizations
|
|
&& fieldValue.ci.product.categorizations.length) {
|
|
category.cognitiveFlag = false;
|
|
updateCategoryField(category, fieldValue.ci.product.categorizations[0].tiers);
|
|
}
|
|
}
|
|
function handlePersonNameChange(fieldName, action) {
|
|
if ((fieldName === 'customer' || fieldName === 'requestedFor') && objectValueMapperService.getFieldByName(fieldName)) {
|
|
var customer = _.cloneDeep(objectValueMapperService.getFieldByName(fieldName)), previousCustomer, customerPhone, customerEmail, customerCompany, customerOrg, categoriesList, menuFieldsList, affectedAssetList, priority, locationCompany;
|
|
previousCustomer = customer.previousValue;
|
|
customer = customer.value;
|
|
if (!_.isEmpty(customer)) {
|
|
customerPhone = objectValueMapperService.getFieldByName('customerPhone');
|
|
if (customerPhone) {
|
|
customerPhone.value.phoneNumber = customerPhone.ootbValue = customer.phone;
|
|
}
|
|
customerEmail = objectValueMapperService.getFieldByName('customerEmail');
|
|
if (customerEmail) {
|
|
customerEmail.value.internetEmail = customerEmail.ootbValue = customer.email;
|
|
}
|
|
customerCompany = objectValueMapperService.getFieldByName('customerCompany');
|
|
if (customerCompany) {
|
|
customerCompany.value = customer.company.name;
|
|
}
|
|
customerOrg = objectValueMapperService.getFieldByName('organization');
|
|
if (customerOrg && customerOrg.value) {
|
|
if (customerOrg.value.hasOwnProperty('customerOrg')) {
|
|
customerOrg.value.customerOrg = customerOrg.ootbValue = customer.organization;
|
|
}
|
|
else if (customerOrg.value.hasOwnProperty('organization')) {
|
|
customerOrg.value.organization = customerOrg.ootbValue = customer.organization;
|
|
}
|
|
}
|
|
if (action !== 'cancel') {
|
|
updateCustomerSite(customer, fieldName);
|
|
}
|
|
locationCompany = objectValueMapperService.getFieldByName('locationCompany');
|
|
if (locationCompany) {
|
|
locationCompany.ticketCompany = customer.company;
|
|
}
|
|
if ((!locationCompany || !locationCompany.locationCompanySelected)
|
|
&& (!previousCustomer || previousCustomer.company.name !== customer.company.name)) {
|
|
//set the isReadOnly property to false for create screen on customer selection
|
|
categoriesList = objectValueMapperService.getFieldsByType('category');
|
|
_.forEach(categoriesList, function (categoryField) {
|
|
if (categoryField.readOnlyCondition) {
|
|
categoryField.isReadOnly = expressionEvaluatorService.evaluate(categoryField.readOnlyCondition);
|
|
return;
|
|
}
|
|
if (categoryField.readOnly) {
|
|
return;
|
|
}
|
|
categoryField.isReadOnly = false;
|
|
});
|
|
}
|
|
menuFieldsList = objectValueMapperService.getFieldsByType('dynamicSelectionField');
|
|
_.forEach(menuFieldsList, function (menuField) {
|
|
if (menuField.readOnlyCondition) {
|
|
menuField.isReadOnly = expressionEvaluatorService.evaluate(menuField.readOnlyCondition);
|
|
return;
|
|
}
|
|
if (menuField.readOnly) {
|
|
return;
|
|
}
|
|
menuField.isReadOnly = false;
|
|
});
|
|
affectedAssetList = objectValueMapperService.getFieldsByType('affectedAsset');
|
|
_.forEach(affectedAssetList, function (affectedAsset) {
|
|
if (affectedAsset.readOnlyCondition) {
|
|
affectedAsset.isReadOnly = expressionEvaluatorService.evaluate(affectedAsset.readOnlyCondition);
|
|
return;
|
|
}
|
|
if (affectedAsset.readOnly) {
|
|
return;
|
|
}
|
|
affectedAsset.isReadOnly = false;
|
|
});
|
|
priority = objectValueMapperService.getFieldsByType('priority');
|
|
if (priority && priority[0] && priority[0].members) {
|
|
if (priority[0].readOnlyCondition) {
|
|
var isReadOnly = expressionEvaluatorService.evaluate(priority[0].readOnlyCondition);
|
|
priority[0].isReadOnly = isReadOnly;
|
|
_.forEach(priority[0].members, function (member) {
|
|
member.isReadOnly = isReadOnly;
|
|
});
|
|
return;
|
|
}
|
|
if (priority[0].readOnly) {
|
|
return;
|
|
}
|
|
priority[0].isReadOnly = false;
|
|
_.forEach(priority[0].members, function (member) {
|
|
member.isReadOnly = false;
|
|
});
|
|
}
|
|
}
|
|
else {
|
|
customerCompany = objectValueMapperService.getFieldByName('customerCompany');
|
|
if (customerCompany) {
|
|
customerCompany.value = '';
|
|
}
|
|
customerPhone = objectValueMapperService.getFieldByName('customerPhone');
|
|
if (!_.isEmpty(customerPhone)) {
|
|
customerPhone.value.phoneNumber = customerPhone.ootbValue = '';
|
|
}
|
|
customerEmail = objectValueMapperService.getFieldByName('customerEmail');
|
|
if (!_.isEmpty(customerEmail)) {
|
|
customerEmail.value.internetEmail = customerEmail.ootbValue = '';
|
|
}
|
|
customerOrg = objectValueMapperService.getFieldByName('organization');
|
|
if (!_.isEmpty(customerOrg) && customerOrg.value) {
|
|
if (customerOrg.value.hasOwnProperty('customerOrg')) {
|
|
customerOrg.value.customerOrg = customerOrg.ootbValue = '';
|
|
}
|
|
else {
|
|
customerOrg.value.organization = customerOrg.ootbValue = '';
|
|
}
|
|
}
|
|
var customerSite = objectValueMapperService.getFieldByName('site');
|
|
if (!_.isEmpty(customerSite) && customerSite.dataType === 'widget') {
|
|
if (!_.isEmpty(customerSite)) {
|
|
customerSite.setValue({
|
|
site: {
|
|
name: '',
|
|
id: '',
|
|
attributeMap: {
|
|
companyName: '',
|
|
siteAddress: '',
|
|
regionName: '',
|
|
siteGroupName: '',
|
|
siteId: ''
|
|
}
|
|
},
|
|
siteGroup: {
|
|
name: '',
|
|
attributeMap: {
|
|
regionName: ''
|
|
}
|
|
},
|
|
region: {
|
|
name: ''
|
|
}
|
|
});
|
|
}
|
|
}
|
|
locationCompany = objectValueMapperService.getFieldByName('locationCompany');
|
|
if (locationCompany) {
|
|
locationCompany.ticketCompany = null;
|
|
if (!locationCompany.locationCompanySelected) {
|
|
locationCompany.value = null;
|
|
}
|
|
}
|
|
if (!locationCompany || !locationCompany.locationCompanySelected) {
|
|
//set the isReadOnly property to true for create screen on removing customer
|
|
categoriesList = objectValueMapperService.getFieldsByType('category');
|
|
_.forEach(categoriesList, function (categoryField) {
|
|
categoryField.isReadOnly = true;
|
|
});
|
|
}
|
|
menuFieldsList = objectValueMapperService.getFieldsByType('dynamicSelectionField');
|
|
_.forEach(menuFieldsList, function (menuField) {
|
|
if (menuField.name === 'company' || menuField.name === 'customerCompany') {
|
|
if (menuField.readOnlyCondition) {
|
|
menuField.isReadOnly = expressionEvaluatorService.evaluate(menuField.readOnlyCondition);
|
|
return;
|
|
}
|
|
if (menuField.readOnly) {
|
|
return;
|
|
}
|
|
}
|
|
else if (['operationCategoryTier1', 'operationCategoryTier2', 'operationCategoryTier3',
|
|
'productCategoryTier1', 'productCategoryTier2', 'productCategoryTier3', 'productName', 'productModelVersion',
|
|
'resOperationCategoryTier1', 'resOperationCategoryTier2', 'resOperationCategoryTier3',
|
|
'resProductCategoryTier1', 'resProductCategoryTier2', 'resProductCategoryTier3', 'resProductName', 'resProductModelVersion',
|
|
'impactedService', 'causalCI'].indexOf(menuField.name) !== -1) {
|
|
menuField.isReadOnly = true;
|
|
}
|
|
});
|
|
affectedAssetList = objectValueMapperService.getFieldsByType('affectedAsset');
|
|
_.forEach(affectedAssetList, function (affectedAsset) {
|
|
affectedAsset.isReadOnly = true;
|
|
});
|
|
priority = objectValueMapperService.getFieldsByType('priority');
|
|
if (priority && priority[0] && priority[0].members) {
|
|
priority[0].isReadOnly = true;
|
|
_.forEach(priority[0].members, function (member) {
|
|
member.isReadOnly = true;
|
|
});
|
|
}
|
|
}
|
|
}
|
|
else if (fieldName === 'contact') {
|
|
var contact = objectValueMapperService.getValueByFieldName('contact'), contactPhone, contactEmail;
|
|
if (!_.isEmpty(contact)) {
|
|
contactEmail = objectValueMapperService.getFieldByName('contactEmail');
|
|
if (contactEmail) {
|
|
contactEmail.value.contactEmail = contactEmail.ootbValue = contact.email;
|
|
}
|
|
contactPhone = objectValueMapperService.getFieldByName('contactPhone');
|
|
if (contactPhone) {
|
|
contactPhone.value.contactPhoneNumber = contactPhone.ootbValue = contact.phone;
|
|
if (contactPhone.readOnlyCondition) {
|
|
contactPhone.isReadOnly = expressionEvaluatorService.evaluate(contactPhone.readOnlyCondition);
|
|
return;
|
|
}
|
|
if (contactPhone.readOnly) {
|
|
return;
|
|
}
|
|
contactPhone.isReadOnly = false;
|
|
}
|
|
}
|
|
else {
|
|
contactPhone = objectValueMapperService.getFieldByName('contactPhone');
|
|
if (!_.isEmpty(contactPhone)) {
|
|
contactPhone.value.contactPhoneNumber = contactPhone.ootbValue = '';
|
|
contactPhone.isReadOnly = true;
|
|
}
|
|
contactEmail = objectValueMapperService.getFieldByName('contactEmail');
|
|
if (!_.isEmpty(contactEmail)) {
|
|
contactEmail.value.contactEmail = contactEmail.ootbValue = '';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
function handleCustomerSiteChange() {
|
|
var customerSite = _.cloneDeep(objectValueMapperService.getFieldByName('site')), customerLocationMap = objectValueMapperService.getFieldByName('customerLocationMap');
|
|
if (!_.isEmpty(customerLocationMap) && !_.isEmpty(customerSite) && !_.isEmpty(customerSite.value) && !_.isEmpty(customerSite.value.site)) {
|
|
objectValueMapperService.setValueByFieldName('customerLocationMap', customerSite.value.site.attributeMap.siteAddress);
|
|
}
|
|
var customerSiteMap = objectValueMapperService.getFieldByName('googleMap');
|
|
if (!_.isEmpty(customerSiteMap) && !_.isEmpty(customerSite) && !_.isEmpty(customerSite.value)) {
|
|
customerSiteMap.setValue(customerSite.value.site.attributeMap.siteAddress);
|
|
}
|
|
}
|
|
function updateCategoryField(category, newCategoryValues) {
|
|
_.forEach(category.listOfTiers, function (tier) {
|
|
var tierName = tier.name;
|
|
if (!(newCategoryValues.hasOwnProperty(tier.name))) {
|
|
//converting resProductCategoryTier1/resOperationalCategoryTier1 to productCategoryTier1/operationalCategoryTier1
|
|
//as we are getting productCategory/operationalCategory from backend which will populate into resProductCategory
|
|
if (category.name === "resolutionProduct") {
|
|
tierName = "p" + tier.name.slice(4);
|
|
}
|
|
else if (category.name === "resolution") {
|
|
tierName = "o" + tier.name.slice(4);
|
|
}
|
|
}
|
|
tier.selectedValue = newCategoryValues[tierName];
|
|
});
|
|
category.serializedValue = categoriesService.getDisplayValues(category);
|
|
}
|
|
function updateCustomerSite(customer, fieldName) {
|
|
var customerSite;
|
|
if (fieldName === 'requestedFor') {
|
|
customerSite = objectValueMapperService.getFieldByName('changeLocation');
|
|
if (!_.isEmpty(customerSite) && customerSite.dataType === 'widget') {
|
|
customerSite.setValue({
|
|
address: {
|
|
address: customer.site.address.address,
|
|
city: customer.site.address.city,
|
|
country: customer.site.address.country,
|
|
street: customer.site.address.street,
|
|
state: customer.site.address.state,
|
|
zip: customer.site.address.zip
|
|
},
|
|
companyName: customer.company.name,
|
|
name: customer.site.name,
|
|
siteGroup: customer.site.siteGroup,
|
|
siteId: customer.site.siteId,
|
|
region: customer.site.region
|
|
});
|
|
}
|
|
var company = objectValueMapperService.getFieldByName('company');
|
|
if (!_.isEmpty(company)) {
|
|
company.setValue(customer.company.name);
|
|
}
|
|
}
|
|
else {
|
|
customerSite = objectValueMapperService.getFieldByName('site');
|
|
if (!_.isEmpty(customerSite) && customerSite.dataType === 'widget') {
|
|
customerSite.setValue({
|
|
site: {
|
|
name: customer.site.name,
|
|
id: customer.site.siteId,
|
|
attributeMap: {
|
|
companyName: customer.company.name,
|
|
siteAddress: customer.site.address,
|
|
regionName: customer.site.region,
|
|
siteGroupName: customer.site.siteGroup,
|
|
siteId: customer.site.siteId
|
|
}
|
|
},
|
|
siteGroup: {
|
|
name: customer.site.siteGroup,
|
|
attributeMap: {
|
|
regionName: customer.site.region
|
|
}
|
|
},
|
|
region: {
|
|
name: customer.site.region
|
|
},
|
|
company: {
|
|
name: customer.company && customer.company.name
|
|
}
|
|
});
|
|
handleCustomerSiteChange();
|
|
}
|
|
}
|
|
}
|
|
function handleOpertaionalCategoryChange() {
|
|
if (objectValueMapperService.getTicketType() === EntityVO.TYPE_CHANGE) {
|
|
$rootScope.$broadcast(events.RELOAD_RISK_QUESTION);
|
|
}
|
|
}
|
|
return {
|
|
handleValueChange: _handleValueChange,
|
|
handleCategoryChange: updateCategoryField
|
|
};
|
|
}]);
|
|
})();
|