templus_models 1.6.9 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/crud_controller.rb +48 -53
  3. data/app/helpers/crud_helper.rb +27 -3
  4. data/app/helpers/search_helper.rb +25 -20
  5. data/app/raro_crud/raro_crud.rb +66 -20
  6. data/app/views/crud/_default_actions_crud.html.erb +2 -2
  7. data/app/views/crud/_form.html.erb +5 -5
  8. data/app/views/crud/_form_group.html.erb +3 -3
  9. data/app/views/crud/_record.html.erb +46 -43
  10. data/app/views/crud/_records.html.erb +12 -12
  11. data/app/views/crud/_scopes.html.erb +4 -5
  12. data/app/views/crud/_search.html.erb +3 -3
  13. data/app/views/crud/_shared.html.erb +31 -18
  14. data/app/views/crud/_show.html.erb +8 -7
  15. data/app/views/crud/listing.pdf.erb +21 -19
  16. data/app/views/crud/listing.xls.erb +2 -2
  17. data/app/views/crud/printing.pdf.erb +100 -0
  18. data/app/views/kaminari/templus/_first_page.html.erb +1 -1
  19. data/app/views/kaminari/templus/_gap.html.erb +1 -1
  20. data/app/views/kaminari/templus/_last_page.html.erb +1 -1
  21. data/app/views/kaminari/templus/_next_page.html.erb +1 -1
  22. data/app/views/kaminari/templus/_paginator.html.erb +2 -2
  23. data/app/views/kaminari/templus/_prev_page.html.erb +1 -1
  24. data/app/views/layouts/_menu_crud.html.erb +1 -1
  25. data/app/views/layouts/_template_raro_crud.html.erb +1 -1
  26. data/config/initializers/simple_form.rb +2 -5
  27. data/config/routes.rb +32 -25
  28. data/lib/templus_models/configuration.rb +14 -0
  29. data/lib/templus_models/version.rb +1 -1
  30. data/lib/templus_models.rb +29 -1
  31. data/test/dummy/app/helpers/menu_helper.rb +17 -17
  32. data/test/dummy/app/models/templus.rb +4 -4
  33. data/test/dummy/app/raro_crud/endereco_crud.rb +1 -1
  34. data/test/dummy/app/raro_crud/papel_crud.rb +1 -1
  35. data/test/dummy/app/raro_crud/teste1_crud.rb +1 -1
  36. data/test/dummy/app/raro_crud/teste_crud.rb +1 -1
  37. data/test/dummy/app/raro_crud/usuario_crud.rb +6 -3
  38. data/test/dummy/config/locales/pt-BR.yml +25 -31
  39. data/test/dummy/config/locales/simple_form.pt-BR.yml +2 -0
  40. data/test/dummy/db/development.sqlite3 +0 -0
  41. metadata +627 -625
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6ae0620e6eba343d31342d59071a04a9ae52209
4
- data.tar.gz: 07ae1285226134a93a4d4fefcad70d5d1f0c667d
3
+ metadata.gz: 749829c56974ebda6ca4e4c53aa76d2971b67a67
4
+ data.tar.gz: a771e4b88920e4072c6db69fe32891b8e2b32e12
5
5
  SHA512:
6
- metadata.gz: 4ad915585be13740748dbee801b00f9a8d31ab029a4e71b21ccc01291fd01d8726cd4f73da459501649a40c02a607ff8fdb1a82c47d5a1504cdaefd84fc1569f
7
- data.tar.gz: 49e1a72feb488e510091e28d032de316dc26422d6b5e7c47e05c2e5ad59015cee704f88866240de6b10f0e72fcddd6d96605c47662db8680dce20d7c60d2d1ca
6
+ metadata.gz: 9fde57d73ce9e7e3781eadff3b8919f8d4e3bb745a9806a26dd54539befdfd7c45a60cbf2e0239853cf0037077af883b48cd66e81e862e64d42d72b6eb24a988
7
+ data.tar.gz: d7b354949f3407c01c99620a5ba84abc88650c014d61943a6c14b82c12bc028932981a33ffbb831ce8d5235fd6889aa2a07c87aae2a5dc7aa2bc86afe66ea95c
@@ -1,9 +1,31 @@
1
1
  class CrudController < ApplicationController
2
2
  before_filter :setup, except: :autocomplete
3
3
 
