prefs model added
This commit is contained in:
parent
da03add37b
commit
86e1817e29
|
@ -8,22 +8,22 @@ class ApplicationController < ActionController::Base
|
|||
protected
|
||||
|
||||
def load_defaults
|
||||
@defaults = YAML::load(File.open(Rails.root.join('config','defaults.yml')))
|
||||
$defaults ||= YAML::load(File.open(Rails.root.join('config','defaults.yml')))
|
||||
end
|
||||
|
||||
def theme_resolver
|
||||
if @current_user.nil?
|
||||
@defaults['theme']
|
||||
$defaults['theme']
|
||||
else
|
||||
@current_user.theme
|
||||
@current_user.prefs.theme
|
||||
end
|
||||
end
|
||||
|
||||
def set_locale
|
||||
if @current_user.nil?
|
||||
I18n.locale = @defaults['locale'] || I18n.default_locale
|
||||
I18n.locale = $defaults['locale'] || I18n.default_locale
|
||||
else
|
||||
I18n.locale = @current_user.locale || I18n.default_locale
|
||||
I18n.locale = @current_user.prefs.locale || I18n.default_locale
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ class MessagesController < ApplicationController
|
|||
theme :theme_resolver
|
||||
|
||||
def index
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -17,9 +17,15 @@ class UserController < ApplicationController
|
|||
if user.nil?
|
||||
redirect_to :action => 'unknown'
|
||||
else
|
||||
auten = false
|
||||
auten = true
|
||||
if auten == true
|
||||
|
||||
session[:user_id] = user.id
|
||||
if session["return_to"]
|
||||
redirect_to(session["return_to"])
|
||||
session["return_to"] = nil
|
||||
else
|
||||
redirect_to :controller=> "messages",:action=>"index"
|
||||
end
|
||||
else
|
||||
flash[:error] = t(:login_failure)
|
||||
redirect_to :action => 'login'
|
||||
|
@ -49,6 +55,7 @@ class UserController < ApplicationController
|
|||
@user.save
|
||||
@server.user_id = @user.id
|
||||
@server.save
|
||||
Prefs.create_default(@user.id)
|
||||
flash[:notice] = t(:setup_done)
|
||||
redirect_to :action => 'login'
|
||||
else
|
||||
|
|
17
app/models/prefs.rb
Normal file
17
app/models/prefs.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
class Prefs < ActiveRecord::Base
|
||||
|
||||
validates_presence_of :theme,:locale
|
||||
|
||||
has_one :user
|
||||
|
||||
protected
|
||||
|
||||
def self.create_default(user_id)
|
||||
Prefs.create(:user_id => user_id,
|
||||
:theme => $defaults['theme'],
|
||||
:locale => $defaults['locale'],
|
||||
:msgs_per_page => $defaults['msgs_per_page'],
|
||||
:msg_send_type => $defaults['msg_send_type']
|
||||
)
|
||||
end
|
||||
end
|
|
@ -3,4 +3,5 @@ class User < ActiveRecord::Base
|
|||
validates_presence_of :first_name,:last_name
|
||||
validates_uniqueness_of :email
|
||||
has_many :servers, :dependent => :destroy
|
||||
has_one :prefs, :dependent => :destroy
|
||||
end
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
theme: olive
|
||||
locale: en
|
||||
msgs_per_page: 20
|
||||
msg_send_type: html
|
||||
|
|
14
db/migrate/20110724125806_create_prefs.rb
Normal file
14
db/migrate/20110724125806_create_prefs.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
class CreatePrefs < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :prefs do |t|
|
||||
t.string :theme
|
||||
t.string :locale
|
||||
t.references :user
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :prefs
|
||||
end
|
||||
end
|
11
db/migrate/20110724134917_add_params_to_prefs.rb
Normal file
11
db/migrate/20110724134917_add_params_to_prefs.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
class AddParamsToPrefs < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :prefs, :msgs_per_page, :string
|
||||
add_column :prefs, :msg_send_type, :string
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :prefs, :msg_send_type
|
||||
remove_column :prefs, :msgs_per_page
|
||||
end
|
||||
end
|
12
db/schema.rb
12
db/schema.rb
|
@ -10,7 +10,17 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20110723153214) do
|
||||
ActiveRecord::Schema.define(:version => 20110724134917) do
|
||||
|
||||
create_table "prefs", :force => true do |t|
|
||||
t.string "theme"
|
||||
t.string "locale"
|
||||
t.integer "user_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "msgs_per_page"
|
||||
t.string "msg_send_type"
|
||||
end
|
||||
|
||||
create_table "servers", :force => true do |t|
|
||||
t.string "name"
|
||||
|
|
9
test/fixtures/prefs.yml
vendored
Normal file
9
test/fixtures/prefs.yml
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
one:
|
||||
theme: MyString
|
||||
locale: MyString
|
||||
|
||||
two:
|
||||
theme: MyString
|
||||
locale: MyString
|
8
test/unit/prefs_test.rb
Normal file
8
test/unit/prefs_test.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
class PrefsTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
|
@ -8,8 +8,6 @@ PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|||
|
||||
<%=stylesheet_link_tag current_theme_stylesheet_path('base') %>
|
||||
<%=stylesheet_link_tag current_theme_stylesheet_path('style') %>
|
||||
<%=javascript_include_tag current_theme_javascript_path('global') %>
|
||||
<%=javascript_include_tag current_theme_javascript_path('webmail') %>
|
||||
|
||||
<%=javascript_include_tag :defaults %>
|
||||
|
||||
|
|
Loading…
Reference in a new issue