rsanchez
2014-11-18 b33557d3faf3e45eff3d3e19f4a1549ffe907b4c
securis/src/main/webapp/js/licenses.js
....@@ -178,16 +178,16 @@
178178 cancel: {
179179 method: "POST",
180180 params: {action: "cancel"}
181
- },
181
+ }, // Download a file cannot be done form AJAX, We should do it manually, using $http
182182 download: {
183183 method: "GET",
184184 params: {action: "download"}
185
- },
185
+ },
186186 block: {
187187 method: "POST",
188188 params: {action: "block"}
189189 },
190
- send: {
190
+ sendEmail: {
191191 method: "POST",
192192 params: {action: "send"}
193193 },
....@@ -256,13 +256,35 @@
256256 console.log('Block on license: ' + license.id);
257257 var _success = _createSuccessCallback($L.get('Block'), $L.get("License '{0}' {1} successfully", license.code, $L.get("blocked")), _onsuccess);
258258 var _error = _createErrorCallback(license, $L.get('Block'), _onerror);
259
- licenseResource.putonhold({id: license.id}, _success, _error);
259
+ licenseResource.block({id: license.id}, _success, _error);
260260 }
261261 this.unblock = function(license, _onsuccess, _onerror) {
262262 console.log('Unblock on license: ' + license.id);
263263 var _success = _createSuccessCallback($L.get('Unblock'), $L.get("License '{0}' {1} successfully", license.code, $L.get("unblocked")), _onsuccess);
264264 var _error = _createErrorCallback(license, $L.get('Unblock'), _onerror);
265
- licenseResource.putonhold({id: license.id}, _success, _error);
265
+ licenseResource.unblock({id: license.id}, _success, _error);
266
+ }
267
+ this.send = function(license, _onsuccess, _onerror) {
268
+ console.log('Sending email: ' + license.id);
269
+ var _success = _createSuccessCallback($L.get('Send email'), $L.get("License '{0}' was sent by email ({1}) successfully", license.code, license.email), _onsuccess);
270
+ var _error = _createErrorCallback(license, $L.get('Send email'), _onerror);
271
+ licenseResource.sendEmail({id: license.id}, _success, _error);
272
+ }
273
+ this.download = function(license, _onsuccess, _onerror) {
274
+ console.log('Download license: ' + license.id);
275
+ var _success = _createSuccessCallback($L.get('Download'), $L.get("License '{0}' {1} successfully", license.code, $L.get("downloaded")), _onsuccess);
276
+ var _error = _createErrorCallback(license, $L.get('Download license file'), _onerror);
277
+ //window.open(downloadPath, '_blank', '');
278
+ var _success2 = function(data, headers) {
279
+ //console.log(headers.get("Content-Disposition"));
280
+ // attachment; filename="license.lic"
281
+ var filename = JSON.parse(headers('Content-Disposition').match(/".*"$/g)[0]);
282
+ data.$promise.then(function(content) {
283
+ saveAs( new Blob([ JSON.stringify(content, null, 2) ], { type : 'application/octet-stream' }), filename);
284
+ });
285
+ _success();
286
+ };
287
+ licenseResource.download({licenseId: license.id}, _success2, _error);
266288 }
267289 this.cancel = function(license, extra_data, _onsuccess, _onerror) {
268290 console.log('Cancellation on license: ' + license.id);