Roberto Sánchez
2014-02-05 8e6db5714c3884cc74c3230abf7b20589ccd1552
securis/src/main/resources/static/js/licenses.js
....@@ -1,5 +1,22 @@
11 (function() {
22 'use strict';
3
+
4
+ var LIC_STATUS = {
5
+ CREATED: 1,
6
+ REQUESTED: 2,
7
+ PREACTIVE: 3,
8
+ ACTIVE: 4,
9
+ CANCELED: 5
10
+ }
11
+
12
+ var ACTIONS_BY_STATUS = {
13
+ activate: [LIC_STATUS.REQUESTED, LIC_STATUS.PREACTIVE],
14
+ send: [LIC_STATUS.ACTIVE, LIC_STATUS.PREACTIVE],
15
+ download: [LIC_STATUS.ACTIVE, LIC_STATUS.PREACTIVE],
16
+ request: [LIC_STATUS.CREATED, LIC_STATUS.REQUESTED],
17
+ cancel: [LIC_STATUS.REQUESTED, LIC_STATUS.PREACTIVE, LIC_STATUS.ACTIVE],
18
+ 'delete': [LIC_STATUS.CREATED, LIC_STATUS.CANCELED],
19
+ }
320
421 var HTTP_ERRORS = {
522 401: "Unathorized action",
....@@ -19,26 +36,29 @@
1936 console.log('scope.license: ' + scope.$parent.license);
2037 var setter = $parse(attrs.fileLoader).assign;
2138 element.bind('change', function(evt) {
22
- console.log('scope.license: ' + scope.$parent.license);
39
+ if (!window.FileReader) { // Browser is not compatible
40
+ BootstrapDialog.alert($L.get("Open your .req file with a text editor and copy&paste the content in the form text field?"));
41
+ return;
42
+ }
43
+ //console.log('scope.license: ' + scope.$parent.license);
2344 var field = $parse(attrs.fileLoader);
24
- console.log('field: ' + field);
45
+ //console.log('field: ' + field);
2546 var fileList = evt.target.files;
2647 if (fileList != null && fileList[0]) {
2748 var reader = new FileReader();
2849 reader.onerror = function(data) {
2950 setter(scope.$parent, 'ERROR');
30
- scope.$apply();
51
+ //scope.$apply();
3152 }
3253 reader.onload = function(data) {
3354 setter(scope.$parent, reader.result);
34
- scope.$apply();
55
+ //scope.$apply();
3556 }
3657
3758 reader.readAsText(fileList[0]);
3859 } else {
39
- console.log('NO FILE: ');
40
- field = '';
41
- scope.$apply();
60
+ setter(scope.$parent, '');
61
+ //scope.$apply();
4262 }
4363 });
4464
....@@ -46,7 +66,6 @@
4666 };
4767 });
4868
49
- console.log(' OK ????? ');
5069
5170 app.controller('PackAndLicensesCtrl', [
5271 '$scope',
....@@ -312,11 +331,12 @@
312331 $scope.showStatus = function(lic) {
313332
314333 }
315
- $scope.showStatusComplete = function(license) {
334
+ $scope.showStatusLong = function(license) {
316335
317336 }
318
- $scope.isActionVisible = function(actionMask, lic) {
319
-
337
+ $scope.isActionVisible = function(action, lic) {
338
+ var validStatuses = ACTIONS_BY_STATUS[action];
339
+ return lic && validStatuses.indexOf(lic.status) !== -1;
320340 }
321341
322342 } ]);