4
+ private
5
+ def setup
6
+ if params[:associacao]
7
+ @crud_associacao = Module.const_get("#{params[:model].to_s.singularize}_crud".camelize)
8
+ @model = Module.const_get(params[:model].camelize).find(params[:id]).send(params[:associacao])
9
+ c_helper = Module.const_get(params[:model].camelize).reflect_on_association(params[:associacao]).class_name
10
+ @crud_helper = Module.const_get("#{c_helper}Crud") unless params[:render] == "modal" and params[:action] == "new"
11
+ @url = crud_associacao_models_path(model: params[:model], id: params[:id], associacao: params[:associacao], page: params[:page], q: params[:q])
12
+ @clean_url = crud_associacao_models_path(model: params[:model], id: params[:id], associacao: params[:associacao])
13
+ @model_permission = c_helper.constantize
14
+ @id = params[:associacao_id] if params[:associacao_id]
15
+ else
16
+ @model = Module.const_get(params[:model].camelize)
17
+ @model_permission = @model
18
+ @crud_helper = Module.const_get("#{params[:model]}_crud".camelize) unless params[:render] == "modal" and params[:action] == "new"
19
+ @url = crud_models_path(model: params[:model], page: params[:page], q: params[:q])
20
+ @clean_url = crud_models_path(model: params[:model])
21
+ @id = params[:id] if params[:id]
22
+ end
23
+ end
24
+
25
+ public
4
26
  def index
5
27
  authorize! :read, @model_permission if respond_to?(:current_usuario)
6
- if params[:scope].present? && valid_method?(params[:scope])
28
+ if params[:scope].present?
7
29
  @q = @model.send(params[:scope]).search(params[:q])
8
30
  else
9
31
  @q = @model.search(params[:q])
@@ -53,13 +75,13 @@ class CrudController < ApplicationController
53
75
  def action
54
76
  @record = @model.find(@id)
55
77
  authorize! :create_or_update, @record if respond_to?(:current_usuario)
56
- if valid_instance_method?(params[:acao])
78
+ if @model.method_defined?(params[:acao])
57
79
  if @record.send(params[:acao])
58
- flash.now[:success] = "Ação #{params[:acao]} efetuada com sucesso."
80
+ flash.now[:success] = I18n.t("mensagem_action", acao: params[:acao])
59
81
  else
60
- flash.now[:error] = "Erro ao tentar executar a ação #{params[:acao]}."
82
+ flash.now[:error] = I18n.t("mensagem_erro_action", acao: params[:acao])
61
83
  end
62
- index
84
+ redirect_to "#{@url}?page=#{params[:page]}"
63
85
  else
64
86
  @titulo = @record.to_s
65
87
  @texto = params[:acao]
@@ -81,8 +103,8 @@ class CrudController < ApplicationController
81
103
 
82
104
  respond_to do |format|
83
105
  if @saved
84
- flash[:success] = params[:id].present? ? "Cadastro alterado com sucesso." : "Cadastro efetuado com sucesso."
85
- format.html { redirect_to @url }
106
+ flash[:success] = params[:id].present? ? I18n.t("updated", model: I18n.t("model.#{@model.name.underscore}")) : I18n.t("created", model: I18n.t("model.#{@model.name.underscore}"))
107
+ format.html { redirect_to "#{@url}?page=#{params[:page]}" }
86
108
  unless params[:render] == 'modal'
87
109
  format.js { render action: :index}
88
110
  else
@@ -101,7 +123,7 @@ class CrudController < ApplicationController
101
123
  authorize! :destroy, @record if respond_to?(:current_usuario)
102
124
  if @record.destroy
103
125
  respond_to do |format|
104
- flash[:success] = "Cadastro removido com sucesso."
126
+ flash[:success] = I18n.t("destroyed", model: I18n.t("model.#{@model.name.underscore}"))
105
127
  format.html { redirect_to @url }
106
128
  format.js { render action: :index }
107
129
  end
@@ -144,11 +166,7 @@ class CrudController < ApplicationController
144
166
  else
145
167
  results = @q.result.page(params[:page])
146
168
  end
147
- if valid_instance_method?(params[:label])
148
- method_label = params[:label]
149
- else
150
- raise "Ação inválida"
151
- end
169
+ method_label = params[:label]
152
170
  render json: results.map {|result| {id: result.id, label: result.send(method_label), value: result.send(method_label)} }
153
171
  end
