beautiful_scaffold 1.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/CHANGELOG +78 -1
  4. data/Gemfile +25 -9
  5. data/README.rdoc +45 -28
  6. data/Rakefile +29 -0
  7. data/beautiful_scaffold.gemspec +7 -7
  8. data/lib/beautiful_scaffold/version.rb +3 -0
  9. data/lib/generators/USAGE +3 -1
  10. data/lib/generators/beautiful_cancancan_generator.rb +51 -0
  11. data/lib/generators/beautiful_jointable_generator.rb +41 -8
  12. data/lib/generators/beautiful_locale_generator.rb +107 -104
  13. data/lib/generators/beautiful_migration_generator.rb +14 -20
  14. data/lib/generators/beautiful_scaffold_common_methods.rb +56 -26
  15. data/lib/generators/beautiful_scaffold_generator.rb +116 -78
  16. data/lib/generators/beautiful_sorcery_generator.rb +137 -0
  17. data/lib/generators/beautiful_storage_generator.rb +61 -0
  18. data/lib/generators/templates/app/assets/javascripts/application-bs.js +5 -7
  19. data/lib/generators/templates/app/assets/javascripts/beautiful_scaffold.js +65 -79
  20. data/lib/generators/templates/app/assets/javascripts/bootstrap-datetimepicker-for-beautiful-scaffold.js +26 -23
  21. data/lib/generators/templates/app/assets/javascripts/fixed_menu.js +3 -1
  22. data/lib/generators/templates/app/assets/javascripts/jstree.min.js +6 -0
  23. data/lib/generators/templates/app/assets/stylesheets/application-bs.css +14 -6
  24. data/lib/generators/templates/app/assets/stylesheets/beautiful-scaffold.css.scss +20 -3
  25. data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/32px.png +0 -0
  26. data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/40px.png +0 -0
  27. data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/style.scss +1146 -0
  28. data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/throbber.gif +0 -0
  29. data/lib/generators/templates/app/assets/stylesheets/themes/default/32px.png +0 -0
  30. data/lib/generators/templates/app/assets/stylesheets/themes/default/40px.png +0 -0
  31. data/lib/generators/templates/app/assets/stylesheets/themes/default/style.scss +1102 -0
  32. data/lib/generators/templates/app/assets/stylesheets/themes/default/throbber.gif +0 -0
  33. data/lib/generators/templates/app/controllers/base.rb +14 -7
  34. data/lib/generators/templates/app/controllers/master_base.rb +19 -25
  35. data/lib/generators/templates/app/controllers/user_sessions_controller.rb +20 -0
  36. data/lib/generators/templates/app/helpers/beautiful_helper.rb +102 -66
  37. data/lib/generators/templates/app/initializers/link_renderer.rb +23 -18
  38. data/lib/generators/templates/app/locales/beautiful_scaffold.en.yml +8 -0
  39. data/lib/generators/templates/app/locales/beautiful_scaffold.fr.yml +9 -1
  40. data/lib/generators/templates/app/locales/beautiful_scaffold.ja.yml +9 -2
  41. data/lib/generators/templates/app/mailers/user_mailer.rb +13 -0
  42. data/lib/generators/templates/app/models/ability.rb +39 -0
  43. data/lib/generators/templates/app/models/concerns/caption_concern.rb +1 -1
  44. data/lib/generators/templates/app/models/user.rb +11 -0
  45. data/lib/generators/templates/app/views/_form.html.erb +4 -1
  46. data/lib/generators/templates/app/views/_form_habtm_tag.html.erb +6 -2
  47. data/lib/generators/templates/app/views/_mass_inserting.html.erb +38 -30
  48. data/lib/generators/templates/app/views/_modal_columns.html.erb +3 -3
  49. data/lib/generators/templates/app/views/edit.html.erb +1 -3
  50. data/lib/generators/templates/app/views/index.html.erb +83 -79
  51. data/lib/generators/templates/app/views/layout.html.erb +36 -36
  52. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_needed_email.en.html.erb +16 -0
  53. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_needed_email.en.text.erb +9 -0
  54. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_needed_email.fr.html.erb +16 -0
  55. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_needed_email.fr.text.erb +8 -0
  56. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_success_email.en.html.erb +19 -0
  57. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_success_email.en.text.erb +8 -0
  58. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_success_email.fr.html.erb +19 -0
  59. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_success_email.fr.text.erb +8 -0
  60. data/lib/generators/templates/app/views/login_logout/user_sessions/_form.html.erb +15 -0
  61. data/lib/generators/templates/app/views/login_logout/user_sessions/new.html.erb +3 -0
  62. data/lib/generators/templates/app/views/new.html.erb +0 -2
  63. data/lib/generators/templates/app/views/partials/_forget_password.html.erb +2 -2
  64. data/lib/generators/templates/app/views/partials/_form_field.html.erb +37 -29
  65. data/lib/generators/templates/app/views/partials/_index_batch.html.erb +1 -1
  66. data/lib/generators/templates/app/views/partials/_index_column.html.erb +6 -4
  67. data/lib/generators/templates/app/views/partials/_index_header.html.erb +1 -1
  68. data/lib/generators/templates/app/views/partials/_index_search.html.erb +1 -1
  69. data/lib/generators/templates/app/views/partials/_login_logout_register.html.erb +7 -0
  70. data/lib/generators/templates/app/views/partials/_show_field.html.erb +5 -3
  71. data/lib/generators/templates/app/views/show.html.erb +2 -2
  72. data/lib/generators/templates/app/views/treeview.html.erb +8 -5
  73. metadata +38 -24
  74. data/lib/generators/beautiful_devisecancan_generator.rb +0 -128
  75. data/lib/generators/templates/app/assets/javascripts/bootstrap-colorpicker.js +0 -520
  76. data/lib/generators/templates/app/assets/javascripts/jquery.jstree.js +0 -4551
  77. data/lib/generators/templates/app/assets/stylesheets/bootstrap_and_overrides.css.less +0 -40
  78. data/lib/generators/templates/app/assets/stylesheets/colorpicker.css +0 -127
  79. data/lib/generators/templates/app/assets/stylesheets/datepicker.css +0 -224
  80. data/lib/generators/templates/app/assets/stylesheets/reset.css +0 -48
  81. data/lib/generators/templates/app/assets/stylesheets/themes/default/d.gif +0 -0
  82. data/lib/generators/templates/app/assets/stylesheets/themes/default/d.png +0 -0
  83. data/lib/generators/templates/app/assets/stylesheets/themes/default/style.css +0 -74
  84. data/lib/generators/templates/app/assets/stylesheets/timepicker.css +0 -89
  85. data/lib/generators/templates/app/views/partials/_register_form.html.erb +0 -44
  86. data/lib/generators/templates/app/views/partials/_sign_in_form.html.erb +0 -18
  87. data/lib/generators/templates/app/views/partials/_sign_in_sign_out.html.erb +0 -19
  88. data/lib/generators/templates/lib/custom_failure.rb +0 -15
