templus_models 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4375243bea6ad4021fbd11dcdc796f445c623d1
4
- data.tar.gz: 4dbc1ce1f203547d791b2a79933db11c91ece85f
3
+ metadata.gz: eb53a205b3effb5725e79f8942766cd329e0063c
4
+ data.tar.gz: de6dd1d86ba4130aeb08c1466514c7b0e209ca94
5
5
  SHA512:
6
- metadata.gz: 2f1c40caabbc3676af69a4020a2bd79a7a135940ef1f37f833b03cd4409f8e17a6c9593071c2b456ea7f021bb3374089bec876f26c5c86d80aa0004b4e160961
7
- data.tar.gz: 9418bee70eca2242c497d81d57c3b763efe70de8d010dbfe129b9cd8411e9117d396aa9b043ef335124161753953c3055cad7067cd9efb591a7b26d1c107880f
6
+ metadata.gz: e0932e8c5b3f3f57457f0996bb1fe8d77a34b3ba5837a7fb5202062e00cd7a732d484fcf3bf19d44e98b46c111b58d6bd53113762b1bcfb7c4d284ac7545e124
7
+ data.tar.gz: 9c5ca770f1f106e43333db2a9deca647289bea59ae05674b83b61bb4ea91da50aae719e7e50bc440fd499c0f4c7b81404fee11c1bc48d4dfcc0d6f173fd3609b
@@ -1,28 +1,7 @@
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
4
 
25
- public
26
5
  def index
27
6
  authorize! :read, @model_permission if respond_to?(:current_usuario)
28
7
  if params[:scope].present?
@@ -180,18 +159,7 @@ class CrudController < ApplicationController
180
159
  end
181
160
  report_name = "#{@crud_helper.title}_#{DateTime.now.strftime('%Y%m%d')}"
182
161
  respond_to do |format|
183
- format.xls {headers["Content-Disposition"] = "attachment; filename=#{report_name}.xls"}
184
- format.pdf do
185
- pdf = WickedPdf.new.pdf_from_string(
186
- render_to_string('crud/listing.pdf.erb'),
187
- encoding: 'UTF-8',
188
- page_size: 'A4',
189
- show_as_html: params[:debug],
190
- margin: { top: 20, bottom: 20 }
191
- )
192
- send_data(pdf, filename: "#{report_name}.pdf", type: "application/pdf", disposition: "inline")
193
- end
194
- format.html
162
+ format.xls { headers["Content-Disposition"] = "attachment; filename=#{report_name}.xls" }
195
163
  end
196
164
  end
197
165
 
@@ -214,7 +182,29 @@ class CrudController < ApplicationController
214
182
  end
215
183
  end
216
184
 
185
+
217
186
  private
187
+
188
+ def setup
189
+ if params[:associacao]
190
+ @crud_associacao = Module.const_get("#{params[:model].to_s.singularize}_crud".camelize)
191
+ @model = Module.const_get(params[:model].camelize).find(params[:id]).send(params[:associacao])
192
+ c_helper = Module.const_get(params[:model].camelize).reflect_on_association(params[:associacao]).class_name
193
+ @crud_helper = Module.const_get("#{c_helper}Crud") unless params[:render] == "modal" and params[:action] == "new"
194
+ @url = crud_associacao_models_path(model: params[:model], id: params[:id], associacao: params[:associacao], page: params[:page], q: params[:q])
195
+ @clean_url = crud_associacao_models_path(model: params[:model], id: params[:id], associacao: params[:associacao])
196
+ @model_permission = c_helper.constantize
197
+ @id = params[:associacao_id] if params[:associacao_id]
198
+ else
199
+ @model = Module.const_get(params[:model].camelize)
200
+ @model_permission = @model
201
+ @crud_helper = Module.const_get("#{params[:model]}_crud".camelize) unless params[:render] == "modal" and params[:action] == "new"
202
+ @url = crud_models_path(model: params[:model], page: params[:page], q: params[:q])
203
+ @clean_url = crud_models_path(model: params[:model])
204
+ @id = params[:id] if params[:id]
205
+ end
206
+ end
207
+
218
208
  def params_permitt
219
209
  params.require(@model.name.underscore.to_sym).permit(fields_model)
220
210
  end
@@ -0,0 +1,32 @@
1
+ module AttributesHelper
2
+
3
+ def association?(model, attribute)
4
+ !!model.reflect_on_association(attribute)
5
+ end
6
+
7
+ def belongs_to_association?(model, attribute)
8
+ association_type?(model, attribute, :belongs_to)
9
+ end
10
+
11
+ def has_one_association?(model, attribute)
12
+ association_type?(model, attribute, :has_one)
13
+ end
14
+
15
+ def array?(record, attribute)
16
+ attribute_class?(record, attribute, Array)
17
+ end
18
+
19
+ def boolean?(record, attribute)
20
+ ['false', 'true'].include? record.send(attribute).to_s
21
+ end
22
+
23
+ private
24
+
25
+ def association_type?(model, attribute, association_type)
26
+ association?(model, attribute) && model.reflect_on_association(attribute).macro == association_type
27
+ end
28
+
29
+ def attribute_class?(record, attribute, klass)
30
+ record.send(attribute).class == klass
31
+ end
32
+ end
@@ -1,11 +1,11 @@
1
1
  module CrudHelper
2
2
 
3
3
  def is_active_controller(controller_name)
4
- params[:controller] == controller_name ? "active" : nil
4
+ params[:controller] == controller_name ? "active" : nil
5
5
  end
6
6
 
7
7
  def is_active_action(action_name)
8
- params[:action] == action_name ? "active" : nil
8
+ params[:action] == action_name ? "active" : nil
9
9
  end
10
10
 
11
11
  def is_raro_crud(classe)
@@ -174,9 +174,9 @@ module CrudHelper
174
174
  end
175
175
 
176
176
  def render_field_file(field)
177
- if imagem?(field) && field.url(:thumb)
177
+ if imagem?(field) && field.respond_to?(:thumb)
178
178
  if is_active_action("printing")
179
- wicked_pdf_image_tag(field.url(:thumb))
179
+ pdf_image_tag(field)
180
180
  else
181
181
  image_tag(field.url(:thumb))
182
182
  end
@@ -196,45 +196,65 @@ module CrudHelper
196
196
  end
197
197
 
198
198
  #Permissions
199
- def should_view?(crud_helper,record)
199
+ def should_view?(crud_helper, record)
200
200
  return false unless can?(:read, record)
201
201
  return true if crud_helper.condition_view_action.nil?
202
202
  crud_helper.condition_view_action.call(record)
203
203
  end
204
204
 
205
- def should_edit?(crud_helper,record)
205
+ def should_edit?(crud_helper, record)
206
206
  return false unless can?(:update, record)
207
207
  return true if crud_helper.condition_edit_action.nil?
208
208
  crud_helper.condition_edit_action.call(record)
209
209
  end
210
210
 
211
- def should_destroy?(crud_helper,record)
211
+ def should_destroy?(crud_helper, record)
212
212
  return false unless can?(:destroy, record)
213
213
  return true if crud_helper.condition_destroy_action.nil?