154
172
 
@@ -160,7 +178,7 @@ class CrudController < ApplicationController
160
178
  else
161
179
  @records = @q.result
162
180
  end
163
- report_name = "Listagem de #{@crud_helper.title} #{DateTime.now.strftime('%Y%m%d')}"
181
+ report_name = "#{@crud_helper.title}_#{DateTime.now.strftime('%Y%m%d')}"
164
182
  respond_to do |format|
165
183
  format.xls {headers["Content-Disposition"] = "attachment; filename=#{report_name}.xls"}
166
184
  format.pdf do
@@ -177,31 +195,26 @@ class CrudController < ApplicationController
177
195
  end
178
196
  end
179
197
 
180
- private
181
- def setup
182
- if params[:associacao]
183
- @crud_associacao = Module.const_get("#{params[:model].to_s.singularize}_crud".camelize)
184
- if Module.const_get(params[:model].camelize).reflect_on_association(params[:associacao])
185
- @model = Module.const_get(params[:model].camelize).find(params[:id]).send(params[:associacao])
186
- else
187
- raise "Ação inválida"
198
+ def printing
199
+ @record = @model.find(@id)
200
+ authorize! :read, @record if respond_to?(:current_usuario)
201
+ report_name = "#{@record}_#{DateTime.now.strftime('%Y%m%d')}"
202
+ respond_to do |format|
203
+ format.pdf do
204
+ pdf = WickedPdf.new.pdf_from_string(
205
+ render_to_string('crud/printing.pdf.erb'),
206
+ encoding: 'UTF-8',
207
+ page_size: 'A4',
208
+ show_as_html: params[:debug],
209
+ margin: { top: 20, bottom: 20 }
210
+ )
211
+ send_data(pdf, filename: "#{report_name}.pdf", type: "application/pdf", disposition: "inline")
188
212
  end
189
- c_helper = Module.const_get(params[:model].camelize).reflect_on_association(params[:associacao]).class_name
190
- @crud_helper = Module.const_get("#{c_helper}Crud") unless params[:render] == "modal" and params[:action] == "new"
191
- @url = crud_associacao_models_path(model: params[:model], id: params[:id], associacao: params[:associacao], page: params[:page], q: params[:q])
192
- @clean_url = crud_associacao_models_path(model: params[:model], id: params[:id], associacao: params[:associacao])
193
- @model_permission = c_helper.constantize
194
- @id = params[:associacao_id] if params[:associacao_id]
195
- else
196
- @model = Module.const_get(params[:model].camelize)
197
- @model_permission = @model
198
- @crud_helper = Module.const_get("#{params[:model]}_crud".camelize) unless params[:render] == "modal" and params[:action] == "new"
199
- @url = crud_models_path(model: params[:model], page: params[:page], q: params[:q])
200
- @clean_url = crud_models_path(model: params[:model])
201
- @id = params[:id] if params[:id]
213
+ format.html
202
214
  end
203
215
  end
204
216
 
217
+ private
205
218
  def params_permitt
206
219
  params.require(@model.name.underscore.to_sym).permit(fields_model)
207
220
  end
@@ -257,22 +270,4 @@ class CrudController < ApplicationController
257
270
  end
258
271
  group
259
272
  end
260
-
261
- def valid_method?(method)
262
- list_methods = []
263
- @model.ancestors.each do |m|
264
- list_methods << m.methods(false).reject{ |m| /^_/ =~ m.to_s }
265
- break if m.superclass.to_s == "ActiveRecord::Base"
266
- end
267
- list_methods.flatten.include? method.to_sym
268
- end
269
-
270
- def valid_instance_method?(method)
271
- list_methods = []
272
- @model.ancestors.each do |m|
273
- list_methods << m.instance_methods(false).reject{ |m| /^_/ =~ m.to_s }
274
- break if m.superclass.to_s == "ActiveRecord::Base"
275
- end
276
- list_methods.flatten.include? method.to_sym
277
- end
278
273
  end
@@ -61,12 +61,13 @@ module CrudHelper
61
61
 
62
62
 
63
63
  def render_link(link,url)
64
+ nome_modelo = I18n.t("model.#{link[:modelo].underscore}")
64
65
  if link[:partial].present?
65
66
  render link[:partial]
66
67
  elsif link[:link].present?
