From fdbc8ca146b8e3aff0425e2faf94c0b4a6e3dd28 Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Tue, 18 Nov 2014 20:07:36 +0000
Subject: [PATCH] #396 fix - Corrected cancel action and added Settings entity

---
 securis/src/main/webapp/js/licenses.js | 1267 ++++++++++++++++++++++++++++----------------------------
 1 files changed, 636 insertions(+), 631 deletions(-)

diff --git a/securis/src/main/webapp/js/licenses.js b/securis/src/main/webapp/js/licenses.js
index 31302e4..5df0f34 100644
--- a/securis/src/main/webapp/js/licenses.js
+++ b/securis/src/main/webapp/js/licenses.js
@@ -1,72 +1,72 @@
 (function() {
 	'use strict';
-	
 
 
-	   var HTTP_ERRORS = {
-	            401: "Unathorized action",
-	            418: "Application error",
-	            403: "Forbidden action",
-	            500: "Server error",
-	            404: "Element not found"
-	    }
+
+	var HTTP_ERRORS = {
+			401: "Unathorized action",
+			418: "Application error",
+			403: "Forbidden action",
+			500: "Server error",
+			404: "Element not found"
+	}
 
 	var app = angular.module('securis');
 	app.service('Packs', ['$L','$resource', 'toaster', function($L, $resource, toaster) {
 		var PACK_STATUS = {
-		        CREATED: 'CR',
-	            ACTIVE: 'AC',
-	            ONHOLD: 'OH',
-	            EXPIRED: 'EX',
-	            CANCELLED: 'CA'
+				CREATED: 'CR',
+				ACTIVE: 'AC',
+				ONHOLD: 'OH',
+				EXPIRED: 'EX',
+				CANCELLED: 'CA'
 		}
 		var PACK_STATUSES = {
 				'CR': $L.get('Created'),
-	            'AC': $L.get('Active'),
-	            'OH': $L.get('On Hold'),
-	            'EX': $L.get('Expired'),
-	            'CA': $L.get('Cancelled')
-	            };
+				'AC': $L.get('Active'),
+				'OH': $L.get('On Hold'),
+				'EX': $L.get('Expired'),
+				'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
 		 */
 		var PACK_ACTIONS_BY_STATUS = {
-	            activate: [PACK_STATUS.CREATED, PACK_STATUS.EXPIRED, PACK_STATUS.ONHOLD],
-	            putonhold: [PACK_STATUS.ACTIVE],
-	            cancel: [PACK_STATUS.EXPIRED, PACK_STATUS.ONHOLD, PACK_STATUS.ACTIVE],
-	            'delete': [PACK_STATUS.CREATED, PACK_STATUS.CANCELLED]
-	    }
-		
+				activate: [PACK_STATUS.CREATED, PACK_STATUS.EXPIRED, PACK_STATUS.ONHOLD],
+				putonhold: [PACK_STATUS.ACTIVE],
+				cancel: [PACK_STATUS.EXPIRED, PACK_STATUS.ONHOLD, PACK_STATUS.ACTIVE],
+				'delete': [PACK_STATUS.CREATED, PACK_STATUS.CANCELLED]
+		}
+
 		var packResource = $resource('pack/:packId/:action', 
 				{
-					packId : '@id',
-					action : '@action'
+			packId : '@id',
+			action : '@action'
 				},
 				{
-                    activate: {
-                        method: "POST",
-                        params: {action: "activate"}
-                    },
-                    putonhold: {
-                        method: "POST",
-                        params: {action: "putonhold"}
-                    },
-                    cancel: {
-                        method: "POST",
-                        params: {action: "cancel"}
-                    }
-                }
-			);
+					activate: {
+						method: "POST",
+						params: {action: "activate"}
+					},
+					putonhold: {
+						method: "POST",
+						params: {action: "putonhold"}
+					},
+					cancel: {
+						method: "POST",
+						params: {action: "cancel"}
+					}
+				}
+		);
 		this.getStatusColor = function(status) {
 			var COLORS_BY_STATUS = {
 					'CR': '#808080',
-		            'AC': '#329e5a',
-		            'OH': '#9047c7',
-		            'EX': '#ea7824',
-		            'CA': '#a21717'
-		            };
-			
+					'AC': '#329e5a',
+					'OH': '#9047c7',
+					'EX': '#ea7824',
+					'CA': '#a21717'
+			};
+
 			return COLORS_BY_STATUS[status];
 		},
 		this.getStatusName = function(status) {
@@ -79,15 +79,15 @@
 				toaster.pop('success', 'Packs', $L.get("Pack '{0}' {1} successfully", pack.code, isNew ? $L.get("created") : $L.get("updated")));
 			}
 			var _error =  function(error) {
-                console.log(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-MSG'))));
 			}
 			packResource.save(pack, _success, _error);
 		} 
 
 		this.isActionAvailable = function(action, pack) {
-            var validStatuses = PACK_ACTIONS_BY_STATUS[action];
-            return pack && validStatuses && validStatuses.indexOf(pack.status) !== -1;
+			var validStatuses = PACK_ACTIONS_BY_STATUS[action];
+			return pack && validStatuses && validStatuses.indexOf(pack.status) !== -1;
 		}
 		var _createSuccessCallback = function(actionName, message, _innerCallback) {
 			return function() {
@@ -97,8 +97,8 @@
 		}
 		var _createErrorCallback = function(pack, actionName, _innerCallback) {
 			return function(error) {
-	            console.log(error);
-	            _innerCallback && _innerCallback();
+				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-MSG'))));
 			}
 		}
@@ -132,85 +132,86 @@
 		}
 
 	}]);
