templus_models 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/crud_helper.rb +15 -13
- data/app/helpers/search_helper.rb +8 -8
- data/app/raro_crud/raro_crud.rb +15 -0
- data/app/views/crud/_form_group.html.erb +3 -3
- data/app/views/crud/_record.html.erb +1 -1
- data/app/views/crud/_records.html.erb +2 -2
- data/app/views/crud/_show.html.erb +2 -6
- data/app/views/crud/listing.pdf.erb +2 -6
- data/app/views/crud/listing.xls.erb +2 -6
- data/app/views/crud/printing.pdf.erb +2 -6
- data/config/routes.rb +1 -1
- data/lib/templus_models/configuration.rb +2 -1
- data/lib/templus_models/version.rb +1 -1
- data/lib/templus_models.rb +0 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4375243bea6ad4021fbd11dcdc796f445c623d1
|
4
|
+
data.tar.gz: 4dbc1ce1f203547d791b2a79933db11c91ece85f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f1c40caabbc3676af69a4020a2bd79a7a135940ef1f37f833b03cd4409f8e17a6c9593071c2b456ea7f021bb3374089bec876f26c5c86d80aa0004b4e160961
|
7
|
+
data.tar.gz: 9418bee70eca2242c497d81d57c3b763efe70de8d010dbfe129b9cd8411e9117d396aa9b043ef335124161753953c3055cad7067cd9efb591a7b26d1c107880f
|
data/app/helpers/crud_helper.rb
CHANGED
@@ -110,12 +110,12 @@ module CrudHelper
|
|
110
110
|
permissions.uniq.flatten
|
111
111
|
end
|
112
112
|
|
113
|
-
def render_plus_button(field,f,modelo,record)
|
114
|
-
field[:sf][:wrapper] = :with_button
|
115
|
-
render_field(field,f,modelo,record)
|
113
|
+
def render_plus_button(field, f, modelo, record, options = {})
|
114
|
+
field[:sf][:wrapper] = options[:wrapper] || :with_button
|
115
|
+
render_field(field, f, modelo, record)
|
116
116
|
end
|
117
117
|
|
118
|
-
def render_field(field,f,modelo,record)
|
118
|
+
def render_field(field, f, modelo, record)
|
119
119
|
field[:sf][:wrapper] ||= :default
|
120
120
|
if field[:sf].present? && field[:sf][:if].present?
|
121
121
|
return unless field[:sf][:if].call(f.object)
|
@@ -129,32 +129,34 @@ module CrudHelper
|
|
129
129
|
if !field[:sf][:edit].nil? && !field[:sf][:edit] && !record.new_record?
|
130
130
|
elsif !field[:sf][:create].nil? && !field[:sf][:create] && record.new_record?
|
131
131
|
else
|
132
|
+
opts = field[:sf].merge(label: I18n.t(field[:sf][:label]))
|
132
133
|
unless modelo.reflect_on_association(field[:attribute])
|
133
134
|
if modelo.new.send(field[:attribute]).class.to_s =~ /Uploader/ and f.object.send(field[:attribute]).present?
|
134
|
-
f.input field[:attribute],
|
135
|
+
f.input field[:attribute], opts.merge(hint: "Arquivo Atual: #{f.object.send(field[:attribute]).file.filename}")
|
135
136
|
else
|
136
|
-
f.input field[:attribute],
|
137
|
+
f.input field[:attribute], opts
|
137
138
|
end
|
138
139
|
else
|
139
|
-
f.association field[:attribute],
|
140
|
+
f.association field[:attribute], opts
|
140
141
|
end
|
141
142
|
end
|
142
143
|
else
|
143
144
|
if field[:sf][:value] and field[:sf][:value].class == Proc
|
144
145
|
field[:sf][:input_html] ||= {}
|
145
|
-
field[:sf][:input_html][:value] = f.instance_eval
|
146
|
+
field[:sf][:input_html][:value] = f.instance_eval(&field[:sf][:value])
|
146
147
|
end
|
147
148
|
if field[:sf][:collection_if] and field[:sf][:collection_if].class == Proc
|
148
|
-
field[:sf][:collection] = f.instance_eval
|
149
|
+
field[:sf][:collection] = f.instance_eval(&field[:sf][:collection_if])
|
149
150
|
end
|
151
|
+
opts = field[:sf].merge(label: I18n.t(field[:sf][:label]))
|
150
152
|
unless modelo.reflect_on_association(field[:attribute])
|
151
153
|
if modelo.new.send(field[:attribute]).class.to_s =~ /Uploader/ and f.object.send(field[:attribute]).present?
|
152
|
-
f.input field[:attribute],
|
154
|
+
f.input field[:attribute], opts.merge(hint: "Arquivo Atual: #{f.object.send(field[:attribute]).file.filename}")
|
153
155
|
else
|
154
|
-
f.input field[:attribute],
|
156
|
+
f.input field[:attribute], opts
|
155
157
|
end
|
156
158
|
else
|
157
|
-
f.association field[:attribute],
|
159
|
+
f.association field[:attribute], opts
|
158
160
|
end
|
159
161
|
end
|
160
162
|
end
|
@@ -211,7 +213,7 @@ module CrudHelper
|
|
211
213
|
return true if crud_helper.condition_destroy_action.nil?
|
212
214
|
crud_helper.condition_destroy_action.call(record)
|
213
215
|
end
|
214
|
-
|
216
|
+
|
215
217
|
def should_listing?(crud_helper,model)
|
216
218
|
return false unless can?(:read, model)
|
217
219
|
return true if crud_helper.condition_listing_action.nil?
|
@@ -16,7 +16,7 @@ module SearchHelper
|
|
16
16
|
"<div><input type='submit' class='btn btn-primary pull-right' value='#{name}' id='submit_raro_search'></div><br><br>"
|
17
17
|
end
|
18
18
|
|
19
|
-
def raro_field
|
19
|
+
def raro_field(name, opts = {})
|
20
20
|
modelo = opts[:model] || @model
|
21
21
|
unless opts[:model]
|
22
22
|
prototype = @model.columns_hash[name.to_s]
|
@@ -26,7 +26,7 @@ module SearchHelper
|
|
26
26
|
modelo = Module.const_get(opts[:model])
|
27
27
|
name = opts[:full_name]
|
28
28
|
end
|
29
|
-
label =
|
29
|
+
label = "simple_form.labels.#{modelo.name.underscore}.#{name}"
|
30
30
|
label = opts[:label] if opts[:label]
|
31
31
|
|
32
32
|
@buffer << "<div class=\"form-group\">"
|
@@ -81,7 +81,7 @@ module SearchHelper
|
|
81
81
|
case opts[:as]
|
82
82
|
when :select
|
83
83
|
if opts[:collection_if] and opts[:collection_if].class == Proc
|
84
|
-
opts[:collection] = ActionView::Helpers::FormBuilder.instance_eval
|
84
|
+
opts[:collection] = ActionView::Helpers::FormBuilder.instance_eval(&opts[:collection_if])
|
85
85
|
end
|
86
86
|
raro_select(name,opts,opts[:collection])
|
87
87
|
when :hidden
|
@@ -115,7 +115,7 @@ module SearchHelper
|
|
115
115
|
else
|
116
116
|
buf << "<select name=#{name} class='form-control'>"
|
117
117
|
end
|
118
|
-
buf <<"<option value ='' selected>#{I18n.t('search')}</option>"
|
118
|
+
buf << "<option value ='' selected>#{I18n.t('search')}</option>"
|
119
119
|
collection.each do |e|
|
120
120
|
buf << "<option value=#{e[0]}>#{e[1]}</option>"
|
121
121
|
end
|
@@ -128,7 +128,7 @@ module SearchHelper
|
|
128
128
|
if opts[:as] and opts[:as] == :hidden
|
129
129
|
""
|
130
130
|
else
|
131
|
-
"<label class='col-sm-2 control-label'>#{name}</label>"
|
131
|
+
"<label class='col-sm-2 control-label'>#{I18n.t(name)}</label>"
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
@@ -227,9 +227,9 @@ module SearchHelper
|
|
227
227
|
"<input type='hidden' name='partial' value='#{partial}'>" +
|
228
228
|
"<input type='hidden' name='var' value='#{var}'>"
|
229
229
|
if sort
|
230
|
-
|
231
|
-
|
232
|
-
|
230
|
+
buffer << "<input type='hidden' name='q[s]' value='#{sort}'>"
|
231
|
+
end
|
232
|
+
buffer
|
233
233
|
end
|
234
234
|
|
235
235
|
def raro_after_form
|
data/app/raro_crud/raro_crud.rb
CHANGED
@@ -244,6 +244,7 @@ class RaroCrud
|
|
244
244
|
|
245
245
|
def self.campo_tabela nome, opts={}
|
246
246
|
@@index_fields[self.to_s.to_sym] = [] unless @@index_fields[self.to_s.to_sym]
|
247
|
+
opts = set_default_label nome, opts
|
247
248
|
@@index_fields[self.to_s.to_sym].push(
|
248
249
|
{
|
249
250
|
attribute: nome
|
@@ -270,6 +271,7 @@ class RaroCrud
|
|
270
271
|
|
271
272
|
def self.campo_formulario nome, opts={}
|
272
273
|
@@form_fields[self.to_s.to_sym] = [] unless @@form_fields[self.to_s.to_sym]
|
274
|
+
opts = set_default_label nome, opts
|
273
275
|
if opts.present? && opts[:autocomplete].present?
|
274
276
|
opts[:as] = :autocomplete
|
275
277
|
label_method = opts[:autocomplete][:label_method] || opts[:autocomplete][:campo]
|
@@ -309,10 +311,18 @@ class RaroCrud
|
|
309
311
|
end
|
310
312
|
field[:grupo] = true
|
311
313
|
end
|
314
|
+
|
315
|
+
def self.set_default_label nome, opts
|
316
|
+
unless opts[:label].present?
|
317
|
+
opts[:label] = "simple_form.labels.#{self.modelo.underscore}.#{nome}"
|
318
|
+
end
|
319
|
+
opts
|
320
|
+
end
|
312
321
|
|
313
322
|
public
|
314
323
|
def self.campo_visualizacao nome, opts = {}
|
315
324
|
@@view_fields[self.to_s.to_sym] = [] unless @@view_fields[self.to_s.to_sym]
|
325
|
+
opts = set_default_label nome, opts
|
316
326
|
@@view_fields[self.to_s.to_sym].push(
|
317
327
|
{
|
318
328
|
attribute: nome
|
@@ -322,6 +332,7 @@ class RaroCrud
|
|
322
332
|
|
323
333
|
def self.campo_busca nome, opts = {}
|
324
334
|
@@search_fields[self.to_s.to_sym] = [] unless @@search_fields[self.to_s.to_sym]
|
335
|
+
opts = set_default_label nome, opts
|
325
336
|
@@search_fields[self.to_s.to_sym].push(
|
326
337
|
{
|
327
338
|
attribute: nome
|
@@ -331,6 +342,7 @@ class RaroCrud
|
|
331
342
|
|
332
343
|
def self.campo_listagem nome, opts = {}
|
333
344
|
@@listing_fields[self.to_s.to_sym] = [] unless @@listing_fields[self.to_s.to_sym]
|
345
|
+
opts = set_default_label nome, opts
|
334
346
|
@@listing_fields[self.to_s.to_sym].push(
|
335
347
|
{
|
336
348
|
attribute: nome
|
@@ -340,6 +352,7 @@ class RaroCrud
|
|
340
352
|
|
341
353
|
def self.campo_impressao nome, opts = {}
|
342
354
|
@@printing_fields[self.to_s.to_sym] = [] unless @@printing_fields[self.to_s.to_sym]
|
355
|
+
opts = set_default_label nome, opts
|
343
356
|
@@printing_fields[self.to_s.to_sym].push(
|
344
357
|
{
|
345
358
|
attribute: nome
|
@@ -442,9 +455,11 @@ class RaroCrud
|
|
442
455
|
].each do |field|
|
443
456
|
attribute = field[:campo]
|
444
457
|
field.delete(:campo)
|
458
|
+
field[:label] ||= "shared.#{attribute}"
|
445
459
|
opts[:fields].push({attribute: attribute,sf: field})
|
446
460
|
end
|
447
461
|
opts[:grupo] = true
|
462
|
+
opts[:label] ||= "shared.adicionar_endereco"
|
448
463
|
@@form_fields[self.to_s.to_sym].push(
|
449
464
|
{
|
450
465
|
attribute: :endereco
|
@@ -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[:
|
11
|
+
<h3><%= I18n.t(groups[:label]) %></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]
|
27
|
+
<%= g.link_to_remove "Remover #{I18n.t(groups[:sublabel] || groups[:label])}" %>
|
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]
|
35
|
+
<%= f.link_to_add "Adicionar #{I18n.t(groups[:sublabel] || groups[:label])}", key %>
|
36
36
|
</div>
|
37
37
|
</div>
|
38
38
|
<% end %>
|
@@ -38,7 +38,7 @@
|
|
38
38
|
<% if record.send(att[:attribute]).to_s == "false" or record.send(att[:attribute]).to_s == "true" %>
|
39
39
|
<td class="row">
|
40
40
|
<div class="col-xs-9">
|
41
|
-
<%= record.send(att[:attribute]) ? "
|
41
|
+
<%= I18n.t(record.send(att[:attribute]) ? "shared.sim" : "shared.nao") %>
|
42
42
|
</div>
|
43
43
|
</td>
|
44
44
|
<% else %>
|
@@ -14,9 +14,9 @@
|
|
14
14
|
<% end %>
|
15
15
|
<th>
|
16
16
|
<% if att[:sort_field].present? %>
|
17
|
-
<%= sort_link @q, att[:sort_field], I18n.t(
|
17
|
+
<%= sort_link @q, att[:sort_field], I18n.t(att[:label]), {},data: {push: 'partial', target: "#form"}%>
|
18
18
|
<% else %>
|
19
|
-
<%= sort_link @q, att[:attribute], I18n.t(
|
19
|
+
<%= sort_link @q, att[:attribute], I18n.t(att[:label]), {},data: {push: 'partial', target: "#form"}%>
|
20
20
|
<% end %>
|
21
21
|
</th>
|
22
22
|
<%end%>
|
@@ -11,11 +11,7 @@
|
|
11
11
|
<% next %>
|
12
12
|
<% end %>
|
13
13
|
<% end %>
|
14
|
-
|
15
|
-
<th><%= field[:sf][:label].to_s.mb_chars.upcase.to_s %></th>
|
16
|
-
<% else %>
|
17
|
-
<th><%= I18n.t("simple_form.labels.#{@model.name.underscore}.#{field[:attribute]}") %></th>
|
18
|
-
<% end %>
|
14
|
+
<th><%= I18n.t(field[:sf][:label]) %></th>
|
19
15
|
|
20
16
|
<% if @model.columns_hash[field[:attribute].to_s].present? && [:date, :datetime].include?(@model.columns_hash[field[:attribute].to_s].type)%>
|
21
17
|
<% if field[:date_format].present?%>
|
@@ -56,7 +52,7 @@
|
|
56
52
|
<%= render_field_file(@record.send(field[:attribute])) %>
|
57
53
|
</td>
|
58
54
|
<% elsif ["false","true"].include? @record.send(field[:attribute]).to_s %>
|
59
|
-
<td><%=
|
55
|
+
<td><%= I18n.t(@record.send(field[:attribute]) ? "shared.sim" : "shared.nao") %></td>
|
60
56
|
<% else %>
|
61
57
|
<td>
|
62
58
|
<% if field[:sf].present? && field[:sf][:label_method].present? && @record.send(field[:attribute]).present?%>
|
@@ -17,11 +17,7 @@
|
|
17
17
|
<% next %>
|
18
18
|
<% end %>
|
19
19
|
<% end %>
|
20
|
-
|
21
|
-
<th><%= att[:sf][:label].to_s.mb_chars.upcase.to_s %></th>
|
22
|
-
<% else %>
|
23
|
-
<th><%= I18n.t("simple_form.labels.#{@model.name.underscore}.#{att[:attribute]}") %></th>
|
24
|
-
<% end %>
|
20
|
+
<th><%= I18n.t(att[:sf][:label]) %></th>
|
25
21
|
<% end %>
|
26
22
|
</tr>
|
27
23
|
</thead>
|
@@ -40,7 +36,7 @@
|
|
40
36
|
<td><%= record.send(att[:attribute]).map{|rec| rec.to_s}.join(",") %></td>
|
41
37
|
<% else %>
|
42
38
|
<% if record.send(att[:attribute]).to_s == "false" or record.send(att[:attribute]).to_s == "true" %>
|
43
|
-
<td><%= record.send(att[:attribute]) ? "
|
39
|
+
<td><%= I18n.t(record.send(att[:attribute]) ? "shared.sim" : "shared.nao") %></td>
|
44
40
|
<% elsif att[:sf][:label_method].present? %>
|
45
41
|
<td><%= record.send(att[:attribute]).send(att[:sf][:label_method]).to_s %></td>
|
46
42
|
<% else %>
|
@@ -13,11 +13,7 @@ xmlns:html="http://www.w3.org/TR/REC-html40">
|
|
13
13
|
<% next %>
|
14
14
|
<% end %>
|
15
15
|
<% end %>
|
16
|
-
|
17
|
-
<Cell><Data ss:Type="String"><%= att[:sf][:label].to_s.mb_chars.upcase.to_s %></Data></Cell>
|
18
|
-
<% else %>
|
19
|
-
<Cell><Data ss:Type="String"><%= I18n.t("simple_form.labels.#{@model.name.underscore}.#{att[:attribute]}") %></Data></Cell>
|
20
|
-
<% end %>
|
16
|
+
<Cell><Data ss:Type="String"><%= I18n.t(att[:sf][:label]) %></Data></Cell>
|
21
17
|
<% end %>
|
22
18
|
</Row>
|
23
19
|
<% @records.each do |record| %>
|
@@ -34,7 +30,7 @@ xmlns:html="http://www.w3.org/TR/REC-html40">
|
|
34
30
|
<Cell><Data ss:Type="String"><%= record.send(att[:attribute]).map{|rec| rec.to_s}.join(",") %></Data></Cell>
|
35
31
|
<% else %>
|
36
32
|
<% if record.send(att[:attribute]).to_s == "false" or record.send(att[:attribute]).to_s == "true" %>
|
37
|
-
<Cell><Data ss:Type="String"><%= record.send(att[:attribute]) ? "
|
33
|
+
<Cell><Data ss:Type="String"><%= I18n.t(record.send(att[:attribute]) ? "shared.sim" : "shared.nao") %></Data></Cell>
|
38
34
|
<% elsif att[:sf][:label_method].present? %>
|
39
35
|
<Cell><Data ss:Type="String"><%= record.send(att[:attribute]).send(att[:sf][:label_method]).to_s %></Data></Cell>
|
40
36
|
<% else %>
|
@@ -20,11 +20,7 @@
|
|
20
20
|
<% next %>
|
21
21
|
<% end %>
|
22
22
|
<% end %>
|
23
|
-
|
24
|
-
<th><%= field[:sf][:label].to_s.mb_chars.upcase.to_s %></th>
|
25
|
-
<% else %>
|
26
|
-
<th><%= I18n.t("simple_form.labels.#{@model.name.underscore}.#{field[:attribute]}") %></th>
|
27
|
-
<% end %>
|
23
|
+
<th><%= I18n.t(att[:sf][:label]) %></th>
|
28
24
|
|
29
25
|
<% if @model.columns_hash[field[:attribute].to_s].present? && [:date, :datetime].include?(@model.columns_hash[field[:attribute].to_s].type)%>
|
30
26
|
<% if field[:date_format].present?%>
|
@@ -65,7 +61,7 @@
|
|
65
61
|
<%= render_field_file(@record.send(field[:attribute])) %>
|
66
62
|
</td>
|
67
63
|
<% elsif ["false","true"].include? @record.send(field[:attribute]).to_s %>
|
68
|
-
<td><%= @record.send(field[:attribute]) ? "
|
64
|
+
<td><%= I18n.t(@record.send(field[:attribute]) ? "shared.sim" : "shared.nao") %></td>
|
69
65
|
<% else %>
|
70
66
|
<td>
|
71
67
|
<% if field[:sf].present? && field[:sf][:label_method].present? && @record.send(field[:attribute]).present?%>
|
data/config/routes.rb
CHANGED
data/lib/templus_models.rb
CHANGED
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.
|
4
|
+
version: 2.0.1
|
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-
|
13
|
+
date: 2017-02-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|