189 lines
10 KiB
JavaScript
189 lines
10 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('myitsmApp')
|
|
.directive('titleBar', ['events', 'chatModel', 'ticketModel', 'systemAlertService', 'ticketActionService', 'relationService', '$filter', 'relationModel', 'objectValueMapperService', 'userModel', 'screenConfigurationModel', '$modal', 'roles', 'permissionModel',
|
|
function (events, chatModel, ticketModel, systemAlertService, ticketActionService, relationService, $filter, relationModel, objectValueMapperService, userModel, screenConfigurationModel, $modal, roles, permissionModel) {
|
|
return {
|
|
restrict: 'EA',
|
|
scope: {
|
|
state: '=',
|
|
isDraft: '=',
|
|
ticket: '=',
|
|
isFullVersion: '=',
|
|
screenLayout: '=',
|
|
metadata: '=',
|
|
update: '&',
|
|
moreDropDownOptions: '='
|
|
},
|
|
templateUrl: 'views/layout-configuration/title-bar-component/title-bar.html',
|
|
link: function (scope) {
|
|
var relations, titlePanel, temp, cssClass, relationCounters = {};
|
|
scope.editMode = false;
|
|
scope.chatModel = chatModel;
|
|
scope.hideMoreActionsButton = true;
|
|
if (!scope.isFullVersion) {
|
|
scope.fullDetailsText = getFullDetailsText();
|
|
}
|
|
scope.isSummaryEditable = scope.ticket.accessMappings
|
|
&& scope.ticket.accessMappings.fieldMappings
|
|
&& scope.ticket.accessMappings.fieldMappings.summary
|
|
&& scope.ticket.accessMappings.fieldMappings.summary === 'write';
|
|
scope.iconClass = function () {
|
|
cssClass = 'icon-' + scope.ticket.type;
|
|
if (scope.isAutomatic) {
|
|
cssClass += '-auto';
|
|
}
|
|
if (scope.ticket.brokerVendorName) {
|
|
cssClass += '-brokered';
|
|
}
|
|
return cssClass;
|
|
};
|
|
_.forEach(scope.screenLayout.panels, function (panel) {
|
|
if (panel.name === 'titleSection' || panel.name === 'titleBarSection') {
|
|
scope.titleBarLayout = panel.panels[0];
|
|
scope.titleBarPanelId = scope.screenLayout.name + '.' + scope.titleBarLayout.name;
|
|
}
|
|
});
|
|
relations = relationModel.cache;
|
|
relationCounters.tasks = relationService.getRelatedTasks(relations[scope.ticket.id]).length;
|
|
relationCounters.linkedItems = relationService.getRelatedLinkedItems(relations[scope.ticket.id], scope.ticket, false).length;
|
|
relationCounters.CIs = relationService.getRelatedCIs(relations[scope.ticket.id]).length;
|
|
scope.ticketActions = {
|
|
assignToMe: function ($e) {
|
|
var assignParams = {
|
|
originalEvent: $e,
|
|
assignToMe: true,
|
|
saveSelection: true,
|
|
role: 'assignee'
|
|
};
|
|
scope.$emit(events.SHOW_ASSIGN_TICKET_BLADE, assignParams);
|
|
},
|
|
share: function () {
|
|
ticketActionService.share(scope.ticket);
|
|
},
|
|
follow: function () {
|
|
return ticketActionService.follow(scope.ticket);
|
|
},
|
|
unfollow: function () {
|
|
return ticketActionService.unfollow(scope.ticket);
|
|
},
|
|
showPrintDialog: function ($event) {
|
|
ticketActionService.showPrintDialog($event, scope.ticket, relationCounters, scope.ticket.feed, scope.metadata, scope.screenLayout);
|
|
},
|
|
confirmAction: function (action) {
|
|
ticketActionService.confirmAction(scope.ticket, action, scope).then(function () {
|
|
scope.$emit(events.TICKET_PROFILE_RESEND_EVENT, { eventName: events.REFRESH_ACTIVITY_FEED });
|
|
ticketActionService.applyAction(scope.ticket, action, scope);
|
|
});
|
|
},
|
|
applyAction: function (action) {
|
|
ticketActionService.applyAction(scope.ticket, action, scope);
|
|
},
|
|
copyChangeAllowed: function () {
|
|
if (scope.ticket.accessMappings && scope.ticket.accessMappings.hasOwnProperty('allEditAllowed')) {
|
|
return scope.ticket.accessMappings.allEditAllowed;
|
|
}
|
|
else {
|
|
return true;
|
|
}
|
|
}
|
|
};
|
|
scope.isAssignToMeEnabled = function () {
|
|
var currentAssignee = objectValueMapperService.getValueByFieldName('assignee');
|
|
return currentAssignee && userModel.userId !== currentAssignee.id;
|
|
};
|
|
scope.editButtonClickHandler = function () {
|
|
scope.$parent.handleExternalEditClick();
|
|
};
|
|
scope.summaryField = new FieldVO().build({
|
|
name: 'summary',
|
|
value: scope.ticket.summary,
|
|
type: 'characterField',
|
|
dataType: 'text',
|
|
maxLength: 100,
|
|
ootb: true,
|
|
required: true
|
|
});
|
|
if (scope.ticket.type === 'incident') {
|
|
titlePanel = screenConfigurationModel.getPanelById('incidentViewScreen.summaryPanel');
|
|
}
|
|
else if (scope.ticket.type === 'change') {
|
|
titlePanel = screenConfigurationModel.getPanelById('changeViewScreen.summaryPanel');
|
|
}
|
|
else if (scope.ticket.type === 'task') {
|
|
titlePanel = screenConfigurationModel.getPanelById('taskViewScreen.summaryPanel');
|
|
}
|
|
if (titlePanel) {
|
|
temp = _.find(titlePanel.fields, { name: 'summary' });
|
|
if (temp && temp.maxLength) {
|
|
scope.summaryField.maxLength = temp.maxLength;
|
|
}
|
|
}
|
|
objectValueMapperService.addFields([scope.summaryField]);
|
|
scope.onSummaryChange = function () {
|
|
scope.$emit(events.WIDGET_VALUE_CHANGE, { fieldName: scope.summaryField.name, memberName: scope.summaryField.name });
|
|
};
|
|
scope.toggleFollowingFlag = function () {
|
|
var toggleFollowingFunction = scope.ticket.following ? scope.ticketActions.unfollow : scope.ticketActions.follow;
|
|
toggleFollowingFunction(scope.ticket).then(function () {
|
|
scope.ticket.following = !scope.ticket.following;
|
|
});
|
|
};
|
|
scope.refreshTicket = function () {
|
|
scope.$emit(events.REFRESH_TICKET_FROM_TITLE_BAR);
|
|
};
|
|
scope.copyChangeTicket = function () {
|
|
var modalInstance = $modal.open({
|
|
templateUrl: 'views/ticket/copy-change.html',
|
|
controller: 'CopyChangeController',
|
|
windowClass: 'action-blade',
|
|
backdrop: 'custom',
|
|
size: 'md',
|
|
resolve: {
|
|
ticket: function () {
|
|
return scope.ticket;
|
|
},
|
|
}
|
|
});
|
|
modalInstance.result.then(function (response) {
|
|
});
|
|
};
|
|
scope.$on(events.TOGGLE_EDIT_MODE, handleToggleEditMode);
|
|
scope.$on(events.AFTER_SAVED_CHANGES, afterSaveChangesHandler);
|
|
scope.$on(events.DISCARD_CHANGES, handleDiscardChanges);
|
|
scope.$on(events.OPEN_EDIT_MODE, openEditMode);
|
|
function handleToggleEditMode() {
|
|
scope.editMode = true;
|
|
}
|
|
function afterSaveChangesHandler(event, updatedTicket) {
|
|
scope.editMode = false;
|
|
scope.ticket = updatedTicket;
|
|
}
|
|
function handleDiscardChanges() {
|
|
scope.editMode = false;
|
|
scope.summaryField.value = _.cloneDeep(scope.ticket.summary);
|
|
}
|
|
function openEditMode() {
|
|
if (!scope.editMode) {
|
|
scope.editButtonClickHandler();
|
|
}
|
|
}
|
|
function getFullDetailsText() {
|
|
var fullDetailsText;
|
|
if (scope.ticket.type === EntityVO.TYPE_INCIDENT) {
|
|
fullDetailsText = $filter('i18n')('search.preview.viewFullIncident');
|
|
}
|
|
else if (scope.ticket.type === EntityVO.TYPE_CHANGE) {
|
|
fullDetailsText = $filter('i18n')('search.preview.viewFullChange');
|
|
}
|
|
else if (scope.ticket.type === EntityVO.TYPE_TASK) {
|
|
fullDetailsText = $filter('i18n')('search.preview.viewFullTask');
|
|
}
|
|
return fullDetailsText;
|
|
}
|
|
}
|
|
};
|
|
}]);
|
|
}());
|