@@ -48,7 +48,7 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
48
48
  render
49
49
  }
50
50
  format.json{
51
- render :json => @<%= model %>_scope.to_a
51
+ render :json => @<%= model %>_scope.to_json(methods: :caption)
52
52
  }
53
53
  format.csv{
54
54
  require 'csv'
@@ -58,7 +58,7 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
58
58
  csv << <%= model_camelize %>.attribute_names.map{ |a| o[a] }
59
59
  }
60
60
  end
61
- render :text => csvstr
61
+ render :plain => csvstr
62
62
  }
63
63
  format.xml{
64
64
  render :xml => @<%= model %>_scope.to_a
@@ -110,7 +110,7 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
110
110
  else
111
111
  format.html {
112
112
  if params[:mass_inserting] then
113
- 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(", ")}" }
114
114
  else
115
115
  render :action => "new"
116
116
  end
@@ -123,7 +123,7 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
123
123
  def update
124
124
 
125
125
  respond_to do |format|
126
- if @<%= model %>.update_attributes(params_for_model)
126
+ if @<%= model %>.update(params_for_model)
127
127
  format.html { redirect_to <%= namespace_for_route %><%= singular_table_name %>_path(@<%= model %>), :flash => { :notice => t(:update_success, :model => "<%= model %>") }}
128
128
  format.json { head :ok }
129
129
  else
@@ -153,7 +153,7 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
153
153
  do_sort_and_paginate(:<%= model %>)
154
154
 
155
155
  @<%= model_pluralize %> = <%= model_camelize %>.ransack(
156
- params[:q]
156
+ session['search']['<%= model %>']
157
157
  ).result(
158
158
  :distinct => true
159
159
  )
@@ -173,12 +173,14 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
173
173
  # <%= model %>.save
174
174
  when "destroy" then
175
175
  <%= model %>.destroy
176
+ when "touch" then
177
+ <%= model %>.touch
176
178
  end
177
179
  end
178
180
  }
