casein 4.0.0 → 5.0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +246 -0
- data/PUBLIC_VERSION.yml +2 -2
- data/README.rdoc +73 -49
- data/Rakefile +7 -5
- data/app/assets/fonts/casein/glyphiconshalflings-regular.eot +0 -0
- data/app/assets/fonts/casein/glyphiconshalflings-regular.otf +0 -0
- data/app/assets/fonts/casein/glyphiconshalflings-regular.svg +175 -0
- data/app/assets/fonts/casein/glyphiconshalflings-regular.ttf +0 -0
- data/app/assets/fonts/casein/glyphiconshalflings-regular.woff +0 -0
- data/app/assets/images/casein/casein.png +0 -0
- data/app/assets/javascripts/casein/bootstrap.js +1966 -0
- data/app/assets/javascripts/casein/casein.js +34 -19
- data/app/assets/javascripts/casein/html5shiv.js +8 -0
- data/app/assets/stylesheets/casein/bootstrap-glyphicons.css.scss +2 -0
- data/app/assets/stylesheets/casein/bootstrap.css +4692 -0
- data/app/assets/stylesheets/casein/casein-bootstrap-overrides.css.scss +76 -0
- data/app/assets/stylesheets/casein/casein.css.scss +258 -3
- data/app/assets/stylesheets/casein/login.css.scss +48 -109
- data/app/controllers/casein/{user_sessions_controller.rb → admin_user_sessions_controller.rb} +6 -10
- data/app/controllers/casein/admin_users_controller.rb +124 -0
- data/app/controllers/casein/casein_controller.rb +11 -9
- data/app/controllers/casein/password_resets_controller.rb +8 -10
- data/app/helpers/casein/casein_helper.rb +94 -31
- data/app/mailers/casein/casein_notification.rb +13 -13
- data/app/models/casein/{user.rb → admin_user.rb} +2 -2
- data/app/models/casein/{user_session.rb → admin_user_session.rb} +1 -1
- data/app/views/casein/admin_user_sessions/new.html.erb +56 -0
- data/app/views/casein/admin_users/index.html.erb +39 -0
- data/app/views/casein/admin_users/new.html.erb +57 -0
- data/app/views/casein/admin_users/show.html.erb +104 -0
- data/app/views/casein/casein/blank.html.erb +12 -1
- data/app/views/casein/casein_notification/generate_new_password.erb +1 -1
- data/app/views/casein/casein_notification/new_user_information.erb +1 -1
- data/app/views/casein/casein_notification/password_reset_instructions.erb +1 -1
- data/app/views/casein/password_resets/edit.html.erb +21 -33
- data/app/views/layouts/casein_auth.html.erb +34 -22
- data/app/views/layouts/casein_main.html.erb +111 -64
- data/config/initializers/will_paginate.rb +40 -0
- data/config/routes.rb +2 -2
- data/lib/casein.rb +9 -3
- data/lib/casein/engine.rb +5 -1
- data/lib/generators/casein/install/install_generator.rb +3 -3
- data/lib/generators/casein/install/templates/app/helpers/casein/config_helper.rb +10 -11
- data/lib/generators/casein/install/templates/app/views/casein/layouts/{_left_navigation.html.erb → _tab_navigation.html.erb} +0 -0
- data/lib/generators/casein/install/templates/app/views/casein/layouts/_top_navigation.html.erb +4 -0
- data/lib/generators/casein/install/templates/db/migrate/{casein_create_users.rb → casein_create_admin_users.rb} +3 -3
- data/lib/generators/casein/scaffold/scaffold_generator.rb +20 -8
- data/lib/generators/casein/scaffold/templates/controller.rb +6 -6
- data/lib/generators/casein/scaffold/templates/views/_form.html.erb +11 -8
- data/lib/generators/casein/scaffold/templates/views/_table.html.erb +12 -10
- data/lib/generators/casein/scaffold/templates/views/index.html.erb +7 -3
- data/lib/generators/casein/scaffold/templates/views/new.html.erb +3 -3
- data/lib/generators/casein/scaffold/templates/views/show.html.erb +5 -5
- data/lib/railties/tasks.rake +15 -13
- metadata +67 -46
- data/MIT-LICENSE +0 -21
- data/app/assets/images/casein/header.png +0 -0
- data/app/assets/images/casein/icons/add.png +0 -0
- data/app/assets/images/casein/icons/delete.png +0 -0
- data/app/assets/images/casein/icons/table.png +0 -0
- data/app/assets/images/casein/login/alertBg.png +0 -0
- data/app/assets/images/casein/login/background.png +0 -0
- data/app/assets/images/casein/login/bottom.png +0 -0
- data/app/assets/images/casein/login/loginBoxBg.png +0 -0
- data/app/assets/images/casein/login/loginBoxBottom.png +0 -0
- data/app/assets/images/casein/login/loginBoxTop.png +0 -0
- data/app/assets/images/casein/login/loginSubmit.png +0 -0
- data/app/assets/images/casein/login/recoverSubmit.png +0 -0
- data/app/assets/images/casein/login/top.png +0 -0
- data/app/assets/images/casein/nav.png +0 -0
- data/app/assets/images/casein/rightNav.png +0 -0
- data/app/assets/images/casein/rightNavButton.png +0 -0
- data/app/assets/images/casein/visitSiteNav.png +0 -0
- data/app/assets/javascripts/casein/login.js +0 -27
- data/app/assets/stylesheets/casein/elements.css.scss +0 -307
- data/app/assets/stylesheets/casein/screen.css.scss +0 -224
- data/app/controllers/casein/users_controller.rb +0 -108
- data/app/views/casein/user_sessions/new.html.erb +0 -66
- data/app/views/casein/users/index.html.erb +0 -35
- data/app/views/casein/users/new.html.erb +0 -46
- data/app/views/casein/users/show.html.erb +0 -94
- data/lib/generators/casein/install/templates/app/views/casein/layouts/_right_navigation.html.erb +0 -1
data/app/controllers/casein/{user_sessions_controller.rb → admin_user_sessions_controller.rb}
RENAMED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
module Casein
|
|
2
|
-
class
|
|
3
|
-
|
|
4
|
-
unloadable
|
|
2
|
+
class AdminUserSessionsController < Casein::CaseinController
|
|
5
3
|
|
|
6
4
|
skip_before_filter :authorise, :only => [:new, :create]
|
|
7
5
|
before_filter :requires_no_session_user, :except => [:destroy]
|
|
@@ -9,13 +7,12 @@ module Casein
|
|
|
9
7
|
layout 'casein_auth'
|
|
10
8
|
|
|
11
9
|
def new
|
|
12
|
-
@
|
|
10
|
+
@admin_user_session = Casein::AdminUserSession.new
|
|
13
11
|
end
|
|
14
12
|
|
|
15
13
|
def create
|
|
16
|
-
@
|
|
17
|
-
if @
|
|
18
|
-
flash[:notice] = "Login successful"
|
|
14
|
+
@admin_user_session = Casein::AdminUserSession.new params[:casein_admin_user_session]
|
|
15
|
+
if @admin_user_session.save
|
|
19
16
|
redirect_back_or_default :controller => :casein, :action => :index
|
|
20
17
|
else
|
|
21
18
|
render :action => :new
|
|
@@ -23,9 +20,8 @@ module Casein
|
|
|
23
20
|
end
|
|
24
21
|
|
|
25
22
|
def destroy
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
redirect_back_or_default new_casein_user_session_url
|
|
23
|
+
current_admin_user_session.destroy
|
|
24
|
+
redirect_back_or_default new_casein_admin_user_session_url
|
|
29
25
|
end
|
|
30
26
|
|
|
31
27
|
private
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
require 'securerandom'
|
|
2
|
+
|
|
3
|
+
module Casein
|
|
4
|
+
class AdminUsersController < Casein::CaseinController
|
|
5
|
+
|
|
6
|
+
before_filter :needs_admin, :except => [:show, :destroy, :update, :update_password]
|
|
7
|
+
before_filter :needs_admin_or_current_user, :only => [:show, :destroy, :update, :update_password]
|
|
8
|
+
|
|
9
|
+
def index
|
|
10
|
+
@casein_page_title = "Users"
|
|
11
|
+
@users = Casein::AdminUser.order(sort_order(:login)).paginate :page => params[:page]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def new
|
|
15
|
+
@casein_page_title = "Add a new user"
|
|
16
|
+
@casein_admin_user = Casein::AdminUser.new
|
|
17
|
+
@casein_admin_user.time_zone = Rails.configuration.time_zone
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def create
|
|
21
|
+
|
|
22
|
+
generate_random_password if params[:generate_random_password]
|
|
23
|
+
|
|
24
|
+
@casein_admin_user = Casein::AdminUser.new casein_admin_user_params
|
|
25
|
+
|
|
26
|
+
if @casein_admin_user.save
|
|
27
|
+
flash[:notice] = "An email has been sent to " + @casein_admin_user.name + " with the new account details"
|
|
28
|
+
redirect_to casein_admin_users_path
|
|
29
|
+
else
|
|
30
|
+
flash.now[:warning] = "There were problems when trying to create a new user"
|
|
31
|
+
render :action => :new
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def show
|
|
36
|
+
@casein_admin_user = Casein::AdminUser.find params[:id]
|
|
37
|
+
@casein_page_title = @casein_admin_user.name + " > View user"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def update
|
|
41
|
+
@casein_admin_user = Casein::AdminUser.find params[:id]
|
|
42
|
+
@casein_page_title = @casein_admin_user.name + " > Update user"
|
|
43
|
+
|
|
44
|
+
if @casein_admin_user.update_attributes casein_admin_user_params
|
|
45
|
+
flash[:notice] = @casein_admin_user.name + " has been updated"
|
|
46
|
+
else
|
|
47
|
+
flash.now[:warning] = "There were problems when trying to update this user"
|
|
48
|
+
render :action => :show
|
|
49
|
+
return
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
if @session_user.is_admin?
|
|
53
|
+
redirect_to casein_admin_users_path
|
|
54
|
+
else
|
|
55
|
+
redirect_to :controller => :casein, :action => :index
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def update_password
|
|
60
|
+
@casein_admin_user = Casein::AdminUser.find params[:id]
|
|
61
|
+
@casein_page_title = @casein_admin_user.name + " > Update password"
|
|
62
|
+
|
|
63
|
+
if @casein_admin_user.valid_password? params[:form_current_password]
|
|
64
|
+
if params[:casein_admin_user][:password].blank? && params[:casein_admin_user][:password_confirmation].blank?
|
|
65
|
+
flash[:warning] = "New password cannot be blank"
|
|
66
|
+
elsif @casein_admin_user.update_attributes casein_admin_user_params
|
|
67
|
+
flash[:notice] = "Your password has been changed"
|
|
68
|
+
else
|
|
69
|
+
flash[:warning] = "There were problems when trying to change your password"
|
|
70
|
+
end
|
|
71
|
+
else
|
|
72
|
+
flash[:warning] = "The current password is incorrect"
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
redirect_to :action => :show
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def reset_password
|
|
79
|
+
@casein_admin_user = Casein::AdminUser.find params[:id]
|
|
80
|
+
@casein_page_title = @casein_admin_user.name + " > Reset password"
|
|
81
|
+
|
|
82
|
+
if params[:generate_random_password].blank? && params[:casein_admin_user][:password].blank? && params[:casein_admin_user][:password_confirmation].blank?
|
|
83
|
+
flash[:warning] = "New password cannot be blank"
|
|
84
|
+
else
|
|
85
|
+
generate_random_password if params[:generate_random_password]
|
|
86
|
+
@casein_admin_user.notify_of_new_password = true unless (@casein_admin_user.id == @session_user.id && params[:generate_random_password].blank?)
|
|
87
|
+
|
|
88
|
+
if @casein_admin_user.update_attributes casein_admin_user_params
|
|
89
|
+
unless @casein_admin_user.notify_of_new_password
|
|
90
|
+
flash[:notice] = "Your password has been reset"
|
|
91
|
+
else
|
|
92
|
+
flash[:notice] = "Password has been reset and " + @casein_admin_user.name + " has been notified by email"
|
|
93
|
+
end
|
|
94
|
+
else
|
|
95
|
+
flash[:warning] = "There were problems when trying to reset this user's password"
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
redirect_to :action => :show
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def destroy
|
|
103
|
+
user = Casein::AdminUser.find params[:id]
|
|
104
|
+
if user.is_admin? == false || Casein::AdminUser.has_more_than_one_admin
|
|
105
|
+
user.destroy
|
|
106
|
+
flash[:notice] = user.name + " has been deleted"
|
|
107
|
+
end
|
|
108
|
+
redirect_to casein_admin_users_path
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
private
|
|
112
|
+
|
|
113
|
+
def generate_random_password
|
|
114
|
+
random_password = random_string = SecureRandom.hex
|
|
115
|
+
params[:casein_admin_user] = Hash.new if params[:casein_admin_user].blank?
|
|
116
|
+
params[:casein_admin_user].merge! ({:password => random_password, :password_confirmation => random_password})
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def casein_admin_user_params
|
|
120
|
+
params.require(:casein_admin_user).permit(:login, :name, :email, :time_zone, :access_level, :password, :password_confirmation)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
end
|
|
124
|
+
end
|
|
@@ -3,8 +3,6 @@ require 'authlogic'
|
|
|
3
3
|
module Casein
|
|
4
4
|
class CaseinController < ApplicationController
|
|
5
5
|
|
|
6
|
-
unloadable
|
|
7
|
-
|
|
8
6
|
require 'casein/casein_helper'
|
|
9
7
|
include Casein::CaseinHelper
|
|
10
8
|
|
|
@@ -13,11 +11,11 @@ module Casein
|
|
|
13
11
|
|
|
14
12
|
layout 'casein_main'
|
|
15
13
|
|
|
16
|
-
helper_method :
|
|
14
|
+
helper_method :current_admin_user_session, :current_user
|
|
17
15
|
before_filter :authorise
|
|
18
16
|
before_filter :set_time_zone
|
|
19
17
|
|
|
20
|
-
ActionView::Base.field_error_proc = proc { |input, instance| "
|
|
18
|
+
ActionView::Base.field_error_proc = proc { |input, instance| "#{input}".html_safe }
|
|
21
19
|
|
|
22
20
|
def index
|
|
23
21
|
redirect_to casein_config_dashboard_url
|
|
@@ -32,7 +30,7 @@ module Casein
|
|
|
32
30
|
def authorise
|
|
33
31
|
unless current_user
|
|
34
32
|
session[:return_to] = request.fullpath
|
|
35
|
-
redirect_to
|
|
33
|
+
redirect_to new_casein_admin_user_session_url
|
|
36
34
|
return false
|
|
37
35
|
end
|
|
38
36
|
end
|
|
@@ -41,14 +39,14 @@ module Casein
|
|
|
41
39
|
Time.zone = current_user.time_zone if current_user
|
|
42
40
|
end
|
|
43
41
|
|
|
44
|
-
def
|
|
45
|
-
return @
|
|
46
|
-
@
|
|
42
|
+
def current_admin_user_session
|
|
43
|
+
return @current_admin_user_session if defined?(@current_admin_user_session)
|
|
44
|
+
@current_admin_user_session = Casein::AdminUserSession.find
|
|
47
45
|
end
|
|
48
46
|
|
|
49
47
|
def current_user
|
|
50
48
|
return @session_user if defined?(@session_user)
|
|
51
|
-
@session_user =
|
|
49
|
+
@session_user = current_admin_user_session && current_admin_user_session.admin_user
|
|
52
50
|
end
|
|
53
51
|
|
|
54
52
|
def needs_admin
|
|
@@ -68,5 +66,9 @@ module Casein
|
|
|
68
66
|
session[:return_to] = nil
|
|
69
67
|
end
|
|
70
68
|
|
|
69
|
+
def sort_order(default)
|
|
70
|
+
"#{(params[:c] || default.to_s).gsub(/[\s;'\"]/,'')} #{'ASC' if params[:d] == 'up'} #{'DESC' if params[:d] == 'down'}"
|
|
71
|
+
end
|
|
72
|
+
|
|
71
73
|
end
|
|
72
74
|
end
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
module Casein
|
|
2
2
|
class PasswordResetsController < Casein::CaseinController
|
|
3
3
|
|
|
4
|
-
unloadable
|
|
5
|
-
|
|
6
4
|
skip_before_filter :authorise
|
|
7
5
|
before_filter :load_user_using_perishable_token, :only => [:edit, :update]
|
|
8
6
|
|
|
9
7
|
layout 'casein_auth'
|
|
10
8
|
|
|
11
9
|
def create
|
|
12
|
-
users = Casein::
|
|
10
|
+
users = Casein::AdminUser.where(:email => params[:recover_email]).all
|
|
13
11
|
|
|
14
12
|
if users.length > 0
|
|
15
13
|
users.each do |user|
|
|
@@ -25,7 +23,7 @@ module Casein
|
|
|
25
23
|
flash[:warning] = "There is no user with that email"
|
|
26
24
|
end
|
|
27
25
|
|
|
28
|
-
redirect_to
|
|
26
|
+
redirect_to new_casein_admin_user_session_url
|
|
29
27
|
end
|
|
30
28
|
|
|
31
29
|
def edit
|
|
@@ -34,16 +32,16 @@ module Casein
|
|
|
34
32
|
|
|
35
33
|
def update
|
|
36
34
|
|
|
37
|
-
if params[:
|
|
35
|
+
if params[:casein_admin_user][:password].empty? || params[:casein_admin_user][:password_confirmation].empty?
|
|
38
36
|
flash.now[:warning] = "A field has been left empty"
|
|
39
37
|
else
|
|
40
38
|
|
|
41
|
-
@reset_user.password = params[:
|
|
42
|
-
@reset_user.password_confirmation = params[:
|
|
39
|
+
@reset_user.password = params[:casein_admin_user][:password]
|
|
40
|
+
@reset_user.password_confirmation = params[:casein_admin_user][:password_confirmation]
|
|
43
41
|
|
|
44
42
|
if @reset_user.save
|
|
45
43
|
flash[:notice] = "Password successfully updated"
|
|
46
|
-
redirect_to
|
|
44
|
+
redirect_to new_casein_admin_user_session_url
|
|
47
45
|
return
|
|
48
46
|
end
|
|
49
47
|
end
|
|
@@ -55,11 +53,11 @@ module Casein
|
|
|
55
53
|
|
|
56
54
|
def load_user_using_perishable_token
|
|
57
55
|
|
|
58
|
-
@reset_user = Casein::
|
|
56
|
+
@reset_user = Casein::AdminUser.find_using_perishable_token params[:token]
|
|
59
57
|
|
|
60
58
|
unless @reset_user
|
|
61
59
|
flash[:warning] = "Your account could not be located. Try to copy and paste the URL directly from the email."
|
|
62
|
-
redirect_to
|
|
60
|
+
redirect_to new_casein_admin_user_session_url
|
|
63
61
|
end
|
|
64
62
|
end
|
|
65
63
|
end
|
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
module Casein
|
|
2
2
|
module CaseinHelper
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
def casein_get_footer_string include_version = false
|
|
5
|
+
if include_version
|
|
6
|
+
"Running on #{link_to 'Casein', 'http://www.github.com/russellquinn/casein'} #{casein_get_full_version_string}, an open-source project.".html_safe
|
|
7
|
+
else
|
|
8
|
+
"Running on #{link_to 'Casein', 'http://www.github.com/russellquinn/casein'}, an open-source project.".html_safe
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def casein_get_version_info
|
|
5
13
|
YAML::load_file File.join(File.dirname(__FILE__), '..', '..', '..', 'PUBLIC_VERSION.yml')
|
|
6
14
|
end
|
|
7
15
|
|
|
8
16
|
def casein_get_full_version_string
|
|
9
17
|
version_info = casein_get_version_info
|
|
10
|
-
"v
|
|
18
|
+
"v#{version_info['major']}.#{version_info['minor']}.#{version_info['patch']}.#{version_info['build']}"
|
|
11
19
|
end
|
|
12
20
|
|
|
13
21
|
def casein_get_short_version_string
|
|
14
22
|
version_info = casein_get_version_info
|
|
15
|
-
"v
|
|
23
|
+
"v#{version_info['major']}"
|
|
16
24
|
end
|
|
17
25
|
|
|
18
26
|
def casein_generate_page_title
|
|
@@ -21,7 +29,7 @@ module Casein
|
|
|
21
29
|
return casein_config_website_name
|
|
22
30
|
end
|
|
23
31
|
|
|
24
|
-
|
|
32
|
+
casein_config_website_name + " > " + @casein_page_title
|
|
25
33
|
end
|
|
26
34
|
|
|
27
35
|
def casein_get_access_level_text level
|
|
@@ -38,6 +46,10 @@ module Casein
|
|
|
38
46
|
def casein_get_access_level_array
|
|
39
47
|
[["Administrator", $CASEIN_USER_ACCESS_LEVEL_ADMIN], ["User", $CASEIN_USER_ACCESS_LEVEL_USER]]
|
|
40
48
|
end
|
|
49
|
+
|
|
50
|
+
def casein_pagination_details objs
|
|
51
|
+
" <small class='pagination-details'>/ page #{objs.current_page} of #{objs.total_pages}</small>".html_safe if objs.current_page && objs.total_pages > 1
|
|
52
|
+
end
|
|
41
53
|
|
|
42
54
|
def casein_table_cell_link contents, link, options = {}
|
|
43
55
|
|
|
@@ -54,43 +66,77 @@ module Casein
|
|
|
54
66
|
contents = truncate(contents, :length => options[:casein_truncate], :omission => "...")
|
|
55
67
|
end
|
|
56
68
|
|
|
57
|
-
"<div class='
|
|
69
|
+
"<div class='no-link'>#{contents}</div>".html_safe
|
|
58
70
|
end
|
|
59
71
|
|
|
60
72
|
def casein_show_icon icon_name
|
|
61
|
-
"<div class='icon'
|
|
73
|
+
"<div class='icon'><span class='glyphicon glyphicon-#{icon_name}'></span></div>".html_safe
|
|
62
74
|
end
|
|
63
75
|
|
|
64
76
|
def casein_show_row_icon icon_name
|
|
65
|
-
"<div class='iconRow'
|
|
77
|
+
"<div class='iconRow'><span class='glyphicon glyphicon-#{icon_name}'></span></div>".html_safe
|
|
66
78
|
end
|
|
79
|
+
|
|
80
|
+
def casein_format_date date, format = "%b %d, %Y"
|
|
81
|
+
date.strftime(format)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def casein_format_time time, format = "%H:%M"
|
|
85
|
+
time.strftime(format)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def casein_format_datetime datetime, format = "%b %d, %Y %H:%M"
|
|
89
|
+
datetime.strftime(format)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def casein_sort_link title, column, options = {}
|
|
93
|
+
condition = options[:unless] if options.has_key?(:unless)
|
|
94
|
+
icon_to_show_html = "<div class='table-header-icon'> </div>".html_safe
|
|
95
|
+
if params[:c].to_s == column.to_s
|
|
96
|
+
icon_to_show = params[:d] == 'down' ? 'chevron-up' : 'chevron-down'
|
|
97
|
+
icon_to_show_html = "<div class='table-header-icon glyphicon glyphicon-#{icon_to_show}'></div>".html_safe
|
|
98
|
+
end
|
|
99
|
+
sort_dir = params[:d] == 'down' ? 'up' : 'down'
|
|
100
|
+
link_to_unless(condition, title, request.parameters.merge({:c => column, :d => sort_dir})) + icon_to_show_html
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def casein_yes_no_label value
|
|
104
|
+
if value
|
|
105
|
+
return "<span class='label label-success'>Yes</span>".html_safe
|
|
106
|
+
else
|
|
107
|
+
return "<span class='label label-danger'>No</span>".html_safe
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def casein_no_yes_label value
|
|
112
|
+
if value
|
|
113
|
+
return "<span class='label label-danger'>Yes</span>".html_safe
|
|
114
|
+
else
|
|
115
|
+
return "<span class='label label-success'>No</span>".html_safe
|
|
116
|
+
end
|
|
117
|
+
end
|
|
67
118
|
|
|
68
119
|
# Styled form tag helpers
|
|
69
120
|
|
|
70
121
|
def casein_text_field form, obj, attribute, options = {}
|
|
71
|
-
casein_form_tag_wrapper(form.text_field(attribute, strip_casein_options(options_hash_with_merged_classes(options, '
|
|
122
|
+
casein_form_tag_wrapper(form.text_field(attribute, strip_casein_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
|
|
72
123
|
end
|
|
73
124
|
|
|
74
125
|
def casein_password_field form, obj, attribute, options = {}
|
|
75
|
-
casein_form_tag_wrapper(form.password_field(attribute, strip_casein_options(options_hash_with_merged_classes(options, '
|
|
126
|
+
casein_form_tag_wrapper(form.password_field(attribute, strip_casein_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
|
|
76
127
|
end
|
|
77
128
|
|
|
78
129
|
def casein_text_area form, obj, attribute, options = {}
|
|
79
|
-
casein_form_tag_wrapper(form.text_area(attribute, strip_casein_options(options_hash_with_merged_classes(options, '
|
|
130
|
+
casein_form_tag_wrapper(form.text_area(attribute, strip_casein_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
|
|
80
131
|
end
|
|
81
132
|
|
|
82
133
|
def casein_text_area_big form, obj, attribute, options = {}
|
|
83
|
-
casein_form_tag_wrapper(form.text_area(attribute, strip_casein_options(options_hash_with_merged_classes(options, '
|
|
134
|
+
casein_form_tag_wrapper(form.text_area(attribute, strip_casein_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
|
|
84
135
|
end
|
|
85
136
|
|
|
86
137
|
def casein_check_box form, obj, attribute, options = {}
|
|
87
|
-
form_tag = form.check_box(attribute, strip_casein_options(options))
|
|
88
|
-
|
|
89
|
-
if options.key? :casein_box_label
|
|
90
|
-
form_tag = "<div>" + form_tag + "<span class=\"rcText\">#{options[:casein_box_label]}</span></div>".html_safe
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
casein_form_tag_wrapper(form_tag, form, obj, attribute, options).html_safe
|
|
138
|
+
form_tag = "<div class='check-box'>#{form.check_box(attribute, strip_casein_options(options))}</div>".html_safe
|
|
139
|
+
casein_form_tag_wrapper(form_tag, form, obj, attribute, options).html_safe
|
|
94
140
|
end
|
|
95
141
|
|
|
96
142
|
def casein_check_box_group form, obj, check_boxes = {}
|
|
@@ -100,7 +146,7 @@ module Casein
|
|
|
100
146
|
form_tags += casein_check_box form, obj, check_box[0], check_box[1]
|
|
101
147
|
end
|
|
102
148
|
|
|
103
|
-
casein_form_tag_wrapper
|
|
149
|
+
casein_form_tag_wrapper(form_tag, form, obj, attribute, options)
|
|
104
150
|
end
|
|
105
151
|
|
|
106
152
|
def casein_radio_button form, obj, attribute, tag_value, options = {}
|
|
@@ -124,38 +170,47 @@ module Casein
|
|
|
124
170
|
end
|
|
125
171
|
|
|
126
172
|
def casein_select form, obj, attribute, option_tags, options = {}
|
|
127
|
-
casein_form_tag_wrapper(form.select(attribute, option_tags, strip_casein_options(options), merged_class_hash(options, '
|
|
173
|
+
casein_form_tag_wrapper(form.select(attribute, option_tags, strip_casein_options(options), merged_class_hash(options, 'form-control')), form, obj, attribute, options).html_safe
|
|
128
174
|
end
|
|
129
175
|
|
|
130
176
|
def casein_time_zone_select form, obj, attribute, option_tags, options = {}
|
|
131
|
-
casein_form_tag_wrapper(form.time_zone_select(attribute, option_tags, strip_casein_options(options), merged_class_hash(options, '
|
|
177
|
+
casein_form_tag_wrapper(form.time_zone_select(attribute, option_tags, strip_casein_options(options), merged_class_hash(options, 'form-control')), form, obj, attribute, options).html_safe
|
|
132
178
|
end
|
|
133
179
|
|
|
134
|
-
def casein_collection_select form, obj,
|
|
135
|
-
casein_form_tag_wrapper(collection_select(
|
|
180
|
+
def casein_collection_select form, obj, attribute, collection, value_method, text_method, options = {}
|
|
181
|
+
casein_form_tag_wrapper(collection_select(obj, attribute, collection, value_method, text_method, strip_casein_options(options), merged_class_hash(options, 'form-control')), form, obj, attribute, options).html_safe
|
|
136
182
|
end
|
|
137
183
|
|
|
138
184
|
def casein_date_select form, obj, attribute, options = {}
|
|
139
|
-
casein_form_tag_wrapper(form.date_select(attribute, strip_casein_options(options), merged_class_hash(options, '
|
|
185
|
+
casein_form_tag_wrapper("<div class='casein-date-select'>".html_safe + form.date_select(attribute, strip_casein_options(options), merged_class_hash(options, 'form-control')) + "</div>".html_safe, form, obj, attribute, options).html_safe
|
|
140
186
|
end
|
|
141
187
|
|
|
142
188
|
def casein_time_select form, obj, attribute, options = {}
|
|
143
|
-
casein_form_tag_wrapper(form.time_select(attribute, strip_casein_options(options), merged_class_hash(options, '
|
|
189
|
+
casein_form_tag_wrapper("<div class='casein-time-select'>".html_safe + form.time_select(attribute, strip_casein_options(options), merged_class_hash(options, 'form-control')) + "</div>".html_safe, form, obj, attribute, options).html_safe
|
|
144
190
|
end
|
|
145
191
|
|
|
146
192
|
def casein_datetime_select form, obj, attribute, options = {}
|
|
147
|
-
casein_form_tag_wrapper(form.datetime_select(attribute, strip_casein_options(options), merged_class_hash(options, '
|
|
193
|
+
casein_form_tag_wrapper("<div class='casein-datetime-select'>".html_safe + form.datetime_select(attribute, strip_casein_options(options), merged_class_hash(options, 'form-control')) + "</div>".html_safe, form, obj, attribute, options).html_safe
|
|
148
194
|
end
|
|
149
195
|
|
|
150
196
|
def casein_file_field form, obj, object_name, attribute, options = {}
|
|
151
|
-
class_hash = merged_class_hash(options, '
|
|
197
|
+
class_hash = merged_class_hash(options, 'form-control')
|
|
152
198
|
contents = "<div class='#{class_hash[:class]}'>" + file_field(object_name, attribute, strip_casein_options(options)) + '</div>'
|
|
199
|
+
|
|
200
|
+
if options.key? :casein_contents_preview
|
|
201
|
+
contents = options[:casein_contents_preview].html_safe + contents.html_safe
|
|
202
|
+
end
|
|
203
|
+
|
|
153
204
|
casein_form_tag_wrapper(contents, form, obj, attribute, options).html_safe
|
|
154
205
|
end
|
|
155
206
|
|
|
156
207
|
def casein_hidden_field form, obj, attribute, options = {}
|
|
157
208
|
form.hidden_field(attribute, strip_casein_options(options)).html_safe
|
|
158
209
|
end
|
|
210
|
+
|
|
211
|
+
def casein_custom_field form, obj, attribute, custom_contents, options = {}
|
|
212
|
+
casein_form_tag_wrapper(custom_contents, form, obj, attribute, options).html_safe
|
|
213
|
+
end
|
|
159
214
|
|
|
160
215
|
protected
|
|
161
216
|
|
|
@@ -186,15 +241,23 @@ module Casein
|
|
|
186
241
|
human_attribute_name = options[:casein_label]
|
|
187
242
|
end
|
|
188
243
|
|
|
189
|
-
|
|
244
|
+
sublabel = ""
|
|
245
|
+
|
|
246
|
+
if options.key? :casein_sublabel
|
|
247
|
+
sublabel = " <small>#{options[:casein_sublabel]}</small>".html_safe
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
html = ""
|
|
190
251
|
|
|
191
252
|
if obj && obj.errors[attribute].any?
|
|
192
|
-
|
|
253
|
+
html += "<div class='form-group has-error'>"
|
|
254
|
+
html += form.label(attribute, "#{human_attribute_name} #{obj.errors[attribute].first}".html_safe, :class => "control-label")
|
|
193
255
|
else
|
|
194
|
-
|
|
256
|
+
html += "<div class='form-group'>"
|
|
257
|
+
html += form.label(attribute, "#{human_attribute_name}#{sublabel}".html_safe, :class => "control-label")
|
|
195
258
|
end
|
|
196
259
|
|
|
197
|
-
html += "
|
|
260
|
+
html += "<div class='well'>#{form_tag}</div></div>"
|
|
198
261
|
end
|
|
199
262
|
end
|
|
200
263
|
end
|