updating preferences on user and prefs model work. also add date_format picker

This commit is contained in:
Reinier Balt 2011-08-17 22:51:02 +02:00
parent 89ec9898a3
commit 555311b681
12 changed files with 945 additions and 1010 deletions

View file

@ -1,23 +1,31 @@
class PreferencesController < ApplicationController
def index
@page_title = t('preferences.page_title')
@prefs = current_user.prefs
@user = current_user
end
def edit
@page_title = t('preferences.page_title_edit')
@prefs = current_user.prefs
end
def update
@prefs = current_user.prefs
@user = current_user
user_updated = current_user.update_attributes(params['user'])
prefs_updated = current_user.preference.update_attributes(params['prefs'])
if user_updated && prefs_updated
if (user_updated && prefs_updated)
notify :notice, "Preferences updated"
redirect_to :action => 'index'
else
render :action => 'edit'
msg = "Preferences could not be updated: "
msg += "User model errors; " unless user_updated
msg += "Prefs model errors; " unless prefs_updated
notify :warning, msg
render 'index'
end
end
def render_date_format
format = params[:date_format]
render :text => l(Date.today, :format => format)
end
end

View file

@ -1,6 +1,22 @@
<%= pref_with_text_field('prefs', 'date_format') %>
<div class='prefs_example'>This will result in: <span id='prefs.date_format'><%= l(Date.today, :format => current_user.prefs.date_format) %></span></div>
<br/>
Or pick one of the following:<br/>
<% %w{default short long longer}.each do |format| %>
<%= radio_button_tag("date_picker1", t("date.formats.#{format}")) %> <%= l(Date.today, :format => format.to_sym) %> <br/>
<% end %>
<br/>
<%= pref_with_text_field('prefs', 'title_date_format') %>
<div class='prefs_example'>This will result in: <span id='prefs.title_date_format'><%= l(Date.today, :format => current_user.prefs.title_date_format) %></span></div>
<br/>
Or pick one of the following:<br/>
<% %w{default short long longer}.each do |format| %>
<%= radio_button_tag("date_picker2", t("date.formats.#{format}")) %> <%= l(Date.today, :format => format.to_sym) %> <br/>
<% end %>
<br/>
<%= pref('prefs', 'time_zone') { time_zone_select('prefs','time_zone') } %>
<%= pref_with_select_field('prefs', "week_starts", (0..6).to_a.map {|num| [t('date.day_names')[num], num] }) %>

View file

@ -1,59 +0,0 @@
<div id="display_box" class="container context">
<%= render :partial => 'help' %>
</div>
<div id="input_box" class="container context">
<% form_tag :action => 'update' do %>
<table>
<tr>
<td><label><%= User.human_attribute_name('first_name') %></label></td>
<td><%= text_field 'user', 'first_name' %></td>
</tr>
<tr>
<td><label><%= User.human_attribute_name('last_name') %></label></td>
<td><%= text_field 'user', 'last_name' %></td>
</tr>
<%
def table_row(pref_name, nowrap_label = false, &block)
nowrap_attribute = nowrap_label ? ' nowrap="nowrap"' : ''
s = %Q|<tr>\n<td#{nowrap_attribute}><label>#{Preference.human_attribute_name(pref_name)}:</label></td>\n<td>\n|
s << yield
s << "\n</td></tr>"
s
end
def row_with_select_field(pref_name, collection = [ [t('preferences.is_true'),true], [t('preferences.is_false'), false] ], nowrap_label = false)
table_row(pref_name, nowrap_label) { select('prefs', pref_name, collection) }
end
def row_with_text_field(pref_name, nowrap_label = false)
table_row(pref_name, nowrap_label) { text_field('prefs', pref_name) }
end
%>
<%= row_with_select_field('locale', I18n.available_locales.map {|l| l.to_s}) %>
<%= row_with_text_field('date_format') %>
<%= row_with_text_field('title_date_format') %>
<%= table_row('time_zone', false) { time_zone_select('prefs','time_zone') } %>
<%= row_with_select_field("week_starts", (0..6).to_a.map {|num| [t('date.day_names')[num], num] }) %>
<%= row_with_select_field("due_style", [[t('models.preference.due_styles')[0],Preference.due_styles[:due_in_n_days]],[t('models.preference.due_styles')[1],Preference.due_styles[:due_on]]]) %>
<%= row_with_select_field("show_completed_projects_in_sidebar") %>
<%= row_with_select_field("show_hidden_projects_in_sidebar") %>
<%= row_with_select_field("show_hidden_contexts_in_sidebar") %>
<%= row_with_select_field("show_project_on_todo_done") %>
<% if current_user.is_admin? %> <%= row_with_text_field('admin_email') %> <% end %>
<%= row_with_text_field('staleness_starts', false) %>
<%= row_with_text_field('show_number_completed') %>
<%= row_with_text_field('refresh') %>
<%= row_with_select_field("verbose_action_descriptors") %>
<%= row_with_text_field("mobile_todos_per_page") %>
<%= row_with_text_field("sms_email") %>
<%= table_row("sms_context", false) { select('prefs', 'sms_context_id', current_user.contexts.map{|c| [c.name, c.id]}) } %>
<tr><td><%= submit_tag t('common.update') %></td>
<td><%= link_to t('common.cancel'), :action => 'index' %></td>
</tr>
</table>
<% end %>
</div>

View file

