caseadilla 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -0
  3. data/Gemfile +0 -0
  4. data/LICENSE.txt +0 -0
  5. data/README.md +0 -0
  6. data/Rakefile +0 -0
  7. data/app/assets/fonts/caseadilla/glyphicons-halflings-regular.eot +0 -0
  8. data/app/assets/fonts/caseadilla/glyphicons-halflings-regular.svg +228 -228
  9. data/app/assets/fonts/caseadilla/glyphicons-halflings-regular.ttf +0 -0
  10. data/app/assets/fonts/caseadilla/glyphicons-halflings-regular.woff +0 -0
  11. data/app/assets/images/caseadilla/caseadilla.png +0 -0
  12. data/app/assets/javascripts/caseadilla/bootstrap.js +2114 -2114
  13. data/app/assets/javascripts/caseadilla/bootstrap3-wysihtml5.js +520 -520
  14. data/app/assets/javascripts/caseadilla/caseadilla.js +50 -50
  15. data/app/assets/javascripts/caseadilla/html5shiv.js +8 -8
  16. data/app/assets/javascripts/caseadilla/wysihtml5-0.3.0.min.js +260 -260
  17. data/app/assets/stylesheets/caseadilla/bootstrap-glyphicons.css.scss +2 -2
  18. data/app/assets/stylesheets/caseadilla/bootstrap-theme.css +442 -442
  19. data/app/assets/stylesheets/caseadilla/bootstrap-wysihtml5.css +101 -101
  20. data/app/assets/stylesheets/caseadilla/bootstrap.css +6203 -6203
  21. data/app/assets/stylesheets/caseadilla/caseadilla-bootstrap-overrides.css.scss +79 -79
  22. data/app/assets/stylesheets/caseadilla/caseadilla.scss +269 -269
  23. data/app/assets/stylesheets/caseadilla/login.css.scss +80 -80
  24. data/app/controllers/caseadilla/caseadilla_controller.rb +56 -56
  25. data/app/controllers/caseadilla/caseadilla_user_sessions_controller.rb +35 -35
  26. data/app/controllers/caseadilla/password_resets_controller.rb +63 -63
  27. data/app/controllers/caseadilla/roles_controller.rb +64 -64
  28. data/app/controllers/caseadilla/users_controller.rb +117 -117
  29. data/app/helpers/caseadilla/caseadilla_helper.rb +261 -261
  30. data/app/mailers/caseadilla/caseadilla_notification.rb +38 -38
  31. data/app/views/caseadilla/caseadilla/blank.html.erb +11 -11
  32. data/app/views/caseadilla/caseadilla_notification/generate_new_password.erb +11 -11
  33. data/app/views/caseadilla/caseadilla_notification/new_user_information.erb +11 -11
  34. data/app/views/caseadilla/caseadilla_notification/password_reset_instructions.erb +10 -10
  35. data/app/views/caseadilla/caseadilla_user_sessions/new.html.erb +38 -38
  36. data/app/views/caseadilla/roles/_form.html.erb +11 -11
  37. data/app/views/caseadilla/roles/_table.html.erb +27 -27
  38. data/app/views/caseadilla/roles/index.html.erb +14 -14
  39. data/app/views/caseadilla/roles/new.html.erb +17 -17
  40. data/app/views/caseadilla/roles/show.html.erb +17 -17
  41. data/app/views/caseadilla/users/index.html.erb +36 -36
  42. data/app/views/caseadilla/users/new.html.erb +49 -49
  43. data/app/views/caseadilla/users/show.html.erb +38 -38
  44. data/app/views/layouts/caseadilla_auth.html.erb +36 -36
  45. data/app/views/layouts/caseadilla_main.html.erb +110 -118
  46. data/caseadilla.gemspec +48 -48
  47. data/config/initializers/will_paginate.rb +39 -39
  48. data/config/routes.rb +22 -22
  49. data/lib/caseadilla.rb +13 -13
  50. data/lib/caseadilla/engine.rb +34 -34
  51. data/lib/caseadilla/version.rb +1 -1
  52. data/lib/generators/caseadilla/install/install_generator.rb +153 -153
  53. data/lib/generators/caseadilla/install/templates/app/assets/javascripts/caseadilla/custom.js +1 -1
  54. data/lib/generators/caseadilla/install/templates/app/assets/stylesheets/caseadilla/custom.css.scss +2 -2
  55. data/lib/generators/caseadilla/install/templates/app/helpers/caseadilla/config_helper.rb +44 -44
  56. data/lib/generators/caseadilla/install/templates/app/models/user.rb +23 -23
  57. data/lib/generators/caseadilla/install/templates/app/views/caseadilla/layouts/_tab_navigation.html.erb +1 -1
  58. data/lib/generators/caseadilla/install/templates/app/views/caseadilla/layouts/_top_navigation.html.erb +3 -3
  59. data/lib/generators/caseadilla/install/templates/public/robots.txt +4 -4
  60. data/lib/generators/caseadilla/install/templates/steak/config/initializers/caseadilla.rb +7 -7
  61. data/lib/generators/caseadilla/install/templates/steak/db/migrate/add_name_to_users.rb +8 -8
  62. data/lib/generators/caseadilla/install/templates/veggie/config/initializers/caseadilla.rb +7 -7
  63. data/lib/generators/caseadilla/scaffold/scaffold_generator.rb +110 -110
  64. data/lib/generators/caseadilla/scaffold/templates/controller.rb +71 -71
  65. data/lib/generators/caseadilla/scaffold/templates/migration.rb +12 -12
  66. data/lib/generators/caseadilla/scaffold/templates/model.rb +2 -2
  67. data/lib/generators/caseadilla/scaffold/templates/views/_form.html.erb +11 -11
  68. data/lib/generators/caseadilla/scaffold/templates/views/_table.html.erb +18 -18
  69. data/lib/generators/caseadilla/scaffold/templates/views/index.html.erb +14 -14
  70. data/lib/generators/caseadilla/scaffold/templates/views/new.html.erb +17 -17
  71. data/lib/generators/caseadilla/scaffold/templates/views/show.html.erb +17 -17
  72. data/lib/railties/tasks.rake +31 -31
  73. metadata +2 -2
