From 44ec40e27b3039096c6202bcc19bae9561943818 Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Mon, 20 Oct 2014 16:45:49 +0000
Subject: [PATCH] #2021 fix - Corrected license form validations

---
 securis/src/main/resources/static/licenses.html              |   23 +++++++----
 securis/src/main/java/net/curisit/securis/db/PackStatus.java |   10 ++++
 securis/src/main/resources/static/js/licenses.js             |   32 +++++++++++-----
 3 files changed, 45 insertions(+), 20 deletions(-)

diff --git a/securis/src/main/java/net/curisit/securis/db/PackStatus.java b/securis/src/main/java/net/curisit/securis/db/PackStatus.java
index 110bd36..b5a436a 100644
--- a/securis/src/main/java/net/curisit/securis/db/PackStatus.java
+++ b/securis/src/main/java/net/curisit/securis/db/PackStatus.java
@@ -1,6 +1,7 @@
 package net.curisit.securis.db;
 
 import org.codehaus.jackson.annotate.JsonCreator;
+import org.codehaus.jackson.annotate.JsonValue;
 
 public enum PackStatus {
     PENDING("PE"), ACTIVE("AC"),  ON_HOLD("OH"),  EXPIRED("EX"),  CANCELLED("CA");
@@ -16,9 +17,16 @@
     @JsonCreator
     public static PackStatus valueFromCode(String code) {
         for (PackStatus ps : PackStatus.values()) {
-            if (ps.code.equals(code)) return ps;
+            if (ps.code.equals(code)) {
+                return ps;
+            }
         }
         return null;
     }
 
+    @JsonValue
+    public String getName() {
+        
+        return this.code;
+    }
 }
diff --git a/securis/src/main/resources/static/js/licenses.js b/securis/src/main/resources/static/js/licenses.js
index e0624fd..09a33bd 100644
--- a/securis/src/main/resources/static/js/licenses.js
+++ b/securis/src/main/resources/static/js/licenses.js
@@ -20,6 +20,7 @@
 
 	   var HTTP_ERRORS = {
 	            401: "Unathorized action",
+	            418: "Application error",
 	            403: "Forbidden action",
 	            500: "Server error",
 	            404: "Element not found"
@@ -40,6 +41,7 @@
 	                                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);
@@ -48,17 +50,17 @@
 	                                var reader = new FileReader();
                                     reader.onerror = function(data) {
                                         setter(scope.$parent, 'ERROR');
-                                        //scope.$apply();
+                                        scope.$apply();
                                     }
                                     reader.onload = function(data) {
                                         setter(scope.$parent, reader.result);
-                                        //scope.$apply();
+                                        scope.$apply();
                                     }
                                     
                                     reader.readAsText(fileList[0]);       
 	                            } else {
 	                                setter(scope.$parent, '');
-                                    //scope.$apply();
+                                    scope.$apply();
 	                            }
 	                        });
 	                        
@@ -182,8 +184,14 @@
                 $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;
-                   setTimeout(function() {
+                    setTimeout(function() {
                         $('#code').focus();
                     }, 0);
                 }
@@ -292,6 +300,7 @@
 	                                       }
 	                                       $scope.maxlength = {
 	                                               code: 50,
+	                                               request_data: 500,
 	                                               comments: 1024
 	                                       }
 	                                       $scope.refs = {};
@@ -319,14 +328,17 @@
 //	                                       });
 	                                       
 	                                       $scope.save = function() {
-	                                           $( "form#licenseForm" )
-	                                           .attr( "enctype", "multipart/form-data" )
-	                                           .attr( "encoding", "multipart/form-data" );
+	                                           //$( "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});
-	                                           }
-	                                           licenseResource.save_w_upload($scope.license, _success)
+		                       						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)
 	                                       }
 	                                       
 	                                       $scope.newLicense = function() {
@@ -395,7 +407,7 @@
                                            }
                                            $scope.isActionVisible = function(action, lic) {
                                                var validStatuses = ACTIONS_BY_STATUS[action];
-                                               return lic && validStatuses.indexOf(lic.status) !== -1;
+                                               return lic && validStatuses && validStatuses.indexOf(lic.status) !== -1;
                                            }
 	                                       
 	                                   } ]);
diff --git a/securis/src/main/resources/static/licenses.html b/securis/src/main/resources/static/licenses.html
index a8ed791..d9a9056 100644
--- a/securis/src/main/resources/static/licenses.html
+++ b/securis/src/main/resources/static/licenses.html
@@ -407,17 +407,22 @@
 							ng-maxlength="{{maxlength.request_data}}"></textarea>
 						<div class="alert inline-alert alert-warning"
 							ng-show="licenseForm.request_data.$invalid">
-							<span class="glyphicon glyphicon-warning-sign"></span> <span
-								ng-show="licenseForm.request_data.$error.maxlength"
-								ng-bind="maxlengthErrorMsg('Request data', maxlength.request_data)"></span>
-							<span ng-show="licenseForm.request_data.$error.required"
-								ng-bind="mandatoryFieldErrorMsg('Request data')"></span>
+							Invalid ? {{licenseForm.request_data.$invalid}}
+							Error ? {{licenseForm.request_data.$error | json}}
+							Error ? {{licenseForm.request_data.$error.maxlength}}
+							<span class="glyphicon glyphicon-warning-sign">
+								<span
+									ng-show="licenseForm.request_data.$error.maxlength"
+									ng-bind="maxlengthErrorMsg('Request data', maxlength.request_data)"></span>
+								<span ng-show="licenseForm.request_data.$error.required"
+									ng-bind="mandatoryFieldErrorMsg('Request data')"></span>
+							</span> 
 						</div>
 					</div>
-					<span class="btn btn-file btn-default btn-xs"> <span
-						class="glyphicon glyphicon-folder-open"></span> <input
-						file-loader="license.request_data" type="file">
-					</span>
+						<span class="btn btn-file btn-default btn-xs"> 
+							<span class="glyphicon glyphicon-folder-open"></span> 
+							<input file-loader="license.request_data" type="file" />
+						</span>
 				</div>
 
 				<div class="form-group">

--
Gitblit v1.3.2