a1c3f8adc3649681acbcf662e888ec1248fc95fb
[arvados.git] / apps / workbench / app / views / users / _setup_popup.html.erb
1   <div class="modal-header">
2     <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
3     <h3 class="modal-title">Setup User</h4>
4   </div
5
6   <div class="modal-body">
7     <% if @object%>
8       <% uuid = @object.uuid %>
9       <% email = @object.email %>
10     <% end %>
11     <% disable_email = uuid != nil %>
12     <% identity_url_prefix = @current_selections[:identity_url_prefix] %>
13     <% disable_url_prefix = identity_url_prefix != nil %>
14     <% selected_repo = @current_selections[:repo_name] %>
15     <% selected_vm = @current_selections[:vm_uuid] %>
16     
17     <%= form_tag setup_user_path, {id: 'setup_form', name: 'setup_form', method: 'get', 
18                     class: 'form-search', remote: true} do %>
19       <input id="user_uuid" maxlength="250" name="user_uuid" type="hidden" value="<%=uuid%>">
20       <div>
21         <table><tbody>
22           <tr>
23             <% if disable_email %>
24               <td> Email </td>
25               <td> <input id="email" maxlength="250" name="email" type="text" value="<%=email%>" 
26                     disabled=true > </td>
27             <% else %>
28               <td> Email </td>
29               <td> <input id="email" maxlength="250" name="email" type="text" > </td>
30             <% end %>
31           </tr>
32           <tr>
33             <% if disable_url_prefix %>
34               <td> Identity URL Prefix &nbsp </td>
35               <td> <input id="openid_prefix" maxlength="250" name="openid_prefix" type="text" 
36                     value="<%=identity_url_prefix%>" disabled=true > </td>
37             <% else %>
38               <td> Openid Prefix </td>
39               <td> <input id="openid_prefix" maxlength="250" name="openid_prefix" type="text" 
40                     value="<%= Rails.configuration.default_openid_prefix %>"> </td>
41             <% end %>
42           </tr>
43           <tr>
44             <td> Repository Name </td>
45             <td> <input id="repo_name" maxlength="250" name="repo_name" type="text" value="<%=selected_repo%>">
46           </tr>
47           <tr>
48             <td> Virtual Machine </td>
49             <td>
50               <select name="vm_uuid">
51                 <% if selected_vm %>
52                   <option value=""> Choose One: </option>
53                 <% else %>
54                   <option value="" selected> Choose One: </option>
55                 <% end %>
56                 <% @vms.each do |vm| %>
57                   <% if selected_vm == vm.uuid %>
58                     <option value=<%=vm.uuid%> selected> <%=vm.hostname%> </option>
59                   <% else %> 
60                     <option value=<%=vm.uuid%> > <%=vm.hostname%> </option>
61                   <% end %>
62                 <% end %>
63               </select>
64             </td>
65           </tr>
66         </tbody></table>
67       </div>
68     <% end %>
69   </div>
70
71   <div class="modal-footer">
72     <button type="submit" id="register" class="btn btn-primary" autofocus>Submit</button>
73     <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Cancel</button>
74   </div>
75
76 <script>
77   var $input = $('input:text'),
78   $register = $('#register');
79
80   var email_disabled = document.forms["setup_form"]["email"].disabled;
81   var email_value = document.forms["setup_form"]["email"].value;
82   var prefix_value = document.forms["setup_form"]["openid_prefix"].value;
83   if ((email_disabled == false) && (email_value == null || email_value == "" || 
84         prefix_value == null || prefix_value == "")) {
85     $register.attr('disabled', true);
86   }
87
88   $input.keyup(function() {
89     var trigger = false;
90
91     var email_disabled = document.forms["setup_form"]["email"].disabled;
92     var email_value = document.forms["setup_form"]["email"].value;
93     var prefix_value = document.forms["setup_form"]["openid_prefix"].value;
94
95     var emailRegExp = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
96     var validEmail = false;
97     if (emailRegExp.test(email_value )) {
98       validEmail = true;
99     }
100
101     if ((email_disabled == false) && (!validEmail || email_value == null || 
102             email_value == "" || prefix_value == null || prefix_value == "")){
103       trigger = true;
104     }
105
106     trigger ? $register.attr('disabled', true) : $register.removeAttr('disabled');
107   });
108 </script>