rsanchez
2014-10-20 44ec40e27b3039096c6202bcc19bae9561943818
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 } ]);