67
- link_to "#{gen_icon(link[:icon])} #{link[:text]}".html_safe, "#{url}/#{link[:link]}", class: link[:class], data: data(link)
68
+ link_to "#{gen_icon(link[:icon])} #{I18n.t(link[:text], model: nome_modelo)}".html_safe, "#{url}/#{link[:link]}", class: link[:class], data: data(link)
68
69
  else
69
- link_to "#{gen_icon(link[:icon])} #{link[:text]}".html_safe, link[:url], class: link[:class], data: data(link)
70
+ link_to "#{gen_icon(link[:icon])} #{I18n.t(link[:text], model: nome_modelo)}".html_safe, link[:url], class: link[:class], data: data(link)
70
71
  end
71
72
  end
72
73
 
@@ -119,6 +120,7 @@ module CrudHelper
119
120
  if field[:sf].present? && field[:sf][:if].present?
120
121
  return unless field[:sf][:if].call(f.object)
121
122
  end
123
+ field[:sf][:hint] = false if field[:sf].present? && !field[:sf][:hint].present?
122
124
  if field[:sf].present? && field[:sf][:date_format].present? && f.object.send(field[:attribute]).present? && Date <= modelo.columns_hash[field[:attribute].to_s].type.to_s.camelcase.constantize
123
125
  field[:sf][:input_html] ||= {}
124
126
  field[:sf][:input_html][:value] = f.object.send(field[:attribute]).strftime(field[:sf][:date_format])
@@ -171,7 +173,11 @@ module CrudHelper
171
173
 
172
174
  def render_field_file(field)
173
175
  if imagem?(field) && field.url(:thumb)
174
- image_tag(field.url(:thumb))
176
+ if is_active_action("printing")
177
+ wicked_pdf_image_tag(field.url(:thumb))
178
+ else
179
+ image_tag(field.url(:thumb))
180
+ end
175
181
  elsif video?(field)
176
182
  link_to field, field.url, target: "_blank"
177
183
  else
@@ -211,4 +217,22 @@ module CrudHelper
211
217
  return true if crud_helper.condition_listing_action.nil?
212
218
  crud_helper.condition_listing_action.call(model)
213
219
  end
220
+
221
+ def should_listing_excel?(crud_helper,model)
222
+ return false unless can?(:read, model)
223
+ return true if crud_helper.condition_listing_excel.nil?
224
+ crud_helper.condition_listing_excel.call(model)
225
+ end
226
+
227
+ def should_listing_pdf?(crud_helper,model)
228
+ return false unless can?(:read, model)
229
+ return true if crud_helper.condition_listing_pdf.nil?
230
+ crud_helper.condition_listing_pdf.call(model)
231
+ end
232
+
233
+ def should_printing?(crud_helper,record)
234
+ return false unless can?(:read, record)
235
+ return true if crud_helper.condition_printing_action.nil?
236
+ crud_helper.condition_printing_action.call(record)
237
+ end
214
238
  end
@@ -4,7 +4,7 @@ module SearchHelper
4
4
  @buffer = raro_before_form(model,partial,collection_name,url,sort)
5
5
  @model = model
6
6
  yield
7
- @buffer << raro_submit("Pesquisar")
7
+ @buffer << raro_submit(I18n.t('search'))
8
8
  @buffer << raro_after_form
9
9
  @buffer << raro_script
10
10
  @buffer.html_safe
@@ -17,14 +17,16 @@ module SearchHelper
17
17
  end
18
18
 
19
19
  def raro_field (name, opts = {})
20
+ modelo = opts[:model] || @model
20
21
  unless opts[:model]
21
22
  prototype = @model.columns_hash[name.to_s]
22
23
  return "" unless prototype
23
24
  else
24
25
  prototype = Module.const_get(opts[:model]).columns_hash[name.to_s]
26
+ modelo = Module.const_get(opts[:model])
25
27
  name = opts[:full_name]
26
28
  end
27
- label = name
29
+ label = I18n.t("simple_form.labels.#{modelo.name.underscore}.#{name}")
28
30
  label = opts[:label] if opts[:label]
29
31
 
30
32
  @buffer << "<div class=\"form-group\">"
@@ -88,6 +90,8 @@ module SearchHelper
88
90
  raro_text_field(name, opts)
89
91
  when :range
90
92
  raro_range(name)
93
+ when :monthyear
94
+ raro_monthyear(name, opts)
91
95
  end
92
96
  end