214
214
  crud_helper.condition_destroy_action.call(record)
215
215
  end
216
216
 
217
- def should_listing?(crud_helper,model)
217
+ def should_listing?(crud_helper, model)
218
218
  return false unless can?(:read, model)
219
219
  return true if crud_helper.condition_listing_action.nil?
220
220
  crud_helper.condition_listing_action.call(model)
221
221
  end
222
222
 
223
- def should_listing_excel?(crud_helper,model)
223
+ def should_listing_excel?(crud_helper, model)
224
224
  return false unless can?(:read, model)
225
225
  return true if crud_helper.condition_listing_excel.nil?
226
226
  crud_helper.condition_listing_excel.call(model)
227
227
  end
228
228
 
229
- def should_listing_pdf?(crud_helper,model)
230
- return false unless can?(:read, model)
231
- return true if crud_helper.condition_listing_pdf.nil?
232
- crud_helper.condition_listing_pdf.call(model)
233
- end
234
-
235
- def should_printing?(crud_helper,record)
229
+ def can_print_pdf?(crud_helper, record)
236
230
  return false unless can?(:read, record)
237
231
  return true if crud_helper.condition_printing_action.nil?
238
232
  crud_helper.condition_printing_action.call(record)
239
233
  end
234
+
235
+
236
+ private
237
+
238
+ def pdf_image_tag(field, options = {})
239
+ if Rails.env.development? || Rails.env.test?
240
+ # Unless running a web server that can process 2 requests at the same
241
+ # time, trying to insert an image in a PDF creates a deadlock: the server
242
+ # can't finish processing the PDF request until it gets the image, but it
243
+ # can't start processing the image request until it has finished
244
+ # processing the PDF request.
245
+ # This will not be a problem in production, but in dev, a workaround is
246
+ # to base64 the image and insert its contents into the HTML
247
+ if field.respond_to?(:thumb)
248
+ image_data = File.read(field.thumb.path)
249
+ else
250
+ image_data = Rails.application.assets[field].to_s
251
+ end
252
+ image_tag("data:image/png;base64,#{::Base64.encode64(image_data)}", options)
253
+ else
254
+ if field.respond_to?(:thumb)
255
+ field = field.thumb.url
256
+ end
257
+ wicked_pdf_image_tag(field, options)
258
+ end
259
+ end
240
260
  end
@@ -0,0 +1,15 @@
1
+ module ImagensHelper
2
+
3
+ def carrier_wave_uploader?(model, attribute)
4
+ model.new.send(attribute).class.ancestors.include?(CarrierWave::Uploader::Base)
5
+ end
6
+
7
+ def possui_url?(record, attribute)
8
+ record.send(attribute).respond_to?(:url)
9
+ end
10
+
11
+ def deve_renderizar_imagem?(opts)
12
+ opts.has_key?(:render) && !!opts[:render]
13
+ end
14
+
15
+ end
@@ -8,6 +8,8 @@ class RaroCrud
8
8
  @@view_fields = {}
9
9
  @@listing_fields = {}
10
10
  @@printing_fields = {}
11
+ @@logo_printing_field = {}
12
+ @@titulo_printing_field = {}
11
13
  @@search_fields = {}
12
14
  @@test_fields = {}
13
15
  @@top_links = {}
@@ -128,11 +130,11 @@ class RaroCrud
128
130
  end
129
131
 
130
132
  def self.top_links
131
- (@@top_links[self.to_s.to_sym]) ? @@top_links[self.to_s.to_sym] : []
133
+ @@top_links[self.to_s.to_sym] || []
132
134
  end
133
135
 
134
136
  def self.index_fields
135
- (@@index_fields[self.to_s.to_sym]) ? @@index_fields[self.to_s.to_sym] : []
137
+ @@index_fields[self.to_s.to_sym] || []
136
138
  end
137
139
 
138
140
  def self.order_field
@@ -144,51 +146,59 @@ class RaroCrud
144
146
  end
145
147
 
146
148
  def self.actions
147
- (@@actions[self.to_s.to_sym]) ? @@actions[self.to_s.to_sym] : []
149
+ @@actions[self.to_s.to_sym] || []
148
150
  end
149
151
 
150
152
  def self.actions_links
151
- (@@links[self.to_s.to_sym]) ? @@links[self.to_s.to_sym] : []
153
+ @@links[self.to_s.to_sym] || []
152
154
  end
153
155
 
154
156
  def self.options_link
155
- (@@options_link[self.to_s.to_sym]) ? @@options_link[self.to_s.to_sym] : []
157
+ @@options_link[self.to_s.to_sym] || []
156
158
  end
157
159
 
158
160
  def self.form_fields
159
- (@@form_fields[self.to_s.to_sym]) ? @@form_fields[self.to_s.to_sym] : []
161
+ @@form_fields[self.to_s.to_sym] || []
160
162
  end
161
163
 
162
164
  def self.form_groups
163
- (@@form_group[self.to_s.to_sym]) ? @@form_group[self.to_s.to_sym] : []
165
+ @@form_group[self.to_s.to_sym] || []
164
166
  end
165
167
 
166
168
  def self.form_scripts
167
- (@@form_scripts[self.to_s.to_sym]) ? @@form_scripts[self.to_s.to_sym] : []
169
+ @@form_scripts[self.to_s.to_sym] || []
168
170
  end
169
171
 
170
172
  def self.view_fields
171
- (@@view_fields[self.to_s.to_sym]) ? @@view_fields[self.to_s.to_sym] : []
173
+ @@view_fields[self.to_s.to_sym] || []
172
174
  end
173
175
 
174
176
  def self.listing_fields
175
- (@@listing_fields[self.to_s.to_sym]) ? @@listing_fields[self.to_s.to_sym] : []
177
+ @@listing_fields[self.to_s.to_sym] || []
176
178
  end
177
179
 
178
180
  def self.printing_fields
179
- (@@printing_fields[self.to_s.to_sym]) ? @@printing_fields[self.to_s.to_sym] : []
181
+ @@printing_fields[self.to_s.to_sym] || []
182
+ end
183
+
184
+ def self.logo_printing_field
185
+ @@logo_printing_field[self.to_s.to_sym]
186
+ end
187
+
188
+ def self.titulo_printing_field
189
+ @@titulo_printing_field[self.to_s.to_sym]
180
190
  end
181
191
 
182
192
  def self.search_fields
183
- (@@search_fields[self.to_s.to_sym]) ? @@search_fields[self.to_s.to_sym] : []
193
+ @@search_fields[self.to_s.to_sym] || []
184
194
  end
185
195
 
186
196
  def self.test_fields
187
- (@@test_fields[self.to_s.to_sym]) ? @@test_fields[self.to_s.to_sym] : []
197
+ @@test_fields[self.to_s.to_sym] || []
188
198
  end
189
199
 
190
200
  def self.scopes
191
- (@@scopes[self.to_s.to_sym]) ? @@scopes[self.to_s.to_sym] : []
201
+ @@scopes[self.to_s.to_sym] || []
192
202
  end
193
203
 
