diff --git a/app/controllers/preferences_controller.rb b/app/controllers/preferences_controller.rb index db27434b..e1c8638c 100644 --- a/app/controllers/preferences_controller.rb +++ b/app/controllers/preferences_controller.rb @@ -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 diff --git a/app/helpers/preferences_helper.rb b/app/helpers/preferences_helper.rb index 8838ec68..4dd9330e 100644 --- a/app/helpers/preferences_helper.rb +++ b/app/helpers/preferences_helper.rb @@ -1,2 +1,18 @@ module PreferencesHelper + + def pref(model, pref_name, &block) + s = "
" + s << yield + s << "

" + s + end + + def pref_with_select_field(model, pref_name, collection = [ [t('preferences.is_true'),true], [t('preferences.is_false'), false] ]) + pref(model, pref_name) { select(model, pref_name, collection) } + end + + def pref_with_text_field(model, pref_name) + pref(model, pref_name) { text_field(model, pref_name) } + end + end diff --git a/app/views/preferences/_authentication.html.erb b/app/views/preferences/_authentication.html.erb new file mode 100644 index 00000000..64afc8e7 --- /dev/null +++ b/app/views/preferences/_authentication.html.erb @@ -0,0 +1,37 @@ +

+<%= t('preferences.token_description') %>: <%= current_user.token %> +