@ -1,4 +1,7 @@
<div id="display_box">
<div id="edit_error_status"><%= error_messages_for(:user) + error_messages_for(:prefs) %></div>
<% form_tag :action => 'update' do %>
<div id="tabs">
<ul>

View file

@ -1,68 +0,0 @@
<div id="single_box" class="container context prefscontainer">
<h2><%= t('preferences.title') %></h2>
<ul id="prefs">
<li><%= User.human_attribute_name('first_name') %>: <span class="highlight"><%= current_user.first_name %></span></li>
<li><%= User.human_attribute_name('last_name') %>: <span class="highlight"><%= current_user.last_name %></span></li>
<li><%= Preference.human_attribute_name('date_format') %>: <span class="highlight"><%= current_user.prefs.date_format %></span> Your current date: <%= format_date(current_user.time) %></li>
<li><%= Preference.human_attribute_name('locale') %>: <span class="highlight"><%= current_user.prefs.locale %></span></li>
<li><%= Preference.human_attribute_name('title_date_format') %>: <span class="highlight"><%= current_user.prefs.title_date_format %></span> Your current title date: <%= current_user.time.strftime(current_user.prefs.title_date_format) %></li>
<li><%= Preference.human_attribute_name('time_zone') %>: <span class="highlight"><%= current_user.prefs.time_zone %></span> Your current time: <%= current_user.time.strftime('%I:%M %p') %></li>
<li><%= Preference.human_attribute_name('week_starts') %>: <span class="highlight"><%= t('date.day_names')[current_user.prefs.week_starts] %></span></li>
<li><%= t('preferences.show_number_completed', :number=> "<span class=\"highlight\">#{current_user.prefs.show_number_completed}</span>")%></li>
<li><%= Preference.human_attribute_name('show_completed_projects_in_sidebar') %>: <span class="highlight"><%= current_user.prefs.show_completed_projects_in_sidebar %></span></li>
<li><%= Preference.human_attribute_name('show_hidden_projects_in_sidebar') %>: <span class="highlight"><%= current_user.prefs.show_hidden_projects_in_sidebar %></span></li>
<li><%= Preference.human_attribute_name('show_hidden_contexts_in_sidebar') %>: <span class="highlight"><%= current_user.prefs.show_hidden_contexts_in_sidebar %></span></li>
<li><%= Preference.human_attribute_name('show_project_on_todo_done') %>: <span class="highlight"><%= current_user.prefs.show_project_on_todo_done %></span></li>
<li><%= t('preferences.staleness_starts_after', :days => "<span class=\"highlight\">#{current_user.prefs.staleness_starts}</span>") %></li>
<li><%= Preference.human_attribute_name('due_style') %>: <span class="highlight">
<% if prefs.due_style == Preference.due_styles[:due_in_n_days] %>
<%= t('models.preference.due_styles')[0] %>
<% else %>
<%= t('models.preference.due_styles')[1] %>
<% end %>
</span></li>
<% if current_user.is_admin? %>
<li><%= Preference.human_attribute_name('admin_email') %>: <span class="highlight"><%= current_user.prefs.admin_email %></span></li>
<% end %>
<li><%= Preference.human_attribute_name('refresh') %>: <span class="highlight"><%= current_user.prefs.refresh %></span></li>
<li><%= Preference.human_attribute_name('verbose_action_descriptors') %>: <span class="highlight"><%= current_user.prefs.verbose_action_descriptors %></span></li>
<li><%= Preference.human_attribute_name('mobile_todos_per_page') %>: <span class="highlight"><%= current_user.prefs.mobile_todos_per_page %></span></li>
<li><%= Preference.human_attribute_name('sms_email') %>: <span class="highlight"><%= current_user.prefs.sms_email %></span></li>
<li><%= Preference.human_attribute_name('sms_context') %>: <span class="highlight"><%= current_user.prefs.sms_context.nil? ? t('preferences.sms_context_none') : current_user.prefs.sms_context.name %></span></li>
</ul>
<div class="actions">
<%= link_to t('preferences.edit_preferences') + " &raquo;", { :controller => 'preferences', :action => 'edit'}, :class => 'edit_link' %>
</div>
<h2><%= t('preferences.token_header') %></h2>
<div id="token_area">
<div class="description"><%= t('preferences.token_description') %>:</div>
<div id="token"><span class="highlight"><%= current_user.token %></span></div>
<div class="token_regenerate">
<%= button_to t('preferences.generate_new_token'), refresh_token_user_path(current_user),
:confirm => t('preferences.generate_new_token_confirm') %>
</div>
</div>
<h2><%= t('preferences.authentication_header') %></h2>
<div id="authentication_area">
<% if Tracks::Config.auth_schemes.length > 1 %>
<p><%= t('preferences.current_authentication_type', :auth_type => "<span class=\"highlight\">#{current_user.auth_type}</span>") %>.</p>
<div class="actions">
<%= link_to(t('preferences.change_authentication_type') + " &raquo;", change_auth_type_user_path(current_user), :class => 'edit_link') %>
</div>
<% end %>
<% if current_user.auth_type == 'database' %>
<div class="actions">
<%= link_to(t('preferences.change_password') + ' &raquo;', change_password_user_path(current_user)) %>
</div>
<% end %>
<% if current_user.auth_type == 'open_id' %>
<p><%= t('preferences.open_id_url') %> <span class="highlight"><%= current_user.open_id_url %></span>.</p>
<div class="actions">
<%= link_to(t('preferences.change_identity_url') + ' &raquo;', change_auth_type_user_path(current_user)) %>
</div>
<% end %>
</div>
</div>