179
181
  end
180
182
 
181
- redirect_to :back
183
+ redirect_to <%= namespace_for_route %><%= model_pluralize %>_url
182
184
  end
183
185
 
184
186
  def treeview
@@ -189,7 +191,12 @@ class <%= namespace_for_class %><%= model_camelize.pluralize %>Controller < Beau
189
191
  modelclass = <%= model_camelize %>
190
192
  foreignkey = :<%= model %>_id
191
193
 
192
- 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
193
200
  end
194
201
 
195
202
  private
@@ -23,13 +23,11 @@ class BeautifulController < ApplicationController
23
23
  def select_fields
24
24
  model_sym = params[:model_sym]
25
25
 
26
- do_select_fields(model_sym.to_s) #TODO vérifier si nécessaire
26
+ do_select_fields(model_sym.to_s)
27
27
 
28
- render :nothing => true
28
+ head :ok
29
29
  end
30
30
 
31
- # TODO session use key string because json serializer don't know the type of key.
32
-
33
31
  def do_select_fields(model_str)
34
32
  # Fields
35
33
  session['fields'] ||= {}
@@ -79,32 +77,28 @@ class BeautifulController < ApplicationController
79
77
  elt = modelclass.find(params[:id])
80
78
  elt.attributes = { foreignkey => parent_id }
81
79
 
82
- if modelclass.column_names.include?("position") then
80
+ if modelclass.column_names.include?("position")
83
81
  new_pos = 0
84
82
  modelclass.transaction do
85
83
  all_elt = modelclass.where(foreignkey => parent_id).order("position ASC").to_a
86
84
 
87
- #begin
88
- if index == 0 then
89
- new_pos = (begin (all_elt.first.position - 1) rescue 1 end)
90
- elsif index == all_elt.length then
91
- new_pos = (begin (all_elt.last.position + 1) rescue 1 end)
92
- else
93
- new_pos = all_elt[index].position
94
-
95
- end_of_array = all_elt[index..-1]
96
- end_of_array.each{ |g|
97
- next if g == elt
98
- g.position = g.position.to_i + 1
99
- g.save!
100
-
101
- next_elt = end_of_array[end_of_array.index(g) + 1]
102
- break if not next_elt.nil? and next_elt.position > g.position
103
- }
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
104
100
  end
105
- #rescue
106
- # new_pos = 0
107
- #end
101
+ end
108
102
  end
109
103
  elt.position = new_pos
110
104
  end
@@ -0,0 +1,20 @@
1
+ class UserSessionsController < BeautifulController
2
+
3
+ skip_before_action :require_login, only: [:new, :create]
4
+
5
+ def create
6
+ @user = login(params[:email], params[:password])
7
+
8
+ if @user
9
+ redirect_back_or_to(:users, notice: 'Login successful')
10
+ else
11
+ flash.now[:alert] = 'Login failed'
12
+ render action: 'new'
13
+ end
14
+ end
15
+
16
+ def destroy
17
+ logout
18
+ redirect_to(:users, notice: 'Logged out!')
19
+ end
20
+ end
@@ -25,7 +25,7 @@ module BeautifulHelper
25
25
  attr = nil