-	
+
 	app.service('Licenses', ['$L', '$resource', 'toaster', function($L, $resource, toaster) {
 		var LIC_STATUS = {
-		        CREATED: 'CR',
-	            ACTIVE: 'AC',
-	            REQUESTED: 'RE',
-	            PREACTIVE: 'PA',
-	            EXPIRED: 'EX',
-	            CANCELLED: 'CA'
+				CREATED: 'CR',
+				ACTIVE: 'AC',
+				REQUESTED: 'RE',
+				PREACTIVE: 'PA',
+				EXPIRED: 'EX',
+				CANCELLED: 'CA'
 		}
-		
+
 		var LIC_STATUSES = {
 				'CR': $L.get('Created'),
-	            'AC': $L.get('Active'),
-	            'PA': $L.get('Pre-active'),
-	            'RE': $L.get('Requested'),
-	            'EX': $L.get('Expired'),
-	            'CA': $L.get('Cancelled')
-	            };
+				'AC': $L.get('Active'),
+				'PA': $L.get('Pre-active'),
+				'RE': $L.get('Requested'),
+				'EX': $L.get('Expired'),
+				'CA': $L.get('Cancelled')
+		};
 
 		/**
 		 * 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',
+				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 a file cannot be done form AJAX, We should do it manually, using $http
-            download: {
-                method: "GET",
-                params: {action: "download"}
-            }, 
-            block: {
-                method: "POST",
-                params: {action: "block"}
-            },
-            sendEmail: {
-                method: "POST",
-                params: {action: "send"}
-            },
-            unblock: {
-                method: "POST",
-                params: {action: "unblock"}
-            }
-        });
+			activate: {
+				method: "POST",
+				params: {action: "activate"}
+			},
+			cancel: {
+				method: "POST",
+				params: {action: "cancel"}
+			}, // Download a file cannot be done form AJAX, We should do it
+				// manually, using $http
+			download: {
+				method: "GET",
+				params: {action: "download"}
+			}, 
+			block: {
+				method: "POST",
+				params: {action: "block"}
+			},
+			sendEmail: {
+				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) {
+		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'
-		            };
-			
+					'AC': '#329e5a',
+					'RE': '#2981d4',
+					'EX': '#ea7824',
+					'CA': '#a21717'
+			};
+
 			return COLORS_BY_STATUS[status];
 		},
 		this.getStatusName = function(status) {
@@ -223,7 +224,7 @@
 				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);
+				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);
@@ -237,12 +238,12 @@
 		}
 		var _createErrorCallback = function(license, actionName, _innerCallback) {
 			return function(error) {
-	            console.log(error);
-	            _innerCallback && _innerCallback();
+				console.log(error);
+				_innerCallback && _innerCallback();
 				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.getLicensesList = function(pack, _onsuccess, _onerror) {
 			return licenseResource.query({packId: pack.id}, _onsuccess, _onerror);
 		}
@@ -274,9 +275,9 @@
 			console.log('Download license: ' + license.id);
 			var _success = _createSuccessCallback($L.get('Download'), $L.get("License '{0}' {1} successfully", license.code, $L.get("downloaded")), _onsuccess);
 			var _error = _createErrorCallback(license, $L.get('Download license file'), _onerror);
-			//window.open(downloadPath, '_blank', '');  
+			// window.open(downloadPath, '_blank', '');
 			var _success2 = function(data, headers) {
-				//console.log(headers.get("Content-Disposition"));
+				// console.log(headers.get("Content-Disposition"));
 				// attachment; filename="license.lic"
 				var filename =  JSON.parse(headers('Content-Disposition').match(/".*"$/g)[0]);
 				data.$promise.then(function(content) {
@@ -300,526 +301,530 @@
 			licenseResource.delete({licenseId: license.id}, _success, _error);
 		}
 	}]);
-	
+
 	app.directive('fileLoader',
-	            function($timeout, $parse) {
-	                return {
-	                    restrict : 'A', // only activate on element attribute
-	                    require : '',
-	                    link : function(scope, element, attrs) {
-                            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
-	                                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);
-	                            var field = $parse(attrs.fileLoader);
-	                            // 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();
-                                    }
-                                    reader.onload = function(data) {
-                                        setter(scope.$parent, reader.result);
-                                        scope.$apply();
-                                    }
-                                    
-                                    reader.readAsText(fileList[0]);       
-	                            } else {
-	                                setter(scope.$parent, '');
-                                    scope.$apply();
-	                            }
-	                        });
-	                        
-	                    }
-	                };
-	            });
+			function($timeout, $parse) {
+		return {
+			restrict : 'A', // only activate on element attribute
+			require : '',
+			link : function(scope, element, attrs) {
+				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
+						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);
+					var field = $parse(attrs.fileLoader);
+					// 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();
+						}
+						reader.onload = function(data) {
+							setter(scope.$parent, reader.result);
+							scope.$apply();
+						}
+
+						reader.readAsText(fileList[0]);       
+					} else {
+						setter(scope.$parent, '');
+						scope.$apply();
+					}
+				});
+
+			}
+		};
+	});
 
 
 	app.controller('PackAndLicensesCtrl', [
-	                    			'$scope',
-	                    			'$http',
-	                    			'toaster',
-	                    			'$store',
-	                    			'$L',
-	   			function($scope, $http, toaster, $store, $L) {
-	                    $store.set('location', '/licenses');
-	                    				
-        				$scope.maxLengthErrorMsg = function(displayname, fieldMaxlength) {
-        					return $L.get("{0} length is too long (max: {1}).", $L.get(displayname), fieldMaxlength);
-        				}
-        				$scope.mandatoryFieldErrorMsg = function(displayname) {
-        					return $L.get("'{0}' is required.", $L.get(displayname));
-        				}
-        				$scope.field1ShouldBeGreaterThanField2 = function(field1, field2) {
-        					return $L.get("{0} should be greater than {1}", $L.get(field1), $L.get(field2));
-        				}
-        				$scope.ellipsis = function(txt, len) {
-        					if (!txt || txt.length <= len) return txt;
-        					return txt.substring(0, len) + '...';
-        				}
-                        $scope.currentPack = $store.get('currentPack');
+	                                       '$scope',
+	                                       '$http',
+	                                       'toaster',
+	                                       '$store',
+	                                       '$L',
+	                                       function($scope, $http, toaster, $store, $L) {
+	                                    	   $store.set('location', '/licenses');
 
-	   			}]);
-	
-	app.controller('PacksCtrl', [
-			'$scope',
-			'$http',
-			'$resource',
-			'toaster',
-			'Catalogs',
-			'Packs',
-			'$store',
-			'$L',
-			function($scope, $http, $resource, toaster, Catalogs, Packs, $store, $L) {
-         	   $scope.Packs = Packs;
-				
-				
-				$scope.mandatory = {
-						code: true,
-						num_licenses: true,
-						init_valid_date: true,
-						end_valid_date: true,
-						status: true,
-						organization_id: true,
-						license_type_id: true
-				}
-				$scope.maxlength = {
-						code: 50,
-						comments: 1024
-				}
-				$scope.refs = {};
-                Catalogs.init().then(function() {
-                	var refFields = [{resource: 'organization', name: 'organization_id'},{resource: 'licensetype', name: 'license_type_id'}]; 
-                    Catalogs.loadRefs(function(refs) {
-	                    	$scope.refs = refs;
-	                    }, refFields);
-                }); 
-
-				// Used to create the form with the appropriate data
-				$scope.isNew = undefined;
-
-				// Selected pack from listing
-				// pack is the edited pack, in creation contains the data for
-				// the new pack
-				$scope.pack = null;
-
-				$scope.packs = Packs.getPacksList();
-				
-				$scope.save = function() {
-                	Packs.savePackData($scope.pack, $scope.isNew, function() {
-        			    if (!$scope.isNew) {
-        			    	$scope.showForm = false;
-        			    } else {
-        			    	$scope.newPack();
-        			    }
-        				$scope.packs = Packs.getPacksList();
-                	});
-				}
-
-				/**
-				 * Execute an action over the pack, activation, onhold,
-				 * cancellation
-				 */
-				$scope.execute = function(action, pack) {
-					var _execute = function(extra_data) {
-						if (extra_data) {
-							Packs[action](pack || $scope.pack, extra_data, function() {
-							    if (!$scope.isNew) $scope.showForm = false;
-								$scope.packs = Packs.getPacksList();
-							});
-						} else {
-							Packs[action](pack || $scope.pack, function() {
-							    if (!$scope.isNew) $scope.showForm = false;
-								$scope.packs = Packs.getPacksList();
-							});
-						}
-					}
-					if (action === 'delete') {
-						BootstrapDialog.confirm($L.get("The pack '{0}' will be deleted, are you sure ?", pack.code), function(answer) {
-	                        if (answer) {
-	                        	_execute();
-	                        }
-	                    });
-					} else {
-						if (action === 'cancel') {
-							BootstrapDialog.show({
-								title: $L.get("Pack cancellation"),
-								type: BootstrapDialog.TYPE_DANGER,
-								message: function(dialog) {
-									var $content = $('<div></div>');
-									var $message = $('<div></div>');
-					                $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="_pack_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 pack'),
-							        cssClass: 'btn-primary', 
-							        action: function(dialogRef){
-							        	var reason = $('#_pack_cancellation_reason').val();
-							        	console.log('Ready to cancel pack, by reason: ' + reason);
-							            if (!reason) {
-							            	$('#_pack_cancellation_reason').focus();
-							            } else {
-							            	_execute({reason: reason});
-								            dialogRef.close();
-							            }
-							        }
-							    }]
-							});
-						} else {
-							_execute();
-						}
-					}
-				}
-				
-
-				$scope.newPack = function() {
-					$scope.isNew = true;
-					$scope.showForm = true;
-					$scope.pack = {
-                            license_preactivation: true,
-                            status: 'CR',
-                            num_licenses: 1,
-                            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
-					}
-                   setTimeout(function() {
-                        $('#code').focus();
-                    }, 0);
-				}
-
-                $scope.editPack = function(selectedPack) {
-                    $scope.isNew = false;
-                    $scope.showForm = true;
-                    if (!(selectedPack.init_valid_date instanceof Date)) {
-                    	selectedPack.init_valid_date = new Date(selectedPack.init_valid_date);
-                    }
-                    if (!(selectedPack.end_valid_date instanceof Date)) {
-                    	selectedPack.end_valid_date = new Date(selectedPack.end_valid_date);
-                    }
-                    
-                    $scope.pack = selectedPack;
-
-                    // $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); 
-                    
-                    setTimeout(function() {
-                        $('#code').focus();
-                    }, 0);
-                }
-
-                $scope.deletePack = function(selectedPack) {
-                    $scope.showForm = false;
-                    BootstrapDialog.confirm($L.get("The pack '{0}' will be deleted, are you sure?", selectedPack.code), function(result){
-                        if(result) {
-                            var promise = packResource.remove({}, {id: selectedPack.id}).$promise;
-                            promise.then(function(data) {
-                                $scope.selectPack(null);
-                                $scope.packs = packResource.query();
-                                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-MSG')), 10000);
-                            });
-                        }
-                    });
-                    $scope.isNew = false;
-                }
-
-
-                $scope.cancel = function() {
-                    $scope.showForm = false;
-                }
-
-				$scope.selectPack = function(pack) {
-					$scope.$parent.currentPack = pack;
-					$store.put('currentPack', pack);
-					$scope.$parent.$broadcast('pack_changed', pack);
-				}
-				
-				$scope.getLabelFromId = function(field, myid) {
-					var label = null;
-					$scope.refs[field].forEach(function (elem) {
-						if (elem.id === myid) {
-							label = elem.label;
-						}
-					});
-					return label;
-				}
-				
-				$scope.createMetadataRow = function() {
-					if (!$scope.formu.metadata) {
-						$scope.formu.metadata = [];
-					}
-					$scope.formu.metadata.push({key: '', value: '', mandatory: true});
-				}
-				$scope.removeMetadataKey = function(row_md) {
-					$scope.formu.metadata.splice( $scope.formu.metadata.indexOf(row_md), 1 );
-				}
-				$scope.updateMetadata = function() {
-					// 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
-						Catalogs.getResource('licensetype').get({licenseTypeId: newLTId}).$promise.then(function(lt) {
-							$scope.pack.metadata = [];
-							lt.metadata.forEach(function(md) {
-								$scope.pack.metadata.push({
-									key: md.key,
-									value: md.value,
-									readonly: !!md.value,
-									mandatory: md.mandatory
-								});
-							});
-						});
-					}
-				}
-			} ]);
-
-	   app.controller('LicensesCtrl', [
-	                                   '$scope',
-	                                   '$http',
-	                                   '$resource',
-	                                   'toaster',
-	                       			   'Licenses',
-	                                   '$store',
-	                                   '$L',
-	                                   function($scope, $http, $resource, toaster, Licenses, $store, $L) {
-	                                	   $scope.Licenses = Licenses;
-	                                       $scope.$on('pack_changed', function(evt, message) {
-                                               $scope.licenses = Licenses.getLicensesList($scope.currentPack);
-                                               $scope.creationAvailable = $scope.currentPack.status == 'AC';
-	                                           if ($scope.showForm) {
-	                                               if ($scope.isNew) {
-	                                                   $scope.license.pack_id = $scope.currentPack.id
-	                                               } else {
-	                                                   $scope.showForm = false;    
-	                                               }
-	                                           }
-	                                       })
-	                                           
-	                                       $scope.mandatory = {
-	                                               code: true,
-	                                               email: true
-	                                       }
-	                                       $scope.maxlength = {
-	                                               code: 50,
-	                                               request_data: 500,
-	                                               comments: 1024
-	                                       }
-	                                       $scope.refs = {};
-
-	                                       // 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
-	                                       $scope.license = null;
-	                                       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) {
-	                                               BootstrapDialog.show({
-	                                                   title: $L.get('New license'),
-	                                                   type: BootstrapDialog.TYPE_WARNING,
-	                                                   message: $L.get('Please, select a pack before to create a new license'),
-	                                                   buttons: [{
-	                                                       label: 'OK',
-	                                                       action: function(dialog) {
-	                                                           dialog.close();
-	                                                       }
-	                                                   }]
-	                                               });
-	                                               return;
-	                                           }
-	                                           if (!$scope.creationAvailable) {
-	                                               BootstrapDialog.show({
-	                                                   title: $L.get('Pack not active'),
-	                                                   type: BootstrapDialog.TYPE_WARNING,
-	                                                   message: $L.get('Current pack is not active, so licenses cannot be created'),
-	                                                   buttons: [{
-	                                                       label: 'OK',
-	                                                       action: function(dialog) {
-	                                                           dialog.close();
-	                                                       }
-	                                                   }]
-	                                               });
-	                                               return;
-	                                           }
-	                                               
-	                                           $scope.isNew = true;
-	                                           $scope.showForm = true;
-	                                           $scope.license = {
-	                                                   pack_id: $scope.currentPack.id
-	                                           }
-	                                          setTimeout(function() {
-	                                               $('#licenseForm * #code').focus();
-	                                           }, 0);
-	                                       }
-
-	                                       $scope.editLicense = function(selectedlicense) {
-	                                           $scope.isNew = false;
-	                                           $scope.showForm = true;
-	                                           $scope.license = selectedlicense;
-	                                           $scope.license.status_name = Licenses.getStatusName($scope.license.status); 
-
-	                                          setTimeout(function() {
-	                                               $('#licenseForm * #code').focus();
-	                                           }, 0);
-	                                       }
-
-	                                       $scope.deletelicense = function(selectedlicense) {
-	                                           $scope.showForm = false;
-	                                           BootstrapDialog.confirm($L.get("The license '{0}' will be deleted, are you sure?", selectedlicense.code), function(result){
-	                                               if(result) {
-	                                                   var promise = licenseResource.remove({}, {id: selectedlicense.id}).$promise;
-	                                                   promise.then(function(data) {
-	                                                       $scope.selectlicense(null);
-	                                                       $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-MSG')), 10000);
-	                                                   });
-	                                               }
-	                                           });
-	                                           $scope.isNew = false;
-	                                       }
-
-	                                       $scope.execute = function(action, license) {
-	                                    	   if (!license) {
-	                                    		   license = $scope.license;
+	                                    	   $scope.maxLengthErrorMsg = function(displayname, fieldMaxlength) {
+	                                    		   return $L.get("{0} length is too long (max: {1}).", $L.get(displayname), fieldMaxlength);
 	                                    	   }
-	                       					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);
+	                                    	   $scope.mandatoryFieldErrorMsg = function(displayname) {
+	                                    		   return $L.get("'{0}' is required.", $L.get(displayname));
+	                                    	   }
+	                                    	   $scope.field1ShouldBeGreaterThanField2 = function(field1, field2) {
+	                                    		   return $L.get("{0} should be greater than {1}", $L.get(field1), $L.get(field2));
+	                                    	   }
+	                                    	   $scope.ellipsis = function(txt, len) {
+	                                    		   if (!txt || txt.length <= len) return txt;
+	                                    		   return txt.substring(0, len) + '...';
+	                                    	   }
+	                                    	   $scope.currentPack = $store.get('currentPack');
 
-	                       									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;
-	                                       }
-	                                       
-                                           $scope.showStatus = function(lic) {
-                                               
-                                           }
-                                           $scope.showStatusLong = function(license) {
-                                               
-                                           }
-	                                       
-	                                   } ]);
+	app.controller('PacksCtrl', [
+	                             '$scope',
+	                             '$http',
+	                             '$resource',
+	                             'toaster',
+	                             'Catalogs',
+	                             'Packs',
+	                             '$store',
+	                             '$L',
+	                             function($scope, $http, $resource, toaster, Catalogs, Packs, $store, $L) {
+	                            	 $scope.Packs = Packs;
+
+
+	                            	 $scope.mandatory = {
+	                            			 code: true,
+	                            			 num_licenses: true,
+	                            			 init_valid_date: true,
+	                            			 end_valid_date: true,
+	                            			 status: true,
+	                            			 organization_id: true,
+	                            			 license_type_id: true
+	                            	 }
+	                            	 $scope.maxlength = {
+	                            			 code: 50,
+	                            			 comments: 1024
+	                            	 }
+	                            	 $scope.refs = {};
+	                            	 Catalogs.init().then(function() {
+	                            		 var refFields = [{resource: 'organization', name: 'organization_id'},{resource: 'licensetype', name: 'license_type_id'}]; 
+	                            		 Catalogs.loadRefs(function(refs) {
+	                            			 $scope.refs = refs;
+	                            		 }, refFields);
+	                            	 }); 
+
+	                            	 // Used to create the form with the
+										// appropriate data
+	                            	 $scope.isNew = undefined;
+
+	                            	 // Selected pack from listing
+	                            	 // pack is the edited pack, in creation
+										// contains the data for
+	                            	 // the new pack
+	                            	 $scope.pack = null;
+
+	                            	 $scope.packs = Packs.getPacksList();
+
+	                            	 $scope.save = function() {
+	                            		 Packs.savePackData($scope.pack, $scope.isNew, function() {
+	                            			 if (!$scope.isNew) {
+	                            				 $scope.showForm = false;
+	                            			 } else {
+	                            				 $scope.newPack();
+	                            			 }
+	                            			 $scope.packs = Packs.getPacksList();
+	                            		 });
+	                            	 }
+
+	                            	 /**
+										 * Execute an action over the pack,
+										 * activation, onhold, cancellation
+										 */
+	                            	 $scope.execute = function(action, pack) {
+	                            		 var _execute = function(extra_data) {
+	                            			 if (extra_data) {
+	                            				 Packs[action](pack || $scope.pack, extra_data, function() {
+	                            					 if (!$scope.isNew) $scope.showForm = false;
+	                            					 $scope.packs = Packs.getPacksList();
+	                            				 });
+	                            			 } else {
+	                            				 Packs[action](pack || $scope.pack, function() {
+	                            					 if (!$scope.isNew) $scope.showForm = false;
+	                            					 $scope.packs = Packs.getPacksList();
+	                            				 });
+	                            			 }
+	                            		 }
+	                            		 if (action === 'delete') {
+	                            			 BootstrapDialog.confirm($L.get("The pack '{0}' will be deleted, are you sure ?", pack.code), function(answer) {
+	                            				 if (answer) {
+	                            					 _execute();
+	                            				 }
+	                            			 });
+	                            		 } else {
+	                            			 if (action === 'cancel') {
+	                            				 BootstrapDialog.show({
+	                            					 title: $L.get("Pack cancellation"),
+	                            					 type: BootstrapDialog.TYPE_DANGER,
+	                            					 message: function(dialog) {
+	                            						 var $content = $('<div></div>');
+	                            						 var $message = $('<div></div>');
+	                            						 $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="_pack_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 pack'),
+	                            						 cssClass: 'btn-primary', 
+	                            						 action: function(dialogRef){
+	                            							 var reason = $('#_pack_cancellation_reason').val();
+	                            							 console.log('Ready to cancel pack, by reason: ' + reason);
+	                            							 if (!reason) {
+	                            								 $('#_pack_cancellation_reason').focus();
+	                            							 } else {
+	                            								 _execute({reason: reason});
+	                            								 dialogRef.close();
+	                            							 }
+	                            						 }
+	                            					 }]
+	                            				 });
+	                            			 } else {
+	                            				 _execute();
+	                            			 }
+	                            		 }
+	                            	 }
+
+
+	                            	 $scope.newPack = function() {
+	                            		 $scope.isNew = true;
+	                            		 $scope.showForm = true;
+	                            		 $scope.pack = {
+	                            				 license_preactivation: true,
+	                            				 status: 'CR',
+	                            				 num_licenses: 1,
+	                            				 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
+	                            		 }
+	                            		 setTimeout(function() {
+	                            			 $('#code').focus();
+	                            		 }, 0);
+	                            	 }
+
+	                            	 $scope.editPack = function(selectedPack) {
+	                            		 $scope.isNew = false;
+	                            		 $scope.showForm = true;
+	                            		 if (!(selectedPack.init_valid_date instanceof Date)) {
+	                            			 selectedPack.init_valid_date = new Date(selectedPack.init_valid_date);
+	                            		 }
+	                            		 if (!(selectedPack.end_valid_date instanceof Date)) {
+	                            			 selectedPack.end_valid_date = new Date(selectedPack.end_valid_date);
+	                            		 }
+
+	                            		 $scope.pack = selectedPack;
+
+	                            		 // $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); 
+
+	                            		 setTimeout(function() {
+	                            			 $('#code').focus();
+	                            		 }, 0);
+	                            	 }
+
+	                            	 $scope.deletePack = function(selectedPack) {
+	                            		 $scope.showForm = false;
+	                            		 BootstrapDialog.confirm($L.get("The pack '{0}' will be deleted, are you sure?", selectedPack.code), function(result){
+	                            			 if(result) {
+	                            				 var promise = packResource.remove({}, {id: selectedPack.id}).$promise;
+	                            				 promise.then(function(data) {
+	                            					 $scope.selectPack(null);
+	                            					 $scope.packs = packResource.query();
+	                            					 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-MSG')), 10000);
+	                            				 });
+	                            			 }
+	                            		 });
+	                            		 $scope.isNew = false;
+	                            	 }
+
+
+	                            	 $scope.cancel = function() {
+	                            		 $scope.showForm = false;
+	                            	 }
+
+	                            	 $scope.selectPack = function(pack) {
+	                            		 $scope.$parent.currentPack = pack;
+	                            		 $store.put('currentPack', pack);
+	                            		 $scope.$parent.$broadcast('pack_changed', pack);
+	                            	 }
+
+	                            	 $scope.getLabelFromId = function(field, myid) {
+	                            		 var label = null;
+	                            		 $scope.refs[field].forEach(function (elem) {
+	                            			 if (elem.id === myid) {
+	                            				 label = elem.label;
+	                            			 }
+	                            		 });
+	                            		 return label;
+	                            	 }
+
+	                            	 $scope.createMetadataRow = function() {
+	                            		 if (!$scope.formu.metadata) {
+	                            			 $scope.formu.metadata = [];
+	                            		 }
+	                            		 $scope.formu.metadata.push({key: '', value: '', mandatory: true});
+	                            	 }
+	                            	 $scope.removeMetadataKey = function(row_md) {
+	                            		 $scope.formu.metadata.splice( $scope.formu.metadata.indexOf(row_md), 1 );
+	                            	 }
+	                            	 $scope.updateMetadata = function() {
+	                            		 // 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
+	                            			 Catalogs.getResource('licensetype').get({licenseTypeId: newLTId}).$promise.then(function(lt) {
+	                            				 $scope.pack.metadata = [];
+	                            				 lt.metadata.forEach(function(md) {
+	                            					 $scope.pack.metadata.push({
+	                            						 key: md.key,
+	                            						 value: md.value,
+	                            						 readonly: !!md.value,
+	                            						 mandatory: md.mandatory
+	                            					 });
+	                            				 });
+	                            			 });
+	                            		 }
+	                            	 }
+	                             } ]);
+
+	app.controller('LicensesCtrl', [
+	                                '$scope',
+	                                '$http',
+	                                '$resource',
+	                                'toaster',
+	                                'Licenses',
+	                                '$store',
+	                                '$L',
+	                                function($scope, $http, $resource, toaster, Licenses, $store, $L) {
+	                                	$scope.Licenses = Licenses;
+	                                	$scope.$on('pack_changed', function(evt, message) {
+	                                		$scope.licenses = Licenses.getLicensesList($scope.currentPack);
+	                                		$scope.creationAvailable = $scope.currentPack.status == 'AC';
+	                                		if ($scope.showForm) {
+	                                			if ($scope.isNew) {
+	                                				$scope.license.pack_id = $scope.currentPack.id
+	                                			} else {
+	                                				$scope.showForm = false;    
+	                                			}
+	                                		}
+	                                	})
+
+	                                	$scope.mandatory = {
+	                                		code: true,
+	                                		email: true
+	                                	}
+	                                	$scope.maxlength = {
+	                                		code: 50,
+	                                		request_data: 500,
+	                                		comments: 1024
+	                                	}
+	                                	$scope.refs = {};
+
+	                                	// 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
+	                                	$scope.license = null;
+	                                	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) {
+	                                			BootstrapDialog.show({
+	                                				title: $L.get('New license'),
+	                                				type: BootstrapDialog.TYPE_WARNING,
+	                                				message: $L.get('Please, select a pack before to create a new license'),
+	                                				buttons: [{
+	                                					label: 'OK',
+	                                					action: function(dialog) {
+	                                						dialog.close();
+	                                					}
+	                                				}]
+	                                			});
+	                                			return;
+	                                		}
+	                                		if (!$scope.creationAvailable) {
+	                                			BootstrapDialog.show({
+	                                				title: $L.get('Pack not active'),
+	                                				type: BootstrapDialog.TYPE_WARNING,
+	                                				message: $L.get('Current pack is not active, so licenses cannot be created'),
+	                                				buttons: [{
+	                                					label: 'OK',
+	                                					action: function(dialog) {
+	                                						dialog.close();
+	                                					}
+	                                				}]
+	                                			});
+	                                			return;
+	                                		}
+
+	                                		$scope.isNew = true;
+	                                		$scope.showForm = true;
+	                                		$scope.license = {
+	                                				pack_id: $scope.currentPack.id
+	                                		}
+	                                		setTimeout(function() {
+	                                			$('#licenseForm * #code').focus();
+	                                		}, 0);
+	                                	}
+
+	                                	$scope.editLicense = function(selectedlicense) {
+	                                		$scope.isNew = false;
+	                                		$scope.showForm = true;
+	                                		$scope.license = selectedlicense;
+	                                		$scope.license.status_name = Licenses.getStatusName($scope.license.status); 
+
+	                                		setTimeout(function() {
+	                                			$('#licenseForm * #code').focus();
+	                                		}, 0);
+	                                	}
+
+	                                	$scope.deletelicense = function(selectedlicense) {
+	                                		$scope.showForm = false;
+	                                		BootstrapDialog.confirm($L.get("The license '{0}' will be deleted, are you sure?", selectedlicense.code), function(result){
+	                                			if(result) {
+	                                				var promise = licenseResource.remove({}, {id: selectedlicense.id}).$promise;
+	                                				promise.then(function(data) {
+	                                					$scope.selectlicense(null);
+	                                					$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-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.", license.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;
+	                                	}
+
+	                                	$scope.showStatus = function(lic) {
+
+	                                	}
+	                                	$scope.showStatusLong = function(license) {
+
+	                                	}
+
+	                                } ]);
 
 })();

--
Gitblit v1.3.2