"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', function ($modal, $state, ticketModel, createTicketModel, $timeout, events, systemAlertService, i18nService) { return { restrict: 'E', replace: true, templateUrl: 'views/release/edit-release-plan.html', scope: { ticket: '=' }, 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.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 }; $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; }); } }; }]); })();