rsanchez
2014-12-01 85e2a65874fcd41771b30ebfff93f86edd4f32b3
securis/src/main/webapp/js/licenses.js
....@@ -12,7 +12,7 @@
1212 }
1313
1414 var app = angular.module('securis');
15
- app.service('Packs', ['$L','$resource', 'toaster', function($L, $resource, toaster) {
15
+ app.service('Packs', ['$L','$resource', '$http', 'toaster', function($L, $resource, $http, toaster) {
1616 var PACK_STATUS = {
1717 CREATED: 'CR',
1818 ACTIVE: 'AC',
....@@ -117,6 +117,14 @@
117117 var _error = _createErrorCallback(pack, $L.get('Put on hold'), _onerror);
118118 packResource.putonhold({id: pack.id}, _success, _error);
119119 }
120
+ this.nextliccode = function(packId, _onsuccess, _onerror) {
121
+ console.log('Get next code: ' + packId);
122
+ var _error = function(data, status, headers, config) {
123
+ console.log(headers);
124
+ 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'))));
125
+ }
126
+ $http.get("/securis/pack/"+packId+"/next_license_code").success(_onsuccess).error(_error);
127
+ }
120128 this.cancel = function(pack, extra_data, _onsuccess, _onerror) {
121129 console.log('Cancellation on pack: ' + pack.id);
122130 var _success = _createSuccessCallback($L.get('Cancellation'), $L.get("Pack '{0}' {1} successfully", pack.code, $L.get("cancelled")), _onsuccess);
....@@ -133,7 +141,7 @@
133141
134142 }]);
135143
136
- app.service('Licenses', ['$L', '$resource', 'toaster', function($L, $resource, toaster) {
144
+ app.service('Licenses', ['$L', '$resource', 'toaster', 'Packs', function($L, $resource, toaster, Packs) {
137145 var LIC_STATUS = {
138146 CREATED: 'CR',
139147 ACTIVE: 'AC',
....@@ -225,7 +233,14 @@
225233 }
226234 var _error = function(error) {
227235 console.log(error);
228
- 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'))));
236
+ 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);
237
+ if (error.headers('X-SECURIS-ERROR-CODE') === '1301') {
238
+ Packs.nextliccode(license.pack_id, function(data) {
239
+ console.log('New code: ' + data);
240
+ license.code = data;
241
+ toaster.pop('info', 'Licenses', $L.get("New license code, {0}, has been generated, please try again", license.code), 5000);
242
+ });
243
+ }
229244 }
230245 licenseResource.save(license, _success, _error);
231246 }
....@@ -622,9 +637,10 @@
622637 '$resource',
623638 'toaster',
624639 'Licenses',
640
+ 'Packs',
625641 '$store',
626642 '$L',
627
- function($scope, $http, $resource, toaster, Licenses, $store, $L) {
643
+ function($scope, $http, $resource, toaster, Licenses, Packs, $store, $L) {
628644 $scope.Licenses = Licenses;
629645 $scope.$on('pack_changed', function(evt, message) {
630646 $scope.licenses = Licenses.getLicensesList($scope.currentPack);
....@@ -708,8 +724,12 @@
708724 $scope.license = {
709725 pack_id: $scope.currentPack.id
710726 }
727
+ Packs.nextliccode($scope.currentPack.id, function(data) {
728
+ console.log('New code: ' + data);
729
+ $scope.license.code = data;
730
+ });
711731 setTimeout(function() {
712
- $('#licenseForm * #code').focus();
732
+ $('#licenseForm * #email').focus();
713733 }, 0);
714734 }
715735
....@@ -816,13 +836,6 @@
816836
817837 $scope.cancel = function() {
818838 $scope.showForm = false;
819
- }
820
-
821
- $scope.showStatus = function(lic) {
822
-
823
- }
824
- $scope.showStatusLong = function(license) {
825
-
826839 }
827840
828841 } ]);