From e2aa9b0177cdfeb9e3f26c511f541c37a03134aa Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Thu, 30 Oct 2014 11:52:50 +0000
Subject: [PATCH] #2021 feature - Added menu color based on element status in packs and licenses listings

---
 securis/src/main/resources/static/licenses.html  |   58 +++++--
 securis/src/main/resources/static/js/licenses.js |  285 +++++++++++++++++++++++++----------
 securis/src/main/resources/static/js/admin.js    |    4 
 securis/src/main/resources/static/js/main.js     |  123 +++++++-------
 4 files changed, 307 insertions(+), 163 deletions(-)

diff --git a/securis/src/main/resources/static/js/admin.js b/securis/src/main/resources/static/js/admin.js
index 566f992..3d320fa 100644
--- a/securis/src/main/resources/static/js/admin.js
+++ b/securis/src/main/resources/static/js/admin.js
@@ -105,7 +105,7 @@
 								toaster.pop('success', Catalogs.getName(), $L.get("Element deleted successfully"));
 							},function(error) {
 								console.log(error);
-								toaster.pop('error', Catalogs.getName(), $L.get("Error deleting element, reason: {0}. Details: {1}", $L.get(HTTP_ERRORS[error.status]), error.headers('X-SECURIS-ERROR')), 10000);
+								toaster.pop('error', Catalogs.getName(), $L.get("Error deleting element, reason: {0}. Details: {1}", $L.get(HTTP_ERRORS[error.status]), error.headers('X-SECURIS-ERROR-MSG')), 10000);
 							});
 			            }
 			        });
@@ -180,7 +180,7 @@
 							toaster.pop('success', Catalogs.getName(), $L.get("Element saved successfully"));
 						}, function(error) {
 							console.log(error);
-							toaster.pop('error', Catalogs.getName(), $L.get("Error saving element, reason: {0}. Details: {1}", $L.get(HTTP_ERRORS[error.status]), error.headers('X-SECURIS-ERROR')), 10000);
+							toaster.pop('error', Catalogs.getName(), $L.get("Error saving element, reason: {0}. Details: {1}", $L.get(HTTP_ERRORS[error.status]), error.headers('X-SECURIS-ERROR-MSG')), 10000);
 						});
 					}
 				}
diff --git a/securis/src/main/resources/static/js/licenses.js b/securis/src/main/resources/static/js/licenses.js
index 2e250fa..71b5014 100644
--- a/securis/src/main/resources/static/js/licenses.js
+++ b/securis/src/main/resources/static/js/licenses.js
@@ -28,7 +28,8 @@
 	            '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
+		 * 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],
@@ -57,6 +58,21 @@
                     }
                 }
 			);
+		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();
@@ -64,7 +80,7 @@
 			}
 			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'))));
+				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);
 		} 
@@ -73,10 +89,6 @@
             var validStatuses = PACK_ACTIONS_BY_STATUS[action];
             return pack && validStatuses && validStatuses.indexOf(pack.status) !== -1;
 		}
