download button for ssh commands
Scott Baker [Mon, 26 Jan 2015 01:04:00 +0000 (17:04 -0800)]
planetstack/core/xoslib/static/js/xosTenant.js

index 79e093e..4225cac 100644 (file)
@@ -297,25 +297,8 @@ XOSTenantApp.editUsers = function(model) {
     $("#tenant-edit-users-dialog").dialog("open");\r
 };\r
 \r
-XOSTenantApp.downloadSSHOld = function(model) {\r
-    sshCommands = "";\r
-    for (index in model.attributes.sliceInfo.sshCommands) {\r
-         sshCommand = model.attributes.sliceInfo.sshCommands[index];\r
-         sshCommands = sshCommands + sshCommand + "\n";\r
-    }\r
-\r
-    if (sshCommands.length == 0) {\r
-         alert("this slice has no instantiated slivers yet");\r
-         return;\r
-    }\r
-\r
-    var myWindow = window.open("", "ssh_command_list",""); // "width=640, height=480");\r
-    myWindow.document.write("<html><head><title>SSH Commands</title></head><body><pre>" + sshCommands + "</pre></body></html>");\r
-    myWindow.document.close();\r
-};\r
-\r
 XOSTenantApp.downloadSSH = function(model) {\r
-    sshCommands = "";\r
+    var sshCommands = "";\r
     for (index in model.attributes.sliceInfo.sshCommands) {\r
          sshCommand = model.attributes.sliceInfo.sshCommands[index];\r
          sshCommands = sshCommands + sshCommand + "\n";\r
@@ -334,7 +317,15 @@ XOSTenantApp.downloadSSH = function(model) {
        modal: true,
        width: 640,
        buttons : {
-            "Ok" : function() {
+            "Download": function() {
+                var dlLink = document.createElement('a');
+                dlLink.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(sshCommands));
+                dlLink.setAttribute('download', 'sshcommands.txt');
+                dlLink.click();
+
+                //window.open('data:text/text,' + encodeURIComponent(sshCommands));
+            },
+            "Close" : function() {
               $(this).dialog("close");
             },
           }