Add XV.downloadURL()
authorBen Thompson <ben@xtuple.com>
Mon, 9 Jun 2014 17:51:50 +0000 (13:51 -0400)
committerBen Thompson <ben@xtuple.com>
Mon, 9 Jun 2014 17:51:50 +0000 (13:51 -0400)
enyo-client/extensions/source/oauth2/client/en/strings.js
enyo-client/extensions/source/oauth2/client/models/oauth2.js
lib/enyo-x/source/core.js

index 02efcfd..f34b602 100644 (file)
@@ -19,8 +19,7 @@ strict:true, trailing:true, white:true */
     "_generatingPrivateKey": "A new keypair will be generated for this OAUTH2 client. " +
       "The public key will be saved in the database with this client. The private key " +
       "is available as a one-time download. The password for the key store file will be " +
-      "\"notasecret\". Click \"ok\" to open a new tab for " +
-      "downloading the private key",
+      "\"notasecret\". Click \"ok\" to downloading the private key.",
     "_logoURL": "Logo URL",
     "_maintainOauth2clients": "Maintain OAUTH2 Clients",
     "_oauth2": "OAUTH2",
index 11cd7fd..fd8cf4e 100644 (file)
@@ -65,35 +65,7 @@ white:true*/
         options.success = function (model, resp, options) {
           if (status === XM.Model.READY_NEW && that.get("clientType") === 'jwt bearer') {
             // Download the private key.
-
-            // The javascript download method avoids target = "_blank" and the need to
-            // reload the app to see the new client. Pop up blockers should not be an issue.
-            // @See: http://stackoverflow.com/questions/3749231/download-file-using-javascript-jquery/3749395#3749395
-            var downloadURL = function downloadURL(url) {
-              var hiddenIFrameID = 'hiddenDownloader',
-                iframe = document.getElementById(hiddenIFrameID);
-
-              if (iframe === null) {
-                iframe = document.createElement('iframe');
-                iframe.id = hiddenIFrameID;
-                iframe.style.display = 'none';
-                document.body.appendChild(iframe);
-              }
-
-              iframe.src = url;
-            };
-
-            downloadURL(XT.getOrganizationPath() + '/oauth/generate-key?id=' + that.id);
-
-            // This prompts for the download without using target = "_blank" and a new tab.
-            // It should avoid pop up blockers from preventing the download. It does warn about
-            // leaving the page, but it returns right back to the original path without needing to
-            // reload the app. Downside... it requires reloading the app to see the client just added.
-            //window.location.assign(XT.getOrganizationPath() + '/oauth/generate-key?id=' + that.id);
-
-            // This opens the download in a new tab and causes pop up blockers to block this action.
-            //window.open(XT.getOrganizationPath() + '/oauth/generate-key?id=' + that.id,
-            //  '_newtab');
+            XV.downloadURL(XT.getOrganizationPath() + '/oauth/generate-key?id=' + that.id);
           }
 
           if (success) { success(model, resp, options); }
index 2ff84e0..b5d947e 100644 (file)
@@ -130,6 +130,27 @@ trailing:true, white:true, strict: false*/
       }
     },
 
+    /**
+      The javascript download method avoids target = "_blank" and the need to
+      reload the app to see the new client. Pop up blockers should not be an issue.
+      @See: http://stackoverflow.com/questions/3749231/download-file-using-javascript-jquery/3749395#3749395
+
+      @param {String} The URL for the download route.
+    */
+    downloadURL: function (url) {
+      var hiddenIFrameID = 'hiddenDownloader',
+        iframe = document.getElementById(hiddenIFrameID);
+
+      if (iframe === null) {
+        iframe = document.createElement('iframe');
+        iframe.id = hiddenIFrameID;
+        iframe.style.display = 'none';
+        document.body.appendChild(iframe);
+      }
+
+      iframe.src = url;
+    },
+
     getCache: function (recordType) {
       return XV._modelCaches[recordType];
     },