Disable submit button until all input fields are filled in.
[arvados.git] / apps / workbench / app / views / users / _setup_popup.html.erb
index 6f947efc7b84a49afd4ddeb51d9458822e047edb..8d44e90e5eba66a46abba2dc83316fe1a51406cc 100644 (file)
@@ -1,44 +1,70 @@
- <div class="modal-header">
-    <h3 id="myModalLabel">Information you had already provided is prefilled for you. You may change it as needed.</h3>
-  </div>
-
   <div class="modal-body">
-    <%= uuid = @object.uuid %>
-    <%= disable_email = @object.uuid? %>
-    <%= form_tag setup_user_url(id: uuid), method: 'get', remote: true, class: 'form-search' do %>    
+    <% uuid = @object.uuid %>
+    <% disable_email =  @object.uuid? %>
+    <% identity_url_prefix = @current_selections[:identity_url_prefix] %>
+    <% selected_repo = @current_selections[:repo_name] %>
+    <% selected_vm = @current_selections[:vm_uuid] %>
+    
+    <%= form_tag setup_user_url(id: uuid), {id: 'setup_form', name: 'setup_form', method: 'get', class: 'form-search', remote: true, onSubmit: "validate(); return false;"} do %>    
       <div>
         <table><tbody>
           <tr>
             <% if disable_email %>
-              <td> Email </td>
-              <td> <input id="email" maxlength="250" name="email" type="text" disabled=<%=disable_email%> > </td>
+              <td> Email </td>
+              <td> <input id="email" maxlength="250" name="email" type="text" value="<%=@object.email%>" disabled=<%=disable_email%> > </td>
             <% else %>
-              <td> Email </td>
+              <td> Email </td>
               <td> <input id="email" maxlength="250" name="email" type="text" > </td>
             <% end %>
           </tr>
           <tr>
             <% if disable_email %>
-              <td> Openid Prefix : </td>
-              <td> <input id="openid_prefix" maxlength="250" name="openid_prefix" type="text" disabled=<%=disable_email%> > </td>
+              <td> Identity URL Prefix </td>
+              <td> <input id="openid_prefix" maxlength="250" name="openid_prefix" type="text" value="<%=identity_url_prefix%>" disabled=<%=disable_email%> > </td>
             <% else %>
-              <td> Openid Prefix </td>
-              <td> <input id="openid_prefix" maxlength="250" name="openid_prefix" type="text"> </td>
+              <td> Openid Prefix </td>
+              <td> <input id="openid_prefix" maxlength="250" name="openid_prefix" type="text" value="https://www.google.com/accounts/o8/id"> </td>
             <% end %>
           </tr>
           <tr>
-            <td> Repository Name </td>
-            <td> <input id="repo_name" maxlength="250" name="repo_name" type="text">
+            <td> Repository Name </td>
+            <td> <input id="repo_name" maxlength="250" name="repo_name" type="text" value="<%=selected_repo%>">
           </tr>
           <tr>
-            <td> Virtual Machine : </td>
-            <td> <input id="vm_uuid" maxlength="250" name="vm_uuid" type="text">
+            <td> Virtual Machine </td>
+            <td>
+              <select name="vm_uuid">
+                <% @vms.each do |vm| %>
+                  <% if selected_vm == vm.uuid %>
+                    <option value=<%=vm.uuid%> selected> <%=vm.hostname%> </option>
+                  <% else %> 
+                    <option value=<%=vm.uuid%> > <%=vm.hostname%> </option>
+                  <% end %>
+                <% end %>
+              </select>
+            </td>
           </tr>
         </tbody></table>
       </div>
       <div align="left">
-        <button type="submit" class="btn">Submit</button>
-        <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
+        <button type="submit" id="register" class="btn btn-primary" autofocus>Submit</button>
+        <button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Cancel</button>
       </div>
     <% end %>
   </div>
+
+<script>
+  var $input = $('input:text'),
+  $register = $('#register');    
+  $register.attr('disabled', true);
+
+  $input.keyup(function() {
+    var trigger = false;
+    $input.each(function() {
+        if (!$(this).val()) {
+            trigger = true;
+        }
+    });
+    trigger ? $register.attr('disabled', true) : $register.removeAttr('disabled');
+  });
+</script>