Skip to content

Commit

Permalink
updating preferences on user and prefs model work. also add date_form…
Browse files Browse the repository at this point in the history
…at picker
  • Loading branch information
lrbalt committed Aug 17, 2011
1 parent 89ec989 commit 555311b
Show file tree
Hide file tree
Showing 12 changed files with 750 additions and 815 deletions.
26 changes: 17 additions & 9 deletions app/controllers/preferences_controller.rb
Original file line number Diff line number Diff line change
@@ -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
18 changes: 17 additions & 1 deletion app/views/preferences/_date_and_time.html.erb
Original file line number Diff line number Diff line change
@@ -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] }) %>
Expand Down
59 changes: 0 additions & 59 deletions app/views/preferences/edit.html.erb

This file was deleted.

3 changes: 3 additions & 0 deletions app/views/preferences/index.html.erb
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
68 changes: 0 additions & 68 deletions app/views/preferences/oldindex.html.erb

This file was deleted.

Loading

0 comments on commit 555311b

Please sign in to comment.