Merge branch '5414-keep-service-hints' refs #5414
[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
7 %>
8
9 <div>
10     <div class="panel panel-default">
11         <div class="panel-heading">
12           <h4 class="panel-title">
13             Profile
14           </h4>
15         </div>
16         <div class="panel-body">
17           <% if !missing_required_profile? && params[:offer_return_to] %>
18             <div class="alert alert-success">
19               <% if current_user.prefs[:getting_started_shown] %>
20                 <p>Thank you for filling in your profile. <%= link_to 'Back to work!', params[:offer_return_to], class: 'btn btn-sm btn-primary' %></p>
21               <% else %>
22                 <p>Thank you for filling in your profile. <%= link_to 'Get started', params[:offer_return_to], class: 'btn btn-sm btn-primary' %></p>
23               <% end %>
24             </div>
25           <% else %>
26             <div class="alert alert-info">
27               <p><%=raw(profile_message)%></p>
28             </div>
29           <% end %>
30
31             <%= form_for current_user, html: {id: 'save_profile_form', name: 'save_profile_form', class: 'form-horizontal'} do %>
32               <%= hidden_field_tag :offer_return_to, params[:offer_return_to] %>
33               <%= hidden_field_tag :return_to, profile_user_path(current_user.uuid, offer_return_to: params[:offer_return_to]) %>
34               <div class="form-group">
35                   <label for="email" class="col-sm-3 control-label"> E-mail </label>
36                   <div class="col-sm-8">
37                     <p class="form-control-static" id="email" name="email"><%=current_user.email%></p>
38                   </div>
39               </div>
40               <div class="form-group">
41                   <label for="first_name" class="col-sm-3 control-label"> First Name </label>
42                   <div class="col-sm-8">
43                     <p class="form-control-static" id="first_name" name="first_name"><%=current_user.first_name%></p>
44                   </div>
45               </div>
46               <div class="form-group">
47                   <label for="last_name" class="col-sm-3 control-label"> Last Name </label>
48                   <div class="col-sm-8">
49                     <p class="form-control-static" id="last_name" name="last_name"><%=current_user.last_name%></p>
50                   </div>
51               </div>
52               <div class="form-group">
53                   <label for="identity_url" class="col-sm-3 control-label"> Identity URL </label>
54                   <div class="col-sm-8">
55                     <p class="form-control-static" id="identity_url" name="identity_url"><%=current_user.andand.identity_url%></p>
56                   </div>
57               </div>
58
59               <% profile_config.kind_of?(Array) && profile_config.andand.each do |entry| %>
60                 <% if entry['key'] %>
61                   <%
62                       show_save_button = true
63                       label = entry['required'] ? '* ' : ''
64                       label += entry['form_field_title']
65                       value = current_user_profile[entry['key'].to_sym] if current_user_profile
66                   %>
67                   <div class="form-group">
68                     <label for="<%=entry['key']%>"
69                            class="col-sm-3 control-label"
70                            style=<%="color:red" if entry['required']&&(!value||value.empty?)%>> <%=label%>
71                     </label>
72                     <% if entry['type'] == 'select' %>
73                       <div class="col-sm-8">
74                         <select class="form-control" name="user[prefs][:profile][:<%=entry['key']%>]">
75                           <% entry['options'].each do |option| %>
76                             <option value="<%=option%>" <%='selected' if option==value%>><%=option%></option>
77                           <% end %>
78                         </select>
79                       </div>
80                     <% else %>
81                       <div class="col-sm-8">
82                         <input type="text" class="form-control" name="user[prefs][:profile][:<%=entry['key']%>]" placeholder="<%=entry['form_field_description']%>" value="<%=value%>" ></input>
83                       </div>
84                     <% end %>
85                   </div>
86                 <% end %>
87               <% end %>
88
89               <%# If the user has other prefs, we need to preserve them %>
90               <% current_user.prefs.each do |key, value| %>
91                 <% if key != :profile %>
92                   <input type="hidden" name="user[prefs][:<%=key%>]" value="<%=value.to_json%>">
93                 <% end %>
94               <% end %>
95
96               <% if show_save_button %>
97                 <div class="form-group">
98                   <div class="col-sm-offset-3 col-sm-8">
99                     <button type="submit" class="btn btn-primary">Save profile</button>
100                   </div>
101                 </div>
102               <% end %>
103             <% end %>
104         </div>
105     </div>
106 </div>