beautiful_scaffold 0.3.5 → 2.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +2 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG +66 -1
  5. data/Gemfile +24 -17
  6. data/Gemfile.lock +209 -0
  7. data/README.rdoc +56 -44
  8. data/Rakefile +32 -0
  9. data/beautiful_scaffold.gemspec +8 -5
  10. data/lib/beautiful_scaffold/version.rb +3 -0
  11. data/lib/generators/beautiful_devisecancan_generator.rb +1 -1
  12. data/lib/generators/beautiful_jointable_generator.rb +40 -7
  13. data/lib/generators/beautiful_locale_generator.rb +102 -80
  14. data/lib/generators/beautiful_migration_generator.rb +12 -20
  15. data/lib/generators/beautiful_scaffold_common_methods.rb +88 -29
  16. data/lib/generators/beautiful_scaffold_generator.rb +166 -111
  17. data/lib/generators/templates/app/assets/javascripts/application-bs.js +11 -19
  18. data/lib/generators/templates/app/assets/javascripts/beautiful_scaffold.js +68 -78
  19. data/lib/generators/templates/app/assets/javascripts/bootstrap-datetimepicker-for-beautiful-scaffold.js +23 -42
  20. data/lib/generators/templates/app/assets/javascripts/fixed_menu.js +3 -1
  21. data/lib/generators/templates/app/assets/javascripts/jstree.min.js +6 -0
  22. data/lib/generators/templates/app/assets/stylesheets/application-bs.css +14 -12
  23. data/lib/generators/templates/app/assets/stylesheets/beautiful-scaffold.css.scss +36 -3
  24. data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/32px.png +0 -0
  25. data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/40px.png +0 -0
  26. data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/style.scss +1146 -0
  27. data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/throbber.gif +0 -0
  28. data/lib/generators/templates/app/assets/stylesheets/themes/default/32px.png +0 -0
  29. data/lib/generators/templates/app/assets/stylesheets/themes/default/40px.png +0 -0
  30. data/lib/generators/templates/app/assets/stylesheets/themes/default/style.scss +1102 -0
  31. data/lib/generators/templates/app/assets/stylesheets/themes/default/throbber.gif +0 -0
  32. data/lib/generators/templates/app/controllers/base.rb +32 -15
  33. data/lib/generators/templates/app/controllers/master_base.rb +55 -47
  34. data/lib/generators/templates/app/helpers/beautiful_helper.rb +104 -67
  35. data/lib/generators/templates/app/helpers/model_helper.rb +14 -3
  36. data/lib/generators/templates/app/initializers/link_renderer.rb +24 -17
  37. data/lib/generators/templates/app/initializers/ransack.rb +16 -0
  38. data/lib/generators/templates/app/locales/beautiful_scaffold.ja.yml +50 -0
  39. data/lib/generators/templates/app/models/concerns/fulltext_concern.rb +10 -10
  40. data/lib/generators/templates/app/views/_form.html.erb +5 -2
  41. data/lib/generators/templates/app/views/_form_habtm_tag.html.erb +6 -2
  42. data/lib/generators/templates/app/views/_mass_inserting.html.erb +40 -31
  43. data/lib/generators/templates/app/views/_modal_columns.html.erb +4 -4
  44. data/lib/generators/templates/app/views/edit.html.erb +1 -3
  45. data/lib/generators/templates/app/views/index.html.erb +84 -58
  46. data/lib/generators/templates/app/views/layout.html.erb +29 -47
  47. data/lib/generators/templates/app/views/new.html.erb +0 -2
  48. data/lib/generators/templates/app/views/partials/_forget_password.html.erb +2 -2
  49. data/lib/generators/templates/app/views/partials/_form_field.html.erb +7 -33
  50. data/lib/generators/templates/app/views/partials/_index_batch.html.erb +1 -1
  51. data/lib/generators/templates/app/views/partials/_index_column.html.erb +4 -6
  52. data/lib/generators/templates/app/views/partials/_index_header.html.erb +1 -1
  53. data/lib/generators/templates/app/views/partials/_index_search.html.erb +2 -4
  54. data/lib/generators/templates/app/views/partials/_index_search_default_fields.html.erb +1 -1
  55. data/lib/generators/templates/app/views/partials/_register_form.html.erb +2 -2
  56. data/lib/generators/templates/app/views/partials/_show_field.html.erb +3 -3
  57. data/lib/generators/templates/app/views/partials/_sign_in_form.html.erb +1 -1
  58. data/lib/generators/templates/app/views/partials/_sign_in_sign_out.html.erb +2 -2
  59. data/lib/generators/templates/app/views/show.html.erb +2 -2
  60. data/lib/generators/templates/app/views/treeview.html.erb +8 -5
  61. metadata +43 -188
  62. data/lib/generators/templates/app/assets/javascripts/bootstrap-datepicker.js +0 -834
  63. data/lib/generators/templates/app/assets/javascripts/bootstrap-timepicker.js +0 -797
  64. data/lib/generators/templates/app/assets/javascripts/jquery.jstree.js +0 -4551
  65. data/lib/generators/templates/app/assets/javascripts/jquery.livequery.js +0 -226
  66. data/lib/generators/templates/app/assets/stylesheets/bootstrap_and_overrides.css.less +0 -40
  67. data/lib/generators/templates/app/assets/stylesheets/datepicker.css +0 -224
  68. data/lib/generators/templates/app/assets/stylesheets/reset.css +0 -48
  69. data/lib/generators/templates/app/assets/stylesheets/themes/default/d.gif +0 -0
  70. data/lib/generators/templates/app/assets/stylesheets/themes/default/d.png +0 -0
  71. data/lib/generators/templates/app/assets/stylesheets/themes/default/style.css +0 -74
  72. data/lib/generators/templates/app/assets/stylesheets/timepicker.css +0 -89
  73. data/lib/generators/templates/markitup/jquery.markitup.js +0 -593
  74. data/lib/generators/templates/markitup/sets/bbcode/images/bold.png +0 -0
  75. data/lib/generators/templates/markitup/sets/bbcode/images/clean.png +0 -0
  76. data/lib/generators/templates/markitup/sets/bbcode/images/code.png +0 -0
  77. data/lib/generators/templates/markitup/sets/bbcode/images/fonts.png +0 -0
  78. data/lib/generators/templates/markitup/sets/bbcode/images/italic.png +0 -0
  79. data/lib/generators/templates/markitup/sets/bbcode/images/link.png +0 -0
  80. data/lib/generators/templates/markitup/sets/bbcode/images/list-bullet.png +0 -0
  81. data/lib/generators/templates/markitup/sets/bbcode/images/list-item.png +0 -0
  82. data/lib/generators/templates/markitup/sets/bbcode/images/list-numeric.png +0 -0
  83. data/lib/generators/templates/markitup/sets/bbcode/images/picture.png +0 -0
  84. data/lib/generators/templates/markitup/sets/bbcode/images/preview.png +0 -0
  85. data/lib/generators/templates/markitup/sets/bbcode/images/quotes.png +0 -0
  86. data/lib/generators/templates/markitup/sets/bbcode/images/stroke.png +0 -0
  87. data/lib/generators/templates/markitup/sets/bbcode/images/underline.png +0 -0
  88. data/lib/generators/templates/markitup/sets/bbcode/readme.txt +0 -11
  89. data/lib/generators/templates/markitup/sets/bbcode/set.js +0 -39
  90. data/lib/generators/templates/markitup/sets/bbcode/style.css +0 -47
  91. data/lib/generators/templates/markitup/sets/default/images/bold.png +0 -0
  92. data/lib/generators/templates/markitup/sets/default/images/clean.png +0 -0
  93. data/lib/generators/templates/markitup/sets/default/images/image.png +0 -0
  94. data/lib/generators/templates/markitup/sets/default/images/italic.png +0 -0
  95. data/lib/generators/templates/markitup/sets/default/images/link.png +0 -0
  96. data/lib/generators/templates/markitup/sets/default/images/list-bullet.png +0 -0
  97. data/lib/generators/templates/markitup/sets/default/images/list-numeric.png +0 -0
  98. data/lib/generators/templates/markitup/sets/default/images/picture.png +0 -0
  99. data/lib/generators/templates/markitup/sets/default/images/preview.png +0 -0
  100. data/lib/generators/templates/markitup/sets/default/images/stroke.png +0 -0
  101. data/lib/generators/templates/markitup/sets/default/set.js +0 -30
  102. data/lib/generators/templates/markitup/sets/default/style.css +0 -34
  103. data/lib/generators/templates/markitup/sets/html/images/bold.png +0 -0
  104. data/lib/generators/templates/markitup/sets/html/images/clean.png +0 -0
  105. data/lib/generators/templates/markitup/sets/html/images/h1.png +0 -0
  106. data/lib/generators/templates/markitup/sets/html/images/h2.png +0 -0
  107. data/lib/generators/templates/markitup/sets/html/images/h3.png +0 -0
  108. data/lib/generators/templates/markitup/sets/html/images/h4.png +0 -0
  109. data/lib/generators/templates/markitup/sets/html/images/h5.png +0 -0
  110. data/lib/generators/templates/markitup/sets/html/images/h6.png +0 -0
  111. data/lib/generators/templates/markitup/sets/html/images/image.png +0 -0
  112. data/lib/generators/templates/markitup/sets/html/images/italic.png +0 -0
  113. data/lib/generators/templates/markitup/sets/html/images/link.png +0 -0
  114. data/lib/generators/templates/markitup/sets/html/images/list-bullet.png +0 -0
  115. data/lib/generators/templates/markitup/sets/html/images/list-item.png +0 -0
  116. data/lib/generators/templates/markitup/sets/html/images/list-numeric.png +0 -0
  117. data/lib/generators/templates/markitup/sets/html/images/paragraph.png +0 -0
  118. data/lib/generators/templates/markitup/sets/html/images/picture.png +0 -0
  119. data/lib/generators/templates/markitup/sets/html/images/preview.png +0 -0
  120. data/lib/generators/templates/markitup/sets/html/images/stroke.png +0 -0
  121. data/lib/generators/templates/markitup/sets/html/readme.txt +0 -11
  122. data/lib/generators/templates/markitup/sets/html/set.js +0 -39
  123. data/lib/generators/templates/markitup/sets/html/style.css +0 -59
  124. data/lib/generators/templates/markitup/sets/markdown/images/bold.png +0 -0
  125. data/lib/generators/templates/markitup/sets/markdown/images/code.png +0 -0
  126. data/lib/generators/templates/markitup/sets/markdown/images/h1.png +0 -0
  127. data/lib/generators/templates/markitup/sets/markdown/images/h2.png +0 -0
  128. data/lib/generators/templates/markitup/sets/markdown/images/h3.png +0 -0
  129. data/lib/generators/templates/markitup/sets/markdown/images/h4.png +0 -0
  130. data/lib/generators/templates/markitup/sets/markdown/images/h5.png +0 -0
  131. data/lib/generators/templates/markitup/sets/markdown/images/h6.png +0 -0
  132. data/lib/generators/templates/markitup/sets/markdown/images/italic.png +0 -0
  133. data/lib/generators/templates/markitup/sets/markdown/images/link.png +0 -0
  134. data/lib/generators/templates/markitup/sets/markdown/images/list-bullet.png +0 -0
  135. data/lib/generators/templates/markitup/sets/markdown/images/list-numeric.png +0 -0
  136. data/lib/generators/templates/markitup/sets/markdown/images/picture.png +0 -0
  137. data/lib/generators/templates/markitup/sets/markdown/images/preview.png +0 -0
  138. data/lib/generators/templates/markitup/sets/markdown/images/quotes.png +0 -0
  139. data/lib/generators/templates/markitup/sets/markdown/readme.txt +0 -11
  140. data/lib/generators/templates/markitup/sets/markdown/set.js +0 -52
  141. data/lib/generators/templates/markitup/sets/markdown/style.css +0 -54
  142. data/lib/generators/templates/markitup/sets/textile/images/bold.png +0 -0
  143. data/lib/generators/templates/markitup/sets/textile/images/code.png +0 -0
  144. data/lib/generators/templates/markitup/sets/textile/images/h1.png +0 -0
  145. data/lib/generators/templates/markitup/sets/textile/images/h2.png +0 -0
  146. data/lib/generators/templates/markitup/sets/textile/images/h3.png +0 -0
  147. data/lib/generators/templates/markitup/sets/textile/images/h4.png +0 -0
  148. data/lib/generators/templates/markitup/sets/textile/images/h5.png +0 -0
  149. data/lib/generators/templates/markitup/sets/textile/images/h6.png +0 -0
  150. data/lib/generators/templates/markitup/sets/textile/images/italic.png +0 -0
  151. data/lib/generators/templates/markitup/sets/textile/images/link.png +0 -0
  152. data/lib/generators/templates/markitup/sets/textile/images/list-bullet.png +0 -0
  153. data/lib/generators/templates/markitup/sets/textile/images/list-numeric.png +0 -0
  154. data/lib/generators/templates/markitup/sets/textile/images/paragraph.png +0 -0
  155. data/lib/generators/templates/markitup/sets/textile/images/picture.png +0 -0
  156. data/lib/generators/templates/markitup/sets/textile/images/preview.png +0 -0
  157. data/lib/generators/templates/markitup/sets/textile/images/quotes.png +0 -0
  158. data/lib/generators/templates/markitup/sets/textile/images/stroke.png +0 -0
  159. data/lib/generators/templates/markitup/sets/textile/readme.txt +0 -11
  160. data/lib/generators/templates/markitup/sets/textile/set.js +0 -40
  161. data/lib/generators/templates/markitup/sets/textile/style.css +0 -60
  162. data/lib/generators/templates/markitup/sets/wiki/images/bold.png +0 -0
  163. data/lib/generators/templates/markitup/sets/wiki/images/code.png +0 -0
  164. data/lib/generators/templates/markitup/sets/wiki/images/h1.png +0 -0
  165. data/lib/generators/templates/markitup/sets/wiki/images/h2.png +0 -0
  166. data/lib/generators/templates/markitup/sets/wiki/images/h3.png +0 -0
  167. data/lib/generators/templates/markitup/sets/wiki/images/h4.png +0 -0
  168. data/lib/generators/templates/markitup/sets/wiki/images/h5.png +0 -0
  169. data/lib/generators/templates/markitup/sets/wiki/images/h6.png +0 -0
  170. data/lib/generators/templates/markitup/sets/wiki/images/italic.png +0 -0
  171. data/lib/generators/templates/markitup/sets/wiki/images/link.png +0 -0
  172. data/lib/generators/templates/markitup/sets/wiki/images/list-bullet.png +0 -0
  173. data/lib/generators/templates/markitup/sets/wiki/images/list-numeric.png +0 -0
  174. data/lib/generators/templates/markitup/sets/wiki/images/picture.png +0 -0
  175. data/lib/generators/templates/markitup/sets/wiki/images/preview.png +0 -0
  176. data/lib/generators/templates/markitup/sets/wiki/images/quotes.png +0 -0
  177. data/lib/generators/templates/markitup/sets/wiki/images/stroke.png +0 -0
  178. data/lib/generators/templates/markitup/sets/wiki/images/url.png +0 -0
  179. data/lib/generators/templates/markitup/sets/wiki/readme.txt +0 -11
  180. data/lib/generators/templates/markitup/sets/wiki/set.js +0 -37
  181. data/lib/generators/templates/markitup/sets/wiki/style.css +0 -57
  182. data/lib/generators/templates/markitup/skins/markitup/images/bg-container.png +0 -0
  183. data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-bbcode.png +0 -0
  184. data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-dotclear.png +0 -0
  185. data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-html.png +0 -0
  186. data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-json.png +0 -0
  187. data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-markdown.png +0 -0
  188. data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-textile.png +0 -0
  189. data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-wiki.png +0 -0
  190. data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-xml.png +0 -0
  191. data/lib/generators/templates/markitup/skins/markitup/images/bg-editor.png +0 -0
  192. data/lib/generators/templates/markitup/skins/markitup/images/handle.png +0 -0
  193. data/lib/generators/templates/markitup/skins/markitup/images/menu.png +0 -0
  194. data/lib/generators/templates/markitup/skins/markitup/images/submenu.png +0 -0
  195. data/lib/generators/templates/markitup/skins/markitup/style.css +0 -147
  196. data/lib/generators/templates/markitup/skins/simple/images/handle.png +0 -0
  197. data/lib/generators/templates/markitup/skins/simple/images/menu.png +0 -0
  198. data/lib/generators/templates/markitup/skins/simple/images/submenu.png +0 -0
  199. data/lib/generators/templates/markitup/skins/simple/style.css +0 -118
  200. data/lib/generators/templates/markitup/templates/preview.css +0 -5
  201. data/lib/generators/templates/markitup/templates/preview.html +0 -11
