"use strict"; (function () { 'use strict'; /** * @ngdoc directive * @name myitsmApp:dwpWindow * @restrict E * @desription DWP window is used for showing dwp service question. */ angular.module('myitsmApp') .directive('dwpWindow', ['$sce', 'smartRecorderModel', '$filter', '$state', 'systemAlertService', function ($sce, smartRecorderModel, $filter, $state, systemAlertService) { return { restrict: 'E', template: "", replace: true, scope: { serviceId: '=', requestedFor: '=', requestedBy: '=', modalInstance: '=' }, link: function (scope) { scope.dwpurl = smartRecorderModel.dwpUrl; scope.smartiturl = smartRecorderModel.smartitUrl; //validate dwp url and smartit url if (!(scope.dwpurl.indexOf('http://') === 0 || scope.dwpurl.indexOf('https://') === 0)) { console.error('Invalid DWP url in ccs - it should contain either http:// or https:// :' + scope.dwpurl); } if (!(scope.smartiturl.indexOf('http://') === 0 || scope.smartiturl.indexOf('https://') === 0)) { console.error('Invalid smartiturl url in ccs - it should contain either http:// or https:// :' + scope.smartiturl); } var finalUrl = scope.dwpurl + '/dwp/rest/embed?allow-from-domain=' + scope.smartiturl + '&action=checkout&id=' + scope.serviceId + '&requestedForUserId=' + scope.requestedFor + '&requestedByUserId=' + scope.requestedBy; scope.loadurl = $sce.trustAsResourceUrl(finalUrl); window.onmessage = handler; function handler(e) { if (e.data && typeof e.data === 'object') { var dwpResponse = e.data; if (dwpResponse.action && dwpResponse.action === 'checkout') { if (dwpResponse.status === 'success') { systemAlertService.success({ text: $filter('i18n')('ticket.dwp.submitted'), icon: 'icon-check_circle', clear: true, displayOnStateChange: true, hide: 10000 }); smartRecorderModel.saveState = false; $state.go('sberequest', { id: dwpResponse.requestId }); } else if (dwpResponse.status === 'failure') { systemAlertService.error({ text: dwpResponse.message, clear: false }); scope.modalInstance.dismiss(); } else if (dwpResponse.status === 'cancelRequest') { scope.modalInstance.dismiss(); } } } } } }; }]); }());