@@ -1,65 +1,65 @@
1
- module Caseadilla
2
- class RolesController < Caseadilla::CaseadillaController
3
- filter_resource_access
4
-
5
- ## optional filters for defining usage according to Caseadilla::AdminUser access_levels
6
- # before_filter :needs_admin, :except => [:action1, :action2]
7
- # before_filter :needs_admin_or_current_user, :only => [:action1, :action2]
8
-
9
- def index
10
- @caseadilla_page_title = 'Roles'
11
- @roles = Role.order(sort_order(:title)).paginate :page => params[:page]
12
- end
13
-
14
- def show
15
- @caseadilla_page_title = 'View role'
16
- @role = Role.find params[:id]
17
- end
18
-
19
- def new
20
- @caseadilla_page_title = 'Add a new role'
21
- @role = Role.new
22
- end
23
-
24
- def create
25
- @role = Role.new role_params
26
-
27
- if @role.save
28
- flash[:notice] = 'Role created'
29
- redirect_to caseadilla_roles_path
30
- else
31
- flash.now[:warning] = 'There were problems when trying to create a new role'
32
- render :action => :new
33
- end
34
- end
35
-
36
- def update
37
- @caseadilla_page_title = 'Update role'
38
-
39
- @role = Role.find params[:id]
40
-
41
- if @role.update_attributes role_params
42
- flash[:notice] = 'Role has been updated'
43
- redirect_to caseadilla_roles_path
44
- else
45
- flash.now[:warning] = 'There were problems when trying to update this role'
46
- render :action => :show
47
- end
48
- end
49
-
50
- def destroy
51
- @role = Role.find params[:id]
52
-
53
- @role.destroy
54
- flash[:notice] = 'Role has been deleted'
55
- redirect_to caseadilla_roles_path
56
- end
57
-
58
- private
59
-
60
- def role_params
61
- params.require(:role).permit(:title)
62
- end
63
-
64
- end
1
+ module Caseadilla
2
+ class RolesController < Caseadilla::CaseadillaController
3
+ filter_resource_access
4
+
5
+ ## optional filters for defining usage according to Caseadilla::AdminUser access_levels
6
+ # before_filter :needs_admin, :except => [:action1, :action2]
7
+ # before_filter :needs_admin_or_current_user, :only => [:action1, :action2]
8
+
9
+ def index
10
+ @caseadilla_page_title = 'Roles'
11
+ @roles = Role.order(sort_order(:title)).paginate :page => params[:page]
12
+ end
13
+
14
+ def show
15
+ @caseadilla_page_title = 'View role'
16
+ @role = Role.find params[:id]
17
+ end
18
+
19
+ def new
20
+ @caseadilla_page_title = 'Add a new role'
21
+ @role = Role.new
22
+ end
23
+
24
+ def create
25
+ @role = Role.new role_params
26
+
27
+ if @role.save
28
+ flash[:notice] = 'Role created'
29
+ redirect_to caseadilla_roles_path
30
+ else
31
+ flash.now[:warning] = 'There were problems when trying to create a new role'
32
+ render :action => :new
33
+ end
34
+ end
35
+
36
+ def update
37
+ @caseadilla_page_title = 'Update role'
38
+
39
+ @role = Role.find params[:id]
40
+
41
+ if @role.update_attributes role_params
42
+ flash[:notice] = 'Role has been updated'
43
+ redirect_to caseadilla_roles_path
44
+ else
45
+ flash.now[:warning] = 'There were problems when trying to update this role'
46
+ render :action => :show
47
+ end
48
+ end
49
+
50
+ def destroy
51
+ @role = Role.find params[:id]
52
+
53
+ @role.destroy
54
+ flash[:notice] = 'Role has been deleted'
55
+ redirect_to caseadilla_roles_path
56
+ end
57
+
58
+ private
59
+
60
+ def role_params
61
+ params.require(:role).permit(:title)
62
+ end
63
+
64
+ end
65
65
  end