93
97
 
@@ -111,7 +115,7 @@ module SearchHelper
111
115
  else
112
116
  buf << "<select name=#{name} class='form-control'>"
113
117
  end
114
- buf <<"<option value ='' selected>Escolha...</option>"
118
+ buf <<"<option value ='' selected>#{I18n.t('search')}</option>"
115
119
  collection.each do |e|
116
120
  buf << "<option value=#{e[0]}>#{e[1]}</option>"
117
121
  end
@@ -141,8 +145,8 @@ module SearchHelper
141
145
 
142
146
  def raro_monthyear(name, opts)
143
147
  buffer = ""
144
- buffer += "<div class='col-sm-8'>"
145
- buffer += "<input id='q_#{name}' type='text' name='q[#{name}_cont]' class='form-control #{opts[:class]}'/>"
148
+ buffer += "<div class='col-sm-12'>"
149
+ buffer += "<input id='q_#{name}' type='text' name='q[#{name}_monthyear_eq]' class='form-control monthyearpicker #{opts[:class]}'/>"
146
150
  buffer += "</div>"
147
151
  buffer
148
152
  end
@@ -171,9 +175,9 @@ module SearchHelper
171
175
  if opts[:collection].present?
172
176
  opts[:collection].each do |opt|
173
177
  buff<<"<label>"
174
- buff<<"<div class='checkbox'>"
175
- buff<<"<input id='q_#{name}' type='radio' name='q[#{name}_eq]' value='#{opt[0]}' class='i-checks'/>"
176
- buff<<"</div>"
178
+ buff<<"<div class='checkbox'>"
179
+ buff<<"<input id='q_#{name}' type='radio' name='q[#{name}_eq]' value='#{opt[0]}' class='i-checks'/>"
180
+ buff<<"</div>"
177
181
  buff<<"<span class='lbl'> #{opt[1]}</span>"
178
182
  buff<<"</label>"
179
183
  end
@@ -207,7 +211,8 @@ module SearchHelper
207
211
  end
208
212
 
209
213
  def raro_range(name)
210
- buffer = "<div class='col-sm-4'>"
214
+ buffer = ""
215
+ buffer += "<div class='col-sm-4'>"
211
216
  buffer += "<input type='text' name='q[#{name}_gteq]' class='form-control'/>"
212
217
  buffer += "</div>"
213
218
  buffer += "<div class='col-sm-4 range-separator'>"
@@ -241,21 +246,21 @@ module SearchHelper
241
246
 
242
247
  def raro_comparison_operators(target)
243
248
  "<select class='form-control m-b' onchange='window.search_predicate(this)' data-target='#q_#{target}'>
244
- <option value=eq selected>Igual</option>
245
- <option value=not_eq>Diferente</option>
246
- <option value=gt>Maior</option>
247
- <option value=lt>Menor</option>
248
- <option value=gteq>Maior ou Igual</option>
249
- <option value=lteq>Menor ou Igual</option></select>"
249
+ <option value=eq selected>#{I18n.t('equal')}</option>
250
+ <option value=not_eq>#{I18n.t('different')}</option>
251
+ <option value=gt>#{I18n.t('great')}</option>
252
+ <option value=lt>#{I18n.t('less')}</option>
253
+ <option value=gteq>#{I18n.t('great_then')}</option>
254
+ <option value=lteq>#{I18n.t('less_then')}</option></select>"
250
255
  end
251
256
 
252
257
  def raro_string_operators(target)
253
258
  "<select class='form-control m-b' onchange='window.search_predicate(this)' data-target='#q_#{target}'>
254
- <option value=cont>Contém</option>
255
- <option value=eq>Igual</option>
256
- <option value=not_cont>Não Contém</option>
257
- <option value=start>Começa</option>
258
- <option value=end>Termina</option>
259
+ <option value=cont>#{I18n.t('contains')}</option>
260
+ <option value=eq>#{I18n.t('equal')}</option>
261
+ <option value=not_cont>#{I18n.t('not_contains')}</option>
262
+ <option value=start>#{I18n.t('begins')}</option>
263
+ <option value=end>#{I18n.t('ends')}</option>
259
264
  </select>"
260
265
  end
261
266
 
@@ -7,6 +7,7 @@ class RaroCrud
7
7
  @@form_scripts = {}
8
8
  @@view_fields = {}
9
9
  @@listing_fields = {}