194
204
  def self.add_menus(menu)
@@ -200,6 +210,7 @@ class RaroCrud
200
210
  end
201
211
 
202
212
 
213
+
203
214
  private
204
215
 
205
216
  def self.modelo
@@ -300,7 +311,6 @@ class RaroCrud
300
311
  end
301
312
  end
302
313
 
303
- private
304
314
  def self.add_group_formulario(field)
305
315
  field[:fields] = []
306
316
  field[:grupo].each do |f|
@@ -311,7 +321,7 @@ class RaroCrud
311
321
  end
312
322
  field[:grupo] = true
313
323
  end
314
-
324
+
315
325
  def self.set_default_label nome, opts
316
326
  unless opts[:label].present?
317
327
  opts[:label] = "simple_form.labels.#{self.modelo.underscore}.#{nome}"
@@ -319,9 +329,13 @@ class RaroCrud
319
329
  opts
320
330
  end
321
331
 
332
+
333
+
334
+
322
335
  public
323
- def self.campo_visualizacao nome, opts = {}
324
- @@view_fields[self.to_s.to_sym] = [] unless @@view_fields[self.to_s.to_sym]
336
+
337
+ def self.campo_visualizacao(nome, opts = {})
338
+ @@view_fields[self.to_s.to_sym] ||= []
325
339
  opts = set_default_label nome, opts
