SmartIT_Extensions/BMC/smart-it-full-helix/scripts/app/ticket/ticket-transition-controlle...

63 lines
3.1 KiB
JavaScript

"use strict";
(function () {
'use strict';
angular.module('ticketModule')
.controller('TicketTransitionController', ['$scope', 'ticketModel', '$stateParams', 'systemAlertService', '$state', 'configurationModel', 'permissionModel', 'roles', 'metadataModel',
function ($scope, ticketModel, $stateParams, systemAlertService, $state, configurationModel, permissionModel, roles, metadataModel) {
var state = {
loginPending: true,
ticketNotFound: false,
ticket: '',
};
$scope.state = state;
var init = function () {
state.loginPending = true;
ticketModel.getGUIDByDisplayID($stateParams.type, $stateParams.displayid).then(function (response) {
state.loginPending = false;
if (response !== undefined) {
metadataModel.getMetadataByType('global').then(function (metadata) {
var isPwaEnabled = (metadata.configurationParameters['Enable-Progressive-Views'] === 'T' || metadata.configurationParameters['Enable-Progressive-Views'] === 'true');
isPwaEnabled = localStorage.getItem('overridePV') === 'T' ? false : isPwaEnabled;
if (isPwaEnabled && localStorage.getItem('midtierUrl') && configurationModel.get('pwaEnabledTickets.tickets').indexOf($stateParams.type) >= 0) {
$state.go($stateParams.type + 'PV', { id: response }, { location: "replace", reload: true });
}
else {
$state.go($stateParams.type, { id: response }, { location: "replace", reload: true });
}
}).catch(function (error) {
if (error) {
systemAlertService.error({
text: error.data.error,
clear: false
});
}
});
}
else {
state.loginPending = false;
state.ticketNotFound = true;
state.ticket = $stateParams.type;
}
}, function (err) {
var ticketType = $stateParams.type;
state.loginPending = false;
if (ticketType === 'incident'
|| ticketType === 'workorder'
|| ticketType === 'change'
|| ticketType === 'task') {
state.ticketNotFound = true;
state.ticket = $stateParams.type;
}
else {
systemAlertService.error({
text: (err.data && (err.data.detailedMessage || err.data.error)) || err,
clear: false
});
}
});
};
init();
}
]);
})();