@@ -1,4 +1,14 @@
1
1
  # encoding : utf-8
2
+ <%
3
+ if !engine_name.blank?
4
+ b_module = "module #{engine_camel}"
5
+ e_module = "end"
6
+ else
7
+ b_module = ""
8
+ e_module = ""
9
+ end
10
+ %>
11
+ <%= b_module %>
2
12
  class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < BeautifulController
3
13
 
4
14
  before_action :load_<%= model %>, :only => [:show, :edit, :update, :destroy]
@@ -7,12 +17,12 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
7
17
  #authorize_resource
8
18
 
9
19
  def index
10
- session[:fields] ||= {}
11
- session[:fields]["<%= model %>"] ||= (<%= model_camelize %>.columns.map(&:name) - ["id"])[0..4]
12
- do_select_fields("<%= model %>")
13
- do_sort_and_paginate("<%= model %>")
20
+ session['fields'] ||= {}
21
+ session['fields']['<%= model %>'] ||= (<%= model_camelize %>.columns.map(&:name) - ["id"])[0..4]
22
+ do_select_fields('<%= model %>')
23
+ do_sort_and_paginate('<%= model %>')
14
24
 
15
- @q = <%= model_camelize %>.search(
25
+ @q = <%= model_camelize %>.ransack(
16
26
  params[:q]
17
27
  )
18
28
 
@@ -38,7 +48,7 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
38
48
  render
39
49
  }
