From b33557d3faf3e45eff3d3e19f4a1549ffe907b4c Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Tue, 18 Nov 2014 10:52:52 +0000
Subject: [PATCH] #396 fix - Corrected actions: "Download" and "Send email"

---
 securis/src/main/webapp/js/licenses.js |   32 +++++++++++++++++++++++++++-----
 1 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/securis/src/main/webapp/js/licenses.js b/securis/src/main/webapp/js/licenses.js
index 0921b5d..31302e4 100644
--- a/securis/src/main/webapp/js/licenses.js
+++ b/securis/src/main/webapp/js/licenses.js
@@ -178,16 +178,16 @@
             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"}
             },
-            send: {
+            sendEmail: {
                 method: "POST",
                 params: {action: "send"}
             },
@@ -256,13 +256,35 @@
 			console.log('Block on license: ' + license.id);
 			var _success = _createSuccessCallback($L.get('Block'), $L.get("License '{0}' {1} successfully", license.code, $L.get("blocked")), _onsuccess);
 			var _error = _createErrorCallback(license, $L.get('Block'), _onerror);
-			licenseResource.putonhold({id: license.id}, _success, _error);
+			licenseResource.block({id: license.id}, _success, _error);
 		}
 		this.unblock = function(license, _onsuccess, _onerror) {
 			console.log('Unblock on license: ' + license.id);
 			var _success = _createSuccessCallback($L.get('Unblock'), $L.get("License '{0}' {1} successfully", license.code, $L.get("unblocked")), _onsuccess);
 			var _error = _createErrorCallback(license, $L.get('Unblock'), _onerror);
-			licenseResource.putonhold({id: license.id}, _success, _error);
+			licenseResource.unblock({id: license.id}, _success, _error);
+		}
+		this.send = function(license, _onsuccess, _onerror) {
+			console.log('Sending email: ' + license.id);
+			var _success = _createSuccessCallback($L.get('Send email'), $L.get("License '{0}' was sent by email ({1}) successfully", license.code, license.email), _onsuccess);
+			var _error = _createErrorCallback(license, $L.get('Send email'), _onerror);
+			licenseResource.sendEmail({id: license.id}, _success, _error);
+		}
+		this.download = function(license, _onsuccess, _onerror) {
+			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', '');  
+			var _success2 = function(data, headers) {
+				//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) {
+					saveAs( new Blob([ JSON.stringify(content, null, 2) ], { type : 'application/octet-stream' }), filename);
+				});
+				_success();
+			};
+			licenseResource.download({licenseId: license.id}, _success2, _error);
 		}
 		this.cancel = function(license, extra_data, _onsuccess, _onerror) {
 			console.log('Cancellation on license: ' + license.id);

--
Gitblit v1.3.2