@@ -1,118 +1,118 @@
1
- require 'securerandom'
2
-
3
- module Caseadilla
4
- class UsersController < Caseadilla::CaseadillaController
5
- filter_resource_access
6
-
7
- # before_filter :needs_admin, :except => [:show, :destroy, :update, :update_password]
8
- # before_filter :needs_or_current_user, :only => [:show, :destroy, :update, :update_password]
9
-
10
- def index
11
- @caseadilla_page_title = "Users"
12
- @users = User.order(sort_order(:id)).paginate :page => params[:page]
13
- end
14
-
15
- def new
16
- @caseadilla_page_title = "Add a new user"
17
- @caseadilla_user = User.new
18
- @caseadilla_user.time_zone = Rails.configuration.time_zone
19
- end
20
-
21
- def create
22
-
23
- generate_random_password if params[:generate_random_password]
24
-
25
- @caseadilla_user = User.new caseadilla_user_params
26
-
27
- if @caseadilla_user.save
28
- flash[:notice] = "An email has been sent to " + @caseadilla_user.first_name + " with the new account details"
29
- redirect_to caseadilla_users_path
30
- else
31
- flash.now[:warning] = "There were problems when trying to create a new user"
32
- render :action => :new
33
- end
34
- end
35
-
36
- def show
37
- @caseadilla_user = User.find params[:id]
38
- @caseadilla_page_title = "#{@caseadilla_user.first_name} #{@caseadilla_user.last_name} > View user"
39
- end
40
-
41
- def update
42
- @caseadilla_user = User.find params[:id]
43
- @caseadilla_page_title = "#{@caseadilla_user.first_name} #{@caseadilla_user.last_name} > Update user"
44
-
45
- if @caseadilla_user.update_attributes caseadilla_user_params
46
- flash[:notice] = "#{@caseadilla_user.first_name} #{@caseadilla_user.last_name} has been updated"
47
- redirect_to action: :index
48
- else
49
- flash.now[:warning] = "There were problems when trying to update this user"
50
- render :action => :show
51
- return
52
- end
53
- end
54
-
55
- def update_password
56
- @caseadilla_user = User.find params[:id]
57
- @caseadilla_page_title = "#{@caseadilla_user.first_name} #{@caseadilla_user.last_name} > Update password"
58
-
59
- if @caseadilla_user.valid_password? params[:form_current_password]
60
- if params[:caseadilla_user][:password].blank? && params[:caseadilla_user][:password_confirmation].blank?
61
- flash[:warning] = "New password cannot be blank"
62
- elsif @caseadilla_user.update_attributes caseadilla_user_params
63
- flash[:notice] = "Your password has been changed"
64
- else
65
- flash[:warning] = "There were problems when trying to change your password"
66
- end
67
- else
68
- flash[:warning] = "The current password is incorrect"
69
- end
70
-
71
- redirect_to :action => :show
72
- end
73
-
74
- def reset_password
75
- @caseadilla_user = User.find params[:id]
76
- @caseadilla_page_title = "#{@caseadilla_user.first_name} #{@caseadilla_user.last_name} > Reset password"
77
-
78
- if params[:generate_random_password].blank? && params[:caseadilla_user][:password].blank? && params[:caseadilla_user][:password_confirmation].blank?
79
- flash[:warning] = "New password cannot be blank"
80
- else
81
- generate_random_password if params[:generate_random_password]
82
- @caseadilla_user.notify_of_new_password = true unless (@caseadilla_user.id == @session_user.id && params[:generate_random_password].blank?)
83
-
84
- if @caseadilla_user.update_attributes caseadilla_user_params
85
- unless @caseadilla_user.notify_of_new_password
86
- flash[:notice] = "Your password has been reset"
87
- else
88
- flash[:notice] = "Password has been reset and #{@caseadilla_user.first_name} #{@caseadilla_user.last_name} has been notified by email"
89
- end
90
- else
91
- flash[:warning] = "There were problems when trying to reset this user's password"
92
- end
93
- end
94
-
95
- redirect_to :action => :show
96
- end
97
-
98
- def destroy
99
- user = User.find params[:id]
100
- user.destroy
101
- flash[:notice] = "#{user.first_name} #{user.last_name} has been deleted"
102
- redirect_to caseadilla_users_path
103
- end
104
-
105
- private
106
-
107
- def generate_random_password
108
- random_password = random_string = SecureRandom.hex
109
- params[:user] = Hash.new if params[:user].blank?
110
- params[:user].merge! ({:password => random_password, :password_confirmation => random_password})
111
- end
112
-
113
- def caseadilla_user_params
114
- params.require(:user).permit(:email, :first_name, :last_name, :time_zone, :role, :role_id, :password, :password_confirmation)
115
- end
116
-
117
- end
1
+ require 'securerandom'
2
+
3
+ module Caseadilla
4
+ class UsersController < Caseadilla::CaseadillaController
5
+ filter_resource_access
6
+
7
+ # before_filter :needs_admin, :except => [:show, :destroy, :update, :update_password]
8
+ # before_filter :needs_or_current_user, :only => [:show, :destroy, :update, :update_password]
9
+
10
+ def index
11
+ @caseadilla_page_title = "Users"
12
+ @users = User.order(sort_order(:id)).paginate :page => params[:page]
13
+ end
14
+
15
+ def new
16
+ @caseadilla_page_title = "Add a new user"
17
+ @caseadilla_user = User.new
18
+ @caseadilla_user.time_zone = Rails.configuration.time_zone
19
+ end
20
+
21
+ def create
22
+
23
+ generate_random_password if params[:generate_random_password]
24
+
25
+ @caseadilla_user = User.new caseadilla_user_params
26
+
27
+ if @caseadilla_user.save
28
+ flash[:notice] = "An email has been sent to " + @caseadilla_user.first_name + " with the new account details"
29
+ redirect_to caseadilla_users_path
30
+ else
31
+ flash.now[:warning] = "There were problems when trying to create a new user"
32
+ render :action => :new
33
+ end
34
+ end
35
+
36
+ def show
37
+ @caseadilla_user = User.find params[:id]
38
+ @caseadilla_page_title = "#{@caseadilla_user.first_name} #{@caseadilla_user.last_name} > View user"
39
+ end
40
+
41
+ def update
42
+ @caseadilla_user = User.find params[:id]
43
+ @caseadilla_page_title = "#{@caseadilla_user.first_name} #{@caseadilla_user.last_name} > Update user"
44
+
45
+ if @caseadilla_user.update_attributes caseadilla_user_params
46
+ flash[:notice] = "#{@caseadilla_user.first_name} #{@caseadilla_user.last_name} has been updated"
47
+ redirect_to action: :index
48
+ else
49
+ flash.now[:warning] = "There were problems when trying to update this user"
50
+ render :action => :show
51
+ return
52
+ end
53
+ end
54
+
55
+ def update_password
56
+ @caseadilla_user = User.find params[:id]
57
+ @caseadilla_page_title = "#{@caseadilla_user.first_name} #{@caseadilla_user.last_name} > Update password"
58
+
59
+ if @caseadilla_user.valid_password? params[:form_current_password]
60
+ if params[:caseadilla_user][:password].blank? && params[:caseadilla_user][:password_confirmation].blank?
61
+ flash[:warning] = "New password cannot be blank"
62
+ elsif @caseadilla_user.update_attributes caseadilla_user_params
63
+ flash[:notice] = "Your password has been changed"
64
+ else
65
+ flash[:warning] = "There were problems when trying to change your password"
66
+ end
67
+ else
68
+ flash[:warning] = "The current password is incorrect"
69
+ end
70
+
71
+ redirect_to :action => :show
72
+ end
73
+
74
+ def reset_password
75
+ @caseadilla_user = User.find params[:id]
76
+ @caseadilla_page_title = "#{@caseadilla_user.first_name} #{@caseadilla_user.last_name} > Reset password"
77
+
78
+ if params[:generate_random_password].blank? && params[:caseadilla_user][:password].blank? && params[:caseadilla_user][:password_confirmation].blank?
79
+ flash[:warning] = "New password cannot be blank"
80
+ else
81
+ generate_random_password if params[:generate_random_password]
82
+ @caseadilla_user.notify_of_new_password = true unless (@caseadilla_user.id == @session_user.id && params[:generate_random_password].blank?)
83
+
84
+ if @caseadilla_user.update_attributes caseadilla_user_params
85
+ unless @caseadilla_user.notify_of_new_password
86
+ flash[:notice] = "Your password has been reset"
87
+ else
88
+ flash[:notice] = "Password has been reset and #{@caseadilla_user.first_name} #{@caseadilla_user.last_name} has been notified by email"
89
+ end
90
+ else
91
+ flash[:warning] = "There were problems when trying to reset this user's password"
92
+ end
93
+ end
94
+
95
+ redirect_to :action => :show
96
+ end
97
+
98
+ def destroy
99
+ user = User.find params[:id]
100
+ user.destroy
101
+ flash[:notice] = "#{user.first_name} #{user.last_name} has been deleted"
102
+ redirect_to caseadilla_users_path
103
+ end
104
+
105
+ private
106
+
107
+ def generate_random_password
108
+ random_password = random_string = SecureRandom.hex
109
+ params[:user] = Hash.new if params[:user].blank?
110
+ params[:user].merge! ({:password => random_password, :password_confirmation => random_password})
111
+ end
112
+
113
+ def caseadilla_user_params
114
+ params.require(:user).permit(:email, :first_name, :last_name, :time_zone, :role, :role_id, :password, :password_confirmation)
115
+ end
116
+
117
+ end
118
118
  end
