141 lines
7.3 KiB
JavaScript
141 lines
7.3 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('releaseModule')
|
|
.directive('activityDetailsEditor', ['events', 'createTicketService', 'fieldValidationModel', 'systemAlertService', 'i18nService',
|
|
function (events, createTicketService, fieldValidationModel, systemAlertService, i18nService) {
|
|
return {
|
|
restrict: 'E',
|
|
replace: true,
|
|
templateUrl: 'views/release/activity-details-editor.html',
|
|
scope: {
|
|
ticket: '=',
|
|
metadata: '=',
|
|
form: '='
|
|
},
|
|
link: function (scope) {
|
|
scope.ticketCopy = _.cloneDeep(scope.ticket);
|
|
scope.siteOptions = {
|
|
company: {
|
|
visible: false,
|
|
attribute: 'companyName'
|
|
},
|
|
region: {
|
|
attribute: 'region'
|
|
},
|
|
siteGroup: {
|
|
attribute: 'siteGroup'
|
|
},
|
|
site: {
|
|
attribute: 'name'
|
|
}
|
|
};
|
|
scope.clear = function (attribute) {
|
|
scope.updatedInfo[attribute] = null;
|
|
};
|
|
scope.getListPersons = function (term, company) {
|
|
scope.searchingPersons = true;
|
|
return createTicketService.getListOfPersonsByCompany(term, company).then(function (response) {
|
|
scope.searchingPersons = false;
|
|
return response[0].items;
|
|
});
|
|
};
|
|
scope.buildSiteTag = function (site) {
|
|
var siteGroup = site.siteGroup ? ' > ' + site.siteGroup : '', siteName = site.name ? ' > ' + site.name : '', siteRegion = site.region ? site.region : '';
|
|
return siteRegion + siteGroup + siteName;
|
|
};
|
|
scope.validateRequestedFor = function () {
|
|
if (!scope.updatedInfo.customer.id) {
|
|
scope.updatedInfo.customer = '';
|
|
}
|
|
scope.searchingPersons = false;
|
|
};
|
|
scope.setChangeLocation = function () {
|
|
return systemAlertService.modal({
|
|
title: i18nService.getLocalizedString('create.release.setRequestedForLocation.title'),
|
|
text: i18nService.getLocalizedString('create.release.setRequestedForLocation.text'),
|
|
buttons: [
|
|
{
|
|
text: i18nService.getLocalizedString('common.button.yes'),
|
|
data: true
|
|
},
|
|
{
|
|
text: i18nService.getLocalizedString('common.button.no'),
|
|
data: false
|
|
}
|
|
]
|
|
}).result.then(function (data) {
|
|
if (data) {
|
|
var location = scope.updatedInfo.customer.site;
|
|
location.company = scope.ticket.company.name;
|
|
scope.updatedInfo.location = location;
|
|
}
|
|
});
|
|
};
|
|
function toggleEditMode() {
|
|
scope.editMode = true;
|
|
scope.ticketCopy = _.cloneDeep(scope.ticket);
|
|
scope.updatedInfo = {
|
|
customer: scope.ticket.customer,
|
|
company: scope.ticket.company,
|
|
location: scope.ticket.location,
|
|
priority: _.find(scope.metadata.priorities, function (obj) {
|
|
return obj.name === scope.ticket.priority;
|
|
})
|
|
};
|
|
scope.updatedInfo.location.companyName = scope.updatedInfo.company.name;
|
|
scope.updatedInfo.location.region = scope.ticket.location.region;
|
|
}
|
|
function handleSaveChanges() {
|
|
var changes = collectChanges();
|
|
scope.$emit(events.SAVE_CHANGES_REQUEST, changes);
|
|
}
|
|
function collectChanges() {
|
|
var changes = {};
|
|
if (scope.updatedInfo.priority.name !== scope.ticket.priority) {
|
|
changes.priority = scope.updatedInfo.priority.name;
|
|
}
|
|
if (scope.updatedInfo.location !== scope.ticket.location) {
|
|
changes.location = scope.updatedInfo.location;
|
|
}
|
|
return changes;
|
|
}
|
|
function close() {
|
|
scope.editMode = false;
|
|
scope.updatedInfo = {};
|
|
}
|
|
function handleSaveComplete(event, eventData) {
|
|
if (!_.isEmpty(eventData)) {
|
|
scope.ticket.changeReason = eventData.changeReason;
|
|
scope.ticket.customer = eventData.customer;
|
|
scope.ticket.location = eventData.location;
|
|
scope.ticket.priority = eventData.priority;
|
|
}
|
|
if (scope.isDatesRequired()) {
|
|
scope.ticket.scheduledStartDate = scope.ticketCopy.scheduledStartDate;
|
|
scope.ticket.scheduledEndDate = scope.ticketCopy.scheduledEndDate;
|
|
scope.ticket.actualStartDate = scope.ticketCopy.actualStartDate;
|
|
scope.ticket.actualEndDate = scope.ticketCopy.actualEndDate;
|
|
}
|
|
close();
|
|
}
|
|
function handleSaveFault() {
|
|
scope.$broadcast(events.SAVE_CHANGES_COMPLETE); //needed to reset the child scopes of all contained directives
|
|
close();
|
|
}
|
|
scope.isDatesRequired = function () {
|
|
return (fieldValidationModel.isFieldRequired(scope.ticket.type, scope.ticket.status.value, 'scheduledStartDate')
|
|
|| fieldValidationModel.isFieldRequired(scope.ticket.type, scope.ticket.status.value, 'actualStartDate'))
|
|
&& (scope.ticket.accessMappings.actualdateEditAllowed || scope.ticket.accessMappings.scheduleddateEditAllowed);
|
|
};
|
|
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);
|
|
}
|
|
};
|
|
}
|
|
]);
|
|
})();
|