+ +
+ +<% # TODO: make remote AJAX call for new token %> + +<%= link_to( + t('preferences.generate_new_token'), + refresh_token_user_path( current_user ), + :method => :post, + :confirm => t('preferences.generate_new_token_confirm'), + :id=>'prefs_new_token') %> + +
+
+ +<% if Tracks::Config.auth_schemes.length > 1 %> +
+ <% Tracks::Config.auth_schemes.each do |scheme| %> + <%= radio_button_tag('user[auth_type]', scheme, current_user.auth_type == scheme) %><%=scheme%>
+ <% end %> + +
+ +
+
+ +
+ +
+ <%= render :partial => 'users/update_password' %> +
+ +<% end %> + diff --git a/app/views/preferences/_date_and_time.html.erb b/app/views/preferences/_date_and_time.html.erb new file mode 100644 index 00000000..60c94f5b --- /dev/null +++ b/app/views/preferences/_date_and_time.html.erb @@ -0,0 +1,23 @@ +<%= pref_with_text_field('prefs', 'date_format') %> + +
This will result in: <%= l(Date.today, :format => current_user.prefs.date_format) %>
+
+Or pick one of the following:
+<% %w{default short long longer}.each do |format| %> +<%= radio_button_tag("date_picker1", t("date.formats.#{format}")) %> <%= l(Date.today, :format => format.to_sym) %>
+<% end %> +
+ +<%= pref_with_text_field('prefs', 'title_date_format') %> +
This will result in: <%= l(Date.today, :format => current_user.prefs.title_date_format) %>
+
+Or pick one of the following:
+<% %w{default short long longer}.each do |format| %> +<%= radio_button_tag("date_picker2", t("date.formats.#{format}")) %> <%= l(Date.today, :format => format.to_sym) %>
+<% end %> +
+ +<%= 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] }) %> + diff --git a/app/views/preferences/_profile.html.erb b/app/views/preferences/_profile.html.erb new file mode 100644 index 00000000..478df97b --- /dev/null +++ b/app/views/preferences/_profile.html.erb @@ -0,0 +1,6 @@ +<%= pref_with_text_field 'user', 'first_name' %> +<%= pref_with_text_field 'user', 'last_name' %> +<%= pref_with_select_field('prefs', 'locale', I18n.available_locales.map {|l| l.to_s}) %> +<% if current_user.is_admin? %> + <%= pref_with_text_field('prefs', 'admin_email') %> +<% end %> diff --git a/app/views/preferences/_tracks_behavior.html.erb b/app/views/preferences/_tracks_behavior.html.erb new file mode 100644 index 00000000..480b647f --- /dev/null +++ b/app/views/preferences/_tracks_behavior.html.erb @@ -0,0 +1,13 @@ + +<%= pref_with_select_field('prefs', "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]]]) %> +<%= pref_with_select_field('prefs', "show_completed_projects_in_sidebar") %> +<%= pref_with_select_field('prefs', "show_hidden_projects_in_sidebar") %> +<%= pref_with_select_field('prefs', "show_hidden_contexts_in_sidebar") %> +<%= pref_with_select_field('prefs', "show_project_on_todo_done") %> +<%= pref_with_text_field('prefs', 'staleness_starts') %> +<%= pref_with_text_field('prefs', 'show_number_completed') %> +<%= pref_with_text_field('prefs', 'refresh') %> +<%= pref_with_select_field('prefs', "verbose_action_descriptors") %> +<%= pref_with_text_field('prefs', "mobile_todos_per_page") %> +<%= pref_with_text_field('prefs', "sms_email") %> +<%= pref('prefs', "sms_context") { select('prefs', 'sms_context_id', current_user.contexts.map{|c| [c.name, c.id]}) } %> diff --git a/app/views/preferences/edit.html.erb b/app/views/preferences/edit.html.erb deleted file mode 100644 index e2485b40..00000000 --- a/app/views/preferences/edit.html.erb +++ /dev/null @@ -1,59 +0,0 @@ -
- <%= render :partial => 'help' %> -
- -
- <% form_tag :action => 'update' do %> - - - - - - - - - - <% - def table_row(pref_name, nowrap_label = false, &block) - nowrap_attribute = nowrap_label ? ' nowrap="nowrap"' : '' - s = %Q|\n\n" - 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]}) } %> - - - - -
<%= text_field 'user', 'first_name' %>
<%= text_field 'user', 'last_name' %>
\n| - s << yield - s << "\n
<%= submit_tag t('common.update') %><%= link_to t('common.cancel'), :action => 'index' %>
- <% end %> -
diff --git a/app/views/preferences/index.html.erb b/app/views/preferences/index.html.erb index 138aef73..65c37c77 100644 --- a/app/views/preferences/index.html.erb +++ b/app/views/preferences/index.html.erb @@ -1,68 +1,32 @@ -
+
-

<%= t('preferences.title') %>

+
<%= error_messages_for(:user) + error_messages_for(:prefs) %>
- -
- <%= link_to t('preferences.edit_preferences') + " »", { :controller => 'preferences', :action => 'edit'}, :class => 'edit_link' %> -
- -

<%= t('preferences.token_header') %>

-
-
<%= t('preferences.token_description') %>:
-
<%= current_user.token %>
-
- <%= button_to t('preferences.generate_new_token'), refresh_token_user_path(current_user), - :confirm => t('preferences.generate_new_token_confirm') %> + <% form_tag :action => 'update' do %> +
+ +
+ <%= render :partial => 'profile'%> +
+
+ <%= render :partial => 'authentication'%> +
+
+ <%= render :partial => 'date_and_time'%> +
+
+ <%= render :partial => 'tracks_behavior'%>
-

<%= t('preferences.authentication_header') %>

-
- <% if Tracks::Config.auth_schemes.length > 1 %> -

<%= t('preferences.current_authentication_type', :auth_type => "#{current_user.auth_type}") %>.

-
- <%= link_to(t('preferences.change_authentication_type') + " »", change_auth_type_user_path(current_user), :class => 'edit_link') %> -
- <% end %> - <% if current_user.auth_type == 'database' %> -
- <%= link_to(t('preferences.change_password') + ' »', change_password_user_path(current_user)) %> -
- <% end %> - <% if current_user.auth_type == 'open_id' %> -

<%= t('preferences.open_id_url') %> <%= current_user.open_id_url %>.

-
- <%= link_to(t('preferences.change_identity_url') + ' »', change_auth_type_user_path(current_user)) %> -
- <% end %> -
-
+ +
+ + + + <% end %> +
\ No newline at end of file diff --git a/app/views/shared/_footer.rhtml b/app/views/shared/_footer.rhtml index 49a20da4..aacd2561 100644 --- a/app/views/shared/_footer.rhtml +++ b/app/views/shared/_footer.rhtml @@ -1,7 +1,7 @@