184 lines
9.7 KiB
JavaScript
184 lines
9.7 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Created by andey on 13-01-2017.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
angular.module('releaseModule')
|
|
.directive('editReleasePlan', ['$modal', '$state', 'ticketModel', 'createTicketModel', '$timeout', 'events', 'systemAlertService', 'i18nService', 'pwaModel', 'configurationModel', 'permissionModel', 'roles',
|
|
function ($modal, $state, ticketModel, createTicketModel, $timeout, events, systemAlertService, i18nService, pwaModel, configurationModel, permissionModel, roles) {
|
|
return {
|
|
restrict: 'E',
|
|
replace: true,
|
|
templateUrl: 'views/release/edit-release-plan.html',
|
|
scope: {
|
|
ticket: '=',
|
|
milestones: '='
|
|
},
|
|
link: function (scope) {
|
|
scope.releasePlanMilestoneDirty = false;
|
|
function refreshRelations() {
|
|
//TODO: Code to refresh activities and CRQ related to release.
|
|
$timeout(function () {
|
|
scope.$broadcast(events.REFRESH_RELEASE_PLAN_LIST);
|
|
}, 1000);
|
|
}
|
|
scope.addExistingChange = function ($event) {
|
|
var sequence = 1;
|
|
if (scope.ticket.noOfRelatedItems[scope.ticket.milestone]) {
|
|
sequence = scope.ticket.noOfRelatedItems[scope.ticket.milestone] + 1;
|
|
}
|
|
var modalInstance = $modal.open({
|
|
templateUrl: 'views/release/relate-change-action-blade.html',
|
|
windowClass: 'action-blade-aif',
|
|
controller: 'RelateChangeController',
|
|
resolve: {
|
|
linkParams: function () {
|
|
return {
|
|
selectedItems: [{
|
|
id: scope.ticket.id,
|
|
type: EntityVO.TYPE_RELEASE,
|
|
desc: scope.ticket.summary,
|
|
displayId: scope.ticket.displayId,
|
|
milestone: { name: scope.ticket.milestone }
|
|
}],
|
|
isDraft: true,
|
|
sequence: sequence
|
|
};
|
|
}
|
|
}
|
|
});
|
|
modalInstance.result.then(function () {
|
|
refreshRelations();
|
|
}).finally(function () {
|
|
$event.currentTarget.focus();
|
|
});
|
|
};
|
|
scope.createBlankActivity = function () {
|
|
isReleasePlanDirty(function (status) {
|
|
if (status) {
|
|
ticketModel.activityParent = scope.ticket;
|
|
var modalInstance = $modal.open({
|
|
templateUrl: 'views/create/create-activity.html',
|
|
controller: 'CreateActivityController',
|
|
windowClass: 'ticket__open-modal',
|
|
backdrop: false,
|
|
keyboard: false
|
|
});
|
|
modalInstance.result.then(function () {
|
|
refreshRelations();
|
|
createTicketModel.currentTicket = scope.ticket;
|
|
});
|
|
}
|
|
});
|
|
};
|
|
scope.browseActivityTemplate = function () {
|
|
isReleasePlanDirty(function (status) {
|
|
if (status) {
|
|
ticketModel.activityParent = scope.ticket;
|
|
var modalInstance = $modal.open({
|
|
templateUrl: 'views/template/browse-ticket-template-action-blade.html',
|
|
windowClass: 'action-blade',
|
|
controller: 'BrowseTicketTemplateController',
|
|
resolve: {
|
|
ticketType: function () {
|
|
return EntityVO.TYPE_ACTIVITY;
|
|
},
|
|
metadata: function () {
|
|
return {};
|
|
},
|
|
company: function () {
|
|
return scope.ticket.company;
|
|
}
|
|
}
|
|
});
|
|
modalInstance.result.then(function () {
|
|
refreshRelations();
|
|
});
|
|
}
|
|
});
|
|
};
|
|
scope.haveChangePermission = function () {
|
|
return configurationModel.isServerApplicationEnabled(EntityVO.TYPE_CHANGE)
|
|
&& permissionModel.hasPermission(roles.ITSM_CHANGE_USER_ROLE);
|
|
};
|
|
scope.createRelatedDraft = function (ticketType, location) {
|
|
isReleasePlanDirty(function (status) {
|
|
if (status) {
|
|
ticketModel.cache.draft = {
|
|
type: ticketType
|
|
};
|
|
var sequence = 1;
|
|
if (scope.ticket.noOfRelatedItems[scope.ticket.milestone]) {
|
|
sequence = scope.ticket.noOfRelatedItems[scope.ticket.milestone] + 1;
|
|
}
|
|
ticketModel.cache.relatedDraft = {
|
|
type: ticketType,
|
|
fromType: EntityVO.TYPE_RELEASE,
|
|
id: scope.ticket.id,
|
|
fromContext: scope.ticket,
|
|
relationship: RelationItemVO.TYPE_MEMBEROF,
|
|
sequence: sequence
|
|
};
|
|
if (EntityVO.TYPE_CHANGE == ticketType && pwaModel.isPwaEnabled()) {
|
|
scope.ticket.sequence = sequence;
|
|
scope.ticket.milestoneId = scope.ticket.milestone ? _.find(scope.milestones, { name: scope.ticket.milestone }).index : "";
|
|
pwaModel.createRelatedFromRelease = {
|
|
fromType: ticketType,
|
|
fromContext: scope.ticket
|
|
};
|
|
var stateParam = {
|
|
isSrcRelease: 'true',
|
|
crossLaunchContext: "RELEASE"
|
|
};
|
|
$state.go("pwaDraftChange", stateParam);
|
|
}
|
|
else {
|
|
$state.go(location);
|
|
}
|
|
}
|
|
});
|
|
};
|
|
function isReleasePlanDirty(callback) {
|
|
if (scope.releasePlanMilestoneDirty) {
|
|
var modalInstance = displayDirtyFormAlert();
|
|
modalInstance.result.then(function (data) {
|
|
if (data) {
|
|
callback(true);
|
|
}
|
|
else {
|
|
callback(false);
|
|
}
|
|
});
|
|
}
|
|
else {
|
|
callback(true);
|
|
}
|
|
}
|
|
function displayDirtyFormAlert() {
|
|
var modalInstance = systemAlertService.modal({
|
|
title: i18nService.getLocalizedString('common.notification.dirty.title'),
|
|
text: i18nService.getLocalizedString('common.notification.dirty.message'),
|
|
buttons: [
|
|
{
|
|
text: i18nService.getLocalizedString('common.labels.yes'),
|
|
data: true
|
|
},
|
|
{
|
|
text: i18nService.getLocalizedString('common.labels.no')
|
|
}
|
|
]
|
|
});
|
|
return modalInstance;
|
|
}
|
|
scope.$on(events.RELEASE_PLAN_MILESTONE_CHANGE, function () {
|
|
scope.releasePlanMilestoneDirty = true;
|
|
});
|
|
scope.$on(events.RELEASE_PLAN_MILESTONE_NOT_DIRTY, function () {
|
|
scope.releasePlanMilestoneDirty = false;
|
|
});
|
|
}
|
|
};
|
|
}]);
|
|
})();
|