40
50
  format.json{
41
- render :json => @<%= model %>_scope.to_a
51
+ render :json => @<%= model %>_scope.to_json(methods: :caption)
42
52
  }
43
53
  format.csv{
44
54
  require 'csv'
@@ -48,7 +58,7 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
48
58
  csv << <%= model_camelize %>.attribute_names.map{ |a| o[a] }
49
59
  }
50
60
  end
51
- render :text => csvstr
61
+ render :plain => csvstr
52
62
  }
53
63
  format.xml{
54
64
  render :xml => @<%= model %>_scope.to_a
@@ -85,7 +95,7 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
85
95
  end
86
96
 
87
97
  def create
88
- @<%= model %> = <%= model_camelize %>.create(params_for_model)
98
+ @<%= model %> = <%= model_camelize %>.new(params_for_model)
89
99
 
90
100
  respond_to do |format|
91
101
  if @<%= model %>.save
@@ -100,7 +110,7 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
100
110
  else
101
111
  format.html {
102
112
  if params[:mass_inserting] then
103
- redirect_to <%= namespace_for_route %><%= model_pluralize %>_path(:mass_inserting => true), :flash => { :error => t(:error, "Error") }
113
+ redirect_to <%= namespace_for_route %><%= model_pluralize %>_path(:mass_inserting => true), :flash => { :error => "#{t(:error, default: "Error")} : #{@<%= model %>.errors.full_messages.join(", ")}" }
104
114
  else
105
115
  render :action => "new"
106
116
  end
@@ -113,7 +123,7 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
113
123
  def update
114
124
 
115
125
  respond_to do |format|
116
- if @<%= model %>.update_attributes(params_for_model)
126
+ if @<%= model %>.update(params_for_model)
117
127
  format.html { redirect_to <%= namespace_for_route %><%= singular_table_name %>_path(@<%= model %>), :flash => { :notice => t(:update_success, :model => "<%= model %>") }}
118
128
  format.json { head :ok }
119
129
  else
@@ -142,8 +152,8 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
142
152
  # Selected with filter and search
143
153
  do_sort_and_paginate(:<%= model %>)
144
154
 
145
- @<%= model_pluralize %> = <%= model_camelize %>.search(
146
- params[:q]
155
+ @<%= model_pluralize %> = <%= model_camelize %>.ransack(
156
+ session['search']['<%= model %>']
147
157
  ).result(
148
158
  :distinct => true
149
159
  )
@@ -163,12 +173,14 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
163
173
  # <%= model %>.save
164
174
  when "destroy" then
165
175
  <%= model %>.destroy
176
+ when "touch" then
177
+ <%= model %>.touch
166
178
  end
167
179
  end
168
180
  }
169
181
  end
170
182
 
171
- redirect_to :back
183
+ redirect_to <%= namespace_for_route %><%= model_pluralize %>_url
172
184
  end
173
185
 
174
186
  def treeview
@@ -179,7 +191,12 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
179
191
  modelclass = <%= model_camelize %>
180
192
  foreignkey = :<%= model %>_id
181
193
 
182
- render :nothing => true, :status => (update_treeview(modelclass, foreignkey) ? 200 : 500)
194
+
195
+ if update_treeview(modelclass, foreignkey)
196
+ head :ok
197
+ else
198
+ head :internal_server_error
199
+ end
183
200
  end
184
201
 
185
202
  private
@@ -192,4 +209,4 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
192
209
  params.require(:<%= model %>).permit(<%= model_camelize %>.permitted_attributes)
193
210
  end
194
211
  end
195
-
212
+ <%= e_module %>
@@ -3,53 +3,65 @@ class BeautifulController < ApplicationController
3
3
 
4
4
  layout "beautiful_layout"
5
5
 
6
+ # That clear cookie to avoid cookie overflow
7
+ # if you want to keep all in memory and you use ARCookieStore, just comment next line
8
+ before_action :delete_session_for_others_models_scaffold
9
+
6
10
  def dashboard
7
11
  render :layout => "beautiful_layout"
8
12
  end
9
13
 
14
+ def delete_session_for_others_models_scaffold
15
+ current_model = params[:controller].split('/').last.singularize
16
+
17
+ ['fields','sorting','search','scope','paginate'].each{ |k|
18
+ session[k] = session[k].delete_if {|key, v| key != current_model } if not session[k].blank?
19
+ }
20
+ end
21
+
10
22
  # Call in AJAX
11
23
  def select_fields
12
24
  model_sym = params[:model_sym]
13
25
 
14
- do_select_fields(model_sym)
26
+ do_select_fields(model_sym.to_s)
15
27
 
16
- render :nothing => true
28
+ head :ok
17
29
  end
18
30
 
19
- def do_select_fields(model_sym)
31
+ def do_select_fields(model_str)
20
32
  # Fields
21
- session[:fields] ||= {}
22
- session[:fields][model_sym] ||= nil
23
- params[:fields] ||= session[:fields][model_sym]
24
- session[:fields][model_sym] = params[:fields]
33
+ session['fields'] ||= {}
34
+ session['fields'][model_str] ||= nil
35
+ params[:fields] ||= session['fields'][model_str]
36
+ session['fields'][model_str] = params[:fields]
25
37
  end
26
38
 
27
- def do_sort_and_paginate(model_sym)
39
+ def do_sort_and_paginate(model_str)
28
40
  # Sort
29
- session[:sorting] ||= {}
30
- session[:sorting][model_sym] ||= { :attribute => "id", :sorting => "DESC" }
31
- params[:sorting] ||= session[:sorting][model_sym]
32
- session[:sorting][model_sym] = params[:sorting]
33
-
41
+ session['sorting'] ||= {}
42
+ session['sorting'][model_str] ||= { 'attribute' => "id", 'sorting' => "DESC" }
43
+ params[:sorting] ||= session['sorting'][model_str]
44
+ session['sorting'][model_str] = params[:sorting]
45
+
34
46
  # Search and Filter
35
- session[:search] ||= {}
36
- session[:search][model_sym] = nil if not params[:nosearch].blank?
47
+ session['search'] ||= {}
48
+ session['search'][model_str] = nil if not params[:nosearch].blank?
37
49
  params[:page] = 1 if not params[:q].nil?
38
- params[:q] ||= session[:search][model_sym]
39
- session[:search][model_sym] = params[:q] if params[:skip_save_search].blank?
40
-
50
+ params[:q] ||= session['search'][model_str]
51
+ session['search'][model_str] = params[:q] if params[:skip_save_search].blank?
52
+
41
53
  # Scope
42
- session[:scope] ||= {}
43
- session[:scope][model_sym] ||= nil
54
+ session['scope'] ||= {}
55
+ session['scope'][model_str] ||= nil
44
56
  params[:page] = 1 if not params[:scope].nil?
45
- params[:scope] ||= session[:scope][model_sym]
46
- session[:scope][model_sym] = params[:scope]
57
+ params[:scope] ||= session['scope'][model_str]
58
+ session['scope'][model_str] = params[:scope]
47
59
 
48
60
  # Paginate
49
- session[:paginate] ||= {}
50
- session[:paginate][model_sym] ||= nil
51
- params[:page] ||= session[:paginate][model_sym]
52
- session[:paginate][model_sym] = params[:page]
61
+ session['paginate'] ||= {}
62
+ session['paginate'][model_str] ||= nil
63
+ params[:page] ||= session['paginate'][model_str]
64
+ session['paginate'][model_str] = params[:page]
53
65
  end
54
66
 
55
67
  def boolean(string)
@@ -65,32 +77,28 @@ class BeautifulController < ApplicationController
65
77
  elt = modelclass.find(params[:id])
66
78
  elt.attributes = { foreignkey => parent_id }
67
79
 
68
- if modelclass.column_names.include?("position") then
80
+ if modelclass.column_names.include?("position")
69
81
  new_pos = 0
70
82
  modelclass.transaction do
71
83
  all_elt = modelclass.where(foreignkey => parent_id).order("position ASC").to_a
72
84
 
73
- #begin
74
- if index == 0 then
75
- new_pos = (begin (all_elt.first.position - 1) rescue 1 end)
76
- elsif index == all_elt.length then
77
- new_pos = (begin (all_elt.last.position + 1) rescue 1 end)
78
- else
79
- new_pos = all_elt[index].position
80
-
81
- end_of_array = all_elt[index..-1]
82
- end_of_array.each{ |g|
83
- next if g == elt
84
- g.position = g.position.to_i + 1
85
- g.save!
86
-
87
- next_elt = end_of_array[end_of_array.index(g) + 1]
88
- break if not next_elt.nil? and next_elt.position > g.position
89
- }
85
+ if index == 0
86
+ new_pos = (begin (all_elt.first.position - 1) rescue 1 end)
87
+ elsif index == (all_elt.length - 1)
88
+ new_pos = (begin (all_elt.last.position + 1) rescue 1 end)
89
+ else
90
+ new_pos = all_elt[index].position
91
+
92
+ end_of_array = all_elt[index..-1]
93
+ end_of_array.each do |g|
94
+ next if g == elt
95
+ g.position = g.position.to_i + 1
96
+ g.save!
97
+
98
+ next_elt = end_of_array[end_of_array.index(g) + 1]
99
+ break if !next_elt.nil? && next_elt.position > g.position
90
100
  end
91
- #rescue
92
- # new_pos = 0
93
- #end
101
+ end
94
102
  end
95
103
  elt.position = new_pos
96
104
  end
@@ -1,8 +1,18 @@
1
1
  # encoding : utf-8
2
+ <%
3
+ if !engine_name.blank?
4
+ b_module = "module #{engine_camel}"
5
+ e_module = "end"
6
+ else
7
+ b_module = ""
8
+ e_module = ""
9
+ end
10
+ %>
11
+ <%= b_module %>
2
12
  module BeautifulHelper
3
13
 
4
14
  def visible_column(model_name, field_name, display_default = 'table-cell', other_css = "")
5
- return ('style="display:' + ((session[:fields][model_name].to_a.include?(field_name)) ? display_default : 'none') + ';' + other_css + '"').html_safe
15
+ return ('style="display:' + ((session['fields'][model_name].to_a.include?(field_name)) ? display_default : 'none') + ';' + other_css + '"').html_safe
6
16
  end
7
17
 
8
18
  def dropdown_submenu(link_caption, &block)
@@ -15,7 +25,7 @@ module BeautifulHelper
15
25
  attr = nil
16
26
  sort = nil
17
27
 
18
- if not params[:sorting].blank? then
28
+ if !params[:sorting].blank?
19
29
  attr = params[:sorting][:attribute]
20
30
  sort = params[:sorting][:sorting]
21
31
  end
@@ -24,11 +34,11 @@ module BeautifulHelper
24
34
  sortstr = sort.to_s.downcase
25
35
  opposite_sortstr = ""
26
36
  csort = '' # <i class="fa fa-stop"></i>
27
- if attribute_name == attr then
28
- if sortstr == "asc" then
37
+ if attribute_name == attr
38
+ if sortstr == "asc"
29
39
  csort = '<i class="fa fa-chevron-up"></i>'
30
40
  opposite_sortstr = "desc"
31
- elsif sortstr == "desc" then
41
+ elsif sortstr == "desc"
32
42
  csort = '<i class="fa fa-chevron-down"></i>'
33
43
  opposite_sortstr = "asc"
34
44
  end
@@ -37,7 +47,7 @@ module BeautifulHelper
37
47
  end
38
48
 
39
49
  default_caption = attribute_name.capitalize
40
- if is_belongs_to_column?(default_caption) then
50
+ if is_belongs_to_column?(default_caption)
41
51
  default_caption = get_belongs_to_model(default_caption)
42
52
  end
43
53
 
@@ -45,7 +55,7 @@ module BeautifulHelper
45
55
 
46
56
  caption = t(cap, :default => default_caption).capitalize
47
57
  strpath = model_name.pluralize + "_url"
48
- strpath = namespace + '_' + strpath if not namespace.blank?
58
+ strpath = namespace + '_' + strpath if !namespace.blank?
49
59
 
50
60
  return link_to(
51
61
  "#{csort} #{caption}".html_safe,
@@ -54,18 +64,18 @@ module BeautifulHelper
54
64
  ).html_safe
55
65
  end
56
66
 
57
- def ransack_field(path_of_model, attribute_name, f, caption = nil)
67
+ def ransack_field(path_of_model, attribute_name, f, caption = nil, engine = nil)
58
68
  model_path = path_of_model.split("/")
59
69
  model_name = model_path.last
60
70
  model_path.delete(model_path.first)
61
71
  model_name_for_ransack = model_path.join("_")
62
72
 
63
- ar_model = model_name.camelize.constantize
73
+ ar_model = (engine.blank? ? model_name.camelize.constantize : "#{engine.camelize}::#{model_name.camelize}".constantize)
64
74
 
65
75
  default_caption = caption
66
- if default_caption.blank? then
76
+ if default_caption.blank?
67
77
  default_caption = attribute_name.capitalize
68
- if is_belongs_to_column?(default_caption) then
78
+ if is_belongs_to_column?(default_caption)
69
79
  default_caption = get_belongs_to_model(default_caption)
70
80
  end
71
81
  end
@@ -74,7 +84,7 @@ module BeautifulHelper
74
84
  name_field_bk = attribute_name
75
85
  label_field = attribute_name
76
86
 
77
- if is_belongs_to_column?(name_field_bk) then
87
+ if is_belongs_to_column?(name_field_bk)
78
88
  label_field = get_belongs_to_model(attribute_name)
79
89
  end
80
90
 
@@ -89,98 +99,122 @@ module BeautifulHelper
89
99
  type_of_column = ar_model.columns_hash[attribute_name].type unless ar_model.columns_hash[attribute_name].nil?
90
100
  type_of_column ||= :other
91
101
  case type_of_column
92
- when :date, :datetime then
102
+ when :date, :datetime
93
103
  dt = (type_of_column == :datetime)
94
104
  interval = (dt ? (1..5) : (1..3))
95
105
 
106
+ html_id = "#{name_field}_dp_gt"
107
+ filter = session['search'][model_name]
108
+ filter ||= {}
109
+
96
110
  # Greater than
97
- response += '<div class="input-group input-' + type_of_column.to_s + '">'
98
- response += '<span class="input-group-addon"><i class="fa fa-chevron-right"></i></span>'
111
+ response += '<div class="dpicker input-group input-' + type_of_column.to_s + ' mb-2" data-field="q_' + name_field + '_gteq" id="' + html_id + '_id" data-target-input="nearest">'
112
+ response += '<div class="input-group-prepend"><span class="input-group-text"><i class="fa fa-chevron-right"></i></span></div>'
99
113
  response += f.text_field(
100
- (name_field + "_dp_gt").to_sym,
101
- :value => (begin params[:q][(name_field + "_dp_gt").to_sym] rescue '' end),
102
- :class => "col-md-9 dpicker form-control",
114
+ (html_id).to_sym,
115
+ :value => ("#{filter["#{name_field}_gteq(3i)"]}/#{filter["#{name_field}_gteq(2i)"]}/#{filter["#{name_field}_gteq(1i)"]}"),
116
+ :class => " form-control datetimepicker-input",
117
+ "data-target" => "##{html_id}_id",
103
118
  "data-id" => ("q_" + name_field + "_gteq"))
104
- response += '<span class="input-group-addon"><i class="fa fa-calendar"></i></span>'
119
+ response += '<div class="input-group-append" data-target="' + html_id + '_id" data-toggle="datetimepicker"><span class="input-group-text"><i class="fa fa-calendar"></i></span></div>'
105
120
  response += '</div>'
106
121
 
107
- if dt then
108
- response += '<div class="input-group input-' + type_of_column.to_s + '">'
109
- response += '<span class="input-group-addon"><i class="fa fa-chevron-right"></i></span>'
122
+ html_id = "#{name_field}_tp_gt"
123
+
124
+ if dt
125
+ response += '<div class="tpicker input-group input-' + type_of_column.to_s + ' mb-2" data-field="q_' + name_field + '_gteq" id="' + html_id + '_id" data-target-input="nearest">'
126
+ response += '<div class="input-group-prepend"><span class="input-group-text"><i class="fa fa-chevron-right"></i></span></div>'
110
127
  response += f.text_field(
111
128
  (name_field + "_tp_gt").to_sym,
112
- :value => (begin params[:q][(name_field + "_tp_gt").to_sym] rescue '' end),
113
- :class => "col-md-9 tpicker form-control",
129
+ :value => ("#{filter["#{name_field}_gteq(4i)"]}/#{filter["#{name_field}_gteq(5i)"]}"),
130
+ :class => " form-control datetimepicker-input",
131
+ "data-target" => "##{html_id}_id",
114
132
  "data-id" => ("q_" + name_field + "_gteq"))
115
- response += '<span class="input-group-addon"><i class="fa fa-clock-o"></i></span>'
133
+ response += '<div class="input-group-append" data-target="' + html_id + '_id" data-toggle="datetimepicker"><span class="input-group-text"><i class="fa fa-clock"></i></span></div>'
116
134
  response += '</div>'
117
135
  end
118
136
 
119
137
  for i in interval
120
138
  response += f.hidden_field(name_field + "_gteq(#{i}i)",
121
- :value => (begin params[:q][(name_field + "_gteq(#{i}i)").to_sym] rescue '' end),
139
+ :value => (filter["#{name_field}_gteq(#{i}i)"]),
122
140
  :id => ('q_' + name_field + "_gteq_#{i}i"))
123
141
  end
124
142
 
143
+ html_id = "#{name_field}_dp_lt"
144
+
125
145
  # Less than
126
- response += '<div class="input-group input-' + type_of_column.to_s + '">'
127
- response += '<span class="input-group-addon"><i class="fa fa-chevron-left"></i></span>'
146
+ response += '<div class="dpicker input-group input-' + type_of_column.to_s + ' mb-2" data-field="q_' + name_field + '_lteq" id="' + html_id + '_id" data-target-input="nearest">'
147
+ response += '<div class="input-group-prepend"><span class="input-group-text"><i class="fa fa-chevron-left"></i></span></div>'
128
148
  response += f.text_field(
129
149
  (name_field + "_dp_lt").to_sym,
130
- :value => (begin params[:q][(name_field + "_dp_lt").to_sym] rescue '' end),
131
- :class => "col-md-9 dpicker form-control",
150
+ :value => ("#{filter["#{name_field}_lteq(3i)"]}/#{filter["#{name_field}_lteq(2i)"]}/#{filter["#{name_field}_lteq(1i)"]}"),
151
+ :class => " form-control datetimepicker-input",
152
+ "data-target" => "##{html_id}_id",
132
153
  "data-id" => ("q_" + name_field + "_lteq"))
133
- response += '<span class="input-group-addon"><i class="fa fa-calendar"></i></span>'
154
+ response += '<div class="input-group-append" data-target="' + html_id + '_id" data-toggle="datetimepicker"><span class="input-group-text"><i class="fa fa-calendar"></i></span></div>'
134
155
  response += '</div>'
135
156
 
136
- if dt then
137
- response += '<div class="input-group input-' + type_of_column.to_s + '">'
138
- response += '<span class="input-group-addon"><i class="fa fa-chevron-left"></i></span>'
157
+ html_id = "#{name_field}_tp_lt"
158
+
159
+ if dt
160
+ response += '<div class="tpicker input-group input-' + type_of_column.to_s + ' mb-2" data-field="q_' + name_field + '_lteq" id="' + html_id + '_id" data-target-input="nearest">'
161
+ response += '<div class="input-group-prepend"><span class="input-group-text"><i class="fa fa-chevron-left"></i></span></div>'
139
162
  response += f.text_field(
140
163
  (name_field + "_tp_lt").to_sym,
141
- :value => (begin params[:q][(name_field + "_tp_lt").to_sym] rescue '' end),
142
- :class => "col-md-9 tpicker form-control",
164
+ :value => ("#{filter["#{name_field}_lteq(4i)"]}/#{filter["#{name_field}_lteq(5i)"]}"),
165
+ :class => " form-control datetimepicker-input",
166
+ "data-target" => "##{html_id}_id",
143
167
  "data-id" => ("q_" + name_field + "_lteq"))
144
- response += '<span class="input-group-addon"><i class="fa fa-clock-o"></i></span>'
168
+ response += '<div class="input-group-append" data-target="' + html_id + '_id" data-toggle="datetimepicker"><span class="input-group-text"><i class="fa fa-clock"></i></span></div>'
145
169
  response += '</div>'
146
170
  end
147
171
 
148
172
  for i in interval
149
173
  response += f.hidden_field(name_field + "_lteq(#{i}i)",
150
- :value => (begin params[:q][(name_field + "_lteq(#{i}i)").to_sym] rescue '' end),
174
+ :value => (filter["#{name_field}_lteq(#{i}i)"]),
151
175
  :id => ('q_' + name_field + "_lteq_#{i}i"))
152
176
  end
153
177
 
154
178
  infostr = info_input(model_name, [(name_field + "_dp_lt").to_sym, (name_field + "_tp_lt").to_sym, (name_field + "_dp_gt").to_sym, (name_field + "_tp_gt").to_sym])
155
- when :boolean then
179
+ when :boolean
156
180
  # Specify a default value (false) in rails migration
157
181
  response += f.label name_field + "_eq_true", raw(f.radio_button((name_field + "_eq").to_sym, true)) + " " + h(t(:yes, :default => "Yes")), :class => "checkbox inline"
158
182
  response += f.label name_field + "_eq_false", raw(f.radio_button((name_field + "_eq").to_sym, false)) + " " + h(t(:no, :default => "No")), :class => "checkbox inline"
159
183
  response += f.label name_field + "_eq", raw(f.radio_button((name_field + "_eq").to_sym, nil)) + " " + h(t(:all, :default => "All")), :class => "checkbox inline"
160
184
 
161
- infostr = (begin session[:search][model_name.to_sym][(name_field + "_eq").to_sym] == "on" ? "" : "info" rescue "" end)
162
- when :string then
185
+ infostr = (begin session['search'][model_name][(name_field + "_eq").to_sym] == "on" ? "" : "info" rescue "" end)
186
+ when :string
163
187
  response += f.text_field((name_field + "_cont").to_sym, :class => "filter col-md-12 form-control")
164
188
 
165
189
  infostr = info_input(model_name, (name_field + "_cont").to_sym)
166
- when :integer, :float, :decimal then
167
- if is_belongs_to_column?(name_field_bk) then
168
- btmodel = get_belongs_to_model(name_field_bk).camelize.constantize
169
- response += f.collection_select((name_field + "_eq").to_sym, btmodel.all, :id, :caption, { :include_blank => t(:all, :default => "All") }, { :class => "col-md-12 form-control" })
190
+ when :integer, :float, :decimal #, :other
191
+ if is_belongs_to_column?(name_field_bk)
192
+ bt_model_name = get_belongs_to_model(name_field_bk).camelize
193
+ field = name_field + "_eq"
170
194
 
171
- infostr = info_input(model_name, (name_field + "_eq").to_sym)
172
- elsif name_field == "id" then
195
+ if !engine.blank?
196
+ bt_model_name = "#{engine.camelize}::#{bt_model_name}"
197
+ #field = "#{engine.downcase}_#{field}"
198
+ end
199
+
200
+ btmodel = bt_model_name.constantize
201
+ field = field.to_sym
202
+
203
+ response += f.collection_select(field, btmodel.all, :id, :caption, { :include_blank => t(:all, :default => "All") }, { :class => "col-md-12 form-control" })
204
+
205
+ infostr = info_input(model_name, field)
206
+ elsif name_field == "id"
173
207
  response += f.text_field((name_field + "_eq").to_sym, :class => "filter col-md-12 form-control")
174
208
 
175
209
  infostr = info_input(model_name, (name_field + "_eq").to_sym)
176
210
  else
177
211
  response += '<div class="input-group">'
178
- response += '<span class="input-group-addon" rel="tooltip" title="' + t(:greater_than, :default => "Greater than") + '"><i class="fa fa-chevron-right"></i></span>'
179
- response += f.text_field((name_field + "_gteq").to_sym, :class => "#{align_attribute("integer")} filter-min col-md-10 form-control")
212
+ response += '<div class="input-group-prepend" rel="tooltip" title="' + t(:greater_than, :default => "Greater than") + '"><span class="input-group-text"><i class="fa fa-chevron-right"></i></span></div>'
213
+ response += f.text_field((name_field + "_gteq").to_sym, :class => "#{align_attribute("integer")} filter-min form-control")
180
214
  response += '</div>'
181
215
  response += '<div class="input-group">'
182
- response += '<span class="input-group-addon" rel="tooltip" title="' + t(:smaller_than, :default => "Smaller than") + '"><i class="fa fa-chevron-left"></i></span>'
183
- response += f.text_field((name_field + "_lteq").to_sym, :class => "#{align_attribute("integer")} filter-max col-md-10 form-control")
216
+ response += '<div class="input-group-append" rel="tooltip" title="' + t(:smaller_than, :default => "Smaller than") + '"><span class="input-group-text"><i class="fa fa-chevron-left"></i></span></div>'
217
+ response += f.text_field((name_field + "_lteq").to_sym, :class => "#{align_attribute("integer")} filter-max form-control")
184
218
  response += '</div>'
185
219
 
186
220
  infostr = info_input(model_name, [(name_field + "_lteq").to_sym, (name_field + "_gteq").to_sym])
@@ -199,13 +233,13 @@ module BeautifulHelper
199
233
  end
200
234
 
201
235
  def info_input(modname, attr)
202
- model_name = modname.to_sym
236
+ model_name = modname
203
237
  rep = false
204
- if not session[:search].blank? and not session[:search][model_name].blank? then
205
- if attr.kind_of?(Array) then
206
- rep = (attr.any? { |elt| (not session[:search][model_name][elt].blank?) })
238
+ if !session['search'].blank? and !session['search'][model_name].blank?
239
+ if attr.kind_of?(Array)
240
+ rep = (attr.any? { |elt| (not session['search'][model_name][elt].blank?) })
207
241
  else
208
- rep = (not session[:search][model_name][attr].blank?)
242
+ rep = (!session['search'][model_name][attr].blank?)
209
243
  end
210
244
  end
211
245
  return (rep ? "info" : "")
@@ -213,19 +247,20 @@ module BeautifulHelper
213
247
 
214
248
  def align_attribute(attribute_type)
215
249
  return case attribute_type
216
- when "string" then
217
- "al"
218
- when "integer", "float", "numeric", "decimal" then
219
- "ar"
220
- when "boolean" then
221
- "ac"
222
- when "date", "datetime", "timestamp" then
223
- "ac"
224
- else
225
- "al"
226
- end
250
+ when "string"
251
+ "al"
252
+ when "integer", "float", "numeric", "decimal"
253
+ "ar"
254
+ when "boolean"
255
+ "ac"
256
+ when "date", "datetime", "timestamp"
257
+ "ac"
258
+ else
259
+ "al"
260
+ end
227
261
  end
228
262
 
263
+ # Encore utilisé avec wysihtml5 ?
229
264
  def exclude_richtext_field(array_of_attributes, only_fulltext = true)
230
265
  pattern = /$()_fulltext/
231
266
  richtext_attributes = []
@@ -263,6 +298,7 @@ module BeautifulHelper
263
298
  def clean_params
264
299
  params.delete :q
265
300
  params.delete :fields
301
+ params.delete :scope
266
302
  end
267
303
 
268
304
  def i18n_translate_path(model, attr)
@@ -277,3 +313,4 @@ module BeautifulHelper
277
313
  "app.models.#{model}.bs_caption_plural"
278
314
  end
279
315
  end
316
+ <%= e_module %>