58 lines
2.6 KiB
JavaScript
58 lines
2.6 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('ticketModule')
|
|
.controller('ExtDraftTicketController', ['$state', '$stateParams',
|
|
'localStorageService', 'pwaModel', 'ticketModel', 'smartRecorderModel',
|
|
function ($state, $stateParams, localStorageService, pwaModel, ticketModel, smartRecorderModel) {
|
|
var readyEvent = {
|
|
eventType: 'DRAFT_WINDOW_READY'
|
|
};
|
|
window.onmessage = handleMessage;
|
|
if (window.opener) {
|
|
window.opener.postMessage(readyEvent, '*'); //NOSONAR
|
|
}
|
|
function handleMessage(e) {
|
|
if (e && e.data && e.data.eventData && e.data.eventType === 'TICKET_DATA') {
|
|
if ($stateParams.draftType) {
|
|
var isPwaEnabled = false;
|
|
pwaModel.isPwaEnabledPromise().then(function (result) {
|
|
isPwaEnabled = !!result;
|
|
}).finally(function () {
|
|
openDraftView(isPwaEnabled, $stateParams.draftType, e.data.eventData);
|
|
});
|
|
}
|
|
else {
|
|
$state.go('smartRecorder');
|
|
}
|
|
}
|
|
}
|
|
function openDraftView(isPwaEnabled, draftType, ticketData) {
|
|
var stateToGo, stateParams = {
|
|
isSrcExt: 'true',
|
|
crossLaunchContext: 'CHANGE'
|
|
};
|
|
if (draftType === EntityVO.TYPE_PROBLEM) {
|
|
var smartRecorderData = new SmartRecorderVO();
|
|
smartRecorderData.desc = ticketData.desc;
|
|
smartRecorderData.impact = ticketData.impact;
|
|
smartRecorderData.urgency = ticketData.urgency;
|
|
smartRecorderData.investigationDriver = ticketData.investigationDriver;
|
|
smartRecorderData.confirmedResourceList = ticketData.relatedList;
|
|
smartRecorderData.type = ticketData.type;
|
|
if (isPwaEnabled) {
|
|
pwaModel.smartRecorderData = smartRecorderData;
|
|
stateToGo = 'pwaDraftProblem';
|
|
}
|
|
else {
|
|
smartRecorderModel.smartRecorderData = smartRecorderData;
|
|
smartRecorderModel.saveState = false;
|
|
stateToGo = 'draftProblem';
|
|
}
|
|
}
|
|
$state.go(stateToGo, stateParams);
|
|
}
|
|
}
|
|
]);
|
|
})();
|