rsanchez
2014-10-20 44ec40e27b3039096c6202bcc19bae9561943818
#2021 fix - Corrected license form validations
3 files modified
changed files
securis/src/main/java/net/curisit/securis/db/PackStatus.java patch | view | blame | history
securis/src/main/resources/static/js/licenses.js patch | view | blame | history
securis/src/main/resources/static/licenses.html patch | view | blame | history
securis/src/main/java/net/curisit/securis/db/PackStatus.java
....@@ -1,6 +1,7 @@
11 package net.curisit.securis.db;
22
33 import org.codehaus.jackson.annotate.JsonCreator;
4
+import org.codehaus.jackson.annotate.JsonValue;
45
56 public enum PackStatus {
67 PENDING("PE"), ACTIVE("AC"), ON_HOLD("OH"), EXPIRED("EX"), CANCELLED("CA");
....@@ -16,9 +17,16 @@
1617 @JsonCreator
1718 public static PackStatus valueFromCode(String code) {
1819 for (PackStatus ps : PackStatus.values()) {
19
- if (ps.code.equals(code)) return ps;
20
+ if (ps.code.equals(code)) {
21
+ return ps;
22
+ }
2023 }
2124 return null;
2225 }
2326
27
+ @JsonValue
28
+ public String getName() {
29
+
30
+ return this.code;
31
+ }
2432 }
securis/src/main/resources/static/js/licenses.js
....@@ -20,6 +20,7 @@
2020
2121 var HTTP_ERRORS = {
2222 401: "Unathorized action",
23
+ 418: "Application error",
2324 403: "Forbidden action",
2425 500: "Server error",
2526 404: "Element not found"
....@@ -40,6 +41,7 @@
4041 BootstrapDialog.alert($L.get("Open your .req file with a text editor and copy&paste the content in the form text field?"));
4142 return;
4243 }
44
+ console.log('File selected');
4345 //console.log('scope.license: ' + scope.$parent.license);
4446 var field = $parse(attrs.fileLoader);
4547 //console.log('field: ' + field);
....@@ -48,17 +50,17 @@
4850 var reader = new FileReader();
4951 reader.onerror = function(data) {
5052 setter(scope.$parent, 'ERROR');
51
- //scope.$apply();
53
+ scope.$apply();
5254 }
5355 reader.onload = function(data) {
5456 setter(scope.$parent, reader.result);
55
- //scope.$apply();
57
+ scope.$apply();
5658 }
5759
5860 reader.readAsText(fileList[0]);
5961 } else {
6062 setter(scope.$parent, '');
61
- //scope.$apply();
63
+ scope.$apply();
6264 }
6365 });
6466
....@@ -182,8 +184,14 @@
182184 $scope.editPack = function(selectedPack) {
183185 $scope.isNew = false;
184186 $scope.showForm = true;
187
+ if (!(selectedPack.init_valid_date instanceof Date)) {
188
+ selectedPack.init_valid_date = new Date(selectedPack.init_valid_date);
189
+ }
190
+ if (!(selectedPack.end_valid_date instanceof Date)) {
191
+ selectedPack.end_valid_date = new Date(selectedPack.end_valid_date);
192
+ }
185193 $scope.pack = selectedPack;
186
- setTimeout(function() {
194
+ setTimeout(function() {
187195 $('#code').focus();
188196 }, 0);
189197 }
....@@ -292,6 +300,7 @@
292300 }
293301 $scope.maxlength = {
294302 code: 50,
303
+ request_data: 500,
295304 comments: 1024
296305 }
297306 $scope.refs = {};
....@@ -319,14 +328,17 @@
319328 // });
320329
321330 $scope.save = function() {
322
- $( "form#licenseForm" )
323
- .attr( "enctype", "multipart/form-data" )
324
- .attr( "encoding", "multipart/form-data" );
331
+ //$( "form#licenseForm" ).attr( "enctype", "multipart/form-data" ).attr( "encoding", "multipart/form-data" );
325332 var _success = function() {
326333 if (!$scope.isNew) $scope.showForm = false;
327334 $scope.licenses = licenseResource.query({packId: $scope.currentPack.id});
328
- }
329
- licenseResource.save_w_upload($scope.license, _success)
335
+ toaster.pop('success', Catalogs.getName(), $L.get("License '{0}' {1} successfully", $scope.license.code, $scope.isNew ? $L.get("created") : $L.get("updated")));
336
+ }
337
+ var _error = function(error) {
338
+ console.log(error);
339
+ 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'))));
340
+ }
341
+ licenseResource.save($scope.license, _success, _error)
330342 }
331343
332344 $scope.newLicense = function() {
....@@ -395,7 +407,7 @@
395407 }
396408 $scope.isActionVisible = function(action, lic) {
397409 var validStatuses = ACTIONS_BY_STATUS[action];
398
- return lic && validStatuses.indexOf(lic.status) !== -1;
410
+ return lic && validStatuses && validStatuses.indexOf(lic.status) !== -1;
399411 }
400412
401413 } ]);
securis/src/main/resources/static/licenses.html
....@@ -407,17 +407,22 @@
407407 ng-maxlength="{{maxlength.request_data}}"></textarea>
408408 <div class="alert inline-alert alert-warning"
409409 ng-show="licenseForm.request_data.$invalid">
410
- <span class="glyphicon glyphicon-warning-sign"></span> <span
411
- ng-show="licenseForm.request_data.$error.maxlength"
412
- ng-bind="maxlengthErrorMsg('Request data', maxlength.request_data)"></span>
413
- <span ng-show="licenseForm.request_data.$error.required"
414
- ng-bind="mandatoryFieldErrorMsg('Request data')"></span>
410
+ Invalid ? {{licenseForm.request_data.$invalid}}
411
+ Error ? {{licenseForm.request_data.$error | json}}
412
+ Error ? {{licenseForm.request_data.$error.maxlength}}
413
+ <span class="glyphicon glyphicon-warning-sign">
414
+ <span
415
+ ng-show="licenseForm.request_data.$error.maxlength"
416
+ ng-bind="maxlengthErrorMsg('Request data', maxlength.request_data)"></span>
417
+ <span ng-show="licenseForm.request_data.$error.required"
418
+ ng-bind="mandatoryFieldErrorMsg('Request data')"></span>
419
+ </span>
415420 </div>
416421 </div>
417
- <span class="btn btn-file btn-default btn-xs"> <span
418
- class="glyphicon glyphicon-folder-open"></span> <input
419
- file-loader="license.request_data" type="file">
420
- </span>
422
+ <span class="btn btn-file btn-default btn-xs">
423
+ <span class="glyphicon glyphicon-folder-open"></span>
424
+ <input file-loader="license.request_data" type="file" />
425
+ </span>
421426 </div>
422427
423428 <div class="form-group">