10
+ @@printing_fields = {}
10
11
  @@search_fields = {}
11
12
  @@test_fields = {}
12
13
  @@top_links = {}
@@ -22,12 +23,23 @@ class RaroCrud
22
23
  @@view_action = {}
23
24
  @@condition_view_action = {}
24
25
  @@condition_listing_action = {}
26
+ @@condition_listing_excel = {}
27
+ @@condition_listing_pdf = {}
28
+ @@condition_printing_action = {}
25
29
  @@options_link = {}
26
30
  @@scopes = {}
27
31
  @@menus = []
28
32
  @@layout = {}
29
33
  @@index_path = nil
30
34
 
35
+ def modelo
36
+ self.to_s.gsub("Crud", "").constantize
37
+ end
38
+
39
+ def self.title
40
+ I18n.t("rarocrud.#{self.modelo.underscore}.title")
41
+ end
42
+
31
43
  def self.edit_action
32
44
  if @@edit_action[self.to_s.to_sym] == false
33
45
  return false
@@ -77,6 +89,18 @@ class RaroCrud
77
89
  (@@condition_listing_action[self.to_s.to_sym]) ? @@condition_listing_action[self.to_s.to_sym] : nil
78
90
  end
79
91
 
92
+ def self.condition_listing_excel
93
+ (@@condition_listing_excel[self.to_s.to_sym]) ? @@condition_listing_excel[self.to_s.to_sym] : nil
94
+ end
95
+
96
+ def self.condition_listing_pdf
97
+ (@@condition_listing_pdf[self.to_s.to_sym]) ? @@condition_listing_pdf[self.to_s.to_sym] : nil
98
+ end
99
+
100
+ def self.condition_printing_action
101
+ (@@condition_printing_action[self.to_s.to_sym]) ? @@condition_printing_action[self.to_s.to_sym] : nil
102
+ end
103
+
80
104
  def self.root_path
81
105
  self.to_s.gsub('Crud', '').underscore
82
106
  end
@@ -89,10 +113,6 @@ class RaroCrud
89
113
  @@index_path
90
114
  end
91
115
 
92
- def self.title
93
- @@title[self.to_s.to_sym]
94
- end
95
-
96
116
  def self.subtitle(type)
97
117
  case type
98
118
  when :index
@@ -155,6 +175,10 @@ class RaroCrud
155
175
  (@@listing_fields[self.to_s.to_sym]) ? @@listing_fields[self.to_s.to_sym] : []
156
176
  end
157
177
 
178
+ def self.printing_fields
179
+ (@@printing_fields[self.to_s.to_sym]) ? @@printing_fields[self.to_s.to_sym] : []
180
+ end
181
+
158
182
  def self.search_fields
159
183
  (@@search_fields[self.to_s.to_sym]) ? @@search_fields[self.to_s.to_sym] : []
160
184
  end
@@ -200,11 +224,12 @@ class RaroCrud
200
224
  end
201
225
  end
202
226
 
203
- def self.link_superior nome, opts
227
+ def self.link_superior opts={}
204
228
  @@top_links[self.to_s.to_sym] = [] unless @@top_links[self.to_s.to_sym]
