Merge branch 'master' into 3296-user-profile
[arvados.git] / apps / workbench / app / views / users / profile.html.erb
1 <%
2     profile_config = Rails.configuration.user_profile_form_fields
3     current_user_profile = current_user.prefs[:profile]
4     show_save_button = false
5
6     profile_message = Rails.configuration.user_profile_form_message ? Rails.configuration.user_profile_form_message : 'You can manage your profile using this page. Any feilds in red are required and missing. Please fill in those fields before you can accesse Arvados Workbench.'
7
8     missing_required = missing_required_profile?
9
10     profile_url = '/users/'+current_user.uuid+'/profile'
11     target = request.url.partition('?target=')[-1]
12     target = request.url if target.empty?
13     return_to_url = (request.url.ends_with? profile_url) ? profile_url : profile_url+'?target='+target
14 %>
15
16 <div>
17     <div class="panel panel-default">
18         <div class="panel-heading">
19           <h4 class="panel-title">
20             Profile
21           </h4>
22         </div>
23         <div class="panel-body">
24           <% if !missing_required && params.andand.keys.include?('target') %>
25             <div class="rounded" style="border-width: 1px; border-style: dotted; border-color: lightgray;">
26               <p style="margin: 8px;">Thank you for filling in your profile. If you are done updating your profile,
27                  you can now access Arvados Workbench by clicking on this button.
28                   <form action="<%=target%>">
29                     <input style="margin-left: 8px;" class="btn btn-primary" type="submit" value="Access Arvados Workbench">
30                   </form>
31               </p>
32             </div>
33           <% else %>
34             <div class="rounded" style="border-width: 1px; border-style: dotted; border-color: lightgray;">
35               <p style="margin: 8px;"> <%=raw(profile_message)%> </p>
36             </div>
37           <% end %>
38
39           <div class="rounded" style="border-width: 1px; border-style: dotted; border-color: lightgray;">
40             <%= form_tag "/users/#{current_user.uuid}", {method: 'patch', id: 'save_profile_form', name: 'save_profile_form', class: 'form-horizontal'} do %>
41               <%= hidden_field_tag :return_to, return_to_url %>
42               <div class="form-group">
43                   <label for="email" class="col-sm-3 control-label"> Email </label>
44                   <div class="col-sm-8">
45                     <p class="form-control-static" id="email" name="email"><%=current_user.email%></p>
46                   </div>
47               </div>
48               <div class="form-group">
49                   <label for="first_name" class="col-sm-3 control-label"> First name </label>
50                   <div class="col-sm-8">
51                     <p class="form-control-static" id="first_name" name="first_name"><%=current_user.first_name%></p>
52                   </div>
53               </div>
54               <div class="form-group">
55                   <label for="last_name" class="col-sm-3 control-label"> Last name </label>
56                   <div class="col-sm-8">
57                     <p class="form-control-static" id="last_name" name="last_name"><%=current_user.last_name%></p>
58                   </div>
59               </div>
60               <div class="form-group">
61                   <label for="identity_url" class="col-sm-3 control-label"> Identity URL </label>
62                   <div class="col-sm-8">
63                     <p class="form-control-static" id="identity_url" name="identity_url"><%=current_user.andand.identity_url%></p>
64                   </div>
65               </div>
66
67               <% profile_config.kind_of?(Array) && profile_config.andand.each do |entry| %>
68                 <% if entry['key'] %>
69                   <%
70                       show_save_button = true
71                       label = entry['required'] ? '* ' : ''
72                       label += entry['form_field_title']
73                       value = current_user_profile[entry['key'].to_sym] if current_user_profile
74                   %>
75                   <div class="form-group">
76                     <label for="<%=entry['key']%>"
77                            class="col-sm-3 control-label"
78                            style=<%="color:red" if entry['required']&&(!value||value.empty?)%>> <%=label%>
79                     </label>
80                     <% if entry['type'] == 'select' %>
81                       <div class="col-sm-8">
82                         <select class="form-control" name="user[prefs][:profile][:<%=entry['key']%>]">
83                           <% entry['options'].each do |option| %>
84                             <option value="<%=option%>" <%='selected' if option==value%>><%=option%></option>
85                           <% end %>
86                         </select>
87                       </div>
88                     <% else %>
89                       <div class="col-sm-8">
90                         <input type="text" class="form-control" name="user[prefs][:profile][:<%=entry['key']%>]" placeholder="<%=entry['form_field_description']%>" value="<%=value%>" ></input>
91                       </div>
92                     <% end %>
93                   </div>
94                 <% end %>
95               <% end %>
96
97               <% if show_save_button %>
98                 <div class="form-group">
99                   <div class="col-sm-offset-3 col-sm-8">
100                     <button type="submit" class="btn btn-primary">Save profile</button>
101                   </div>
102                 </div>
103               <% end %>
104             <% end %>
105           </div>
106         </div>
107     </div>
108 </div>