120 lines
6.5 KiB
JavaScript
120 lines
6.5 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Created by etang
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
angular.module('customWidgetsModule')
|
|
.directive('affectedAsset', ['customFieldLinkFunction', 'assetService', 'events', 'objectValueMapperService', '$timeout',
|
|
function (customFieldLinkFunction, assetService, events, objectValueMapperService, $timeout) {
|
|
return {
|
|
restrict: 'E',
|
|
replace: true,
|
|
scope: {
|
|
data: '=',
|
|
isEditable: '=',
|
|
ticketType: '=?',
|
|
ticket: '=?'
|
|
},
|
|
templateUrl: 'views/custom-widgets/affected-asset.html',
|
|
link: function (scope) {
|
|
customFieldLinkFunction(scope);
|
|
scope.data.value.oldDataValue = scope.data.value.ci;
|
|
if (scope.data.value.oldDataValue !== null) {
|
|
scope.data.value.isCheckedValue = true;
|
|
}
|
|
function init() {
|
|
scope.company = objectValueMapperService.getExactValueByFieldName('company') || objectValueMapperService.getExactValueByFieldName('customerCompany');
|
|
scope.customer = objectValueMapperService.getValueByFieldName('customer')
|
|
|| (objectValueMapperService.getValueByFieldName('customerLoginId') && { id: objectValueMapperService.getValueByFieldName('customerLoginId') })
|
|
|| {};
|
|
if (!scope.company && scope.customer && scope.customer.company && scope.customer.company.name) {
|
|
scope.company = scope.customer.company.name;
|
|
}
|
|
if (!scope.company) {
|
|
scope.data.isReadOnly = true;
|
|
}
|
|
if (scope.ticket.serviceCIRequired && scope.data.name === 'impactedService') {
|
|
scope.data.isRequired = true;
|
|
}
|
|
}
|
|
function updateCustomCategory() {
|
|
var fieldValue = scope.data.value, fieldValueChanged = false;
|
|
if (fieldValue.ci.product && fieldValue.ci.product.categorizations
|
|
&& fieldValue.ci.product.categorizations.length) {
|
|
var catMenuFieldsList = objectValueMapperService.getFieldsByType('dynamicSelectionField');
|
|
_.forEach(catMenuFieldsList, function (catMenuField) {
|
|
if (catMenuField.name !== 'company') {
|
|
var catMenuValue = fieldValue.ci.product.categorizations[0].tiers[catMenuField.name];
|
|
if (catMenuValue) {
|
|
objectValueMapperService.setByProperty(catMenuField.name, 'value', catMenuValue, false);
|
|
fieldValueChanged = true;
|
|
return;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
if (fieldValueChanged) {
|
|
scope.$emit(events.CUSTOM_FIELD_VALUE_CHANGE);
|
|
}
|
|
}
|
|
function handleDiscardChanges() {
|
|
scope.data.value.oldDataValue = scope.data.value.ci;
|
|
if (scope.data.value.oldDataValue !== null) {
|
|
scope.data.value.isCheckedValue = true;
|
|
}
|
|
}
|
|
scope.onValueChange = function () {
|
|
updateCustomCategory();
|
|
//TODO
|
|
scope.$emit(events.WIDGET_VALUE_CHANGE, { fieldName: scope.data.name, memberName: scope.data.name });
|
|
//this is to load collisions from the dates directive
|
|
scope.$emit(events.AFFECTED_SERVICE_VALUE_CHANGED, scope.data.value.ci);
|
|
};
|
|
scope.getList = function (term) {
|
|
scope.dataLoading = true;
|
|
init();
|
|
var promise = scope.data.name === 'causalCI' ?
|
|
assetService.getListOfAssetsForCompany(term, scope.company, scope.ticketType, scope.customer.id) :
|
|
assetService.getListOfAssetsByTypeForCompany(term, 'Business Service', scope.company, scope.ticketType, scope.customer.id);
|
|
return promise
|
|
.then(function (response) {
|
|
scope.exceedsChunkSize = response[0].items[0].exceedsChunkSize;
|
|
scope.isTooltipOpen = true;
|
|
$timeout(function () {
|
|
scope.isTooltipOpen = false;
|
|
}, 10000);
|
|
return response[0].items[0].objects;
|
|
})
|
|
.finally(function () {
|
|
scope.dataLoading = false;
|
|
});
|
|
};
|
|
scope.onInputFocusBlur = function () {
|
|
scope.isTooltipOpen = false;
|
|
};
|
|
scope.clearValue = function () {
|
|
scope.data.value.ci = '';
|
|
scope.onValueChange();
|
|
};
|
|
scope.$watch('data.setValueFlag', function (value) {
|
|
if (value !== '#$#' && value) {
|
|
scope.data.value = value;
|
|
scope.onValueChange();
|
|
scope.data.setValueFlag = '#$#';
|
|
}
|
|
});
|
|
scope.$on(events.SERVICECI_REQUIRED, function (events, field) {
|
|
var localField = objectValueMapperService.getFieldByName(field.name);
|
|
if (angular.isUndefined(localField.originalRequired) || localField.originalRequired === null || localField.isRequired !== localField.originalRequired) {
|
|
localField.originalRequired = localField.isRequired;
|
|
}
|
|
localField.isRequired = localField.originalRequired || field.isRequired;
|
|
});
|
|
scope.$on(events.DISCARD_CHANGES, handleDiscardChanges);
|
|
init();
|
|
}
|
|
};
|
|
}]);
|
|
}());
|