26
26
  sort = nil
27
27
 
28
- if not params[:sorting].blank? then
28
+ if !params[:sorting].blank?
29
29
  attr = params[:sorting][:attribute]
30
30
  sort = params[:sorting][:sorting]
31
31
  end
@@ -34,11 +34,11 @@ module BeautifulHelper
34
34
  sortstr = sort.to_s.downcase
35
35
  opposite_sortstr = ""
36
36
  csort = '' # <i class="fa fa-stop"></i>
37
- if attribute_name == attr then
38
- if sortstr == "asc" then
37
+ if attribute_name == attr
38
+ if sortstr == "asc"
39
39
  csort = '<i class="fa fa-chevron-up"></i>'
40
40
  opposite_sortstr = "desc"
41
- elsif sortstr == "desc" then
41
+ elsif sortstr == "desc"
42
42
  csort = '<i class="fa fa-chevron-down"></i>'
43
43
  opposite_sortstr = "asc"
44
44
  end
@@ -47,7 +47,7 @@ module BeautifulHelper
47
47
  end
48
48
 
49
49
  default_caption = attribute_name.capitalize
50
- if is_belongs_to_column?(default_caption) then
50
+ if is_belongs_to_column?(default_caption)
51
51
  default_caption = get_belongs_to_model(default_caption)
52
52
  end
53
53
 
@@ -55,7 +55,7 @@ module BeautifulHelper
55
55
 
56
56
  caption = t(cap, :default => default_caption).capitalize
57
57
  strpath = model_name.pluralize + "_url"
58
- strpath = namespace + '_' + strpath if not namespace.blank?
58
+ strpath = namespace + '_' + strpath if !namespace.blank?
59
59
 
