3551: Merge branch 'master' into 3551-go-layout
[arvados.git] / apps / workbench / app / views / users / profile.html.erb
index 620b3ee459b530d1dbeccec61174a8f687c284b6..2c40fefb63d39c36d6bdc8aeed3fb5e76a5ada0a 100644 (file)
@@ -1,9 +1,16 @@
 <%
     profile_config = Rails.configuration.user_profile_form_fields
-    this_user = User.limit(1).where(uuid: current_user.uuid).first
-    user_prefs = User.limit(1).where(uuid: current_user.uuid).first.prefs
-    current_user_profile = user_prefs[:profile] if user_prefs
+    current_user_profile = current_user.prefs[:profile]
     show_save_button = false
+
+    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.'
+
+    missing_required = missing_required_profile?
+
+    profile_url = '/users/'+current_user.uuid+'/profile'
+    target = request.url.partition('?target=')[-1]
+    target = request.url if target.empty?
+    return_to_url = (request.url.ends_with? profile_url) ? profile_url : profile_url+'?target='+target
 %>
 
 <div>
           </h4>
         </div>
         <div class="panel-body">
-          <div>
-            <% profile_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.'
-                  profile_config.kind_of?(Array) && profile_config.andand.each do |entry| 
-                  if entry['message']
-                    profile_message = entry['message']
-                    break
-                  end
-                end %>
-            <p> <%=profile_message%> </p><br/>
-          </div>
-          <div>
+          <% if !missing_required && params.andand.keys.include?('target') %>
+            <div class="rounded" style="border-width: 1px; border-style: dotted; border-color: lightgray;">
+              <p style="margin: 8px;">Thank you for filling in your profile. If you are done updating your profile,
+                 you can now access Arvados Workbench by clicking on this button.
+                  <form action="<%=target%>">
+                    <input style="margin-left: 8px;" class="btn btn-primary" type="submit" value="Access Arvados Workbench">
+                  </form>
+              </p>
+            </div>
+          <% else %>
+            <div class="rounded" style="border-width: 1px; border-style: dotted; border-color: lightgray;">
+              <p style="margin: 8px;"> <%=raw(profile_message)%> </p>
+            </div>
+          <% end %>
+
+          <div class="rounded" style="border-width: 1px; border-style: dotted; border-color: lightgray;">
             <%= form_tag "/users/#{current_user.uuid}", {method: 'patch', id: 'save_profile_form', name: 'save_profile_form', class: 'form-horizontal'} do %>
-              <%= hidden_field_tag :return_to, request.url %>
+              <%= hidden_field_tag :return_to, return_to_url %>
               <div class="form-group">
                   <label for="email" class="col-sm-3 control-label"> Email </label>
-                  <div class="col-sm-9">
+                  <div class="col-sm-8">
                     <p class="form-control-static" id="email" name="email"><%=current_user.email%></p>
                   </div>
               </div>
               <div class="form-group">
                   <label for="first_name" class="col-sm-3 control-label"> First name </label>
-                  <div class="col-sm-9">
+                  <div class="col-sm-8">
                     <p class="form-control-static" id="first_name" name="first_name"><%=current_user.first_name%></p>
                   </div>
               </div>
               <div class="form-group">
                   <label for="last_name" class="col-sm-3 control-label"> Last name </label>
-                  <div class="col-sm-9">
+                  <div class="col-sm-8">
                     <p class="form-control-static" id="last_name" name="last_name"><%=current_user.last_name%></p>
                   </div>
               </div>
               <div class="form-group">
                   <label for="identity_url" class="col-sm-3 control-label"> Identity URL </label>
-                  <div class="col-sm-9">
-                    <p class="form-control-static" id="identity_url" name="identity_url"><%=this_user.andand.identity_url%></p>
+                  <div class="col-sm-8">
+                    <p class="form-control-static" id="identity_url" name="identity_url"><%=current_user.andand.identity_url%></p>
                   </div>
               </div>
 
                   <div class="form-group">
                     <label for="<%=entry['key']%>"
                            class="col-sm-3 control-label"
-                           style=<%="color:red" if entry['required']&&!value%>> <%=label%>
+                           style=<%="color:red" if entry['required']&&(!value||value.empty?)%>> <%=label%>
                     </label>
                     <% if entry['type'] == 'select' %>
-                      <div class="col-sm-9">
-                        <select class="form-control" id="user[prefs][:profile][:<%=entry['key']%>]" name="user[prefs][:profile][:<%=entry['key']%>]">
+                      <div class="col-sm-8">
+                        <select class="form-control" name="user[prefs][:profile][:<%=entry['key']%>]">
                           <% entry['options'].each do |option| %>
                             <option value="<%=option%>" <%='selected' if option==value%>><%=option%></option>
                           <% end %>
                         </select>
                       </div>
                     <% else %>
-                      <div class="col-sm-9">
-                        <input type="text" class="form-control" id="user[prefs][:profile][:<%=entry['key']%>]" name="user[prefs][:profile][:<%=entry['key']%>]" placeholder="<%=entry['form_field_description']%>" value="<%=value%>" ></input>
+                      <div class="col-sm-8">
+                        <input type="text" class="form-control" name="user[prefs][:profile][:<%=entry['key']%>]" placeholder="<%=entry['form_field_description']%>" value="<%=value%>" ></input>
                       </div>
                     <% end %>
                   </div>
@@ -85,7 +96,7 @@
 
               <% if show_save_button %>
                 <div class="form-group">
-                  <div class="col-sm-offset-3 col-sm-9">
+                  <div class="col-sm-offset-3 col-sm-8">
                     <button type="submit" class="btn btn-primary">Save profile</button>
                   </div>
                 </div>