326
340
  @@view_fields[self.to_s.to_sym].push(
327
341
  {
@@ -330,8 +344,8 @@ class RaroCrud
330
344
  )
331
345
  end
332
346
 
333
- def self.campo_busca nome, opts = {}
334
- @@search_fields[self.to_s.to_sym] = [] unless @@search_fields[self.to_s.to_sym]
347
+ def self.campo_busca(nome, opts = {})
348
+ @@search_fields[self.to_s.to_sym] ||= []
335
349
  opts = set_default_label nome, opts
336
350
  @@search_fields[self.to_s.to_sym].push(
337
351
  {
@@ -340,8 +354,8 @@ class RaroCrud
340
354
  )
341
355
  end
342
356
 
343
- def self.campo_listagem nome, opts = {}
344
- @@listing_fields[self.to_s.to_sym] = [] unless @@listing_fields[self.to_s.to_sym]
357
+ def self.relatorio_listagem(nome, opts = {})
358
+ @@listing_fields[self.to_s.to_sym] ||= []
345
359
  opts = set_default_label nome, opts
346
360
  @@listing_fields[self.to_s.to_sym].push(
347
361
  {
@@ -350,14 +364,46 @@ class RaroCrud
350
364
  )
351
365
  end
352
366
 
353
- def self.campo_impressao nome, opts = {}
354
- @@printing_fields[self.to_s.to_sym] = [] unless @@printing_fields[self.to_s.to_sym]
367
+ def self.relatorio_impressao(nome, opts = {})
368
+ @@printing_fields[self.to_s.to_sym] ||= []
355
369
  opts = set_default_label nome, opts
356
- @@printing_fields[self.to_s.to_sym].push(
357
- {
358
- attribute: nome
359
- }.merge({sf: opts})
360
- )
370
+ @@printing_fields[self.to_s.to_sym].push({
371
+ attribute: nome,
372
+ sf: opts
373
+ })
374
+ end
375
+
376
+ def self.relatorio_impressao_logo(field_or_url = nil, options = {})
377
+ url = nil
378
+ field = nil
379
+ if field_or_url.blank?
380
+ url = Templus.logo
381
+ elsif field_or_url.is_a?(String)
382
+ url = field_or_url
383
+ else
384
+ field = field_or_url
385
+ end
386
+
387
+ @@logo_printing_field[self.to_s.to_sym] = {
388
+ url: url,
389
+ field: field,
390
+ sf: options
391
+ }
392
+ end
393
+
394
+ def self.relatorio_impressao_titulo(field_or_string = nil)
395
+ field = nil
396
+ titulo = nil
397
+ if field_or_string.is_a?(String)
398
+ titulo = I18n.t(field_or_string)
399
+ elsif field_or_string.present?
400
+ field = field_or_string
401
+ end
402
+
403
+ @@titulo_printing_field[self.to_s.to_sym] = {
404
+ field: field,
405
+ titulo: titulo
406
+ }
361
407
  end
362
408
 
363
409
  def self.sem_visualizacao
@@ -1,55 +1,55 @@
1
1
  <%= render_crud do %>
2
- <div>
3
- <%= render "/crud/links" %>
4
- </div>
5
- <div class="dataTables_wrapper form-inline">
6
- <table class="table table-striped table-bordered table-hover dataTables-example dataTable">
7
- <thead>
8
- <tr>
9
- <%@crud_helper.index_fields.each do |att| %>
10
- <% if !att[:visible_if].nil?%>
11
- <% if ((att[:visible_if].class == Proc && !att[:visible_if].call(att)) || (att[:visible_if].class != Proc && !att[:visible_if])) %>
12
- <% next %>
13
- <% end %>
14
- <% end %>
15
- <th>
16
- <% if att[:sort_field].present? %>
17
- <%= sort_link @q, att[:sort_field], I18n.t(att[:label]), {},data: {push: 'partial', target: "#form"}%>
18
- <% else %>
19
- <%= sort_link @q, att[:attribute], I18n.t(att[:label]), {},data: {push: 'partial', target: "#form"}%>
20
- <% end %>
21
- </th>
22
- <%end%>
23
- <%if @crud_helper.view_action || @crud_helper.edit_action || @crud_helper.destroy_action || @crud_helper.actions.present?%>
24
- <td><%= I18n.t("simple_form.index.options") %></td>
25
- <% end %>
26
- </tr>
27
- </thead>
28
- <tbody id="records-body">
29
- <% @records.each do |record| %>
30
- <%= render '/crud/record', record: record %>
31
- <% end %>
32
- </tbody>
33
- </table>
34
- <%= paginate @records, target: '#form', theme: 'templus'%>
35
- </div>
2
+ <div>
3
+ <%= render "/crud/links" %>
4
+ </div>
5
+ <div class="dataTables_wrapper form-inline">
6
+ <table class="table table-striped table-bordered table-hover dataTables-example dataTable">
7
+ <thead>
8
+ <tr>
9
+ <%@crud_helper.index_fields.each do |att| %>
10
+ <% if !att[:visible_if].nil?%>
11
+ <% if ((att[:visible_if].class == Proc && !att[:visible_if].call(att)) || (att[:visible_if].class != Proc && !att[:visible_if])) %>
12
+ <% next %>
13
+ <% end %>
14
+ <% end %>
15
+ <th>
16
+ <% if att[:sort_field].present? %>
17
+ <%= sort_link @q, att[:sort_field], I18n.t(att[:label]), {},data: {push: 'partial', target: "#form"}%>
18
+ <% else %>
19
+ <%= sort_link @q, att[:attribute], I18n.t(att[:label]), {},data: {push: 'partial', target: "#form"}%>
20
+ <% end %>
21
+ </th>
22
+ <%end%>
23
+ <%if @crud_helper.view_action || @crud_helper.edit_action || @crud_helper.destroy_action || @crud_helper.actions.present?%>
24
+ <td><%= I18n.t("simple_form.index.options") %></td>
25
+ <% end %>
26
+ </tr>
27
+ </thead>
28
+ <tbody id="records-body">
29
+ <% @records.each do |record| %>
30
+ <%= render '/crud/record', record: record %>
31
+ <% end %>
32
+ </tbody>
33
+ </table>
34
+ <%= paginate @records, target: '#form', theme: 'templus'%>
35
+ </div>
36
36
  <% end %>
37
37
  <script type="text/javascript">
38
- var theadtxt = [];
39
- var headers = document.querySelectorAll("thead");
40
- var tablebody = document.querySelectorAll("tbody");
41
- for (var x = 0; x < headers.length; x++) {
42
- theadtxt[x]=[];
43
- for (var j = 0, headrow; headrow = headers[x].rows[0].cells[j]; j++) {
44
- var current = headrow;
45
- theadtxt[x].push(current.innerHTML);
46
- }
47
- }
48
- for (var v = 0, tbody; tbody = tablebody[v]; v++) {
49
- for (var x = 0, row; row = tbody.rows[x]; x++) {
50
- for (var j = 0, col; col = row.cells[j]; j++) {
38
+ var theadtxt = [];
39
+ var headers = document.querySelectorAll("thead");
40
+ var tablebody = document.querySelectorAll("tbody");
41
+ for (var x = 0; x < headers.length; x++) {
42
+ theadtxt[x]=[];
43
+ for (var j = 0, headrow; headrow = headers[x].rows[0].cells[j]; j++) {
44
+ var current = headrow;
45
+ theadtxt[x].push(current.innerHTML);
46
+ }
47
+ }
48
+ for (var v = 0, tbody; tbody = tablebody[v]; v++) {
49
+ for (var x = 0, row; row = tbody.rows[x]; x++) {
50
+ for (var j = 0, col; col = row.cells[j]; j++) {
51
51
  col.insertAdjacentHTML('afterbegin', '<div class="col-xs-3 no-padding">' + theadtxt[v][j] + '</div>');
52
- }
53
- }
54
- }
55
- </script>
52
+ }
53
+ }
54
+ }
55
+ </script>
@@ -1,30 +1,30 @@
1
1
  <div class="modal inmodal" id="modal_search" tabindex="-1" role="dialog" aria-hidden="true">
2
- <div class="modal-dialog modal-lg">
3
- <div class="modal-content animated bounceInRight">
4
- <div class="modal-header">
5
- <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only"><%= I18n.t("close") %></span></button>
6
- <i class="fa fa-search modal-icon"></i>
7
- <h4 class="modal-title"><%= I18n.t("search") %></h4>
8
- <small class="font-bold"></small>
9
- </div>
10
- <div class="modal-body">
11
- <% if @crud_associacao.present? %>
12
- <% url = query_crud_associacao_path(model: params[:model], id: params[:id], associacao: params[:associacao]) %>
13
- <% else %>
14
- <% url = query_crud_path(model: @model.name.underscore) %>
15
- <% end %>
16
- <%=raro_search_form(@model, 'records','records', url) do%>
17
- <%raro_group "#{@crud_helper.title}"%>
18
- <%@crud_helper.search_fields.each do |att| %>
19
- <% if att[:sf].present? && !att[:sf][:visible_if].nil?%>
20
- <% if ((att[:sf][:visible_if].class == Proc && !att[:sf][:visible_if].call(att)) || (att[:sf][:visible_if].class != Proc && !att[:sf][:visible_if])) %>
21
- <% next %>
22
- <% end %>
23
- <% end %>
24
- <%raro_field att[:attribute], att[:sf]%>
25
- <%end%>
26
- <%end%>
27
- </div>
28
- </div>
29
- </div>
2
+ <div class="modal-dialog modal-lg">
3
+ <div class="modal-content animated bounceInRight">
4
+ <div class="modal-header">
5
+ <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only"><%= I18n.t("close") %></span></button>
6
+ <i class="fa fa-search modal-icon"></i>
7
+ <h4 class="modal-title"><%= I18n.t("search") %></h4>
8
+ <small class="font-bold"></small>
9
+ </div>
10
+ <div class="modal-body">
11
+ <% if @crud_associacao.present? %>
12
+ <% url = query_crud_associacao_path(model: params[:model], id: params[:id], associacao: params[:associacao]) %>
13
+ <% else %>
14
+ <% url = query_crud_path(model: @model.name.underscore) %>
15
+ <% end %>
16
+ <%=raro_search_form(@model, 'records','records', url) do%>
17
+ <%raro_group "#{@crud_helper.title}"%>
18
+ <%@crud_helper.search_fields.each do |att| %>
19
+ <% if att[:sf].present? && !att[:sf][:visible_if].nil?%>
20
+ <% if ((att[:sf][:visible_if].class == Proc && !att[:sf][:visible_if].call(att)) || (att[:sf][:visible_if].class != Proc && !att[:sf][:visible_if])) %>
21
+ <% next %>
22
+ <% end %>
23
+ <% end %>
24
+ <%raro_field att[:attribute], att[:sf]%>
25
+ <%end%>
26
+ <%end%>
27
+ </div>
28
+ </div>
29
+ </div>
30
30
  </div>
@@ -1,98 +1,97 @@
1
- <%unless params[:render] == 'modal'%>
1
+ <% unless params[:render] == 'modal' %>
2
2
  <div class="wrapper wrapper-content animated fadeInRight">
3
- <div class="row">
4
- <div class="col-lg-12">
5
- <div class="ibox float-e-margins">
6
- <div class="ibox-title">
7
- <% if content_for?(:ibox_title) %>
8
- <%= yield :ibox_title %>
9
- <% elsif is_action_edit? && @model.present?%>
10
- <h5>
11
- <%= I18n.t("edit") %>
12
- <small style="margin-left: 2px;"><%= @record.to_s %> - #<%= @record.id %></small>
13
- </h5>
14
- <% elsif (is_action_create? || is_action_new?) && @model.present? %>
15
- <h5><%= I18n.t("new", model: I18n.t("model.#{@model.name.underscore}")) %></h5>
16
- <% elsif @record.present? && !@record.new_record? %>
17
- <h5>
18
- <%= @record.to_s %>
19
- <small style="margin-left: 2px;">#<%= @record.id %></small>
20
- </h5>
21
- <% elsif @crud_helper.present? %>
22
- <h5>
23
- <%= @crud_helper.subtitle(:index) %>
24
- <small><%= @crud_helper.description(:index) %></small>
25
- </h5>
26
- <% end %>
27
- <% if (@crud_helper.present? && (is_action_index? || is_action_query?))%>
28
- <div class="pull-right actions">
29
- <% @crud_helper.top_links.each do |link| %>
30
- <% if link[:can].present? %>
31
- <%=render_link(link,@clean_url) if self.instance_eval &link[:can]%>
32
- <% else %>
33
- <%=render_link(link,@clean_url)%>
34
- <% end %>
35
- <%end%>
36
- <% if params[:associacao] %>
37
- <% if @crud_helper.listing_fields.present? && should_listing?(@crud_helper, @model_permission) %>
38
- <%= link_to listing_crud_associacao_path(model: params[:model], id: params[:id], associacao: params[:associacao], q: params[:q], format: :xls), class: "btn btn-success btn-rounded" do %>
39
- <%= I18n.t("devise.reports.excel").html_safe %>
40
- <% end if should_listing_excel?(@crud_helper, @model_permission) %>
41
- <%= link_to listing_crud_associacao_path(model: params[:model], id: params[:id], associacao: params[:associacao], q: params[:q], format: :pdf), class: "btn btn-success btn-rounded", target: '_blank' do %>
42
- <%= I18n.t("devise.reports.pdf").html_safe %>
43
- <% end if should_listing_pdf?(@crud_helper, @model_permission) %>
44
- <% end %>
45
- <% else %>
46
- <% if @crud_helper.listing_fields.present? && should_listing?(@crud_helper, @model) %>
47
- <%= link_to listing_crud_path(model: @model.name.underscore, q: params[:q], format: :xls), class: "btn btn-success btn-rounded" do %>
48
- <%= I18n.t("devise.reports.excel").html_safe %>
49
- <% end if should_listing_excel?(@crud_helper, @model) %>
50
- <%= link_to listing_crud_path(model: @model.name.underscore, q: params[:q], target: '_blank', format: :pdf), class: "btn btn-success btn-rounded", target: '_blank' do %>
51
- <%= I18n.t("devise.reports.pdf").html_safe %>
52
- <% end if should_listing_pdf?(@crud_helper, @model) %>
53
- <% end %>
54
- <% end %>
55
- <% if @crud_helper.search_fields.present? %>
56
- <button id="button_search_<%=@model.name.underscore%>" class="btn btn-warning btn-rounded" data-toggle="modal" data-target="#modal_search">
57
- <i class="fa fa-search"></i>
58
- </button>
59
- <% end %>
60
- </div>
61
- <% elsif is_action_show? %>
62
- <% if (@crud_helper.present? && @crud_helper.destroy_action) && should_destroy?(@crud_helper, @record) %>
63
- <% if @crud_associacao.present? %>
64
- <%= link_to I18n.t("destroy"), destroy_crud_associacao_path(model: params[:model], id: params[:id], associacao: params[:associacao], associacao_id: @record.id, page: params[:page], q: params[:q]), class: 'btn btn-danger btn-xs pull-right m-l-xs', data: {method: 'delete', confirm: I18n.t('mensagem_confirm_destroy')} %>
65
- <% else %>
66
- <%= link_to I18n.t("destroy"), destroy_crud_path(model: @model.name.underscore, id: @record.id, page: params[:page], q: params[:q]), class: 'btn btn-danger btn-xs pull-right m-l-xs', data: {method: 'delete', confirm: I18n.t('mensagem_confirm_destroy')} %>
67
- <% end %>
68
- <% end %>
69
- <% if (@crud_helper.present? && @crud_helper.edit_action) && should_edit?(@crud_helper, @record) %>
70
- <% if @crud_associacao.present? %>
71
- <%= link_to I18n.t("edit"), edit_crud_associacao_path(model: params[:model], id: params[:id], associacao: params[:associacao], associacao_id: @record.id, page: params[:page], q: params[:q]), class: 'btn btn-primary btn-xs pull-right m-l-xs', data: {push: 'partial', target: '#form'} %>
72
- <% else %>
73
- <%= link_to I18n.t("edit"), edit_crud_path(model: @model.name.underscore, id: @record.id, page: params[:page], q: params[:q]), class: 'btn btn-primary btn-xs pull-right m-l-xs', data: {push: 'partial', target: '#form'} %>
74
- <% end %>
75
- <% end %>
76
- <% if @crud_helper.printing_fields.present? && should_printing?(@crud_helper, @record) %>
77
- <% if @crud_associacao.present? %>
78
- <%= link_to printing_crud_associacao_path(model: params[:model], id: params[:id], associacao: params[:associacao], associacao_id: @record.id, page: params[:page], q: params[:q], format: :pdf), class: "btn btn-success btn-xs pull-right m-l-xs", target: "_blank" do %>
79
- <%= I18n.t("devise.printing").html_safe %>
80
- <% end %>
81
- <% else %>
82
- <%= link_to printing_crud_path(model: @model.name.underscore, id: @record.id, page: params[:page], q: params[:q], format: :pdf), class: "btn btn-success btn-xs pull-right m-l-xs", target: "_blank" do %>
83
- <%= I18n.t("devise.printing").html_safe %>
84
- <% end %>
85
- <% end %>
86
- <% end %>
87
- <% end %>
88
- </div>
89
- <div class="ibox-content">
90
- <% block.call %>
91
- </div>
92
- </div>
93
- </div>
94
- </div>
3
+ <div class="row">
4
+ <div class="col-lg-12">
5
+ <div class="ibox float-e-margins">
6
+ <div class="ibox-title">
7
+ <% if content_for?(:ibox_title) %>
8
+ <%= yield :ibox_title %>
9
+ <% elsif is_action_edit? && @model.present?%>
10
+ <h5>
11
+ <%= I18n.t("edit") %>
12
+ <small style="margin-left: 2px;"><%= @record.to_s %> - #<%= @record.id %></small>
13
+ </h5>
14
+ <% elsif (is_action_create? || is_action_new?) && @model.present? %>
15
+ <h5><%= I18n.t("new", model: I18n.t("model.#{@model.name.underscore}")) %></h5>
16
+ <% elsif @record.present? && !@record.new_record? %>
17
+ <h5>
18
+ <%= @record.to_s %>
19
+ <small style="margin-left: 2px;">#<%= @record.id %></small>
20
+ </h5>
21
+ <% elsif @crud_helper.present? %>
22
+ <h5>
23
+ <%= @crud_helper.subtitle(:index) %>
24
+ <small><%= @crud_helper.description(:index) %></small>
25
+ </h5>
26
+ <% end %>
27
+
28
+
29
+ <% if (@crud_helper.present? && (is_action_index? || is_action_query?)) %>
30
+ <div class="pull-right actions">
31
+ <% @crud_helper.top_links.each do |link| %>
32
+ <% if link[:can].present? %>
33
+ <%= render_link(link,@clean_url) if self.instance_eval &link[:can] %>
34
+ <% else %>
35
+ <%= render_link(link,@clean_url) %>
36
+ <% end %>
37
+ <% end %>
38
+ <% if params[:associacao] %>
39
+ <% if @crud_helper.listing_fields.present? && should_listing?(@crud_helper, @model_permission) && should_listing_excel?(@crud_helper, @model_permission) %>
40
+ <%= link_to listing_crud_associacao_path(model: params[:model], id: params[:id], associacao: params[:associacao], q: params[:q], format: :xls), class: "btn btn-success btn-rounded" do %>
41
+ <%= I18n.t("devise.reports.excel").html_safe %>
42
+ <% end %>
43
+ <% end %>
44
+ <% else %>
45
+ <% if @crud_helper.listing_fields.present? && should_listing?(@crud_helper, @model) && should_listing_excel?(@crud_helper, @model) %>
46
+ <%= link_to listing_crud_path(model: @model.name.underscore, q: params[:q], format: :xls), class: "btn btn-success btn-rounded" do %>
47
+ <%= I18n.t("devise.reports.excel").html_safe %>
48
+ <% end %>
49
+ <% end %>
50
+ <% end %>
51
+ <% if @crud_helper.search_fields.present? %>
52
+ <button id="button_search_<%=@model.name.underscore%>" class="btn btn-warning btn-rounded" data-toggle="modal" data-target="#modal_search">
53
+ <i class="fa fa-search"></i>
54
+ </button>
55
+ <% end %>
56
+ </div>
57
+
58
+ <% elsif is_action_show? %>
59
+ <% if (@crud_helper.present? && @crud_helper.destroy_action) && should_destroy?(@crud_helper, @record) %>
60
+ <% if @crud_associacao.present? %>
61
+ <%= link_to I18n.t("destroy"), destroy_crud_associacao_path(model: params[:model], id: params[:id], associacao: params[:associacao], associacao_id: @record.id, page: params[:page], q: params[:q]), class: 'btn btn-danger btn-xs pull-right m-l-xs', data: {method: 'delete', confirm: I18n.t('mensagem_confirm_destroy')} %>
62
+ <% else %>
63
+ <%= link_to I18n.t("destroy"), destroy_crud_path(model: @model.name.underscore, id: @record.id, page: params[:page], q: params[:q]), class: 'btn btn-danger btn-xs pull-right m-l-xs', data: {method: 'delete', confirm: I18n.t('mensagem_confirm_destroy')} %>
64
+ <% end %>
65
+ <% end %>
66
+
67
+ <% if (@crud_helper.present? && @crud_helper.edit_action) && should_edit?(@crud_helper, @record) %>
68
+ <% if @crud_associacao.present? %>
69
+ <%= link_to I18n.t("edit"), edit_crud_associacao_path(model: params[:model], id: params[:id], associacao: params[:associacao], associacao_id: @record.id, page: params[:page], q: params[:q]), class: 'btn btn-primary btn-xs pull-right m-l-xs', data: {push: 'partial', target: '#form'} %>
70
+ <% else %>
71
+ <%= link_to I18n.t("edit"), edit_crud_path(model: @model.name.underscore, id: @record.id, page: params[:page], q: params[:q]), class: 'btn btn-primary btn-xs pull-right m-l-xs', data: {push: 'partial', target: '#form'} %>
72
+ <% end %>
73
+ <% end %>
74
+
75
+ <% if @crud_helper.printing_fields.present? && can_print_pdf?(@crud_helper, @record) %>
76
+ <% if @crud_associacao.present? %>
77
+ <%= link_to printing_crud_associacao_path(model: params[:model], id: params[:id], associacao: params[:associacao], associacao_id: @record.id, page: params[:page], q: params[:q], format: :pdf), class: "btn btn-success btn-xs pull-right m-l-xs", target: "_blank" do %>
78
+ <%= I18n.t("devise.printing").html_safe %>
79
+ <% end %>
80
+ <% else %>
81
+ <%= link_to printing_crud_path(model: @model.name.underscore, id: @record.id, page: params[:page], q: params[:q], format: :pdf), class: "btn btn-success btn-xs pull-right m-l-xs", target: "_blank" do %>
82
+ <%= I18n.t("devise.printing").html_safe %>
83
+ <% end %>
84
+ <% end %>
85
+ <% end %>
86
+ <% end %>
87
+ </div>
88
+ <div class="ibox-content">
89
+ <% block.call %>
90
+ </div>
91
+ </div>
92
+ </div>
93
+ </div>
95
94
  </div>
96
95
  <% else %>
97
- <% block.call %>
96
+ <% block.call %>
98
97
  <% end %>
@@ -5,44 +5,45 @@ xmlns:x="urn:schemas-microsoft-com:office:excel"
5
5
  xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
6
6
  xmlns:html="http://www.w3.org/TR/REC-html40">
7
7
  <Worksheet ss:Name="<%= @crud_helper.title %>">
8
- <Table>
9
- <Row>
10
- <% @crud_helper.listing_fields.each do |att|%>
11
- <% if !att[:visible_if].nil?%>
12
- <% if ((att[:visible_if].class == Proc && !att[:visible_if].call(att)) || (att[:visible_if].class != Proc && !att[:visible_if])) %>
13
- <% next %>
14
- <% end %>
15
- <% end %>
16
- <Cell><Data ss:Type="String"><%= I18n.t(att[:sf][:label]) %></Data></Cell>
17
- <% end %>
18
- </Row>
19
- <% @records.each do |record| %>
20
- <Row>
21
- <%@crud_helper.listing_fields.each do |att| %>
22
- <% if record.send(att[:attribute]).present? or record.send(att[:attribute]).to_s == "false"%>
23
- <% if @model.columns_hash[att[:attribute].to_s].present? && [:date, :datetime].include?(@model.columns_hash[att[:attribute].to_s].type)%>
24
- <% if att[:date_format].present?%>
25
- <Cell><Data ss:Type="String"><%= record.send(att[:attribute]).strftime(att[:date_format]) %></Data></Cell>
26
- <% else %>
27
- <Cell><Data ss:Type="String"><%= l record.send(att[:attribute]) %></Data></Cell>
28
- <% end %>
29
- <% elsif ((@model.reflect_on_association(att[:attribute]) && @model.reflect_on_association(att[:attribute]).macro != :belongs_to && @model.reflect_on_association(att[:attribute]).macro != :has_one) || record.send(att[:attribute]).class == Array)%>
30
- <Cell><Data ss:Type="String"><%= record.send(att[:attribute]).map{|rec| rec.to_s}.join(",") %></Data></Cell>
31
- <% else %>
32
- <% if record.send(att[:attribute]).to_s == "false" or record.send(att[:attribute]).to_s == "true" %>
33
- <Cell><Data ss:Type="String"><%= I18n.t(record.send(att[:attribute]) ? "shared.sim" : "shared.nao") %></Data></Cell>
34
- <% elsif att[:sf][:label_method].present? %>
35
- <Cell><Data ss:Type="String"><%= record.send(att[:attribute]).send(att[:sf][:label_method]).to_s %></Data></Cell>
36
- <% else %>
37
- <Cell><Data ss:Type="String"><%= record.send(att[:attribute]).to_s %></Data></Cell>
38
- <% end %>
39
- <% end %>
40
- <% else %>
41
- <Cell><Data ss:Type="String"></Data></Cell>
42
- <% end %>
43
- <% end %>
44
- </Row>
45
- <% end %>
46
- </Table>
8
+ <Table>
9
+ <Row>
10
+ <% @crud_helper.listing_fields.each do |att| %>
11
+ <% if !att[:visible_if].nil?%>
12
+ <% if ((att[:visible_if].class == Proc && !att[:visible_if].call(att)) || (att[:visible_if].class != Proc && !att[:visible_if])) %>
13
+ <% next %>
14
+ <% end %>
15
+ <% end %>
16
+ <Cell><Data ss:Type="String"><%= I18n.t(att[:sf][:label]) %></Data></Cell>
17
+ <% end %>
18
+ </Row>
19
+ <% @records.each do |record| %>
20
+ <Row>
21
+ <% @crud_helper.listing_fields.each do |att| %>
22
+ <% if record.send(att[:attribute]).present? || record.send(att[:attribute]).to_s == "false" %>
23
+ <% if @model.columns_hash[att[:attribute].to_s].present? && [:date, :datetime].include?(@model.columns_hash[att[:attribute].to_s].type) %>
24
+ <% if att[:date_format].present?%>
25
+ <Cell><Data ss:Type="String"><%= record.send(att[:attribute]).strftime(att[:date_format]) %></Data></Cell>
26
+ <% else %>
27
+ <Cell><Data ss:Type="String"><%= l record.send(att[:attribute]) %></Data></Cell>
28
+ <% end %>
29
+ <% elsif array?(record, att[:attribute]) || (association?(@model, att[:attribute]) && !belongs_to_association?(@model, att[:attribute]) && !has_one_association?(@model, att[:attribute])) %>
30
+ <%# binding.pry %>
31
+ <Cell><Data ss:Type="String"><%= record.send(att[:attribute]).map{ |rec| rec.to_s }.join(",") %></Data></Cell>
32
+ <% elsif boolean?(record, att[:attribute]) %>
33
+ <Cell><Data ss:Type="String"><%= I18n.t(record.send(att[:attribute]) ? "shared.sim" : "shared.nao") %></Data></Cell>
34
+ <% elsif possui_url?(record, att[:attribute]) %>
35
+ <Cell><Data ss:Type="String"><%= record.send(att[:attribute]).url %></Data></Cell>
36
+ <% elsif att[:sf][:label_method].present? %>
37
+ <Cell><Data ss:Type="String"><%= record.send(att[:attribute]).send(att[:sf][:label_method]).to_s %></Data></Cell>
38
+ <% else %>
39
+ <Cell><Data ss:Type="String"><%= record.send(att[:attribute]).to_s %></Data></Cell>
40
+ <% end %>
41
+ <% else %>
42
+ <Cell><Data ss:Type="String"></Data></Cell>
43
+ <% end %>
44
+ <% end %>
45
+ </Row>
46
+ <% end %>
47
+ </Table>
47
48
  </Worksheet>
48
49
  </Workbook>
@@ -4,64 +4,98 @@
4
4
  <div class="widget-body">
5
5
  <div class="widget-main">
6
6
  <div class="profile-element">
7
- <div class="header">
8
- <h1>
7
+ <div>
8
+ <div class="row">
9
+ <% if @crud_helper.logo_printing_field.present? %>
10
+ <div class="col-xs-3">
11
+ <% if @crud_helper.logo_printing_field[:field].present? %>
12
+ <%= render_field_file(@record.send(@crud_helper.logo_printing_field[:field])) %>
13
+ <% elsif @crud_helper.logo_printing_field[:url].present? %>
14
+ <%= pdf_image_tag(@crud_helper.logo_printing_field[:url], width: '100px') %>
15
+ <% end %>
16
+ </div>
17
+ <% end %>
18
+
19
+ <% if @crud_helper.titulo_printing_field.present? %>
20
+ <div class="col-xs-9">
21
+ <h1>
22
+ <% if @crud_helper.titulo_printing_field[:titulo].present? %>
23
+ <%= t(@crud_helper.titulo_printing_field[:titulo]) %>
24
+ <% elsif @crud_helper.titulo_printing_field[:field].present? %>
25
+ <%= @record.send(@crud_helper.titulo_printing_field[:field]) %>
26
+ <% else %>
27
+ <%= Templus.nome_aplicacao %>
28
+ <% end %>
29
+ </h1>
30
+ </div>
31
+ <% end %>
32
+ </div>
33
+ </div>
34
+ </div>
35
+
36
+ <div style="clear: both;"></div>
37
+
38
+ <div class="row">
39
+ <div class="col-lg-12">
40
+ <h2>
9
41
  <small><%= @crud_helper.title %></small><br />
10
42
  <%= @record.to_s %>
11
- </h1>
43
+ </h2>
12
44
  </div>
13
45
  </div>
46
+
47
+
14
48
  <table class="table table-bordered table-striped">
15
49
  <tbody>
16
- <% @crud_helper.view_fields.each do |field|%>
50
+ <% @crud_helper.printing_fields.each do |field| %>
51
+ <% next if field[:sf].present? && !field[:sf][:visible_if].nil? && ((field[:sf][:visible_if].class == Proc && !field[:sf][:visible_if].call(@record)) || (field[:sf][:visible_if].class != Proc && !field[:sf][:visible_if])) %>
17
52
  <tr>
18
- <% if field[:sf].present? && !field[:sf][:visible_if].nil?%>
19
- <% if ((field[:sf][:visible_if].class == Proc && !field[:sf][:visible_if].call(@record)) || (field[:sf][:visible_if].class != Proc && !field[:sf][:visible_if])) %>
20
- <% next %>
21
- <% end %>
22
- <% end %>
23
- <th><%= I18n.t(att[:sf][:label]) %></th>
53
+ <th><%= I18n.t(field[:sf][:label]) %></th>
24
54
 
25
- <% if @model.columns_hash[field[:attribute].to_s].present? && [:date, :datetime].include?(@model.columns_hash[field[:attribute].to_s].type)%>
55
+ <% if @model.columns_hash[field[:attribute].to_s].present? && [:date, :datetime].include?(@model.columns_hash[field[:attribute].to_s].type) %>
26
56
  <% if field[:date_format].present?%>
27
- <td><%= l @record.send(field[:attribute]).strftime(field[:date_format]) if @record.send(field[:attribute]).present?%></td>
57
+ <td><%= l @record.send(field[:attribute]).strftime(field[:date_format]) if @record.send(field[:attribute]).present? %></td>
28
58
  <% else %>
29
- <td><%= l @record.send(field[:attribute]) if @record.send(field[:attribute]).present?%></td>
59
+ <td><%= l @record.send(field[:attribute]) if @record.send(field[:attribute]).present? %></td>
30
60
  <% end %>
31
- <% elsif @model.reflect_on_association(field[:attribute]) && @model.reflect_on_association(field[:attribute]).macro != :belongs_to && @model.reflect_on_association(field[:attribute]).macro != :has_one%>
61
+ <% elsif association?(@model, field[:attribute]) && !belongs_to_association?(@model, field[:attribute]) && !has_one_association?(@model, field[:attribute]) %>
32
62
  <td>
33
63
  <% @record.send(field[:attribute]).each do |rec| %>
34
- <li>
35
- <% if field[:sf].present? && field[:sf][:label_method].present? %>
36
- <% if rec.send(field[:sf][:label_method]).respond_to?(:url) %>
37
- <%= render_field_file(rec.send(field[:sf][:label_method])) %>
38
- <% else %>
39
- <%= rec.send(field[:sf][:label_method]) %>
40
- <% end %>
41
- <% else %>
42
- <% if rec.to_s.respond_to?(:url) %>
43
- <%= render_field_file(rec.to_s) %>
64
+ <li>
65
+ <% if field[:sf].present? && field[:sf][:label_method].present? %>
66
+ <% if possui_url?(rec, field[:sf][:label_method]) && deve_renderizar_imagem?(field[:sf]) %>
67
+ <% if deve_renderizar_imagem?(field[:sf]) %>
68
+ <%= render_field_file(rec.send(field[:sf][:label_method])) %>
69
+ <% else %>
70
+ <%= rec.send(field[:sf][:label_method]).url %>
71
+ <% end %>
72
+ <% else %>
73
+ <%= rec.send(field[:sf][:label_method]) %>
74
+ <% end %>
44
75
  <% else %>
45
- <%= rec.to_s %>
76
+ <% if rec.respond_to?(:url) && deve_renderizar_imagem?(field[:sf]) %>
77
+ <%= render_field_file(rec.to_s) %>
78
+ <% else %>
79
+ <%= rec.to_s %>
80
+ <% end %>
46
81
  <% end %>
47
- <% end %>
48
- </li>
82
+ </li>
49
83
  <% end %>
50
84
  </td>
51
- <% elsif @record.send(field[:attribute]).class == Array %>
85
+ <% elsif array?(@record, field[:attribute]) %>
52
86
  <td>
53
87
  <% @record.send(field[:attribute]).each do |rec| %>
54
- <li>
55
- <%= rec.to_s %>
56
- </li>
88
+ <li><%= rec.to_s %></li>
57
89
  <% end %>
58
90
  </td>
59
- <% elsif @record.send(field[:attribute]).respond_to?(:url) %>
60
- <td>
61
- <%= render_field_file(@record.send(field[:attribute])) %>
62
- </td>
63
- <% elsif ["false","true"].include? @record.send(field[:attribute]).to_s %>
64
- <td><%= I18n.t(@record.send(field[:attribute]) ? "shared.sim" : "shared.nao") %></td>
91
+ <% elsif possui_url?(@record, field[:attribute]) %>
92
+ <% if deve_renderizar_imagem?(field[:sf]) %>
93
+ <td><%= render_field_file(@record.send(field[:attribute])) %></td>
94
+ <% else %>
95
+ <td><%= @record.send(field[:attribute]).url %></td>
96
+ <% end %>
97
+ <% elsif boolean?(@record, field[:attribute]) %>
98
+ <td><%= I18n.t(@record.send(field[:attribute]) ? "shared.sim" : "shared.nao") %></td>
65
99
  <% else %>
66
100
  <td>
67
101
  <% if field[:sf].present? && field[:sf][:label_method].present? && @record.send(field[:attribute]).present?%>
@@ -1,3 +1,3 @@
1
1
  module TemplusModels
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: templus_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Sol
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-02-17 00:00:00.000000000 Z
13
+ date: 2017-03-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -153,7 +153,9 @@ files:
153
153
  - app/assets/javascripts/raro_crud.js
154
154
  - app/assets/javascripts/templus_models.js.coffee
155
155
  - app/controllers/crud_controller.rb
156
+ - app/helpers/attributes_helper.rb
156
157
  - app/helpers/crud_helper.rb
158
+ - app/helpers/imagens_helper.rb
157
159
  - app/helpers/mensagens_helper.rb
158
160
  - app/helpers/search_helper.rb
159
161
  - app/raro_crud/raro_crud.rb
@@ -174,7 +176,6 @@ files:
174
176
  - app/views/crud/create.js.erb
175
177
  - app/views/crud/edit.html.erb
176
178
  - app/views/crud/index.html.erb
177
- - app/views/crud/listing.pdf.erb
178
179
  - app/views/crud/listing.xls.erb
179
180
  - app/views/crud/mensagens/_avisos.html.erb
180
181
  - app/views/crud/mensagens/_erros_formulario.html.erb
@@ -1,72 +0,0 @@
1
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
2
-
3
- <div class="widget-box" id="relatorio">
4
- <div class="widget-body">
5
- <div class="widget-main">
6
- <div class="profile-element">
7
- <div class="header">
8
- <h1><%= @crud_helper.title %></h1>
9
- </div>
10
- </div>
11
- <table class="table table-bordered table-striped">
12
- <thead>
13
- <tr>
14
- <% @crud_helper.listing_fields.each do |att|%>
15
- <% if !att[:visible_if].nil?%>
16
- <% if ((att[:visible_if].class == Proc && !att[:visible_if].call(att)) || (att[:visible_if].class != Proc && !att[:visible_if])) %>
17
- <% next %>
18
- <% end %>
19
- <% end %>
20
- <th><%= I18n.t(att[:sf][:label]) %></th>
21
- <% end %>
22
- </tr>
23
- </thead>
24
- <tbody>
25
- <% @records.each do |record| %>
26
- <tr>
27
- <%@crud_helper.listing_fields.each do |att| %>
28
- <% if record.send(att[:attribute]).present? or record.send(att[:attribute]).to_s == "false"%>
29
- <% if @model.columns_hash[att[:attribute].to_s].present? && [:date, :datetime].include?(@model.columns_hash[att[:attribute].to_s].type)%>
30
- <% if att[:date_format].present?%>
31
- <td><%= record.send(att[:attribute]).strftime(att[:date_format]) %></td>
32
- <% else %>
33
- <td><%= l record.send(att[:attribute]) %></td>
34
- <% end %>
35
- <% elsif ((@model.reflect_on_association(att[:attribute]) && @model.reflect_on_association(att[:attribute]).macro != :belongs_to && @model.reflect_on_association(att[:attribute]).macro != :has_one) || record.send(att[:attribute]).class == Array)%>
36
- <td><%= record.send(att[:attribute]).map{|rec| rec.to_s}.join(",") %></td>
37
- <% else %>
38
- <% if record.send(att[:attribute]).to_s == "false" or record.send(att[:attribute]).to_s == "true" %>
39
- <td><%= I18n.t(record.send(att[:attribute]) ? "shared.sim" : "shared.nao") %></td>
40
- <% elsif att[:sf][:label_method].present? %>
41
- <td><%= record.send(att[:attribute]).send(att[:sf][:label_method]).to_s %></td>
42
- <% else %>
43
- <td><%= record.send(att[:attribute]).to_s %></td>
44
- <% end %>
45
- <% end %>
46
- <% else %>
47
- <td></td>
48
- <% end %>
49
- <% end %>
50
- </tr>
51
- <% end %>
52
- </tbody>
53
- </table>
54
- </div>
55
- </div>
56
- </div>
57
- <style>
58
- #relatorio {
59
- clear: both;
60
- page-break-inside: avoid;
61
- }
62
- .header {
63
- float: left;
64
- }
65
- table {
66
- font-size: 0.75em;
67
- }
68
- thead { display: table-header-group }
69
- tfoot { display: table-row-group }
70
- tr { page-break-inside: avoid }
71
- h1 { padding-bottom: 20px; }
72
- </style>