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.
- checksums.yaml +7 -0
- data/.gitattributes +2 -0
- data/.gitignore +1 -0
- data/CHANGELOG +66 -1
- data/Gemfile +24 -17
- data/Gemfile.lock +209 -0
- data/README.rdoc +56 -44
- data/Rakefile +32 -0
- data/beautiful_scaffold.gemspec +8 -5
- data/lib/beautiful_scaffold/version.rb +3 -0
- data/lib/generators/beautiful_devisecancan_generator.rb +1 -1
- data/lib/generators/beautiful_jointable_generator.rb +40 -7
- data/lib/generators/beautiful_locale_generator.rb +102 -80
- data/lib/generators/beautiful_migration_generator.rb +12 -20
- data/lib/generators/beautiful_scaffold_common_methods.rb +88 -29
- data/lib/generators/beautiful_scaffold_generator.rb +166 -111
- data/lib/generators/templates/app/assets/javascripts/application-bs.js +11 -19
- data/lib/generators/templates/app/assets/javascripts/beautiful_scaffold.js +68 -78
- data/lib/generators/templates/app/assets/javascripts/bootstrap-datetimepicker-for-beautiful-scaffold.js +23 -42
- data/lib/generators/templates/app/assets/javascripts/fixed_menu.js +3 -1
- data/lib/generators/templates/app/assets/javascripts/jstree.min.js +6 -0
- data/lib/generators/templates/app/assets/stylesheets/application-bs.css +14 -12
- data/lib/generators/templates/app/assets/stylesheets/beautiful-scaffold.css.scss +36 -3
- data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/32px.png +0 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/40px.png +0 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/style.scss +1146 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/throbber.gif +0 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default/32px.png +0 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default/40px.png +0 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default/style.scss +1102 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default/throbber.gif +0 -0
- data/lib/generators/templates/app/controllers/base.rb +32 -15
- data/lib/generators/templates/app/controllers/master_base.rb +55 -47
- data/lib/generators/templates/app/helpers/beautiful_helper.rb +104 -67
- data/lib/generators/templates/app/helpers/model_helper.rb +14 -3
- data/lib/generators/templates/app/initializers/link_renderer.rb +24 -17
- data/lib/generators/templates/app/initializers/ransack.rb +16 -0
- data/lib/generators/templates/app/locales/beautiful_scaffold.ja.yml +50 -0
- data/lib/generators/templates/app/models/concerns/fulltext_concern.rb +10 -10
- data/lib/generators/templates/app/views/_form.html.erb +5 -2
- data/lib/generators/templates/app/views/_form_habtm_tag.html.erb +6 -2
- data/lib/generators/templates/app/views/_mass_inserting.html.erb +40 -31
- data/lib/generators/templates/app/views/_modal_columns.html.erb +4 -4
- data/lib/generators/templates/app/views/edit.html.erb +1 -3
- data/lib/generators/templates/app/views/index.html.erb +84 -58
- data/lib/generators/templates/app/views/layout.html.erb +29 -47
- data/lib/generators/templates/app/views/new.html.erb +0 -2
- data/lib/generators/templates/app/views/partials/_forget_password.html.erb +2 -2
- data/lib/generators/templates/app/views/partials/_form_field.html.erb +7 -33
- data/lib/generators/templates/app/views/partials/_index_batch.html.erb +1 -1
- data/lib/generators/templates/app/views/partials/_index_column.html.erb +4 -6
- data/lib/generators/templates/app/views/partials/_index_header.html.erb +1 -1
- data/lib/generators/templates/app/views/partials/_index_search.html.erb +2 -4
- data/lib/generators/templates/app/views/partials/_index_search_default_fields.html.erb +1 -1
- data/lib/generators/templates/app/views/partials/_register_form.html.erb +2 -2
- data/lib/generators/templates/app/views/partials/_show_field.html.erb +3 -3
- data/lib/generators/templates/app/views/partials/_sign_in_form.html.erb +1 -1
- data/lib/generators/templates/app/views/partials/_sign_in_sign_out.html.erb +2 -2
- data/lib/generators/templates/app/views/show.html.erb +2 -2
- data/lib/generators/templates/app/views/treeview.html.erb +8 -5
- metadata +43 -188
- data/lib/generators/templates/app/assets/javascripts/bootstrap-datepicker.js +0 -834
- data/lib/generators/templates/app/assets/javascripts/bootstrap-timepicker.js +0 -797
- data/lib/generators/templates/app/assets/javascripts/jquery.jstree.js +0 -4551
- data/lib/generators/templates/app/assets/javascripts/jquery.livequery.js +0 -226
- data/lib/generators/templates/app/assets/stylesheets/bootstrap_and_overrides.css.less +0 -40
- data/lib/generators/templates/app/assets/stylesheets/datepicker.css +0 -224
- data/lib/generators/templates/app/assets/stylesheets/reset.css +0 -48
- data/lib/generators/templates/app/assets/stylesheets/themes/default/d.gif +0 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default/d.png +0 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default/style.css +0 -74
- data/lib/generators/templates/app/assets/stylesheets/timepicker.css +0 -89
- data/lib/generators/templates/markitup/jquery.markitup.js +0 -593
- data/lib/generators/templates/markitup/sets/bbcode/images/bold.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/clean.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/code.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/fonts.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/italic.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/link.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/list-bullet.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/list-item.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/list-numeric.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/picture.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/preview.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/quotes.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/stroke.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/underline.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/readme.txt +0 -11
- data/lib/generators/templates/markitup/sets/bbcode/set.js +0 -39
- data/lib/generators/templates/markitup/sets/bbcode/style.css +0 -47
- data/lib/generators/templates/markitup/sets/default/images/bold.png +0 -0
- data/lib/generators/templates/markitup/sets/default/images/clean.png +0 -0
- data/lib/generators/templates/markitup/sets/default/images/image.png +0 -0
- data/lib/generators/templates/markitup/sets/default/images/italic.png +0 -0
- data/lib/generators/templates/markitup/sets/default/images/link.png +0 -0
- data/lib/generators/templates/markitup/sets/default/images/list-bullet.png +0 -0
- data/lib/generators/templates/markitup/sets/default/images/list-numeric.png +0 -0
- data/lib/generators/templates/markitup/sets/default/images/picture.png +0 -0
- data/lib/generators/templates/markitup/sets/default/images/preview.png +0 -0
- data/lib/generators/templates/markitup/sets/default/images/stroke.png +0 -0
- data/lib/generators/templates/markitup/sets/default/set.js +0 -30
- data/lib/generators/templates/markitup/sets/default/style.css +0 -34
- data/lib/generators/templates/markitup/sets/html/images/bold.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/clean.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/h1.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/h2.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/h3.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/h4.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/h5.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/h6.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/image.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/italic.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/link.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/list-bullet.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/list-item.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/list-numeric.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/paragraph.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/picture.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/preview.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/stroke.png +0 -0
- data/lib/generators/templates/markitup/sets/html/readme.txt +0 -11
- data/lib/generators/templates/markitup/sets/html/set.js +0 -39
- data/lib/generators/templates/markitup/sets/html/style.css +0 -59
- data/lib/generators/templates/markitup/sets/markdown/images/bold.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/code.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/h1.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/h2.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/h3.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/h4.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/h5.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/h6.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/italic.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/link.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/list-bullet.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/list-numeric.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/picture.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/preview.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/quotes.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/readme.txt +0 -11
- data/lib/generators/templates/markitup/sets/markdown/set.js +0 -52
- data/lib/generators/templates/markitup/sets/markdown/style.css +0 -54
- data/lib/generators/templates/markitup/sets/textile/images/bold.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/code.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/h1.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/h2.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/h3.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/h4.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/h5.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/h6.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/italic.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/link.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/list-bullet.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/list-numeric.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/paragraph.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/picture.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/preview.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/quotes.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/stroke.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/readme.txt +0 -11
- data/lib/generators/templates/markitup/sets/textile/set.js +0 -40
- data/lib/generators/templates/markitup/sets/textile/style.css +0 -60
- data/lib/generators/templates/markitup/sets/wiki/images/bold.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/code.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/h1.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/h2.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/h3.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/h4.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/h5.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/h6.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/italic.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/link.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/list-bullet.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/list-numeric.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/picture.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/preview.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/quotes.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/stroke.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/url.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/readme.txt +0 -11
- data/lib/generators/templates/markitup/sets/wiki/set.js +0 -37
- data/lib/generators/templates/markitup/sets/wiki/style.css +0 -57
- data/lib/generators/templates/markitup/skins/markitup/images/bg-container.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-bbcode.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-dotclear.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-html.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-json.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-markdown.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-textile.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-wiki.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-xml.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/bg-editor.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/handle.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/menu.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/submenu.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/style.css +0 -147
- data/lib/generators/templates/markitup/skins/simple/images/handle.png +0 -0
- data/lib/generators/templates/markitup/skins/simple/images/menu.png +0 -0
- data/lib/generators/templates/markitup/skins/simple/images/submenu.png +0 -0
- data/lib/generators/templates/markitup/skins/simple/style.css +0 -118
- data/lib/generators/templates/markitup/templates/preview.css +0 -5
- data/lib/generators/templates/markitup/templates/preview.html +0 -11
Binary file
|
@@ -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[
|
11
|
-
session[
|
12
|
-
do_select_fields(
|
13
|
-
do_sort_and_paginate(
|
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 %>.
|
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.
|
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 :
|
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 %>.
|
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 %>.
|
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 %>.
|
146
|
-
|
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
|
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
|
-
|
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
|
-
|
28
|
+
head :ok
|
17
29
|
end
|
18
30
|
|
19
|
-
def do_select_fields(
|
31
|
+
def do_select_fields(model_str)
|
20
32
|
# Fields
|
21
|
-
session[
|
22
|
-
session[
|
23
|
-
params[:fields] ||= session[
|
24
|
-
session[
|
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(
|
39
|
+
def do_sort_and_paginate(model_str)
|
28
40
|
# Sort
|
29
|
-
session[
|
30
|
-
session[
|
31
|
-
params[:sorting] ||= session[
|
32
|
-
session[
|
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[
|
36
|
-
session[
|
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[
|
39
|
-
session[
|
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[
|
43
|
-
session[
|
54
|
+
session['scope'] ||= {}
|
55
|
+
session['scope'][model_str] ||= nil
|
44
56
|
params[:page] = 1 if not params[:scope].nil?
|
45
|
-
params[:scope] ||= session[
|
46
|
-
session[
|
57
|
+
params[:scope] ||= session['scope'][model_str]
|
58
|
+
session['scope'][model_str] = params[:scope]
|
47
59
|
|
48
60
|
# Paginate
|
49
|
-
session[
|
50
|
-
session[
|
51
|
-
params[:page] ||= session[
|
52
|
-
session[
|
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")
|
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
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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
|
-
|
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[
|
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
|
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
|
28
|
-
if sortstr == "asc"
|
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"
|
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)
|
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
|
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?
|
76
|
+
if default_caption.blank?
|
67
77
|
default_caption = attribute_name.capitalize
|
68
|
-
if is_belongs_to_column?(default_caption)
|
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)
|
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
|
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-
|
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
|
-
(
|
101
|
-
:value => (
|
102
|
-
:class => "
|
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-
|
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
|
-
|
108
|
-
|
109
|
-
|
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 => (
|
113
|
-
:class => "
|
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-
|
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 => (
|
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-
|
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 => (
|
131
|
-
:class => "
|
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-
|
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
|
-
|
137
|
-
|
138
|
-
|
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 => (
|
142
|
-
:class => "
|
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-
|
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 => (
|
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
|
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[
|
162
|
-
when :string
|
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
|
167
|
-
if is_belongs_to_column?(name_field_bk)
|
168
|
-
|
169
|
-
|
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
|
-
|
172
|
-
|
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 += '<
|
179
|
-
response += f.text_field((name_field + "_gteq").to_sym, :class => "#{align_attribute("integer")} filter-min
|
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 += '<
|
183
|
-
response += f.text_field((name_field + "_lteq").to_sym, :class => "#{align_attribute("integer")} filter-max
|
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
|
236
|
+
model_name = modname
|
203
237
|
rep = false
|
204
|
-
if
|
205
|
-
if attr.kind_of?(Array)
|
206
|
-
rep = (attr.any? { |elt| (not session[
|
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 = (
|
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
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
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 %>
|