195 lines
11 KiB
JavaScript
195 lines
11 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Created by ygowtham on 7/14/2015.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
angular.module('ticketModule')
|
|
.directive('problemDetailsEditor', ['events', 'userModel', 'systemAlertService', '$filter', 'screenConfigurationModel', 'ticketModel', 'categoriesService', 'searchModel',
|
|
function (events, userModel, systemAlertService, $filter, screenConfigurationModel, ticketModel, categoriesService, searchModel) {
|
|
return {
|
|
restrict: 'E',
|
|
replace: true,
|
|
templateUrl: 'views/problem/problem-details-editor.html',
|
|
scope: {
|
|
ticket: '=',
|
|
metadata: '=',
|
|
form: '=',
|
|
updateIsHandledByParent: '='
|
|
},
|
|
link: function (scope) {
|
|
scope.state = {
|
|
tooManyCompanies: false
|
|
};
|
|
scope.siteOptions = {
|
|
company: {
|
|
visible: false,
|
|
attribute: 'companyName'
|
|
},
|
|
region: {
|
|
attribute: 'region'
|
|
},
|
|
siteGroup: {
|
|
attribute: 'siteGroup'
|
|
},
|
|
site: {
|
|
attribute: 'name'
|
|
}
|
|
};
|
|
scope.selections = {
|
|
investigationDrivers: scope.metadata.investigationDrivers,
|
|
companies: [],
|
|
rootCause: []
|
|
};
|
|
scope.getCompaniesByName = function (name) {
|
|
return searchModel.getCompaniesByText(name).then(function (response) {
|
|
return { list: response.companies, exceedsChunkSize: response.exceedsChunkSize };
|
|
});
|
|
};
|
|
searchModel.getOperatingCompanies(null, -1).then(function (response) {
|
|
scope.selections.companies = _.cloneDeep(response.companies);
|
|
scope.state.tooManyCompanies = response.exceedsChunkSize;
|
|
});
|
|
scope.updatedInfo = {
|
|
location: scope.ticket.location ? scope.ticket.location : {}
|
|
};
|
|
scope.updatedInfo.location.companyName = scope.ticket.company.name;
|
|
getRootCause(null, scope.ticket.categorizations);
|
|
scope.updateCompany = function () {
|
|
showCompanyChangeDialog().then(function (result) {
|
|
if (result) {
|
|
scope.$broadcast(events.CLEAR_AFFECTED_SERVICE, scope.updatedInfo.company);
|
|
scope.$broadcast(events.CLEAR_CATEGORY_DETAILS, scope.updatedInfo.company);
|
|
scope.$broadcast(events.CLEAR_FOUNDATION_SERVICE, scope.updatedInfo.company);
|
|
scope.updatedInfo.rootCause = { name: '' };
|
|
}
|
|
else {
|
|
scope.updatedInfo.company = scope.ticket.company;
|
|
}
|
|
});
|
|
};
|
|
scope.buildSiteTag = function (site) {
|
|
var siteGroup = site.siteGroup ? ' > ' + site.siteGroup : '', siteName = site.name ? ' > ' + site.name : '', siteRegion = site.region ? site.region : '';
|
|
return siteRegion + siteGroup + siteName;
|
|
};
|
|
function showCompanyChangeDialog() {
|
|
var modal = systemAlertService.modal({
|
|
type: 'info',
|
|
title: $filter('i18n')('common.notification.dirty.title'),
|
|
text: $filter('i18n')('create.problem.companyChange.warning'),
|
|
buttons: [
|
|
{
|
|
text: $filter('i18n')('common.button.yes'),
|
|
data: true
|
|
},
|
|
{
|
|
text: $filter('i18n')('common.button.no'),
|
|
data: false
|
|
}
|
|
]
|
|
});
|
|
return modal.result;
|
|
}
|
|
scope.clear = function (attribute) {
|
|
scope.updatedInfo[attribute] = null;
|
|
};
|
|
function toggleEditMode() {
|
|
scope.editMode = true;
|
|
getInitialUpdateData();
|
|
}
|
|
function getInitialUpdateData() {
|
|
scope.isDescRequired = _.includes(scope.metadata && scope.metadata.requiredOOTBObjectName, 'desc');
|
|
scope.updatedInfo = {
|
|
location: scope.ticket.location ? scope.ticket.location : {},
|
|
company: scope.ticket.company,
|
|
workaround: scope.ticket.workaround,
|
|
resolution: scope.ticket.resolution,
|
|
rootCause: scope.ticket.rootCause ? { name: scope.ticket.rootCause } : null,
|
|
investigationDriver: !scope.ticket.investigationDriver ? '' : _.find(scope.metadata.investigationDrivers, function (obj) {
|
|
return obj.name === scope.ticket.investigationDriver;
|
|
}) || { name: scope.ticket.investigationDriver }
|
|
};
|
|
scope.updatedInfo.location.companyName = scope.updatedInfo.company.name; //necessary in order to limit the search for sites based on company
|
|
}
|
|
function handleSaveChanges() {
|
|
var changes = collectChanges();
|
|
var singleMode = !scope.updateIsHandledByParent;
|
|
scope.$emit(events.SAVE_CHANGES_REQUEST, changes, singleMode || scope.ticket.isDraft);
|
|
}
|
|
function collectChanges() {
|
|
var problemChanges = {};
|
|
if (scope.updatedInfo.company.name !== scope.ticket.company.name) {
|
|
problemChanges.company = scope.updatedInfo.company.name;
|
|
}
|
|
if (scope.updatedInfo.investigationDriver.name !== scope.ticket.investigationDriver) {
|
|
problemChanges.investigationDriver = scope.updatedInfo.investigationDriver.name;
|
|
}
|
|
if (scope.updatedInfo.location !== scope.ticket.location) {
|
|
problemChanges.location = scope.updatedInfo.location;
|
|
}
|
|
if (scope.updatedInfo.workaround !== scope.ticket.workaround) {
|
|
problemChanges.workaround = scope.updatedInfo.workaround;
|
|
}
|
|
if (scope.updatedInfo.resolution !== scope.ticket.resolution) {
|
|
problemChanges.resolution = scope.updatedInfo.resolution;
|
|
}
|
|
problemChanges.rootCause = scope.updatedInfo.rootCause ? scope.updatedInfo.rootCause.name : '';
|
|
return problemChanges;
|
|
}
|
|
function close() {
|
|
scope.editMode = false;
|
|
}
|
|
function handleSaveComplete(event, eventData) {
|
|
if (!_.isEmpty(eventData)) {
|
|
scope.ticket.company = eventData.company ? eventData.company : scope.ticket.company;
|
|
scope.ticket.investigationDriver = eventData.investigationDriver ? eventData.investigationDriver : scope.ticket.investigationDriver;
|
|
scope.ticket.location = eventData.location ? eventData.location : scope.ticket.location;
|
|
scope.ticket.workaround = eventData.workaround ? eventData.workaround : "";
|
|
scope.ticket.resolution = eventData.resolution ? eventData.resolution : "";
|
|
scope.ticket.rootCause = eventData.rootCause ? eventData.rootCause : "";
|
|
}
|
|
if (scope.ticket.isDraft) {
|
|
applyChanges();
|
|
scope.$emit(events.SAVE_CHANGES_COMPLETE);
|
|
}
|
|
close();
|
|
}
|
|
function applyChanges() {
|
|
scope.ticket.company = scope.updatedInfo.company.name !== scope.ticket.company.name ? scope.updatedInfo.company.name : scope.ticket.company;
|
|
scope.ticket.investigationDriver = scope.updatedInfo.investigationDriver.name !== scope.ticket.investigationDriver ? scope.updatedInfo.investigationDriver.name : scope.ticket.investigationDriver;
|
|
scope.ticket.location = scope.updatedInfo.location !== scope.ticket.location ? scope.updatedInfo.location : scope.ticket.location;
|
|
scope.ticket.rootCause = scope.updatedInfo.rootCause ? scope.updatedInfo.rootCause.name : '';
|
|
scope.ticket.workaround = scope.updatedInfo.workaround !== scope.ticket.workaround ? scope.updatedInfo.workaround : scope.ticket.workaround;
|
|
scope.ticket.resolution = scope.updatedInfo.resolution !== scope.ticket.resolution ? scope.updatedInfo.resolution : scope.ticket.resolution;
|
|
}
|
|
function handleSaveFault() {
|
|
scope.$broadcast(events.SAVE_CHANGES_COMPLETE); //needed to reset the child scopes of all contained directives
|
|
close();
|
|
}
|
|
scope.hasCustomFields = function (panelId) {
|
|
var panel = screenConfigurationModel.getPanelById(panelId);
|
|
return panel && panel.hasCustomFields();
|
|
};
|
|
function getRootCause(event, data) {
|
|
var params = {};
|
|
params.depends = categoriesService.buildCategoriesForRootCause(data, scope.metadata.allCategories);
|
|
params.depends.productManufacturer = null;
|
|
ticketModel.getRootCause(params, scope.ticket.company).then(function (response) {
|
|
if (response) {
|
|
scope.selections.rootCause = response;
|
|
}
|
|
});
|
|
}
|
|
getInitialUpdateData();
|
|
scope.$on(events.TICKET_UPDATE_ROOTCAUSE, getRootCause);
|
|
scope.$on(events.SAVE_CHANGES, handleSaveChanges);
|
|
scope.$on(events.TOGGLE_EDIT_MODE, toggleEditMode);
|
|
scope.$on(events.SAVE_ALL_CHANGES_COMPLETE, handleSaveComplete);
|
|
scope.$on(events.SAVE_ALL_CHANGES_FAULT, handleSaveFault);
|
|
scope.$on(events.DISCARD_CHANGES, close);
|
|
}
|
|
};
|
|
}
|
|
]);
|
|
})();
|