4951: add ajax handling for request shell access button.
authorRadhika Chippada <radhika@curoverse.com>
Wed, 4 Feb 2015 23:54:18 +0000 (18:54 -0500)
committerRadhika Chippada <radhika@curoverse.com>
Wed, 4 Feb 2015 23:54:18 +0000 (18:54 -0500)
apps/workbench/app/assets/javascripts/request_shell_access.js [new file with mode: 0644]
apps/workbench/app/views/users/_manage_virtual_machines.html.erb
apps/workbench/config/routes.rb

diff --git a/apps/workbench/app/assets/javascripts/request_shell_access.js b/apps/workbench/app/assets/javascripts/request_shell_access.js
new file mode 100644 (file)
index 0000000..57e3026
--- /dev/null
@@ -0,0 +1,18 @@
+$(document).
+  on('click', "#request_shell_submit", function(e){
+    $(this).html('Sending request ...');
+    $(this).prop('disabled', true);
+    $('div').remove('.request_shell_access_failed');
+
+    $.ajax('/').
+      success(function(data, status, jqxhr) {
+        $('div').remove('.no_shell_access_msg');
+        $('.no_shell_access').append('<div class="alert alert-success"><p class="contain-align-left">Request sent for shell access.</p></div>');
+      }).
+      fail(function(jqxhr, status, error) {
+        var $sendButton = $('#request_shell_submit');
+        $sendButton.html('Request shell access');
+        $sendButton.prop('disabled', false);
+        $('.no_shell_access').append('<div class="request_shell_access_failed alert alert-danger"><p class="contain-align-left">Something went wrong. Please try again.</p></div>');
+      });
+  });
index 9c40d708a1c833439d67551ea278833f418d4bb2..897f1d8369064a60527420c0f6fb9f4be6217899 100644 (file)
@@ -6,9 +6,16 @@
   </p>
 
   <% if !@my_virtual_machines.any? %>
-    You do not have access to any virtual machines. Many of the Arvados features depend on having shell access to a hosted VM.
-    &nbsp; <%= link_to 'Request shell access', request_shell_access_user_url(id: current_user.uuid),
-                        {class: 'btn btn-xs btn-primary', :remote => true}  %>
+    <div id='no_shell_access' class='no_shell_access'>
+      <div id='no_shell_access_msg' class='no_shell_access_msg'>
+        You do not have access to any virtual machines. Many of the Arvados features depend on having shell access to a hosted VM.
+        &nbsp;&nbsp;&nbsp;
+        <div style='display:inline-block'>
+          <%= button_to('Request shell access', request_shell_access_user_url(id: current_user.uuid),
+                         id: 'request_shell_submit', class: 'btn btn-xs btn-primary', remote: true) %>
+        </div>
+      </div>
+    </div>
   <% else %>
     <table class="table virtual-machines-table">
       <colgroup>
index 9225fe18cac31ccb5e1186d434b3efdead211065..7ed02e7dc9ba11aa8beb07cae5f9c934ce77fd9f 100644 (file)
@@ -39,7 +39,7 @@ ArvadosWorkbench::Application.routes.draw do
     post 'unsetup', :on => :member
     get 'setup_popup', :on => :member
     get 'profile', :on => :member
-    get 'request_shell_access', :on => :member
+    post 'request_shell_access', :on => :member
   end
   get '/manage_account' => 'users#manage_account'
   get "/add_ssh_key_popup" => 'users#add_ssh_key_popup', :as => :add_ssh_key_popup