205
229
  @@top_links[self.to_s.to_sym].push(
206
230
  {
207
- text: nome,
231
+ text: opts[:nome],
232
+ modelo: self.modelo,
208
233
  id: opts[:id],
209
234
  data: {push: 'partial', target: '#form'},
210
235
  icon: "fa fa-#{opts[:icon]}",
@@ -217,7 +242,7 @@ class RaroCrud
217
242
  )
218
243
  end
219
244
 
220
- def self.campo_tabela nome, opts
245
+ def self.campo_tabela nome, opts={}
221
246
  @@index_fields[self.to_s.to_sym] = [] unless @@index_fields[self.to_s.to_sym]
222
247
  @@index_fields[self.to_s.to_sym].push(
223
248
  {
@@ -234,7 +259,7 @@ class RaroCrud
234
259
  @@per_page[self.to_s.to_sym] = qtd
235
260
  end
236
261
 
237
- def self.campo_teste nome, opts
262
+ def self.campo_teste nome, opts = {}
238
263
  @@test_fields[self.to_s.to_sym] = [] unless @@test_fields[self.to_s.to_sym]
239
264
  @@test_fields[self.to_s.to_sym].push(
240
265
  {
@@ -243,7 +268,7 @@ class RaroCrud
243
268
  )
244
269
  end
245
270
 
246
- def self.campo_formulario nome, opts
271
+ def self.campo_formulario nome, opts={}
247
272
  @@form_fields[self.to_s.to_sym] = [] unless @@form_fields[self.to_s.to_sym]
248
273
  if opts.present? && opts[:autocomplete].present?
249
274
  opts[:as] = :autocomplete
@@ -286,7 +311,7 @@ class RaroCrud
286
311
  end
287
312
 
288
313
  public
289
- def self.campo_visualizacao nome, opts = nil
314
+ def self.campo_visualizacao nome, opts = {}
290
315
  @@view_fields[self.to_s.to_sym] = [] unless @@view_fields[self.to_s.to_sym]
291
316
  @@view_fields[self.to_s.to_sym].push(
292
317
  {
@@ -295,7 +320,7 @@ class RaroCrud
295
320
  )
296
321
  end
297
322
 
298
- def self.campo_busca nome, opts = nil
323
+ def self.campo_busca nome, opts = {}
299
324
  @@search_fields[self.to_s.to_sym] = [] unless @@search_fields[self.to_s.to_sym]
300
325
  @@search_fields[self.to_s.to_sym].push(
301
326
  {
@@ -304,7 +329,7 @@ class RaroCrud
304
329
  )
305
330
  end
306
331
 
307
- def self.campo_listagem nome, opts = nil
332
+ def self.campo_listagem nome, opts = {}
308
333
  @@listing_fields[self.to_s.to_sym] = [] unless @@listing_fields[self.to_s.to_sym]
309
334
  @@listing_fields[self.to_s.to_sym].push(
310
335
  {
@@ -313,6 +338,15 @@ class RaroCrud
313
338
  )
314
339
  end
315
340
 
341
+ def self.campo_impressao nome, opts = {}
342
+ @@printing_fields[self.to_s.to_sym] = [] unless @@printing_fields[self.to_s.to_sym]
343
+ @@printing_fields[self.to_s.to_sym].push(
344
+ {
345
+ attribute: nome
346
+ }.merge({sf: opts})
347
+ )
348
+ end
349
+
316
350
  def self.sem_visualizacao
317
351
  @@view_action[self.to_s.to_sym] = false
318
352
  end
@@ -341,6 +375,18 @@ class RaroCrud
341
375
  @@condition_listing_action[self.to_s.to_sym] = condicao
342
376
  end
343
377
 
378
+ def self.listagem_excel(condicao = nil)
379
+ @@condition_listing_excel[self.to_s.to_sym] = condicao
380
+ end
381
+
382
+ def self.listagem_pdf(condicao = nil)
383
+ @@condition_listing_pdf[self.to_s.to_sym] = condicao
384
+ end
385
+
386
+ def self.impressao(condicao)
387
+ @@condition_printing_action[self.to_s.to_sym] = condicao
388
+ end
389
+
344
390
  def self.acoes(method,desc,proc = nil)
345
391
  @@actions[self.to_s.to_sym] = [] unless @@actions[self.to_s.to_sym]
346
392
  @@actions[self.to_s.to_sym].push([method,desc,proc])
@@ -366,7 +412,7 @@ class RaroCrud
366
412
  name = attribute.to_s.singularize.titleize
367
413
  end
368
414
  @@form_group[self.to_s.to_sym] ||= {}
369
- @@form_group[self.to_s.to_sym][attribute] = {label: name, fields: []}
415
+ @@form_group[self.to_s.to_sym][attribute] = {fields: []}
370
416
  fields.each do |field|
371
417
  value = {}
372
418
  field.each do |atr|
@@ -386,13 +432,13 @@ class RaroCrud
386
432
  opts = {}
387
433
  opts[:fields] = []
388
434
  [
389
- {campo: :cep, label: "CEP"},
390
- {campo: :logradouro, label: "Endereço"},
391
- {campo: :numero, label: "Número"},
392
- {campo: :complemento, label: "Complemento"},
393
- {campo: :bairro, label: "Bairro"},
394
- {campo: :estado, label: "Estado", collection: Estado.order(:sigla).pluck(:sigla)},
395
- {campo: :cidade_id, label: "Cidade", collection_if: Proc.new{|f| f.try(:object).try(:estado).try(:present?) ? (f.try(:object).try(:estado).try(:cidades) || []) : []}}
435
+ {campo: :cep, input_html: {class: "mask-cep"}},
436
+ {campo: :logradouro},
437
+ {campo: :numero},
438
+ {campo: :complemento},
439
+ {campo: :bairro},
440
+ {campo: :estado, collection: Estado.order(:sigla).pluck(:sigla)},
441
+ {campo: :cidade_id, collection_if: Proc.new{|f| f.try(:object).try(:estado).try(:present?) ? (f.try(:object).try(:estado).try(:cidades) || []) : []}}
396
442
  ].each do |field|
397
443
  attribute = field[:campo]
398
444
  field.delete(:campo)
@@ -1,2 +1,2 @@
1
- <%= submit_tag("Salvar", class: "btn btn-primary") %>
2
- <%= link_to "Voltar", @url, class: 'btn btn-default', data: {push: 'partial', target: "#form"} %>
1
+ <%= submit_tag(I18n.t("save"), class: "btn btn-primary") %>
2
+ <%= link_to I18n.t("undo"), crud_models_path(model: @model.name.underscore), class: 'btn btn-default', data: {push: 'partial', target: "#form"} %>
@@ -4,9 +4,9 @@
4
4
  <div class="modal-content animated bounceInRight">
5
5
  <div class="modal-body">
6
6
  </div>
7
- <div class="modal-footer">
8
- <button type="button" class="btn btn-white" data-dismiss="modal">Cancelar</button>
9
- </div>
7
+ <div class="modal-footer">
8
+ <button type="button" class="btn btn-white" data-dismiss="modal"><%= I18n.t("cancel") %></button>
9
+ </div>
10
10
  </div>
11
11
  </div>
12
12
  </div>
@@ -50,9 +50,9 @@
50
50
  <% end %>
51
51
  <div class="form-group">
52
52
  <div class="col-sm-4 col-sm-offset-2">
53
- <%= f.submit "Salvar", class: 'btn btn-primary' %>
53
+ <%= f.submit I18n.t("save"), class: 'btn btn-primary' %>
54
54
  <%unless params[:render] == 'modal'%>
55
- <%= link_to "Voltar", @url, class: 'btn btn-default', data: {push: 'partial', target: "#form"} %>
55
+ <%= link_to I18n.t("undo"), "#{@url}?page=#{params[:page]}", class: 'btn btn-default', data: {push: 'partial', target: "#form"} %>
56
56
  <% end %>
57
57
  </div>
58
58
  </div>
@@ -8,7 +8,7 @@
8
8
  <% end %>
9
9
  <%= f.simple_fields_for key do |g| %>
10
10
  <div class="col-sm-12">
11
- <h3><%= groups[:label] %></h3>
11
+ <h3><%= groups[:sublabel] || groups[:label] || I18n.t("simple_form.labels.#{modelo.name.underscore}.#{key}") %></h3>
12
12
  </div>
13
13
  <% groups[:fields].each do |field| %>
14
14
  <% if field[:sf].present? && field[:sf][:grupo].present? %>
@@ -24,7 +24,7 @@
24
24
  <% if [:has_many,:has_and_belongs_to_many].include?(f.object.class.reflect_on_association(key).macro) %>
25
25
  <div class="form-group">
26
26
  <div class="col-sm-10 col-sm-offset-2">
27
- <%= g.link_to_remove "Remover #{groups[:sublabel] || groups[:label].downcase}" %>
27
+ <%= g.link_to_remove "Remover #{groups[:sublabel] || groups[:label].try(:downcase) || I18n.t("simple_form.labels.#{modelo.name.underscore}.#{key}")}" %>
28
28
  </div>
29
29
  </div>
30
30
  <% end %>
@@ -32,7 +32,7 @@
32
32
  <% if [:has_many,:has_and_belongs_to_many].include?(f.object.class.reflect_on_association(key).macro) %>
33
33
  <div class="form-group">
34
34
  <div class="col-sm-12">
35
- <%= f.link_to_add "Adicionar #{groups[:sublabel] || groups[:label].downcase}", key %>
35
+ <%= f.link_to_add "Adicionar #{groups[:sublabel] || groups[:label].try(:downcase) || I18n.t("simple_form.labels.#{modelo.name.underscore}.#{key}")}", key %>
36
36
  </div>
37
37
  </div>
38
38
  <% end %>