From 8e6db5714c3884cc74c3230abf7b20589ccd1552 Mon Sep 17 00:00:00 2001
From: Roberto Sánchez <roberto.sanchez@curisit.net>
Date: Wed, 05 Feb 2014 09:51:58 +0000
Subject: [PATCH] #0 feature - Upgrade to Bootstrap 3.1 and jQuery 1.11.0

---
 securis/src/main/resources/static/js/licenses.js |   42 +++++++++++++++++++++++++++++++-----------
 1 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/securis/src/main/resources/static/js/licenses.js b/securis/src/main/resources/static/js/licenses.js
index 1fe1bdb..0955db4 100644
--- a/securis/src/main/resources/static/js/licenses.js
+++ b/securis/src/main/resources/static/js/licenses.js
@@ -1,5 +1,22 @@
 (function() {
 	'use strict';
+	
+	var LIC_STATUS = {
+	        CREATED: 1,
+            REQUESTED: 2,
+            PREACTIVE: 3,
+            ACTIVE: 4,
+            CANCELED: 5
+	}
+	
+	var ACTIONS_BY_STATUS = {
+            activate: [LIC_STATUS.REQUESTED, LIC_STATUS.PREACTIVE],
+            send: [LIC_STATUS.ACTIVE, LIC_STATUS.PREACTIVE],
+            download: [LIC_STATUS.ACTIVE, LIC_STATUS.PREACTIVE],
+            request: [LIC_STATUS.CREATED, LIC_STATUS.REQUESTED],
+            cancel: [LIC_STATUS.REQUESTED, LIC_STATUS.PREACTIVE, LIC_STATUS.ACTIVE],
+            'delete': [LIC_STATUS.CREATED, LIC_STATUS.CANCELED],
+    }
 
 	   var HTTP_ERRORS = {
 	            401: "Unathorized action",
@@ -19,26 +36,29 @@
                             console.log('scope.license: ' + scope.$parent.license);
                             var setter = $parse(attrs.fileLoader).assign;
 	                        element.bind('change', function(evt) {
-	                            console.log('scope.license: ' + scope.$parent.license);
+	                            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('scope.license: ' + scope.$parent.license);
 	                            var field = $parse(attrs.fileLoader);
-	                            console.log('field: ' + field);
+	                            //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();
+                                        //scope.$apply();
                                     }
                                     reader.onload = function(data) {
                                         setter(scope.$parent, reader.result);
-                                        scope.$apply();
+                                        //scope.$apply();
                                     }
                                     
                                     reader.readAsText(fileList[0]);       
 	                            } else {
-                                    console.log('NO FILE: ');
-                                    field = '';
-                                    scope.$apply();
+	                                setter(scope.$parent, '');
+                                    //scope.$apply();
 	                            }
 	                        });
 	                        
@@ -46,7 +66,6 @@
 	                };
 	            });
 
-	console.log(' OK ????? ');
 
 	app.controller('PackAndLicensesCtrl', [
 	                    			'$scope',
@@ -312,11 +331,12 @@
                                            $scope.showStatus = function(lic) {
                                                
                                            }
-                                           $scope.showStatusComplete = function(license) {
+                                           $scope.showStatusLong = function(license) {
                                                
                                            }
-                                           $scope.isActionVisible = function(actionMask, lic) {
-                                               
+                                           $scope.isActionVisible = function(action, lic) {
+                                               var validStatuses = ACTIONS_BY_STATUS[action];
+                                               return lic && validStatuses.indexOf(lic.status) !== -1;
                                            }
 	                                       
 	                                   } ]);

--
Gitblit v1.3.2