rsanchez
2014-10-23 c4d513ca26fe80946a5d90264de5d8e13e4ea974
securis/src/main/resources/static/js/licenses.js
....@@ -101,11 +101,20 @@
101101 '$store',
102102 '$L',
103103 function($scope, $http, $resource, toaster, Catalogs, $store, $L) {
104
- var packResource = $resource('/pack/:packId', {
105
- packId : '@id'
106
- });
104
+ var packResource = $resource('/pack/:packId/:action',
105
+ {
106
+ packId : '@id',
107
+ action : '@action'
108
+ },
109
+ {
110
+ activate: {
111
+ method: "POST",
112
+ params: {action: "activate"}
113
+ }
114
+ }
115
+ );
107116 var PACK_STATUS = [
108
- {id: 'PE', label: $L.get('Pending')},
117
+ {id: 'CR', label: $L.get('Created')},
109118 {id: 'AC', label: $L.get('Active')},
110119 {id: 'OH', label: $L.get('On Hold')},
111120 {id: 'EX', label: $L.get('Expired')},
....@@ -165,13 +174,31 @@
165174 _savePackData();
166175 }
167176 }
177
+
178
+ /**
179
+ * Execute an action over the pack, activation, onhold, cancellation
180
+ */
181
+ $scope.execute = function(action) {
182
+ console.log('Action: '+ action +' on pack: ' + $scope.pack.id);
183
+ var _success = function() {
184
+ if (!$scope.isNew) $scope.showForm = false;
185
+ $scope.packs = packResource.query();
186
+ toaster.pop('success', Catalogs.getName(), $L.get("Pack '{0}' {1} successfully", $scope.pack.code, $L.get("activated")));
187
+ }
188
+ var _error = function(error) {
189
+ console.log(error);
190
+ toaster.pop('error', Catalogs.getName(), $L.get("Error {0} pack '{1}'. Reason: {2}", $L.get("activating"), $scope.pack.code, $L.get(error.headers('X-SECURIS-ERROR'))));
191
+ }
192
+ packResource.activate({id: $scope.pack.id}, _success, _error);
193
+ }
168194
195
+
169196 $scope.newPack = function() {
170197 $scope.isNew = true;
171198 $scope.showForm = true;
172199 $scope.pack = {
173200 license_preactivation: true,
174
- status: 'PE',
201
+ status: 'CR',
175202 num_licenses: 1,
176203 license_type_id: null,
177204 organization_id: null //!$scope.refs.organization_id || !$scope.refs.organization_id.length ? null : $scope.refs.organization_id[0].id
....@@ -190,7 +217,13 @@
190217 if (!(selectedPack.end_valid_date instanceof Date)) {
191218 selectedPack.end_valid_date = new Date(selectedPack.end_valid_date);
192219 }
220
+
193221 $scope.pack = selectedPack;
222
+
223
+ //$scope.pack.organization_name = $scope.getLabelFromId('organization_id', $scope.pack.organization_id);
224
+ $scope.pack.license_type_name = $scope.getLabelFromId('license_type_id', $scope.pack.license_type_id);
225
+ $scope.pack.status_name = $scope.getLabelFromId('pack_status', $scope.pack.status);
226
+
194227 setTimeout(function() {
195228 $('#code').focus();
196229 }, 0);
....@@ -223,6 +256,16 @@
223256 $scope.$parent.currentPack = pack;
224257 $store.put('currentPack', pack);
225258 $scope.$parent.$broadcast('pack_changed', pack);
259
+ }
260
+
261
+ $scope.getLabelFromId = function(field, myid) {
262
+ var label = null;
263
+ $scope.refs[field].forEach(function (elem) {
264
+ if (elem.id === myid) {
265
+ label = elem.label;
266
+ }
267
+ });
268
+ return label;
226269 }
227270
228271 $scope.createMetadataRow = function() {
....@@ -264,6 +307,7 @@
264307 function($scope, $http, $resource, toaster, $store, $L) {
265308 $scope.$on('pack_changed', function(evt, message) {
266309 $scope.licenses = licenseResource.query({packId: $scope.currentPack.id});
310
+ $scope.creationAvailable = $scope.currentPack.status == 'AC';
267311 if ($scope.showForm) {
268312 if ($scope.isNew) {
269313 $scope.license.pack_id = $scope.currentPack.id
....@@ -296,7 +340,8 @@
296340 }
297341 });
298342 $scope.mandatory = {
299
- code: true
343
+ code: true,
344
+ email: true
300345 }
301346 $scope.maxlength = {
302347 code: 50,
....@@ -356,6 +401,20 @@
356401 });
357402 return;
358403 }
404
+ if (!$scope.creationAvailable) {
405
+ BootstrapDialog.show({
406
+ title: $L.get('Pack not active'),
407
+ type: BootstrapDialog.TYPE_WARNING,
408
+ message: $L.get('Current pack is not active, so licenses cannot be created'),
409
+ buttons: [{
410
+ label: 'OK',
411
+ action: function(dialog) {
412
+ dialog.close();
413
+ }
414
+ }]
415
+ });
416
+ return;
417
+ }
359418
360419 $scope.isNew = true;
361420 $scope.showForm = true;