@@ -1,262 +1,262 @@
1
- module Caseadilla
2
- module CaseadillaHelper
3
-
4
- def caseadilla_get_footer_string include_version = false
5
- if include_version
6
- "Running on #{link_to 'Caseadilla', 'http://www.github.com/zeiv/caseadilla'} #{caseadilla_get_full_version_string}, an open-source project.".html_safe
7
- else
8
- "Running on #{link_to 'Caseadilla', 'http://www.github.com/zeiv/caseadilla'}, an open-source project.".html_safe
9
- end
10
- end
11
-
12
- def caseadilla_get_full_version_string
13
- Caseadilla::VERSION
14
- end
15
-
16
- def caseadilla_get_short_version_string
17
- Caseadilla::VERSION.slice(0..(str.index('.')))
18
- end
19
-
20
- def caseadilla_generate_page_title
21
-
22
- if @caseadilla_page_title.nil?
23
- return caseadilla_config_website_name
24
- end
25
-
26
- caseadilla_config_website_name + " > " + @caseadilla_page_title
27
- end
28
-
29
- def caseadilla_get_access_level_text level
30
- case level
31
- when $CASEIN_USER_ACCESS_LEVEL_ADMIN
32
- return "Administrator"
33
- when $CASEIN_USER_ACCESS_LEVEL_USER
34
- return "User"
35
- else
36
- return "Unknown"
37
- end
38
- end
39
-
40
- def caseadilla_get_access_level_array
41
- [["Administrator", $CASEIN_USER_ACCESS_LEVEL_ADMIN], ["User", $CASEIN_USER_ACCESS_LEVEL_USER]]
42
- end
43
-
44
- def caseadilla_pagination_details objs
45
- " <small class='pagination-details'>/ page #{objs.current_page} of #{objs.total_pages}</small>".html_safe if objs.current_page && objs.total_pages > 1
46
- end
47
-
48
- def caseadilla_table_cell_link contents, link, options = {}
49
-
50
- if options.key? :caseadilla_truncate
51
- contents = truncate(contents, :length => options[:caseadilla_truncate], :omission => "...")
52
- end
53
-
54
- link_to "#{contents}".html_safe, link, options
55
- end
56
-
57
- def caseadilla_table_cell_no_link contents, options = {}
58
-
59
- if options.key? :caseadilla_truncate
60
- contents = truncate(contents, :length => options[:caseadilla_truncate], :omission => "...")
61
- end
62
-
63
- "<div class='no-link'>#{contents}</div>".html_safe
64
- end
65
-
66
- def caseadilla_show_icon icon_name
67
- "<div class='icon'><span class='glyphicon glyphicon-#{icon_name}'></span></div>".html_safe
68
- end
69
-
70
- def caseadilla_show_row_icon icon_name
71
- "<div class='iconRow'><span class='glyphicon glyphicon-#{icon_name}'></span></div>".html_safe
72
- end
73
-
74
- def caseadilla_format_date date, format = "%b %d, %Y"
75
- date.strftime(format)
76
- end
77
-
78
- def caseadilla_format_time time, format = "%H:%M"
79
- time.strftime(format)
80
- end
81
-
82
- def caseadilla_format_datetime datetime, format = "%b %d, %Y %H:%M"
83
- datetime.strftime(format)
84
- end
85
-
86
- def caseadilla_sort_link title, column, options = {}
87
- condition = options[:unless] if options.has_key?(:unless)
88
- icon_to_show_html = "<div class='table-header-icon'>&nbsp;</div>".html_safe
89
- if params[:c].to_s == column.to_s
90
- icon_to_show = params[:d] == 'down' ? 'chevron-up' : 'chevron-down'
91
- icon_to_show_html = "<div class='table-header-icon glyphicon glyphicon-#{icon_to_show}'></div>".html_safe
92
- end
93
- sort_dir = params[:d] == 'down' ? 'up' : 'down'
94
- link_to_unless(condition, title, request.parameters.merge({:c => column, :d => sort_dir})) + icon_to_show_html
95
- end
96
-
97
- def caseadilla_yes_no_label value
98
- if value
99
- return "<span class='label label-success'>Yes</span>".html_safe
100
- else
101
- return "<span class='label label-danger'>No</span>".html_safe
102
- end
103
- end
104
-
105
- def caseadilla_no_yes_label value
106
- if value
107
- return "<span class='label label-danger'>Yes</span>".html_safe
108
- else
109
- return "<span class='label label-success'>No</span>".html_safe
110
- end
111
- end
112
-
113
- # Styled form tag helpers
114
-
115
- def caseadilla_text_field form, obj, attribute, options = {}
116
- caseadilla_form_tag_wrapper(form.text_field(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
117
- end
118
-
119
- def caseadilla_password_field form, obj, attribute, options = {}
120
- caseadilla_form_tag_wrapper(form.password_field(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
121
- end
122
-
123
- def caseadilla_text_area form, obj, attribute, options = {}
124
- caseadilla_form_tag_wrapper(form.text_area(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
125
- end
126
-
127
- def caseadilla_text_area_wysiwyg form, obj, attribute, options = {}
128
- options.reverse_merge!({style: "height: 250px;"})
129
- caseadilla_form_tag_wrapper(form.text_area(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control wysihtml5'))), form, obj, attribute, options).html_safe
130
- end
131
-
132
- def caseadilla_check_box form, obj, attribute, options = {}
133
- form_tag = "<div class='check-box'>#{form.check_box(attribute, strip_caseadilla_options(options))}</div>".html_safe
134
- caseadilla_form_tag_wrapper(form_tag, form, obj, attribute, options).html_safe
135
- end
136
-
137
- def caseadilla_check_box_group form, obj, check_boxes = {}
138
- form_tags = ""
139
-
140
- for check_box in check_boxes
141
- form_tags += caseadilla_check_box form, obj, check_box[0], check_box[1]
142
- end
143
-
144
- caseadilla_form_tag_wrapper(form_tag, form, obj, attribute, options)
145
- end
146
-
147
- def caseadilla_radio_button form, obj, attribute, tag_value, options = {}
148
- form_tag = form.radio_button(obj, attribute, tag_value, strip_caseadilla_options(options))
149
-
150
- if options.key? :caseadilla_button_label
151
- form_tag = "<div>" + form_tag + "<span class=\"rcText\">#{options[:caseadilla_button_label]}</span></div>".html_safe
152
- end
153
-
154
- caseadilla_form_tag_wrapper(form_tag, form, obj, attribute, options).html_safe
155
- end
156
-
157
- def caseadilla_radio_button_group form, obj, radio_buttons = {}
158
- form_tags = ""
159
-
160
- for radio_button in radio_buttons
161
- form_tags += caseadilla_radio_button form, obj, check_box[0], check_box[1], check_box[2]
162
- end
163
-
164
- caseadilla_form_tag_wrapper(form_tag, form, obj, attribute, options).html_safe
165
- end
166
-
167
- def caseadilla_select form, obj, attribute, option_tags, options = {}
168
- caseadilla_form_tag_wrapper(form.select(attribute, option_tags, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')), form, obj, attribute, options).html_safe
169
- end
170
-
171
- def caseadilla_time_zone_select form, obj, attribute, option_tags, options = {}
172
- caseadilla_form_tag_wrapper(form.time_zone_select(attribute, option_tags, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')), form, obj, attribute, options).html_safe
173
- end
174
-
175
- def caseadilla_collection_select form, obj, attribute, collection, value_method, text_method, options = {}
176
- caseadilla_form_tag_wrapper(collection_select(obj.class.name.downcase.to_sym, attribute, collection, value_method, text_method, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')), form, obj, attribute, options).html_safe
177
- end
178
-
179
- def caseadilla_collection_check_boxes form, obj, attribute, collection, value_method, text_method, options = {}
180
- caseadilla_form_tag_wrapper(collection_check_boxes(obj, attribute, collection, value_method, text_method, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')), form, obj, attribute, options).html_safe
181
- end
182
-
183
- def caseadilla_date_select form, obj, attribute, options = {}
184
- caseadilla_form_tag_wrapper("<div class='caseadilla-date-select'>".html_safe + form.date_select(attribute, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')) + "</div>".html_safe, form, obj, attribute, options).html_safe
185
- end
186
-
187
- def caseadilla_time_select form, obj, attribute, options = {}
188
- caseadilla_form_tag_wrapper("<div class='caseadilla-time-select'>".html_safe + form.time_select(attribute, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')) + "</div>".html_safe, form, obj, attribute, options).html_safe
189
- end
190
-
191
- def caseadilla_datetime_select form, obj, attribute, options = {}
192
- caseadilla_form_tag_wrapper("<div class='caseadilla-datetime-select'>".html_safe + form.datetime_select(attribute, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')) + "</div>".html_safe, form, obj, attribute, options).html_safe
193
- end
194
-
195
- def caseadilla_file_field form, obj, object_name, attribute, options = {}
196
- class_hash = merged_class_hash(options, 'form-control')
197
- contents = "<div class='#{class_hash[:class]}'>" + file_field(object_name, attribute, strip_caseadilla_options(options)) + '</div>'
198
-
199
- if options.key? :caseadilla_contents_preview
200
- contents = options[:caseadilla_contents_preview].html_safe + contents.html_safe
201
- end
202
-
203
- caseadilla_form_tag_wrapper(contents, form, obj, attribute, options).html_safe
204
- end
205
-
206
- def caseadilla_hidden_field form, obj, attribute, options = {}
207
- form.hidden_field(attribute, strip_caseadilla_options(options)).html_safe
208
- end
209
-
210
- def caseadilla_custom_field form, obj, attribute, custom_contents, options = {}
211
- caseadilla_form_tag_wrapper(custom_contents, form, obj, attribute, options).html_safe
212
- end
213
-
214
- protected
215
-
216
- def strip_caseadilla_options options
217
- options.reject {|key, value| key.to_s.include? "caseadilla_" }
218
- end
219
-
220
- def merged_class_hash options, new_class
221
- if options.key? :class
222
- new_class += " #{options[:class]}"
223
- end
224
-
225
- {:class => new_class}
226
- end
227
-
228
- def options_hash_with_merged_classes options, new_class
229
- if options.key? :class
230
- new_class += " #{options[:class]}"
231
- end
232
- options[:class] = new_class
233
- options
234
- end
235
-
236
- def caseadilla_form_tag_wrapper form_tag, form, obj, attribute, options = {}
237
- unless options.key? :caseadilla_label
238
- human_attribute_name = attribute.to_s.humanize
239
- else
240
- human_attribute_name = options[:caseadilla_label]
241
- end
242
-
243
- sublabel = ""
244
-
245
- if options.key? :caseadilla_sublabel
246
- sublabel = " <small>#{options[:caseadilla_sublabel]}</small>".html_safe
247
- end
248
-
249
- html = ""
250
-
251
- if obj && obj.errors[attribute].any?
252
- html += "<div class='form-group has-error'>"
253
- html += form.label(attribute, "#{human_attribute_name} #{obj.errors[attribute].first}".html_safe, :class => "control-label")
254
- else
255
- html += "<div class='form-group'>"
256
- html += form.label(attribute, "#{human_attribute_name}#{sublabel}".html_safe, :class => "control-label")
257
- end
258
-
259
- html += "<div class='well'>#{form_tag}</div></div>"
260
- end
261
- end
1
+ module Caseadilla
2
+ module CaseadillaHelper
3
+
4
+ def caseadilla_get_footer_string include_version = false
5
+ if include_version
6
+ "Running on #{link_to 'Caseadilla', 'http://www.github.com/zeiv/caseadilla'} #{caseadilla_get_full_version_string}, an open-source project.".html_safe
7
+ else
8
+ "Running on #{link_to 'Caseadilla', 'http://www.github.com/zeiv/caseadilla'}, an open-source project.".html_safe
9
+ end
10
+ end
11
+
12
+ def caseadilla_get_full_version_string
13
+ Caseadilla::VERSION
14
+ end
15
+
16
+ def caseadilla_get_short_version_string
17
+ Caseadilla::VERSION.slice(0..(str.index('.')))
18
+ end
19
+
20
+ def caseadilla_generate_page_title
21
+
22
+ if @caseadilla_page_title.nil?
23
+ return caseadilla_config_website_name
24
+ end
25
+
26
+ caseadilla_config_website_name + " > " + @caseadilla_page_title
27
+ end
28
+
29
+ def caseadilla_get_access_level_text level
30
+ case level
31
+ when $CASEIN_USER_ACCESS_LEVEL_ADMIN
32
+ return "Administrator"
33
+ when $CASEIN_USER_ACCESS_LEVEL_USER
34
+ return "User"
35
+ else
36
+ return "Unknown"
37
+ end
38
+ end
39
+
40
+ def caseadilla_get_access_level_array
41
+ [["Administrator", $CASEIN_USER_ACCESS_LEVEL_ADMIN], ["User", $CASEIN_USER_ACCESS_LEVEL_USER]]
42
+ end
43
+
44
+ def caseadilla_pagination_details objs
45
+ " <small class='pagination-details'>/ page #{objs.current_page} of #{objs.total_pages}</small>".html_safe if objs.current_page && objs.total_pages > 1
46
+ end
47
+
48
+ def caseadilla_table_cell_link contents, link, options = {}
49
+
50
+ if options.key? :caseadilla_truncate
51
+ contents = truncate(contents, :length => options[:caseadilla_truncate], :omission => "...")
52
+ end
53
+
54
+ link_to "#{contents}".html_safe, link, options
55
+ end
56
+
57
+ def caseadilla_table_cell_no_link contents, options = {}
58
+
59
+ if options.key? :caseadilla_truncate
60
+ contents = truncate(contents, :length => options[:caseadilla_truncate], :omission => "...")
61
+ end
62
+
63
+ "<div class='no-link'>#{contents}</div>".html_safe
64
+ end
65
+
66
+ def caseadilla_show_icon icon_name
67
+ "<div class='icon'><span class='glyphicon glyphicon-#{icon_name}'></span></div>".html_safe
68
+ end
69
+
70
+ def caseadilla_show_row_icon icon_name
71
+ "<div class='iconRow'><span class='glyphicon glyphicon-#{icon_name}'></span></div>".html_safe
72
+ end
73
+
74
+ def caseadilla_format_date date, format = "%b %d, %Y"
75
+ date.strftime(format)
76
+ end
77
+
78
+ def caseadilla_format_time time, format = "%H:%M"
79
+ time.strftime(format)
80
+ end
81
+
82
+ def caseadilla_format_datetime datetime, format = "%b %d, %Y %H:%M"
83
+ datetime.strftime(format)
84
+ end
85
+
86
+ def caseadilla_sort_link title, column, options = {}
87
+ condition = options[:unless] if options.has_key?(:unless)
88
+ icon_to_show_html = "<div class='table-header-icon'>&nbsp;</div>".html_safe
89
+ if params[:c].to_s == column.to_s
90
+ icon_to_show = params[:d] == 'down' ? 'chevron-up' : 'chevron-down'
91
+ icon_to_show_html = "<div class='table-header-icon glyphicon glyphicon-#{icon_to_show}'></div>".html_safe
92
+ end
93
+ sort_dir = params[:d] == 'down' ? 'up' : 'down'
94
+ link_to_unless(condition, title, request.parameters.merge({:c => column, :d => sort_dir})) + icon_to_show_html
95
+ end
96
+
97
+ def caseadilla_yes_no_label value
98
+ if value
99
+ return "<span class='label label-success'>Yes</span>".html_safe
100
+ else
101
+ return "<span class='label label-danger'>No</span>".html_safe
102
+ end
103
+ end
104
+
105
+ def caseadilla_no_yes_label value
106
+ if value
107
+ return "<span class='label label-danger'>Yes</span>".html_safe
108
+ else
109
+ return "<span class='label label-success'>No</span>".html_safe
110
+ end
111
+ end
112
+
113
+ # Styled form tag helpers
114
+
115
+ def caseadilla_text_field form, obj, attribute, options = {}
116
+ caseadilla_form_tag_wrapper(form.text_field(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
117
+ end
118
+
119
+ def caseadilla_password_field form, obj, attribute, options = {}
120
+ caseadilla_form_tag_wrapper(form.password_field(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
121
+ end
122
+
123
+ def caseadilla_text_area form, obj, attribute, options = {}
124
+ caseadilla_form_tag_wrapper(form.text_area(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control'))), form, obj, attribute, options).html_safe
125
+ end
126
+
127
+ def caseadilla_text_area_wysiwyg form, obj, attribute, options = {}
128
+ options.reverse_merge!({style: "height: 250px;"})
129
+ caseadilla_form_tag_wrapper(form.text_area(attribute, strip_caseadilla_options(options_hash_with_merged_classes(options, 'form-control wysihtml5'))), form, obj, attribute, options).html_safe
130
+ end
131
+
132
+ def caseadilla_check_box form, obj, attribute, options = {}
133
+ form_tag = "<div class='check-box'>#{form.check_box(attribute, strip_caseadilla_options(options))}</div>".html_safe
134
+ caseadilla_form_tag_wrapper(form_tag, form, obj, attribute, options).html_safe
135
+ end
136
+
137
+ def caseadilla_check_box_group form, obj, check_boxes = {}
138
+ form_tags = ""
139
+
140
+ for check_box in check_boxes
141
+ form_tags += caseadilla_check_box form, obj, check_box[0], check_box[1]
142
+ end
143
+
144
+ caseadilla_form_tag_wrapper(form_tag, form, obj, attribute, options)
145
+ end
146
+
147
+ def caseadilla_radio_button form, obj, attribute, tag_value, options = {}
148
+ form_tag = form.radio_button(obj, attribute, tag_value, strip_caseadilla_options(options))
149
+
150
+ if options.key? :caseadilla_button_label
151
+ form_tag = "<div>" + form_tag + "<span class=\"rcText\">#{options[:caseadilla_button_label]}</span></div>".html_safe
152
+ end
153
+
154
+ caseadilla_form_tag_wrapper(form_tag, form, obj, attribute, options).html_safe
155
+ end
156
+
157
+ def caseadilla_radio_button_group form, obj, radio_buttons = {}
158
+ form_tags = ""
159
+
160
+ for radio_button in radio_buttons
161
+ form_tags += caseadilla_radio_button form, obj, check_box[0], check_box[1], check_box[2]
162
+ end
163
+
164
+ caseadilla_form_tag_wrapper(form_tag, form, obj, attribute, options).html_safe
165
+ end
166
+
167
+ def caseadilla_select form, obj, attribute, option_tags, options = {}
168
+ caseadilla_form_tag_wrapper(form.select(attribute, option_tags, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')), form, obj, attribute, options).html_safe
169
+ end
170
+
171
+ def caseadilla_time_zone_select form, obj, attribute, option_tags, options = {}
172
+ caseadilla_form_tag_wrapper(form.time_zone_select(attribute, option_tags, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')), form, obj, attribute, options).html_safe
173
+ end
174
+
175
+ def caseadilla_collection_select form, obj, attribute, collection, value_method, text_method, options = {}
176
+ caseadilla_form_tag_wrapper(collection_select(obj.class.name.downcase.to_sym, attribute, collection, value_method, text_method, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')), form, obj, attribute, options).html_safe
177
+ end
178
+
179
+ def caseadilla_collection_check_boxes form, obj, attribute, collection, value_method, text_method, options = {}
180
+ caseadilla_form_tag_wrapper(collection_check_boxes(obj, attribute, collection, value_method, text_method, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')), form, obj, attribute, options).html_safe
181
+ end
182
+
183
+ def caseadilla_date_select form, obj, attribute, options = {}
184
+ caseadilla_form_tag_wrapper("<div class='caseadilla-date-select'>".html_safe + form.date_select(attribute, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')) + "</div>".html_safe, form, obj, attribute, options).html_safe
185
+ end
186
+
187
+ def caseadilla_time_select form, obj, attribute, options = {}
188
+ caseadilla_form_tag_wrapper("<div class='caseadilla-time-select'>".html_safe + form.time_select(attribute, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')) + "</div>".html_safe, form, obj, attribute, options).html_safe
189
+ end
190
+
191
+ def caseadilla_datetime_select form, obj, attribute, options = {}
192
+ caseadilla_form_tag_wrapper("<div class='caseadilla-datetime-select'>".html_safe + form.datetime_select(attribute, strip_caseadilla_options(options), merged_class_hash(options, 'form-control')) + "</div>".html_safe, form, obj, attribute, options).html_safe
193
+ end
194
+
195
+ def caseadilla_file_field form, obj, object_name, attribute, options = {}
196
+ class_hash = merged_class_hash(options, 'form-control')
197
+ contents = "<div class='#{class_hash[:class]}'>" + file_field(object_name, attribute, strip_caseadilla_options(options)) + '</div>'
198
+
199
+ if options.key? :caseadilla_contents_preview
200
+ contents = options[:caseadilla_contents_preview].html_safe + contents.html_safe
201
+ end
202
+
203
+ caseadilla_form_tag_wrapper(contents, form, obj, attribute, options).html_safe
204
+ end
205
+
206
+ def caseadilla_hidden_field form, obj, attribute, options = {}
207
+ form.hidden_field(attribute, strip_caseadilla_options(options)).html_safe
208
+ end
209
+
210
+ def caseadilla_custom_field form, obj, attribute, custom_contents, options = {}
211
+ caseadilla_form_tag_wrapper(custom_contents, form, obj, attribute, options).html_safe
212
+ end
213
+
214
+ protected
215
+
216
+ def strip_caseadilla_options options
217
+ options.reject {|key, value| key.to_s.include? "caseadilla_" }
218
+ end
219
+
220
+ def merged_class_hash options, new_class
221
+ if options.key? :class
222
+ new_class += " #{options[:class]}"
223
+ end
224
+
225
+ {:class => new_class}
226
+ end
227
+
228
+ def options_hash_with_merged_classes options, new_class
229
+ if options.key? :class
230
+ new_class += " #{options[:class]}"
231
+ end
232
+ options[:class] = new_class
233
+ options
234
+ end
235
+
236
+ def caseadilla_form_tag_wrapper form_tag, form, obj, attribute, options = {}
237
+ unless options.key? :caseadilla_label
238
+ human_attribute_name = attribute.to_s.humanize
239
+ else
240
+ human_attribute_name = options[:caseadilla_label]
241
+ end
242
+
243
+ sublabel = ""
244
+
245
+ if options.key? :caseadilla_sublabel
246
+ sublabel = " <small>#{options[:caseadilla_sublabel]}</small>".html_safe
247
+ end
248
+
249
+ html = ""
250
+
251
+ if obj && obj.errors[attribute].any?
252
+ html += "<div class='form-group has-error'>"
253
+ html += form.label(attribute, "#{human_attribute_name} #{obj.errors[attribute].first}".html_safe, :class => "control-label")
254
+ else
255
+ html += "<div class='form-group'>"
256
+ html += form.label(attribute, "#{human_attribute_name}#{sublabel}".html_safe, :class => "control-label")
257
+ end
258
+
259
+ html += "<div class='well'>#{form_tag}</div></div>"
260
+ end
261
+ end
262
262
  end