-		this.getStatusName = function(status) {
-			return PACK_STATUSES[status];
-		}
-		
 		var _createSuccessCallback = function(actionName, message, _innerCallback) {
 			return function() {
 				_innerCallback && _innerCallback();
@@ -87,10 +99,10 @@
 			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'))));
+				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(pack, _onsuccess, _onerror) {
+		this.getPacksList = function(_onsuccess, _onerror) {
 			return packResource.query(_onsuccess, _onerror);
 		}
 		this.activate = function(pack, _onsuccess, _onerror) {
@@ -141,24 +153,81 @@
 	            };
 
 		/**
-		 * These transitions could be get from server, class License.Status, but we copy them for simplicity, this info won't change easily
+		 * 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 = {
 	            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.CANCELLED],
 	            cancel: [LIC_STATUS.REQUESTED, LIC_STATUS.EXPIRED, LIC_STATUS.PREACTIVE, LIC_STATUS.ACTIVE],
 	            'delete': [LIC_STATUS.CREATED, LIC_STATUS.CANCELLED]
 	    }
+		
+        var licenseResource = $resource('/license/:licenseId/:action', {
+            licenseId : '@id',
+			action : '@action'
+		},
+		{
+            activate: {
+                method: "POST",
+                params: {action: "activate"}
+            },
+            cancel: {
+                method: "POST",
+                params: {action: "cancel"}
+            },
+            download: {
+                method: "GET",
+                params: {action: "download"}
+            },
+            block: {
+                method: "POST",
+                params: {action: "block"}
+            },
+            send: {
+                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',
+		            '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'))));
+			}
+			licenseResource.save(license, _success, _error);
+		} 
 
 		var _createSuccessCallback = function(actionName, message, _innerCallback) {
 			return function() {
@@ -166,15 +235,16 @@
 				toaster.pop('success', actionName, message);
 			}
 		}
-		var _createErrorCallback = function(pack, actionName, _innerCallback) {
+		var _createErrorCallback = function(license, 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'))));
+				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.getPacksList = function(pack, _onsuccess, _onerror) {
-			return packResource.query(_onsuccess, _onerror);
+		
+		this.getLicensesList = function(pack, _onsuccess, _onerror) {
+			return licenseResource.query({packId: pack.id}, _onsuccess, _onerror);
 		}
 		this.activate = function(license, _onsuccess, _onerror) {
 			console.log('Activation on license: ' + license.id);
@@ -218,14 +288,16 @@
                             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
+	                            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);
+	                            // 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();
@@ -314,7 +386,8 @@
 				$scope.isNew = undefined;
 
 				// Selected pack from listing
-				// pack is the edited pack, in creation contains the data for the new pack
+				// pack is the edited pack, in creation contains the data for
+				// the new pack
 				$scope.pack = null;
 
 				$scope.packs = Packs.getPacksList();
@@ -331,7 +404,8 @@
 				}
 
 				/**
-				 * Execute an action over the pack, activation, onhold, cancellation
+				 * Execute an action over the pack, activation, onhold,
+				 * cancellation
 				 */
 				$scope.execute = function(action, pack) {
 					var _execute = function(extra_data) {
@@ -348,7 +422,7 @@
 						}
 					}
 					if (action === 'delete') {
-						BootstrapDialog.confirm($L.get("The pack '{0}' will be deleted, are you sure ?", $scope.pack.code), function(answer) {
+						BootstrapDialog.confirm($L.get("The pack '{0}' will be deleted, are you sure ?", pack.code), function(answer) {
 	                        if (answer) {
 	                        	_execute();
 	                        }
@@ -361,14 +435,13 @@
 								message: function(dialog) {
 									var $content = $('<div></div>');
 									var $message = $('<div></div>');
-					                var pageToLoad = dialog.getData('pageToLoad');
-					                $message.append($('<label/>').text($L.get("The pack '{0}' and all its licenses will be cancelled, this action cannot be undone", $scope.pack.code)));
+					                $message.append($('<label/>').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 = $('<div style="margin-top:10pt;"/>');
 					                var pageToLoad = dialog.getData('pageToLoad');
 					                $message.append($('<label style="margin-right:5pt;"/>').text($L.get("Cancellation reason:") + " "));
-					                $message.append($('<input type="text" style="width:100%;" maxlength="512" id="_cancellation_reason"/>'));
+					                $message.append($('<input type="text" style="width:100%;" maxlength="512" id="_pack_cancellation_reason"/>'));
 					                $content.append($message);
 					            	return $content;								 
 								},
@@ -385,10 +458,10 @@
 							        label: $L.get('Cancel pack'),
 							        cssClass: 'btn-primary', 
 							        action: function(dialogRef){
-							        	var reason = $('#_cancellation_reason').val();
+							        	var reason = $('#_pack_cancellation_reason').val();
 							        	console.log('Ready to cancel pack, by reason: ' + reason);
 							            if (!reason) {
-							            	$('#_cancellation_reason').focus();
+							            	$('#_pack_cancellation_reason').focus();
 							            } else {
 							            	_execute({reason: reason});
 								            dialogRef.close();
@@ -413,7 +486,11 @@
                             init_valid_date: new Date(),
                             default_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
+                            organization_id: null  // !$scope.refs.organization_id
+													// ||
+													// !$scope.refs.organization_id.length
+													// ? null :
+													// $scope.refs.organization_id[0].id
 					}
                    setTimeout(function() {
                         $('#code').focus();
@@ -432,7 +509,9 @@
                     
                     $scope.pack = selectedPack;
 
-                    //$scope.pack.organization_name = $scope.getLabelFromId('organization_id', $scope.pack.organization_id); 
+                    // $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); 
                     
@@ -452,7 +531,7 @@
                                 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')), 10000);
+                                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);
                             });
                         }
                     });
@@ -493,7 +572,8 @@
 					// 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
+						// 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) {
@@ -520,7 +600,7 @@
 	                                   function($scope, $http, $resource, toaster, Licenses, $store, $L) {
 	                                	   $scope.Licenses = Licenses;
 	                                       $scope.$on('pack_changed', function(evt, message) {
-                                               $scope.licenses = licenseResource.query({packId: $scope.currentPack.id});
+                                               $scope.licenses = Licenses.getLicensesList($scope.currentPack);
                                                $scope.creationAvailable = $scope.currentPack.status == 'AC';
 	                                           if ($scope.showForm) {
 	                                               if ($scope.isNew) {
@@ -531,28 +611,6 @@
 	                                           }
 	                                       })
 	                                           
-	                                       var licenseResource = $resource('/license/:licenseId', {
-	                                           licenseId : '@id'
-	                                       }, {
-	                                           save_w_upload: {
-	                                               method: "POST",
-	                                               transformRequest: function(data, headersGetter) {
-	                                                   // To use an object without FormData, follow: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest?redirectlocale=en-US&redirectslug=DOM%2FXMLHttpRequest%2FUsing_XMLHttpRequest#Submitting_forms_and_uploading_files
-	                                                   var formData = new FormData();
-	                                                   angular.forEach(data, function(value, key) {
-	                                                       if (key !== 'request_data')
-	                                                           formData.append(key, value)
-                                                           else
-                                                               formData.append(key, $('input#request_data_file').get(0).files[0]);
-	                                                   })
-	                                                   
-	                                                   return formData;
-	                                               },
-	                                               headers: {
-	                                                   'Content-Type': undefined
-	                                               }
-	                                           }
-	                                       });
 	                                       $scope.mandatory = {
 	                                               code: true,
 	                                               email: true
@@ -564,41 +622,29 @@
 	                                       }
 	                                       $scope.refs = {};
 
-	                                       // Used to create the form with the appropriate data
+	                                       // 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
+	                                       // license is the edited license, in
+											// creation contains the data for
+											// the new license
 	                                       $scope.license = null;
-	                                       if ($scope.currentPack)
-	                                           $scope.licenses = licenseResource.query({packId: $scope.currentPack.id});
-	                                       
-//	                                       $(document).on('change', '#request_data_file', function(newValue, oldValue) {
-//	                                          console.log('File changed!!!!'); 
-//	                                           var reader = new FileReader();
-//	                                           reader.onload = function(data) {
-//                                                   console.log('LOAD complete: ' + data);
-//                                                   console.log('LOAD reader.result: ' + reader.result);
-//                                                   $('input#request_data').val(reader.result)
-//	                                           }
-//                                               console.log('file: ' + $('input#request_data_file').get(0).files[0]);
-//                                               console.log('file2: ' + $scope.request_data_file);
-//	                                           reader.readAsText($('input#request_data_file').get(0).files[0]);	                                            
-//	                                       });
-	                                       
-	                                       $scope.save = function() {
-	                                           //$( "form#licenseForm" ).attr( "enctype", "multipart/form-data" ).attr( "encoding", "multipart/form-data" );
-	                                           var _success = function() {
-	                                               if (!$scope.isNew) $scope.showForm = false;
-	                                               $scope.licenses = licenseResource.query({packId: $scope.currentPack.id});
-		                       						toaster.pop('success', Catalogs.getName(), $L.get("License '{0}' {1} successfully", $scope.license.code, $scope.isNew ? $L.get("created") : $L.get("updated")));
-		                       					}
-		                       					var _error =  function(error) {
-		                                            console.log(error);
-		                       						toaster.pop('error', Catalogs.getName(), $L.get("Error {0} license '{1}'. Reason: {2}", $scope.isNew ? $L.get("creating") : $L.get("updating"), $scope.pack.code, $L.get(error.headers('X-SECURIS-ERROR'))));
-		                       					}
-	                                           licenseResource.save($scope.license, _success, _error)
+	                                       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) {
@@ -658,17 +704,88 @@
 	                                                   var promise = licenseResource.remove({}, {id: selectedlicense.id}).$promise;
 	                                                   promise.then(function(data) {
 	                                                       $scope.selectlicense(null);
-	                                                       $scope.licenses = licenseResource.query({packId: $scope.currentPack.id});
+	                                                       $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')), 10000);
+	                                                       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 = $('<div></div>');
+	                       									var $message = $('<div></div>');
+	                       					                var pageToLoad = dialog.getData('pageToLoad');
+	                       					                $message.append($('<label/>').text($L.get("This action cannot be undone.", $scope.pack.code)));
+	                       					                $content.append($message);
+
+	                       									var $message = $('<div style="margin-top:10pt;"/>');
+	                       					                $message.append($('<label style="margin-right:5pt;"/>').text($L.get("Cancellation reason:") + " "));
+	                       					                $message.append($('<input type="text" style="width:100%;" maxlength="512" id="_lic_cancellation_reason"/>'));
+	                       					                $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;
diff --git a/securis/src/main/resources/static/js/main.js b/securis/src/main/resources/static/js/main.js
index 1c7c442..ff529be 100644
--- a/securis/src/main/resources/static/js/main.js
+++ b/securis/src/main/resources/static/js/main.js
@@ -1,6 +1,6 @@
 (function() {
 	'use strict';
-	
+
 	var m = angular.module('securis', [ 'ngRoute', 'ngResource', 'toaster', 'localytics.directives', 'catalogs', 'i18n' ]);
 
 	m.service('$store', function() {
@@ -20,75 +20,76 @@
 			return store.getAll();
 		}
 	});
-	
+
 	m.factory('securisHttpInterceptor', function($q, $location, $store, toaster) {
 		var isUnauthorizedAccess = function(rejection) {
 			return rejection.status === 401 /* Unauthorized */;
 		} 
-		  return {
-		      'request': function(config) {
-                  var token = $store.get('token');
-                  if (token) {
-                      var la = $store.get('last_access');
-    		          var now = new Date().getTime();
-    		          if (la !== null) {
-    		              if (now > (la + 1800000)) { // Session timeout is 1/2 hour
-                              $store.clear();
-                              $location.path('/login');
-                              toaster.pop('warning', 'Session has expired', null, 4000);
-    		              } else {
-    		                  console.debug('Last access recent');
-    		              }
-    		          }
-    		          $store.set('last_access', now);
-                  }
-		          return config || $q.when(config);
-		      },
-		   'responseError': function(rejection) {
-		      // do something on error
-		      if (isUnauthorizedAccess(rejection)) {
-		        if ($location.path() !== '/login') {
-		        	$store.clear();
-		        	$location.path('/login');
-		        	console.error('There was an unathorized access to url {0}, method: {1}'.$i18n(rejection.config.url, rejection.config.method));
-		        } else {
-		        	// console.log('Error on login ...')
-		        }
-		      }
-		      return $q.reject(rejection);
-		    }
-		  };
-		});
+		return {
+			'request': function(config) {
+				var token = $store.get('token');
+				if (token) {
+					var la = $store.get('last_access');
+					var now = new Date().getTime();
+					if (la !== null) {
+						if (now > (la + 1800000)) { // Session timeout is 1/2
+													// hour
+							$store.clear();
+							$location.path('/login');
+							toaster.pop('warning', 'Session has expired', null, 4000);
+						} else {
+							console.debug('Last access recent');
+						}
+					}
+					$store.set('last_access', now);
+				}
+				return config || $q.when(config);
+			},
+			'responseError': function(rejection) {
+				// do something on error
+				if (isUnauthorizedAccess(rejection)) {
+					if ($location.path() !== '/login') {
+						$store.clear();
+						$location.path('/login');
+						console.error('There was an unathorized access to url {0}, method: {1}'.$i18n(rejection.config.url, rejection.config.method));
+					} else {
+						// console.log('Error on login ...')
+					}
+				}
+				return $q.reject(rejection);
+			}
+		};
+	});
 
 	m.config(function($routeProvider, $locationProvider, $httpProvider) {
 		console.debug('Configuring routes...');
-		    $routeProvider.when('/login', {
-		      templateUrl: 'login.html',
-		      controller: 'LoginCtrl'
-		    });
-		    $routeProvider.when('/licenses', {
-			      templateUrl: 'licenses.html',
-			      controller: 'PackAndLicensesCtrl'
-		    });
-		    $routeProvider.when('/admin', {
-			      templateUrl: 'admin.html',
-			      controller: 'AdminCtrl'
-		    });
-		 
-		    // configure html5 to get links working on jsfiddle
-		    $locationProvider.html5Mode(true);
-		    $httpProvider.interceptors.push('securisHttpInterceptor');
+		$routeProvider.when('/login', {
+			templateUrl: 'login.html',
+			controller: 'LoginCtrl'
 		});
-	
+		$routeProvider.when('/licenses', {
+			templateUrl: 'licenses.html',
+			controller: 'PackAndLicensesCtrl'
+		});
+		$routeProvider.when('/admin', {
+			templateUrl: 'admin.html',
+			controller: 'AdminCtrl'
+		});
+
+		// configure html5 to get links working on jsfiddle
+		$locationProvider.html5Mode(true);
+		$httpProvider.interceptors.push('securisHttpInterceptor');
+	});
+
 	m.controller('MainCtrl', ['$scope', '$http', '$location', '$L', '$store',
-	                             function($scope, $http, $location, $L, $store) {
-		
+	                          function($scope, $http, $location, $L, $store) {
+
 		$scope.currentRoute = null;
 		console.log('Current location: ' + $location);
 		console.log($location);
 		$location.path('/login');
 		if ($store.get('token') != null) {
-			
+
 			$http.get('/check', {
 				headers: {
 					'X-SECURIS-TOKEN': $store.get('token')
@@ -98,18 +99,18 @@
 					$http.defaults.headers.common['X-SECURIS-TOKEN'] = $store.get('token');
 					var location = $store.get('location') || '/licenses';
 
-				    $location.path(location);
+					$location.path(location);
 					$store.set('user', data.user);
 				}
 			});
 		}
-		
+
 		$scope.logout = function() {
 			$store.remove('user');
 			$store.remove('token');
 			$location.path('/login');
 		}
-		
-		}]);	
-	
+
+	}]);	
+
 })();
\ No newline at end of file
diff --git a/securis/src/main/resources/static/licenses.html b/securis/src/main/resources/static/licenses.html
index a51263c..425a85e 100644
--- a/securis/src/main/resources/static/licenses.html
+++ b/securis/src/main/resources/static/licenses.html
@@ -294,8 +294,29 @@
 							title="Total: {{p.num_licenses}}, available: {{p.num_available}}">{{p.num_licenses}}
 							({{p.num_available}})</td>
 						<td>
-							<span ng-click="editPack(p)" class="glyphicon glyphicon-pencil"></span> 
-							<span ng-if="Packs.isActionAvailable('delete', p)" ng-click="execute('delete', p)" class="glyphicon glyphicon-remove"></span>
+							<div class="dropdown">
+								<a class="dropdown-toggle" data-toggle="dropdown"> <span
+									class="glyphicon glyphicon-align-justify" style="color: {{Packs.getStatusColor(p.status)}}"></span> 
+									<span style="color: {{Packs.getStatusColor(p.status)}}" class="caret"></span>
+								</a>
+								<ul class="dropdown-menu">
+									<li ng-if="Packs.isActionAvailable('edit', p)"><a
+										ng-click="editPack(p)"><span
+											class="glyphicon glyphicon-pencil"></span> <span i18n>Edit</span></a></li>
+									<li ng-if="Packs.isActionAvailable('activate', p)"><a
+										ng-click="execute('activate', p)"><span
+											class="glyphicon glyphicon-check"></span> <span i18n>Activate</span></a></li>
+									<li ng-if="Packs.isActionAvailable('putonhold', p)"><a
+										ng-click="execute('putonhold', p)"><span
+											class="glyphicon glyphicon-pause"></span> <span i18n>Put on hold</span></a></li>
+									<li ng-if="Packs.isActionAvailable('cancel', p)"><a
+										ng-click="execute('cancel', p)"><span
+											class="glyphicon glyphicon-ban-circle"></span> <span i18n>Cancel</span></a></li>
+									<li ng-if="Packs.isActionAvailable('delete', p)"><a
+										ng-click="execute('delete', p)"><span
+											class="glyphicon glyphicon-trash"></span> <span i18n>Delete</span></a></li>
+								</ul>
+							</div>
 						</td>
 					</tr>
 				</tbody>
@@ -566,11 +587,11 @@
 							<span class="caret"></span>
 						</button>
 						<ul class="dropdown-menu" role="menu">
-						    <li ng-if="Licenses.isActionAvailable('activate', license)"><a ng-click="activateLicense(license)" href="#">Activate</a></li>
-						    <li ng-if="Licenses.isActionAvailable('download', license)"><a ng-click="downloadLicense(license)" href="#">Download</a></li>
-						    <li ng-if="Licenses.isActionAvailable('send', license)"><a ng-click="sendLicense(license)" href="#">Send by email</a></li>
-						    <li ng-if="Licenses.isActionAvailable('cancel', license)"><a ng-click="cancelLicense(license)" href="#">Invalidate</a></li>
-						    <li ng-if="Licenses.isActionAvailable('delete', license)"><a ng-click="removeLicense(license)" href="#">Delete</a></li>
+						    <li ng-if="Licenses.isActionAvailable('activate', license)"><a ng-click="execute('activate', license)" href="#">Activate</a></li>
+						    <li ng-if="Licenses.isActionAvailable('download', license)"><a ng-click="execute('download', license)" href="#">Download</a></li>
+						    <li ng-if="Licenses.isActionAvailable('send', license)"><a ng-click="execute('send', license)" href="#">Send by email</a></li>
+						    <li ng-if="Licenses.isActionAvailable('cancel', license)"><a ng-click="execute('cancel', license)" href="#">Cancel</a></li>
+						    <li ng-if="Licenses.isActionAvailable('delete', license)"><a ng-click="execute('delete', license)" href="#">Delete</a></li>
 						  </ul>
 						
 					</div>
@@ -608,28 +629,33 @@
 						<td>
 							<div class="dropdown">
 								<a class="dropdown-toggle" data-toggle="dropdown"> <span
-									class="glyphicon glyphicon-align-justify"></span> <span
-									class="caret"></span>
+									class="glyphicon glyphicon-align-justify" style="color: {{Licenses.getStatusColor(lic.status)}}"></span> 
+									<span style="color: {{Licenses.getStatusColor(lic.status)}}" class="caret"></span>
 								</a>
 								<ul class="dropdown-menu">
 									<li ng-if="Licenses.isActionAvailable('download', lic)"><a
-										ng-click="downloadLicense(lic)"><span
+										ng-click="execute('download', lic)"><span
 											class="glyphicon glyphicon-download"></span> <span i18n>Download</span></a></li>
 									<li ng-if="Licenses.isActionAvailable('edit', lic)"><a
 										ng-click="editLicense(lic)"><span
 											class="glyphicon glyphicon-pencil"></span> <span i18n>Edit</span></a></li>
 									<li ng-if="Licenses.isActionAvailable('activate', lic)"><a
-										ng-click="activateLicense(lic)"><span
+										ng-click="execute('activate', lic)"><span
 											class="glyphicon glyphicon-check"></span> <span i18n>Activate</span></a></li>
 									<li ng-if="Licenses.isActionAvailable('send', lic)"><a
-										ng-click="sendEmail(lic)"><span
-											class="glyphicon glyphicon-send"></span> <span i18n>Send
-												email</span></a></li>
+										ng-click="execute('send', lic)"><span
+											class="glyphicon glyphicon-send"></span> <span i18n>Send email</span></a></li>
+									<li ng-if="Licenses.isActionAvailable('block', lic)"><a
+										ng-click="execute('block', lic)"><span
+											class="glyphicon glyphicon-exclamation-sign"></span> <span i18n>Block</span></a></li>
+									<li ng-if="Licenses.isActionAvailable('unblock', lic)"><a
+										ng-click="execute('unblock', lic)"><span
+											class="glyphicon glyphicon-ok-sign"></span> <span i18n>Unblock</span></a></li>
 									<li ng-if="Licenses.isActionAvailable('cancel', lic)"><a
-										ng-click="deleteLicense(lic)"><span
+										ng-click="execute('cancel', lic)"><span
 											class="glyphicon glyphicon-ban-circle"></span> <span i18n>Cancel</span></a></li>
 									<li ng-if="Licenses.isActionAvailable('delete', lic)"><a
-										ng-click="deleteLicense(lic)"><span
+										ng-click="execute('delete', lic)"><span
 											class="glyphicon glyphicon-trash"></span> <span i18n>Delete</span></a></li>
 								</ul>
 							</div>

--
Gitblit v1.3.2