60
60
  return link_to(
61
61
  "#{csort} #{caption}".html_safe,
@@ -73,9 +73,9 @@ module BeautifulHelper
73
73
  ar_model = (engine.blank? ? model_name.camelize.constantize : "#{engine.camelize}::#{model_name.camelize}".constantize)
74
74
 
75
75
  default_caption = caption
76
- if default_caption.blank? then
76
+ if default_caption.blank?
77
77
  default_caption = attribute_name.capitalize
78
- if is_belongs_to_column?(default_caption) then
78
+ if is_belongs_to_column?(default_caption)
79
79
  default_caption = get_belongs_to_model(default_caption)
80
80
  end
81
81
  end
@@ -84,7 +84,7 @@ module BeautifulHelper
84
84
  name_field_bk = attribute_name
85
85
  label_field = attribute_name
86
86
 
87
- if is_belongs_to_column?(name_field_bk) then
87
+ if is_belongs_to_column?(name_field_bk)
88
88
  label_field = get_belongs_to_model(attribute_name)
89
89
  end
90
90
 
@@ -92,107 +92,143 @@ module BeautifulHelper
92
92
 
93
93
  cap = i18n_translate_path(model_name, attribute_name)
94
94
 
95
+ type_of_column = ar_model.columns_hash[attribute_name].type unless ar_model.columns_hash[attribute_name].nil?
96
+ type_of_column ||= :other
97
+
95
98
  infostr = ''
96
99
  response = '' # See at end
100
+ response += '<div class="form-check form-check-inline">' if type_of_column == :boolean
97
101
  response += f.label name_field, t(cap, :default => default_caption).capitalize, :class => "control-label"
102
+ response += '</div>' if type_of_column == :boolean
98
103
 
99
- type_of_column = ar_model.columns_hash[attribute_name].type unless ar_model.columns_hash[attribute_name].nil?
100
- type_of_column ||= :other
101
104
  case type_of_column
102
- when :date, :datetime then
105
+ when :date, :datetime
103
106
  dt = (type_of_column == :datetime)
104
107
  interval = (dt ? (1..5) : (1..3))
105
108
 
109
+ html_id = "#{name_field}_dp_gt"
110
+ filter = session['search'][model_name]
111
+ filter ||= {}
112
+
106
113
  # Greater than
107
- response += '<div class="input-group input-' + type_of_column.to_s + '">'
108
- response += '<span class="input-group-addon"><i class="fa fa-chevron-right"></i></span>'
114
+ 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">'
115
+ response += '<div class="input-group-prepend"><span class="input-group-text"><i class="fa fa-chevron-right"></i></span></div>'
109
116
  response += f.text_field(
110
- (name_field + "_dp_gt").to_sym,
111
- :value => (begin params[:q][(name_field + "_dp_gt").to_sym] rescue '' end),
112
- :class => "col-md-9 dpicker form-control",
117
+ (html_id).to_sym,
118
+ :value => ("#{filter["#{name_field}_gteq(3i)"]}/#{filter["#{name_field}_gteq(2i)"]}/#{filter["#{name_field}_gteq(1i)"]}"),
119
+ :class => " form-control datetimepicker-input",
120
+ "data-target" => "##{html_id}_id",
113
121
  "data-id" => ("q_" + name_field + "_gteq"))
114
- response += '<span class="input-group-addon"><i class="fa fa-calendar"></i></span>'
122
+ 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>'
115
123
  response += '</div>'
116
124
 
117
- if dt then
118
- response += '<div class="input-group input-' + type_of_column.to_s + '">'
119
- response += '<span class="input-group-addon"><i class="fa fa-chevron-right"></i></span>'
125
+ html_id = "#{name_field}_tp_gt"
126
+
127
+ if dt
128
+ 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">'
129
+ response += '<div class="input-group-prepend"><span class="input-group-text"><i class="fa fa-chevron-right"></i></span></div>'
120
130
  response += f.text_field(
121
131
  (name_field + "_tp_gt").to_sym,
122
- :value => (begin params[:q][(name_field + "_tp_gt").to_sym] rescue '' end),
123
- :class => "col-md-9 tpicker form-control",
132
+ :value => ("#{filter["#{name_field}_gteq(4i)"]}/#{filter["#{name_field}_gteq(5i)"]}"),
133
+ :class => " form-control datetimepicker-input",
134
+ "data-target" => "##{html_id}_id",
124
135
  "data-id" => ("q_" + name_field + "_gteq"))
125
- response += '<span class="input-group-addon"><i class="fa fa-clock-o"></i></span>'
136
+ 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>'
126
137
  response += '</div>'
127
138
  end
128
139
 
129
140
  for i in interval
130
141
  response += f.hidden_field(name_field + "_gteq(#{i}i)",
131
- :value => (begin params[:q][(name_field + "_gteq(#{i}i)").to_sym] rescue '' end),
142
+ :value => (filter["#{name_field}_gteq(#{i}i)"]),
132
143
  :id => ('q_' + name_field + "_gteq_#{i}i"))
133
144
  end
134
145
 
146
+ html_id = "#{name_field}_dp_lt"
147
+
135
148
  # Less than
136
- response += '<div class="input-group input-' + type_of_column.to_s + '">'
137
- response += '<span class="input-group-addon"><i class="fa fa-chevron-left"></i></span>'
149
+ 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">'
150
+ response += '<div class="input-group-prepend"><span class="input-group-text"><i class="fa fa-chevron-left"></i></span></div>'
138
151
  response += f.text_field(
139
152
  (name_field + "_dp_lt").to_sym,
140
- :value => (begin params[:q][(name_field + "_dp_lt").to_sym] rescue '' end),
141
- :class => "col-md-9 dpicker form-control",
153
+ :value => ("#{filter["#{name_field}_lteq(3i)"]}/#{filter["#{name_field}_lteq(2i)"]}/#{filter["#{name_field}_lteq(1i)"]}"),
154
+ :class => " form-control datetimepicker-input",
155
+ "data-target" => "##{html_id}_id",
142
156
  "data-id" => ("q_" + name_field + "_lteq"))
143
- response += '<span class="input-group-addon"><i class="fa fa-calendar"></i></span>'
157
+ 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>'
144
158
  response += '</div>'
145
159
 
146
- if dt then
147
- response += '<div class="input-group input-' + type_of_column.to_s + '">'
148
- response += '<span class="input-group-addon"><i class="fa fa-chevron-left"></i></span>'
160
+ html_id = "#{name_field}_tp_lt"
161
+
162
+ if dt
163
+ 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">'
164
+ response += '<div class="input-group-prepend"><span class="input-group-text"><i class="fa fa-chevron-left"></i></span></div>'
149
165
  response += f.text_field(
150
166
  (name_field + "_tp_lt").to_sym,
151
- :value => (begin params[:q][(name_field + "_tp_lt").to_sym] rescue '' end),
152
- :class => "col-md-9 tpicker form-control",
167
+ :value => ("#{filter["#{name_field}_lteq(4i)"]}/#{filter["#{name_field}_lteq(5i)"]}"),
168
+ :class => " form-control datetimepicker-input",
169
+ "data-target" => "##{html_id}_id",
153
170
  "data-id" => ("q_" + name_field + "_lteq"))
154
- response += '<span class="input-group-addon"><i class="fa fa-clock-o"></i></span>'
171
+ 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>'
155
172
  response += '</div>'
156
173
  end
157
174
 
158
175
  for i in interval
159
176
  response += f.hidden_field(name_field + "_lteq(#{i}i)",
160
- :value => (begin params[:q][(name_field + "_lteq(#{i}i)").to_sym] rescue '' end),
177
+ :value => (filter["#{name_field}_lteq(#{i}i)"]),
161
178
  :id => ('q_' + name_field + "_lteq_#{i}i"))
162
179
  end
163
180
 
164
181
  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])
165
- when :boolean then
182
+ when :boolean
166
183
  # Specify a default value (false) in rails migration
167
- 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"
168
- 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"
169
- response += f.label name_field + "_eq", raw(f.radio_button((name_field + "_eq").to_sym, nil)) + " " + h(t(:all, :default => "All")), :class => "checkbox inline"
184
+ response += '<div class="form-check form-check-inline">'
185
+ response += f.radio_button((name_field + "_eq").to_sym, true, { class: 'form-check-input'})
186
+ response += f.label name_field + "_eq_true", h(t(:yes, default: "Yes")), class: "form-check-label"
187
+ response += '</div>'
188
+
189
+ response += '<div class="form-check form-check-inline">'
190
+ response += f.radio_button((name_field + "_eq").to_sym, false, { class: 'form-check-input'})
191
+ response += f.label name_field + "_eq_false", h(t(:no, default: "No")), class: "form-check-label"
192
+ response += '</div>'
193
+
194
+ response += '<div class="form-check form-check-inline">'
195
+ response += f.radio_button((name_field + "_eq").to_sym, nil, { class: 'form-check-input'})
196
+ response += f.label name_field + "_eq", h(t(:all, default: "All")), class: "form-check-label"
197
+ response += '</div>'
170
198
 
171
199
  infostr = (begin session['search'][model_name][(name_field + "_eq").to_sym] == "on" ? "" : "info" rescue "" end)
172
- when :string then
200
+ when :string
173
201
  response += f.text_field((name_field + "_cont").to_sym, :class => "filter col-md-12 form-control")
174
202
 
175
203
  infostr = info_input(model_name, (name_field + "_cont").to_sym)
176
- when :integer, :float, :decimal then
177
- if is_belongs_to_column?(name_field_bk) then
204
+ when :integer, :float, :decimal #, :other
205
+ if is_belongs_to_column?(name_field_bk)
178
206
  bt_model_name = get_belongs_to_model(name_field_bk).camelize
179
- bt_model_name = "#{engine.camelize}::#{bt_model_name}" if !engine.blank?
207
+ field = name_field + "_eq"
208
+
209
+ if !engine.blank?
210
+ bt_model_name = "#{engine.camelize}::#{bt_model_name}"
211
+ #field = "#{engine.downcase}_#{field}"
212
+ end
213
+
180
214
  btmodel = bt_model_name.constantize
181
- 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" })
215
+ field = field.to_sym
182
216
 
183
- infostr = info_input(model_name, (name_field + "_eq").to_sym)
184
- elsif name_field == "id" then
217
+ response += f.collection_select(field, btmodel.all, :id, :caption, { :include_blank => t(:all, :default => "All") }, { :class => "col-md-12 form-control" })
218
+
219
+ infostr = info_input(model_name, field)
220
+ elsif name_field == "id"
185
221
  response += f.text_field((name_field + "_eq").to_sym, :class => "filter col-md-12 form-control")
186
222
 
187
223
  infostr = info_input(model_name, (name_field + "_eq").to_sym)
188
224
  else
189
225
  response += '<div class="input-group">'
190
- response += '<span class="input-group-addon" rel="tooltip" title="' + t(:greater_than, :default => "Greater than") + '"><i class="fa fa-chevron-right"></i></span>'
191
- response += f.text_field((name_field + "_gteq").to_sym, :class => "#{align_attribute("integer")} filter-min col-md-10 form-control")
226
+ 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>'
227
+ response += f.text_field((name_field + "_gteq").to_sym, :class => "#{align_attribute("integer")} filter-min form-control")
192
228
  response += '</div>'
193
229
  response += '<div class="input-group">'
194
- response += '<span class="input-group-addon" rel="tooltip" title="' + t(:smaller_than, :default => "Smaller than") + '"><i class="fa fa-chevron-left"></i></span>'
195
- response += f.text_field((name_field + "_lteq").to_sym, :class => "#{align_attribute("integer")} filter-max col-md-10 form-control")
230
+ 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>'
231
+ response += f.text_field((name_field + "_lteq").to_sym, :class => "#{align_attribute("integer")} filter-max form-control")
196
232
  response += '</div>'
197
233
 
198
234
  infostr = info_input(model_name, [(name_field + "_lteq").to_sym, (name_field + "_gteq").to_sym])
@@ -213,11 +249,11 @@ module BeautifulHelper
213
249
  def info_input(modname, attr)
214
250
  model_name = modname
215
251
  rep = false
216
- if not session['search'].blank? and not session['search'][model_name].blank? then
217
- if attr.kind_of?(Array) then
252
+ if !session['search'].blank? and !session['search'][model_name].blank?
253
+ if attr.kind_of?(Array)
218
254
  rep = (attr.any? { |elt| (not session['search'][model_name][elt].blank?) })
219
255
  else
220
- rep = (not session['search'][model_name][attr].blank?)
256
+ rep = (!session['search'][model_name][attr].blank?)
221
257
  end
222
258
  end
223
259
  return (rep ? "info" : "")
@@ -225,17 +261,17 @@ module BeautifulHelper
225
261
 
226
262
  def align_attribute(attribute_type)
227
263
  return case attribute_type
228
- when "string" then
229
- "al"
230
- when "integer", "float", "numeric", "decimal" then
231
- "ar"
232
- when "boolean" then
233
- "ac"
234
- when "date", "datetime", "timestamp" then
235
- "ac"
236
- else
237
- "al"
238
- end
264
+ when "string"
265
+ "al"
266
+ when "integer", "float", "numeric", "decimal"
267
+ "ar"
268
+ when "boolean"
269
+ "ac"
270
+ when "date", "datetime", "timestamp"
271
+ "ac"
272
+ else
273
+ "al"
274
+ end
239
275
  end
240
276
 
241
277
  # Encore utilisé avec wysihtml5 ?