83 lines
3.9 KiB
JavaScript
83 lines
3.9 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('liveChatModule')
|
|
.controller('LiveChatDraftTicketController', ['$state', '$stateParams',
|
|
'localStorageService', 'pwaModel', 'ticketModel',
|
|
function ($state, $stateParams, localStorageService, pwaModel, ticketModel) {
|
|
var ticketType = $stateParams.draftType;
|
|
var draftTicket = localStorageService.get('draft.ticket');
|
|
var pwaEnabled = false;
|
|
console.log('LiveChatDraftTicketController: $stateParams= ' + JSON.stringify($stateParams));
|
|
if (ticketType && draftTicket) {
|
|
var errorCreateFromLiveChat = localStorageService.get('draft.ticket.error');
|
|
var draftTicketVO = null;
|
|
var stateToGo;
|
|
var stateParams = {
|
|
isSrcLiveChat: $stateParams.isSrcLiveChat || 'true',
|
|
error: errorCreateFromLiveChat,
|
|
crossLaunchContext: $stateParams.crossLaunchContext || 'LIVECHAT'
|
|
};
|
|
pwaModel.isPwaEnabledPromise().then(function (result) {
|
|
pwaEnabled = result;
|
|
}).finally(function () {
|
|
openDraftView(pwaEnabled);
|
|
});
|
|
}
|
|
else if ($stateParams.id && ticketType && $stateParams.launchMode) {
|
|
pwaModel.isPwaEnabledPromise().then(function (result) {
|
|
pwaEnabled = result;
|
|
}).finally(function () {
|
|
console.debug('openTicketView() pwaEnabled= ' + pwaEnabled);
|
|
var stateToGo = ticketType;
|
|
var stateParams = {
|
|
id: $stateParams.id,
|
|
editMode: ($stateParams.launchMode === 'edit') ? true : false
|
|
};
|
|
if (pwaEnabled) {
|
|
stateToGo = stateToGo + 'PV';
|
|
}
|
|
console.debug('openTicketView() stateToGo= ' + stateToGo + ' ,stateParams= ' + JSON.stringify(stateParams));
|
|
$state.go(stateToGo, stateParams);
|
|
});
|
|
}
|
|
else {
|
|
$state.go('smartRecorder');
|
|
}
|
|
function openDraftView(pwaEnabled) {
|
|
console.debug('openDraftView() pwaEnabled= ' + pwaEnabled);
|
|
if (draftTicket.type === EntityVO.TYPE_INCIDENT) {
|
|
draftTicketVO = new IncidentVO();
|
|
draftTicketVO = angular.copy(draftTicket, draftTicketVO);
|
|
if (pwaEnabled) {
|
|
pwaModel.createIncFromSmartRecorder = true;
|
|
pwaModel.smartRecorderData = draftTicketVO;
|
|
stateToGo = 'pwaDraftIncident';
|
|
}
|
|
else {
|
|
ticketModel.cache.draft = draftTicketVO;
|
|
stateToGo = 'draftIncident';
|
|
}
|
|
}
|
|
else if (draftTicket.type === EntityVO.TYPE_WORKORDER) {
|
|
draftTicketVO = new WorkOrderVO();
|
|
draftTicketVO = angular.copy(draftTicket, draftTicketVO);
|
|
if (pwaEnabled) {
|
|
pwaModel.createWOFromSmartRecorder = true;
|
|
pwaModel.smartRecorderData = draftTicketVO;
|
|
stateToGo = 'pwaDraftWorkorder';
|
|
}
|
|
else {
|
|
ticketModel.cache.draft = draftTicketVO;
|
|
stateToGo = 'draftWorkorder';
|
|
}
|
|
}
|
|
localStorageService.remove('draft.ticket');
|
|
localStorageService.remove('draft.ticket.error');
|
|
console.debug('openDraftView() stateToGo= ' + stateToGo + ' ,stateParams= ' + JSON.stringify(stateParams));
|
|
$state.go(stateToGo, stateParams);
|
|
}
|
|
}
|
|
]);
|
|
})();
|