Arvados-DCO-1.1-Signed-off-by: Radhika Chippada <radhika@curoverse.com>
[arvados.git] / apps / workbench / app / assets / javascripts / request_shell_access.js
index c8cbe347fc257bd2b2b1e0e352131fd98b19e8af..eb4fbc39018ad02c92f11f10fd411bcaedafd531 100644 (file)
@@ -1,19 +1,14 @@
-$(document).
-  on('click', "#request_shell_submit", function(e){
-    $(this).html('Sending request ...');
-    $(this).prop('disabled', true);
-    $('div').remove('.request_shell_access_failed');
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
 
-    $.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>');
-        localStorage.setItem("request_shell_access", "sent");
-      }).
-      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>');
-      });
-  });
+$(document).on('ready ajax:success storage', function() {
+    // Update the "shell access requested" info box according to the
+    // current state of localStorage.
+    var msg = localStorage.getItem('request_shell_access');
+    var $noShellAccessDiv = $('#no_shell_access');
+    if ($noShellAccessDiv.length > 0) {
+        $('.alert-success p', $noShellAccessDiv).text(msg);
+        $('.alert-success', $noShellAccessDiv).toggle(!!msg);
+    }
+});