SmartIT_Extensions/BMC/smart-it-full-helix/scripts/app/ticket/bulk-assign-controller.js

112 lines
5.2 KiB
JavaScript

"use strict";
(function () {
'use strict';
angular.module('ticketModule').controller('BulkAssignController', ['$scope', '$modalInstance', '$q', 'ticketService', 'assignParams', 'systemAlertService', 'i18nService', 'events',
function ($scope, $modalInstance, $q, ticketService, assignParams, systemAlertService, i18nService, events) {
var selected = {
group: {},
person: {},
isGroup: false,
autoAssign: false
};
var state = {
processing: false
};
var selectedItems = assignParams.selectedItems;
$scope.ticket = selectedItems && selectedItems[0] || {};
if (selectedItems.length > 0 && (Object.keys(_.countBy(selectedItems, 'customer.company.name')).length >= 2)) {
$scope.ticket.customer = null;
}
$scope.groups = [];
if (selectedItems && selectedItems.length && selectedItems[0].supportGroup.id) {
selected.group = new SupportGroupVO().build(selectedItems[0].supportGroup ? selectedItems[0].supportGroup : selectedItems[0].assignedGroup);
}
function assigneeCandidateSelected() {
return selected.person.loginId || selected.isGroup || selected.autoAssign;
}
$scope.close = function () {
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'),
data: false
}
]
});
modalInstance.result.then(function (data) {
if (data) {
$modalInstance.dismiss();
}
});
};
function handleModalBackdropClick() {
$scope.close();
}
$scope.$on(events.MODAL_BACKDROP_CLICK, handleModalBackdropClick);
$scope.submit = function () {
state.processing = true;
if (assigneeCandidateSelected()) {
var attributesMap = {};
if (!selected.autoAssign) {
if (!selected.isGroup) {
selected.group = selected.person.supportGroups[0];
attributesMap.loginId = selected.person.loginId;
attributesMap.fullName = selected.person.fullName;
}
if ($scope.ticket.type === EntityVO.TYPE_KNOWLEDGE) {
attributesMap.assigneeGroup = selected.group.name;
attributesMap.assigneeGroupId = selected.group.id;
attributesMap.assigneeCompany = selected.group.company ? selected.group.company.name : '';
attributesMap.assigneeOrganization = selected.group.organization;
}
else {
attributesMap.group = selected.group.name;
attributesMap.groupId = selected.group.id;
attributesMap.company = selected.group.company ? selected.group.company.name : '';
attributesMap.organization = selected.group.organization;
attributesMap.autoAssign = false;
}
}
else {
attributesMap = {
autoAssign: true
};
selected.person = {};
selected.group = {};
}
var params = {
ids: _.map(selectedItems, function (item) {
return {
uuid: item.id,
type: item.type
};
}),
attributeValueMap: attributesMap
};
ticketService.assignTickets(params).then(function () {
var response = {
assignee: selected.person,
group: selected.group
};
$modalInstance.close(response);
}).catch(function (err) {
systemAlertService.error({
text: err.data.error,
clear: false
});
state.processing = false;
});
}
};
$scope.assignee = selected;
$scope.state = state;
}
]);
})();