(function() { 'use strict'; var HTTP_ERRORS = { 401: "Unathorized action", 418: "Application error", 403: "Forbidden action", 500: "Server error", 404: "Element not found" } var app = angular.module('securis'); app.service('Packs', ['$L','$resource', '$http', 'toaster', function($L, $resource, $http, toaster) { var PACK_STATUS = { CREATED: 'CR', ACTIVE: 'AC', ONHOLD: 'OH', EXPIRED: 'EX', CANCELLED: 'CA' } var PACK_STATUSES = { 'CR': $L.get('Created'), 'AC': $L.get('Active'), 'OH': $L.get('On Hold'), 'EX': $L.get('Expired'), 'CA': $L.get('Cancelled') }; /** * These transitions could be get from server, class Pack.Status, but we * copy them for simplicity, this info won't change easily */ var PACK_ACTIONS_BY_STATUS = { activate: [PACK_STATUS.CREATED, PACK_STATUS.EXPIRED, PACK_STATUS.ONHOLD], putonhold: [PACK_STATUS.ACTIVE], cancel: [PACK_STATUS.EXPIRED, PACK_STATUS.ONHOLD, PACK_STATUS.ACTIVE], 'delete': [PACK_STATUS.CREATED, PACK_STATUS.CANCELLED] } var packResource = $resource('pack/:packId/:action', { packId : '@id', action : '@action' }, { activate: { method: "POST", params: {action: "activate"} }, putonhold: { method: "POST", params: {action: "putonhold"} }, cancel: { method: "POST", params: {action: "cancel"} } } ); this.getStatusColor = function(status) { var COLORS_BY_STATUS = { 'CR': '#808080', 'AC': '#329e5a', 'OH': '#9047c7', 'EX': '#ea7824', 'CA': '#a21717' }; return COLORS_BY_STATUS[status]; }, this.getStatusName = function(status) { return PACK_STATUSES[status]; } this.savePackData = function(pack, isNew, _onsuccess) { var _success = function() { _onsuccess(); toaster.pop('success', 'Packs', $L.get("Pack '{0}' {1} successfully", pack.code, isNew ? $L.get("created") : $L.get("updated"))); } var _error = function(error) { console.log(error); toaster.pop('error', 'Packs', $L.get("Error {0} pack '{1}'. Reason: {2}", isNew ? $L.get("creating") : $L.get("updating"), pack.code, $L.get(error.headers('X-SECURIS-ERROR-MSG')))); } packResource.save(pack, _success, _error); } this.isActionAvailable = function(action, pack) { var validStatuses = PACK_ACTIONS_BY_STATUS[action]; return pack && validStatuses && validStatuses.indexOf(pack.status) !== -1; } var _createSuccessCallback = function(actionName, message, _innerCallback) { return function() { _innerCallback && _innerCallback(); toaster.pop('success', actionName, message); } } var _createErrorCallback = function(pack, actionName, _innerCallback) { return function(error) { console.log(error); _innerCallback && _innerCallback(); toaster.pop('error', actionName, $L.get("Error on action '{0}', pack '{1}'. Reason: {2}", actionName, pack.code, $L.get(error.headers('X-SECURIS-ERROR-MSG')))); } } this.getPacksList = function(_onsuccess, _onerror) { var query = packResource.query(); query.$promise.then(_onsuccess, _onerror); return query; } this.activate = function(pack, _onsuccess, _onerror) { console.log('Activation on pack: ' + pack.id); var _success = _createSuccessCallback($L.get('Activation'), $L.get("Pack '{0}' {1} successfully", pack.code, $L.get("activated")), _onsuccess); var _error = _createErrorCallback(pack, $L.get('Activation'), _onerror); packResource.activate({id: pack.id}, _success, _error); } this.putonhold = function(pack, _onsuccess, _onerror) { console.log('Put on hold on pack: ' + pack.id); var _success = _createSuccessCallback($L.get('Put on hold'), $L.get("Pack '{0}' {1} successfully", pack.code, $L.get("put on hold")), _onsuccess); var _error = _createErrorCallback(pack, $L.get('Put on hold'), _onerror); packResource.putonhold({id: pack.id}, _success, _error); } this.nextliccode = function(packId, _onsuccess, _onerror) { console.log('Get next code: ' + packId); var _error = function(data, status, headers, config) { console.log(headers); toaster.pop('error', $L.get('Getting next code suffix'), $L.get("Error getting license code, pack ID: '{0}'. Reason: {1}", packId, $L.get(headers('X-SECURIS-ERROR-MSG')))); } $http.get("/securis/pack/"+packId+"/next_license_code").success(_onsuccess).error(_error); } this.cancel = function(pack, extra_data, _onsuccess, _onerror) { console.log('Cancellation on pack: ' + pack.id); var _success = _createSuccessCallback($L.get('Cancellation'), $L.get("Pack '{0}' {1} successfully", pack.code, $L.get("cancelled")), _onsuccess); var _error = _createErrorCallback(pack, $L.get('Cancellation'), _onerror); var params = angular.extend({id: pack.id}, extra_data); packResource.cancel(params, _success, _error); } this.delete = function(pack, _onsuccess, _onerror) { console.log('Delete on pack: ' + pack.id); var _success = _createSuccessCallback($L.get('Deletion'), $L.get("Pack '{0}' {1} successfully", pack.code, $L.get("deleted")), _onsuccess); var _error = _createErrorCallback(pack, $L.get('Deletion'), _onerror); packResource.delete({packId: pack.id}, _success, _error); } }]); app.service('Licenses', ['$L', '$resource', 'toaster', 'Packs', function($L, $resource, toaster, Packs) { var LIC_STATUS = { CREATED: 'CR', ACTIVE: 'AC', REQUESTED: 'RE', PREACTIVE: 'PA', EXPIRED: 'EX', BLOCKED: 'BL', CANCELLED: 'CA' } var LIC_STATUSES = { 'CR': $L.get('Created'), 'AC': $L.get('Active'), 'PA': $L.get('Pre-active'), 'RE': $L.get('Requested'), 'EX': $L.get('Expired'), 'BL': $L.get('Blocked'), 'CA': $L.get('Cancelled') }; /** * These transitions could be get from server, class License.Status, but * we copy them for simplicity, this info won't change easily */ var LIC_ACTIONS_BY_STATUS = { add_request: [LIC_STATUS.CREATED], activate: [LIC_STATUS.CREATED, LIC_STATUS.REQUESTED, LIC_STATUS.PREACTIVE], send: [LIC_STATUS.ACTIVE, LIC_STATUS.PREACTIVE], download: [LIC_STATUS.ACTIVE, LIC_STATUS.PREACTIVE], block: [LIC_STATUS.CANCELLED], unblock: [LIC_STATUS.BLOCKED], cancel: [LIC_STATUS.REQUESTED, LIC_STATUS.EXPIRED, LIC_STATUS.PREACTIVE, LIC_STATUS.ACTIVE], 'delete': [LIC_STATUS.CREATED, LIC_STATUS.CANCELLED, LIC_STATUS.BLOCKED] } var licenseResource = $resource('license/:licenseId/:action', { licenseId : '@id', action : '@action' }, { activate: { method: "POST", params: {action: "activate"} }, cancel: { method: "POST", params: {action: "cancel"} }, // Download a file cannot be done form AJAX, We should do it // manually, using $http download: { method: "GET", params: {action: "download"} }, block: { method: "POST", params: {action: "block"} }, sendEmail: { method: "POST", params: {action: "send"} }, unblock: { method: "POST", params: {action: "unblock"} } }); this.isActionAvailable = function(action, lic) { var validStatuses = LIC_ACTIONS_BY_STATUS[action]; return lic && validStatuses && validStatuses.indexOf(lic.status) !== -1; } this.getStatusColor = function(status) { var COLORS_BY_STATUS = { 'CR': '#808080', 'AC': '#329e5a', 'RE': '#2981d4', 'EX': '#ea7824', 'BL': '#ff0000', 'CA': '#a21717' }; return COLORS_BY_STATUS[status]; }, this.getStatusName = function(status) { return LIC_STATUSES[status]; } this.saveLicenseData = function(license, isNew, _onsuccess) { var _success = function() { _onsuccess(); toaster.pop('success', 'Licenses', $L.get("License '{0}' {1} successfully", license.code, isNew ? $L.get("created") : $L.get("updated"))); } var _error = function(error) { console.log(error); toaster.pop('error', 'Licenses', $L.get("Error {0} license '{1}'. Reason: {2}", isNew ? $L.get("creating") : $L.get("updating"), license.code, $L.get(error.headers('X-SECURIS-ERROR-MSG'))), 5000); if (error.headers('X-SECURIS-ERROR-CODE') === '1301') { Packs.nextliccode(license.pack_id, function(data) { if (license.code !== data) { // Only if the new code is different we can think about an erro related with License CODE license.code = data; toaster.pop('info', 'Licenses', $L.get("New license code, {0}, has been generated, please try again", license.code), 5000); } }); } } licenseResource.save(license, _success, _error); } var _createSuccessCallback = function(actionName, message, _innerCallback) { return function() { _innerCallback && _innerCallback(); toaster.pop('success', actionName, message); } } var _createErrorCallback = function(license, actionName, _innerCallback) { return function(error) { console.log(error); _innerCallback && _innerCallback(); toaster.pop('error', actionName, $L.get("Error on action '{0}', license '{1}'. Reason: {2}", actionName, license.code, $L.get(error.headers('X-SECURIS-ERROR-MSG')))); } } this.getLicensesList = function(pack, _onsuccess, _onerror) { var query = licenseResource.query({packId: pack.id}); query.$promise.then(_onsuccess, _onerror); return query; } this.activate = function(license, _onsuccess, _onerror) { console.log('Activation on license: ' + license.id); var _success = _createSuccessCallback($L.get('Activation'), $L.get("License '{0}' {1} successfully", license.code, $L.get("activated")), _onsuccess); var _error = _createErrorCallback(license, $L.get('Activation'), _onerror); licenseResource.activate({id: license.id}, _success, _error); } this.block = function(license, _onsuccess, _onerror) { console.log('Block on license: ' + license.id); var _success = _createSuccessCallback($L.get('Block'), $L.get("License '{0}' {1} successfully", license.code, $L.get("blocked")), _onsuccess); var _error = _createErrorCallback(license, $L.get('Block'), _onerror); licenseResource.block({id: license.id}, _success, _error); } this.unblock = function(license, _onsuccess, _onerror) { console.log('Unblock on license: ' + license.id); var _success = _createSuccessCallback($L.get('Unblock'), $L.get("License '{0}' {1} successfully", license.code, $L.get("unblocked")), _onsuccess); var _error = _createErrorCallback(license, $L.get('Unblock'), _onerror); licenseResource.unblock({id: license.id}, _success, _error); } this.send = function(license, _onsuccess, _onerror) { console.log('Sending email: ' + license.id); var _success = _createSuccessCallback($L.get('Send email'), $L.get("License '{0}' was sent by email ({1}) successfully", license.code, license.email), _onsuccess); var _error = _createErrorCallback(license, $L.get('Send email'), _onerror); licenseResource.sendEmail({id: license.id}, _success, _error); } this.download = function(license, _onsuccess, _onerror) { console.log('Download license: ' + license.id); var _success = _createSuccessCallback($L.get('Download'), $L.get("License '{0}' {1} successfully", license.code, $L.get("downloaded")), _onsuccess); var _error = _createErrorCallback(license, $L.get('Download license file'), _onerror); // window.open(downloadPath, '_blank', ''); var _success2 = function(data, headers) { // console.log(headers.get("Content-Disposition")); // attachment; filename="license.lic" var filename = JSON.parse(headers('Content-Disposition').match(/".*"$/g)[0]); data.$promise.then(function(content) { saveAs( new Blob([ JSON.stringify(content, null, 2) ], { type : 'application/octet-stream' }), filename); }); _success(); }; licenseResource.download({licenseId: license.id}, _success2, _error); } this.cancel = function(license, extra_data, _onsuccess, _onerror) { console.log('Cancellation on license: ' + license.id); var _success = _createSuccessCallback($L.get('Cancellation'), $L.get("License '{0}' {1} successfully", license.code, $L.get("cancelled")), _onsuccess); var _error = _createErrorCallback(license, $L.get('Cancellation'), _onerror); var params = angular.extend({id: license.id}, extra_data); licenseResource.cancel(params, _success, _error); } this.delete = function(license, _onsuccess, _onerror) { console.log('Delete on license: ' + license.id); var _success = _createSuccessCallback($L.get('Deletion'), $L.get("License '{0}' {1} successfully", license.code, $L.get("deleted")), _onsuccess); var _error = _createErrorCallback(license, $L.get('Deletion'), _onerror); licenseResource.delete({licenseId: license.id}, _success, _error); } }]); app.directive('fileLoader', function($timeout, $parse) { return { restrict : 'A', // only activate on element attribute require : '', link : function(scope, element, attrs) { console.log('scope.license: ' + scope.$parent.license); var setter = $parse(attrs.fileLoader).assign; element.bind('change', function(evt) { if (!window.FileReader) { // Browser is not // compatible BootstrapDialog.alert($L.get("Open your .req file with a text editor and copy&paste the content in the form text field?")); return; } console.log('File selected'); // console.log('scope.license: ' + // scope.$parent.license); var field = $parse(attrs.fileLoader); // console.log('field: ' + field); var fileList = evt.target.files; if (fileList != null && fileList[0]) { var reader = new FileReader(); reader.onerror = function(data) { setter(scope.$parent, 'ERROR'); scope.$apply(); } reader.onload = function(data) { setter(scope.$parent, reader.result); scope.$apply(); } reader.readAsText(fileList[0]); element.val(''); } else { setter(scope.$parent, ''); scope.$apply(); } }); } }; }); app.controller('PackAndLicensesCtrl', [ '$scope', '$http', 'toaster', '$store', '$L', function($scope, $http, toaster, $store, $L) { $store.set('location', '/licenses'); $scope.maxLengthErrorMsg = function(displayname, fieldMaxlength) { return $L.get("{0} length is too long (max: {1}).", $L.get(displayname), fieldMaxlength); } $scope.mandatoryFieldErrorMsg = function(displayname) { return $L.get("'{0}' is required.", $L.get(displayname)); } $scope.field1ShouldBeGreaterThanField2 = function(field1, field2) { return $L.get("{0} should be greater than {1}", $L.get(field1), $L.get(field2)); } $scope.ellipsis = function(txt, len) { if (!txt || txt.length <= len) return txt; return txt.substring(0, len) + '...'; } $scope.currentPack = $store.get('currentPack'); if ($scope.currentPack) { $scope.currentPack._selected = true; setTimeout(function() { $scope.$broadcast('pack_changed', $scope.currentPack); }, 0); } }]); app.controller('PacksCtrl', [ '$scope', '$http', '$resource', 'toaster', 'Catalogs', 'Packs', '$store', '$L', function($scope, $http, $resource, toaster, Catalogs, Packs, $store, $L) { $scope.Packs = Packs; $scope.mandatory = { code: true, num_licenses: true, init_valid_date: true, end_valid_date: true, status: true, organization_id: true, license_type_id: true } $scope.maxlength = { code: 50, comments: 1024 } $scope.refs = {}; Catalogs.init().then(function() { var refFields = [{resource: 'organization', name: 'organization_id'},{resource: 'licensetype', name: 'license_type_id'}]; Catalogs.loadRefs(function(refs) { $scope.refs = refs; $scope._extendPackListing($scope.packs); }, refFields); }); // Used to create the form with the // appropriate data $scope.isNew = undefined; // Selected pack from listing // pack is the edited pack, in creation // contains the data for // the new pack $scope.pack = null; $scope.packs = Packs.getPacksList(function(list) { $scope._extendPackListing(list); }); /** * Added calculated fields like org_code and lic_type_code to pack listing */ $scope._extendPackListing = function(listing) { angular.forEach(listing, function(elem) { elem.organization_code = $scope.getOrganizationCode(elem.organization_id); elem.license_type_code = $scope.getLicenseTypeCode(elem.license_type_id); }); } $scope.save = function() { Packs.savePackData($scope.pack, $scope.isNew, function() { if (!$scope.isNew) { $scope.showForm = false; } else { $scope.newPack(); } $scope.packs = Packs.getPacksList(function(list) { $scope._extendPackListing(list); }); }); } /** * Execute an action over the pack, * activation, onhold, cancellation */ $scope.execute = function(action, pack) { var _execute = function(extra_data) { if (extra_data) { Packs[action](pack || $scope.pack, extra_data, function() { if (!$scope.isNew) $scope.showForm = false; $scope.packs = Packs.getPacksList(function(list) { $scope._extendPackListing(list); }); }); } else { Packs[action](pack || $scope.pack, function() { if (!$scope.isNew) $scope.showForm = false; $scope.packs = Packs.getPacksList(function(list) { $scope._extendPackListing(list); }); }); } } if (action === 'delete') { BootstrapDialog.confirm($L.get("The pack '{0}' will be deleted, are you sure ?", pack.code), function(answer) { if (answer) { _execute(); } }); } else { if (action === 'cancel') { BootstrapDialog.show({ title: $L.get("Pack cancellation"), type: BootstrapDialog.TYPE_DANGER, message: function(dialog) { var $content = $('
'); var $message = $(''); $message.append($('').text($L.get("The pack '{0}' and all its licenses will be cancelled, this action cannot be undone", pack.code))); $content.append($message); var $message = $(''); var pageToLoad = dialog.getData('pageToLoad'); $message.append($('').text($L.get("Cancellation reason:") + " ")); $message.append($('')); $content.append($message); return $content; }, closable: true, buttons: [{ id: 'btn-cancel', label: $L.get('Close'), cssClass: 'btn-default', action: function(dialogRef) { dialogRef.close(); } }, { id: 'btn-ok', label: $L.get('Cancel pack'), cssClass: 'btn-primary', action: function(dialogRef){ var reason = $('#_pack_cancellation_reason').val(); console.log('Ready to cancel pack, by reason: ' + reason); if (!reason) { $('#_pack_cancellation_reason').focus(); } else { _execute({reason: reason}); dialogRef.close(); } } }] }); } else { _execute(); } } } $scope.newPack = function() { $scope.isNew = true; $scope.showForm = true; $scope.pack = { license_preactivation: true, status: 'CR', num_licenses: 1, init_valid_date: new Date(), preactivation_valid_period: 7, renew_valid_period: 30, license_type_id: null, organization_id: null // !$scope.refs.organization_id // || // !$scope.refs.organization_id.length // ? null : // $scope.refs.organization_id[0].id } setTimeout(function() { $('#code').focus(); }, 0); } $scope.editPack = function(selectedPack) { $scope.isNew = false; $scope.showForm = true; if (!(selectedPack.init_valid_date instanceof Date)) { selectedPack.init_valid_date = new Date(selectedPack.init_valid_date); } if (!(selectedPack.end_valid_date instanceof Date)) { selectedPack.end_valid_date = new Date(selectedPack.end_valid_date); } $scope.pack = selectedPack; // $scope.pack.organization_name = // $scope.getLabelFromId('organization_id', // $scope.pack.organization_id); $scope.pack.license_type_name = $scope.getLabelFromId('license_type_id', $scope.pack.license_type_id); $scope.pack.status_name = Packs.getStatusName($scope.pack.status); setTimeout(function() { $('#code').focus(); }, 0); } $scope.deletePack = function(selectedPack) { $scope.showForm = false; BootstrapDialog.confirm($L.get("The pack '{0}' will be deleted, are you sure?", selectedPack.code), function(result){ if(result) { var promise = packResource.remove({}, {id: selectedPack.id}).$promise; promise.then(function(data) { $scope.selectPack(null); $scope.packs = packResource.query(); toaster.pop('success', Catalogs.getName(), $L.get("Pack '{0}' deleted successfully", selectedPack.code)); },function(error) { console.log(error); toaster.pop('error', Catalogs.getName(), $L.get("Error deleting pack, reason: {0}. Details: {1}", $L.get(HTTP_ERRORS[error.status]), error.headers('X-SECURIS-ERROR-MSG')), 10000); }); } }); $scope.isNew = false; } $scope.cancel = function() { $scope.showForm = false; } $scope.selectPack = function(pack) { if ($scope.$parent.currentPack) { $scope.$parent.currentPack._selected = false; } $scope.$parent.currentPack = pack._selected ? pack : null; $store.put('currentPack', $scope.$parent.currentPack); $scope.$parent.$broadcast('pack_changed', $scope.$parent.currentPack); } $scope.getLabelFromId = function(field, myid) { var label = null; $scope.refs[field].forEach(function (elem) { if (elem.id === myid) { label = elem.label; } }); return label; } $scope.getOrganizationCode = function(orgId) { return $scope._getCodeFromId('organization_id', orgId); } $scope.getLicenseTypeCode = function(ltId) { return $scope._getCodeFromId('license_type_id', ltId); } $scope._getCodeFromId = function(field, myid) { if (!myid) { return null; } var list = $scope.refs[field]; for(var i = 0; list && i < list.length; i++) { var elem = list[i]; if (elem.id === myid) { return elem.code; } } return null; } $scope.createMetadataRow = function() { if (!$scope.formu.metadata) { $scope.formu.metadata = []; } $scope.formu.metadata.push({key: '', value: '', mandatory: true}); } $scope.removeMetadataKey = function(row_md) { $scope.formu.metadata.splice( $scope.formu.metadata.indexOf(row_md), 1 ); } $scope.updateMetadata = function() { // Called when Application ID change // in current field var newLTId = $scope.pack['license_type_id']; if (newLTId) { // Only if there is a "valid" // value selected we should // update the metadata Catalogs.getResource('licensetype').get({licenseTypeId: newLTId}).$promise.then(function(lt) { $scope.pack.metadata = []; lt.metadata.forEach(function(md) { $scope.pack.metadata.push({ key: md.key, value: md.value, readonly: !!md.value, mandatory: md.mandatory }); }); }); } } } ]); app.controller('LicensesCtrl', [ '$scope', '$http', '$resource', 'toaster', 'Licenses', 'Packs', '$store', '$L', function($scope, $http, $resource, toaster, Licenses, Packs, $store, $L) { $scope.Licenses = Licenses; $scope.$on('pack_changed', function(evt, message) { $scope.licenses = Licenses.getLicensesList($scope.currentPack); $scope.creationAvailable = $scope.currentPack.status == 'AC'; if ($scope.showForm) { if ($scope.isNew) { $scope.license.pack_id = $scope.currentPack.id } else { $scope.showForm = false; } } }) $scope.mandatory = { code: true, email: true } $scope.maxlength = { code: 50, request_data: 500, comments: 1024 } $scope.refs = {}; // Used to create the form with the // appropriate data $scope.isNew = undefined; // Selected license from listing // license is the edited license, in // creation contains the data for // the new license $scope.license = null; if ($scope.currentPack) { $scope.licenses = Licenses.getLicensesList($scope.currentPack); } $scope.save = function() { Licenses.saveLicenseData($scope.license, $scope.isNew, function() { if (!$scope.isNew) { $scope.showForm = false; } else { $scope.newLicense(); } $scope.licenses = Licenses.getLicensesList($scope.currentPack); }); } $scope.newLicense = function() { if (!$scope.currentPack) { BootstrapDialog.show({ title: $L.get('New license'), type: BootstrapDialog.TYPE_WARNING, message: $L.get('Please, select a pack before to create a new license'), buttons: [{ label: 'OK', action: function(dialog) { dialog.close(); } }] }); return; } if (!$scope.creationAvailable) { BootstrapDialog.show({ title: $L.get('Pack not active'), type: BootstrapDialog.TYPE_WARNING, message: $L.get('Current pack is not active, so licenses cannot be created'), buttons: [{ label: 'OK', action: function(dialog) { dialog.close(); } }] }); return; } $scope.isNew = true; $scope.showForm = true; $scope.license = { pack_id: $scope.currentPack.id } Packs.nextliccode($scope.currentPack.id, function(data) { console.log('New code: ' + data); $scope.license.code = data; }); setTimeout(function() { $('#licenseForm * #email').focus(); }, 0); } $scope.editLicense = function(selectedlicense) { $scope.isNew = false; $scope.showForm = true; $scope.license = selectedlicense; $scope.license.status_name = Licenses.getStatusName($scope.license.status); setTimeout(function() { $('#licenseForm * #code').focus(); }, 0); } $scope.deletelicense = function(selectedlicense) { $scope.showForm = false; BootstrapDialog.confirm($L.get("The license '{0}' will be deleted, are you sure?", selectedlicense.code), function(result){ if(result) { var promise = licenseResource.remove({}, {id: selectedlicense.id}).$promise; promise.then(function(data) { $scope.selectlicense(null); $scope.licenses = Licenses.getLicensesList($scope.currentPack); toaster.pop('success', Catalogs.getName(), $L.get("License '{0}' deleted successfully", selectedlicense.code)); },function(error) { console.log(error); toaster.pop('error', Catalogs.getName(), $L.get("Error deleting license, reason: {0}. Details: {1}", $L.get(HTTP_ERRORS[error.status]), error.headers('X-SECURIS-ERROR-MSG')), 10000); }); } }); $scope.isNew = false; } $scope.execute = function(action, license) { if (!license) { license = $scope.license; } var _execute = function(extra_data) { if (extra_data) { Licenses[action](license, extra_data, function() { if (!$scope.isNew) $scope.showForm = false; $scope.licenses = Licenses.getLicensesList($scope.currentPack); }); } else { Licenses[action](license, function() { if (!$scope.isNew) $scope.showForm = false; $scope.licenses = Licenses.getLicensesList($scope.currentPack); }); } } if (action === 'delete') { BootstrapDialog.confirm($L.get("The license '{0}' will be deleted, are you sure?", license.code), function(result){ if(result) { _execute(); } }); } else { if (action === 'cancel') { BootstrapDialog.show({ title: $L.get("License cancellation"), type: BootstrapDialog.TYPE_DANGER, message: function(dialog) { var $content = $(''); var $message = $(''); var pageToLoad = dialog.getData('pageToLoad'); $message.append($('').text($L.get("This action cannot be undone.", license.code))); $content.append($message); var $message = $(''); $message.append($('').text($L.get("Cancellation reason:") + " ")); $message.append($('')); $content.append($message); return $content; }, closable: true, buttons: [{ id: 'btn-cancel', label: $L.get('Close'), cssClass: 'btn-default', action: function(dialogRef) { dialogRef.close(); } }, { id: 'btn-ok', label: $L.get('Cancel license'), cssClass: 'btn-primary', action: function(dialogRef){ var reason = $('#_lic_cancellation_reason').val(); console.log('Ready to cancel license, by reason: ' + reason); if (!reason) { $('#_lic_cancellation_reason').focus(); } else { _execute({reason: reason}); dialogRef.close(); } } }] }); } else { _execute(); } } } $scope.cancel = function() { $scope.showForm = false; } } ]); })();