mdwa_endereco 0.0.1 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -5
- data/Gemfile.lock +135 -0
- data/README.md +42 -17
- data/lib/generators/mdwa_endereco/install/install_generator.rb +85 -0
- data/lib/generators/mdwa_endereco/install/templates/assets/js/endereco.js +35 -0
- data/lib/generators/mdwa_endereco/install/templates/db/seeds.rb +5605 -0
- data/lib/generators/mdwa_endereco/install/templates/entidades/cidade.rb +32 -0
- data/lib/generators/mdwa_endereco/install/templates/entidades/endereco.rb +26 -0
- data/lib/generators/mdwa_endereco/install/templates/entidades/estado.rb +20 -0
- data/lib/generators/mdwa_endereco/install/templates/locales/mdwa.endereco.en.yml +105 -0
- data/lib/generators/mdwa_endereco/install/templates/locales/mdwa.endereco.pt-BR.yml +105 -0
- data/lib/generators/mdwa_endereco/install/templates/requisitos/armazenar_enderecos.rb +10 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/controllers/cidades_controller.rb +167 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/controllers/cidades_controller.rb~ +81 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/controllers/enderecos_controller.rb +36 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/controllers/estados_controller.rb +167 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/controllers/estados_controller.rb~ +81 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/helpers/cidade.rb +7 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/helpers/endereco.rb +7 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/helpers/estado.rb +7 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/models/cidade.rb +14 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/models/endereco.rb +24 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/models/estado.rb +10 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/models/geoposicionamento.rb +46 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/cidades/_form.html.erb +18 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/cidades/_form_fields.html.erb +31 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/cidades/_list.html.erb +36 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/cidades/create.js.erb +7 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/cidades/destroy.js.erb +2 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/cidades/edit.html.erb +9 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/cidades/index.html.erb +53 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/cidades/index.js.erb +1 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/cidades/new.html.erb +9 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/cidades/show.html.erb +54 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/cidades/update.js.erb +12 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/enderecos/_form.html.erb +18 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/enderecos/_form_fields.html.erb +50 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/enderecos/_form_fields_formatado.html.erb +65 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/enderecos/atualizar_dados_cep.js.erb +17 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/enderecos/gerar_combobox_cidade.js.erb +5 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/estados/_form.html.erb +18 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/estados/_form_fields.html.erb +13 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/estados/_list.html.erb +31 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/estados/create.js.erb +7 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/estados/destroy.js.erb +2 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/estados/edit.html.erb +9 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/estados/index.html.erb +45 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/estados/index.js.erb +1 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/estados/new.html.erb +9 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/estados/show.html.erb +39 -0
- data/lib/generators/mdwa_endereco/install/templates/templates/views/estados/update.js.erb +12 -0
- data/lib/mdwa_endereco.rb +1 -0
- data/lib/mdwa_endereco/version.rb +2 -1
- data/mdwa_endereco.gemspec +1 -0
- metadata +75 -18
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'mdwa/dsl'
|
3
|
+
MDWA::DSL.entities.register "Cidade" do |e|
|
4
|
+
|
5
|
+
e.resource = true
|
6
|
+
e.ajax = true
|
7
|
+
e.scaffold_name = 'a/cidade'
|
8
|
+
e.model_name = 'a/cidade'
|
9
|
+
|
10
|
+
e.attribute 'id', 'integer', {filtered: true}
|
11
|
+
e.attribute 'nome', 'string', {default: true, filtered: true}
|
12
|
+
e.attribute 'latitude', 'string'
|
13
|
+
e.attribute 'longitude', 'string'
|
14
|
+
e.attribute 'populacao', 'integer'
|
15
|
+
|
16
|
+
e.association do |a|
|
17
|
+
a.type = 'one_to_many'
|
18
|
+
a.destination = 'Endereco' # entity name
|
19
|
+
end
|
20
|
+
|
21
|
+
e.association do |a|
|
22
|
+
a.type = 'many_to_one'
|
23
|
+
a.destination = 'Estado' # entity name
|
24
|
+
a.options = {
|
25
|
+
:filtered => true,
|
26
|
+
:filter_field => 'nome'
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
MDWA::DSL.entity('Cidade').in_requirements << 'armazenar_enderecos'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'mdwa/dsl'
|
3
|
+
MDWA::DSL.entities.register "Endereco" do |e|
|
4
|
+
|
5
|
+
e.resource = true
|
6
|
+
e.ajax = true
|
7
|
+
e.scaffold_name = 'a/endereco'
|
8
|
+
e.model_name = 'a/endereco'
|
9
|
+
|
10
|
+
e.attribute 'rua', 'string'
|
11
|
+
e.attribute 'numero', 'integer'
|
12
|
+
e.attribute 'cep', 'string'
|
13
|
+
e.attribute 'bairro', 'string'
|
14
|
+
e.attribute 'complemento', 'string'
|
15
|
+
|
16
|
+
e.association do |a|
|
17
|
+
a.type = 'many_to_one'
|
18
|
+
a.destination = 'Cidade'
|
19
|
+
end
|
20
|
+
|
21
|
+
e.collection_action :atualizar_dados_cep, :post, [:ajax]
|
22
|
+
e.collection_action :gerar_combobox_cidade, :post, [:ajax]
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
MDWA::DSL.entity('Endereco').in_requirements << 'armazenar_enderecos'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'mdwa/dsl'
|
3
|
+
MDWA::DSL.entities.register "Estado" do |e|
|
4
|
+
|
5
|
+
e.resource = true
|
6
|
+
e.ajax = true
|
7
|
+
e.scaffold_name = 'a/estado'
|
8
|
+
e.model_name = 'a/estado'
|
9
|
+
|
10
|
+
e.attribute 'nome', 'string', {default: true, filtered: true}
|
11
|
+
e.attribute 'acronimo', 'string', {filtered: true}
|
12
|
+
|
13
|
+
e.association do |a|
|
14
|
+
a.type = 'one_to_many'
|
15
|
+
a.destination = 'Cidade'
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
MDWA::DSL.entity('Estado').in_requirements << 'armazenar_enderecos'
|
@@ -0,0 +1,105 @@
|
|
1
|
+
en:
|
2
|
+
|
3
|
+
cidades:
|
4
|
+
notice:
|
5
|
+
create: "Cidade created at."
|
6
|
+
update: "Cidade updated at."
|
7
|
+
destroy: "Cidade destroyed."
|
8
|
+
title:
|
9
|
+
index: "Cidades"
|
10
|
+
show: "Cidade"
|
11
|
+
new: "Nova Cidade"
|
12
|
+
edit: "Editar Cidade"
|
13
|
+
index:
|
14
|
+
add: 'Adicionar'
|
15
|
+
edit: "Editar"
|
16
|
+
edit_label: "Editar"
|
17
|
+
remove: "Remover"
|
18
|
+
remove_label: "Remover"
|
19
|
+
confirm_deletion: 'Você tem certeza?'
|
20
|
+
nome: "Nome"
|
21
|
+
latitude: "Latitude"
|
22
|
+
longitude: "Longitude"
|
23
|
+
populacao: "População"
|
24
|
+
id: "Id"
|
25
|
+
created_at: "Criado em"
|
26
|
+
updated_at: "Salvo em"
|
27
|
+
endereco: "Endereços"
|
28
|
+
estado: "Estado"
|
29
|
+
edit:
|
30
|
+
nome: "Nome"
|
31
|
+
latitude: "Latitude"
|
32
|
+
longitude: "Longitude"
|
33
|
+
populacao: "População"
|
34
|
+
id: "Id"
|
35
|
+
created_at: "Criado em"
|
36
|
+
updated_at: "Salvo em"
|
37
|
+
endereco: "Endereços"
|
38
|
+
estado: "Estado"
|
39
|
+
show:
|
40
|
+
nome: "Nome"
|
41
|
+
latitude: "Latitude"
|
42
|
+
longitude: "Longitude"
|
43
|
+
populacao: "População"
|
44
|
+
id: "Id"
|
45
|
+
created_at: "Criado em"
|
46
|
+
updated_at: "Salvo em"
|
47
|
+
endereco: "Endereços"
|
48
|
+
estado: "Estado"
|
49
|
+
|
50
|
+
estados:
|
51
|
+
notice:
|
52
|
+
create: "Estado criado."
|
53
|
+
update: "Estado salvo."
|
54
|
+
destroy: "Estado removido."
|
55
|
+
title:
|
56
|
+
index: "Estados"
|
57
|
+
show: "Estado"
|
58
|
+
new: "Novo Estado"
|
59
|
+
edit: "Editar Estado"
|
60
|
+
index:
|
61
|
+
add: 'Adicionar'
|
62
|
+
edit: "Editar"
|
63
|
+
edit_label: "Editar"
|
64
|
+
remove: "Remover"
|
65
|
+
remove_label: "Remover"
|
66
|
+
confirm_deletion: 'Você tem certeza?'
|
67
|
+
nome: "Nome"
|
68
|
+
acronimo: "Acronimo"
|
69
|
+
id: "Id"
|
70
|
+
created_at: "Criado em"
|
71
|
+
updated_at: "Salvo em"
|
72
|
+
cidade: "Cidades"
|
73
|
+
edit:
|
74
|
+
nome: "Nome"
|
75
|
+
acronimo: "Acronimo"
|
76
|
+
id: "Id"
|
77
|
+
created_at: "Criado em"
|
78
|
+
updated_at: "Salvo em"
|
79
|
+
cidade: "Cidades"
|
80
|
+
show:
|
81
|
+
nome: "Nome"
|
82
|
+
acronimo: "Acronimo"
|
83
|
+
id: "Id"
|
84
|
+
created_at: "Criado em"
|
85
|
+
updated_at: "Salvo em"
|
86
|
+
cidade: "Cidades"
|
87
|
+
|
88
|
+
enderecos:
|
89
|
+
create_success: "Endereço criado com sucesso."
|
90
|
+
update_success: "Endereço salvo com sucesso."
|
91
|
+
destroy_success: "Endereço removido com sucesso."
|
92
|
+
index_title: "Endereços"
|
93
|
+
show_title: "Endereço"
|
94
|
+
new_title: "Novo Endereço"
|
95
|
+
edit_title: "Editar Endereço"
|
96
|
+
edit:
|
97
|
+
rua: "Rua"
|
98
|
+
numero: "Número"
|
99
|
+
cep: "CEP"
|
100
|
+
bairro: "Bairro"
|
101
|
+
combo_estados: "-- Selecione um estado --"
|
102
|
+
combo_cidade_inicial: "-- Selecione primeiro um estado --"
|
103
|
+
combo_cidade: "-- Selecione uma cidade --"
|
104
|
+
complemento: "Complemento"
|
105
|
+
|
@@ -0,0 +1,105 @@
|
|
1
|
+
pt-BR:
|
2
|
+
|
3
|
+
cidades:
|
4
|
+
notice:
|
5
|
+
create: "Cidade criada."
|
6
|
+
update: "Cidade salva."
|
7
|
+
destroy: "Cidade removida."
|
8
|
+
title:
|
9
|
+
index: "Cidades"
|
10
|
+
show: "Cidade"
|
11
|
+
new: "Nova Cidade"
|
12
|
+
edit: "Editar Cidade"
|
13
|
+
index:
|
14
|
+
add: 'Adicionar'
|
15
|
+
edit: "Editar"
|
16
|
+
edit_label: "Editar"
|
17
|
+
remove: "Remover"
|
18
|
+
remove_label: "Remover"
|
19
|
+
confirm_deletion: 'Você tem certeza?'
|
20
|
+
nome: "Nome"
|
21
|
+
latitude: "Latitude"
|
22
|
+
longitude: "Longitude"
|
23
|
+
populacao: "População"
|
24
|
+
id: "Id"
|
25
|
+
created_at: "Criado em"
|
26
|
+
updated_at: "Salvo em"
|
27
|
+
endereco: "Endereços"
|
28
|
+
estado: "Estado"
|
29
|
+
edit:
|
30
|
+
nome: "Nome"
|
31
|
+
latitude: "Latitude"
|
32
|
+
longitude: "Longitude"
|
33
|
+
populacao: "População"
|
34
|
+
id: "Id"
|
35
|
+
created_at: "Criado em"
|
36
|
+
updated_at: "Salvo em"
|
37
|
+
endereco: "Endereços"
|
38
|
+
estado: "Estado"
|
39
|
+
show:
|
40
|
+
nome: "Nome"
|
41
|
+
latitude: "Latitude"
|
42
|
+
longitude: "Longitude"
|
43
|
+
populacao: "População"
|
44
|
+
id: "Id"
|
45
|
+
created_at: "Criado em"
|
46
|
+
updated_at: "Salvo em"
|
47
|
+
endereco: "Endereços"
|
48
|
+
estado: "Estado"
|
49
|
+
|
50
|
+
estados:
|
51
|
+
notice:
|
52
|
+
create: "Estado criado."
|
53
|
+
update: "Estado salvo."
|
54
|
+
destroy: "Estado removido."
|
55
|
+
title:
|
56
|
+
index: "Estados"
|
57
|
+
show: "Estado"
|
58
|
+
new: "Novo Estado"
|
59
|
+
edit: "Editar Estado"
|
60
|
+
index:
|
61
|
+
add: 'Adicionar'
|
62
|
+
edit: "Editar"
|
63
|
+
edit_label: "Editar"
|
64
|
+
remove: "Remover"
|
65
|
+
remove_label: "Remover"
|
66
|
+
confirm_deletion: 'Você tem certeza?'
|
67
|
+
nome: "Nome"
|
68
|
+
acronimo: "Acronimo"
|
69
|
+
id: "Id"
|
70
|
+
created_at: "Criado em"
|
71
|
+
updated_at: "Salvo em"
|
72
|
+
cidade: "Cidades"
|
73
|
+
edit:
|
74
|
+
nome: "Nome"
|
75
|
+
acronimo: "Acronimo"
|
76
|
+
id: "Id"
|
77
|
+
created_at: "Criado em"
|
78
|
+
updated_at: "Salvo em"
|
79
|
+
cidade: "Cidades"
|
80
|
+
show:
|
81
|
+
nome: "Nome"
|
82
|
+
acronimo: "Acronimo"
|
83
|
+
id: "Id"
|
84
|
+
created_at: "Criado em"
|
85
|
+
updated_at: "Salvo em"
|
86
|
+
cidade: "Cidades"
|
87
|
+
|
88
|
+
enderecos:
|
89
|
+
create_success: "Endereço criado com sucesso."
|
90
|
+
update_success: "Endereço salvo com sucesso."
|
91
|
+
destroy_success: "Endereço removido com sucesso."
|
92
|
+
index_title: "Endereços"
|
93
|
+
show_title: "Endereço"
|
94
|
+
new_title: "Novo Endereço"
|
95
|
+
edit_title: "Editar Endereço"
|
96
|
+
edit:
|
97
|
+
rua: "Rua"
|
98
|
+
numero: "Número"
|
99
|
+
cep: "CEP"
|
100
|
+
bairro: "Bairro"
|
101
|
+
combo_estados: "-- Selecione um estado --"
|
102
|
+
combo_cidade_inicial: "-- Selecione primeiro um estado --"
|
103
|
+
combo_cidade: "-- Selecione uma cidade --"
|
104
|
+
complemento: "Complemento"
|
105
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'mdwa/dsl'
|
3
|
+
MDWA::DSL.requirements.register do |r|
|
4
|
+
|
5
|
+
r.summary = 'Armazenar endereços de entidades.'
|
6
|
+
r.alias = 'armazenar_enderecos'
|
7
|
+
r.description = %q{Encapsula as funcionalidades de endereços.}
|
8
|
+
|
9
|
+
r.entities = ['Endereco', 'Cidade', 'Estado']
|
10
|
+
end
|
data/lib/generators/mdwa_endereco/install/templates/templates/controllers/cidades_controller.rb
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
<%-
|
3
|
+
@entity = MDWA::DSL.entity('Cidade')
|
4
|
+
@model = @entity.generator_model
|
5
|
+
-%>
|
6
|
+
class <%= @model.controller_name %>Controller < <%= (@model.space == 'a') ? 'A::BackendController' : 'ApplicationController' %>
|
7
|
+
|
8
|
+
<%- if @entity.resource? -%>
|
9
|
+
load_and_authorize_resource :class => "<%= @model.klass %>"
|
10
|
+
<%- end -%>
|
11
|
+
|
12
|
+
# Hook for code generations. Do not delete.
|
13
|
+
#===controller_init===
|
14
|
+
|
15
|
+
def index
|
16
|
+
conditions = []
|
17
|
+
<%-
|
18
|
+
atributos_com_filtro = @entity.attributes.values.select {|attr| attr.options[:filtered]}
|
19
|
+
associacoes_com_filtro = @entity.associations.values.select {|assoc| assoc.options[:filtered]}
|
20
|
+
-%>
|
21
|
+
<%- if !atributos_com_filtro.count.zero? -%>
|
22
|
+
<%- atributos_com_filtro.each do |atributo| -%>
|
23
|
+
<%- if [:integer, :float, :decimal, :boolean].include? atributo.type.to_sym -%>
|
24
|
+
conditions << "(<%= @model.plural_name %>.<%= atributo.name %> = '#{params[:<%= atributo.name %>]}')" unless params[:<%= atributo.name %>].blank?
|
25
|
+
<%- elsif [:string, :text].include? atributo.type.to_sym -%>
|
26
|
+
conditions << "(<%= @model.plural_name %>.<%= atributo.name %> LIKE '%#{params[:<%= atributo.name %>]}%')" unless params[:<%= atributo.name %>].blank?
|
27
|
+
<%- elsif [:date].include? atributo.type.to_sym -%>
|
28
|
+
conditions << "(<%= @model.plural_name %>.<%= atributo.name %> BETWEEN '#{params[:<%= atributo.name %>_0].to_date}' AND '#{params[:<%= atributo.name %>_1].to_date}')" if !params[:<%= atributo.name %>_0].blank? and !params[:<%= atributo.name %>_1].blank?
|
29
|
+
conditions << "(<%= @model.plural_name %>.<%= atributo.name %> >= '#{params[:<%= atributo.name %>_0].to_date}')" if !params[:<%= atributo.name %>_0].blank? and params[:<%= atributo.name %>_0].blank?
|
30
|
+
conditions << "(<%= @model.plural_name %>.<%= atributo.name %> <= '#{params[:<%= atributo.name %>_1].to_date}')" if params[:<%= atributo.name %>_0].blank? and !params[:<%= atributo.name %>_1].blank?
|
31
|
+
<%- elsif [:datetime, :timestamp].include? atributo.type.to_sym -%>
|
32
|
+
conditions << "(<%= @model.plural_name %>.<%= atributo.name %> BETWEEN '#{params[:<%= atributo.name %>_0].to_date.beginning_of_day}' AND '#{params[:<%= atributo.name %>_1].to_date.end_of_day}')" if !params[:<%= atributo.name %>_0].blank? and !params[:<%= atributo.name %>_1].blank?
|
33
|
+
conditions << "(<%= @model.plural_name %>.<%= atributo.name %> >= '#{params[:<%= atributo.name %>_0].to_date.beginning_of_day}')" if !params[:<%= atributo.name %>_0].blank? and params[:<%= atributo.name %>_0].blank?
|
34
|
+
conditions << "(<%= @model.plural_name %>.<%= atributo.name %> <= '#{params[:<%= atributo.name %>_1].to_date.end_of_day}')" if params[:<%= atributo.name %>_0].blank? and !params[:<%= atributo.name %>_1].blank?
|
35
|
+
<%- end -%>
|
36
|
+
<%- end -%>
|
37
|
+
<%- end -%>
|
38
|
+
|
39
|
+
<%- associacoes_com_filtro.each do |associacao| -%>
|
40
|
+
conditions << "(<%= @model.plural_name %>.<%= associacao.name %>_id = #{params[:<%= associacao.name %>_id]})" unless params[:<%= associacao.name %>_id].blank?
|
41
|
+
<%- end -%>
|
42
|
+
|
43
|
+
@<%= @model.plural_name %> = <%= @model.klass %>.paginate :page => params[:page], :conditions => conditions.join(' AND ')
|
44
|
+
|
45
|
+
respond_to do |format|
|
46
|
+
format.html
|
47
|
+
format.js
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def show
|
53
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.find(params[:id])
|
54
|
+
|
55
|
+
<%- if @entity.ajax? -%>
|
56
|
+
render :layout => false
|
57
|
+
<%- else -%>
|
58
|
+
respond_to do |format|
|
59
|
+
format.html
|
60
|
+
end
|
61
|
+
<%- end -%>
|
62
|
+
end
|
63
|
+
|
64
|
+
def new
|
65
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.new
|
66
|
+
<%- @model.associations.select {|a| a.nested_one?}.each do |assoc| -%>
|
67
|
+
@<%= @model.singular_name %>.<%= assoc.model2.singular_name %> = <%= assoc.model2.klass %>.new
|
68
|
+
<%- end -%>
|
69
|
+
|
70
|
+
<%- if @entity.ajax? -%>
|
71
|
+
render :layout => false
|
72
|
+
<%- else -%>
|
73
|
+
respond_to do |format|
|
74
|
+
format.html
|
75
|
+
end
|
76
|
+
<%- end -%>
|
77
|
+
end
|
78
|
+
|
79
|
+
def edit
|
80
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.find(params[:id])
|
81
|
+
|
82
|
+
<%- if @entity.ajax? -%>
|
83
|
+
render :layout => false
|
84
|
+
<%- else -%>
|
85
|
+
respond_to do |format|
|
86
|
+
format.html
|
87
|
+
end
|
88
|
+
<%- end -%>
|
89
|
+
end
|
90
|
+
|
91
|
+
def create
|
92
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.new(params[:<%= @model.to_params %>])
|
93
|
+
saved_ok = @<%= @model.singular_name %>.save
|
94
|
+
@system_notice = t('<%= @model.plural_name %>.notice.create') if saved_ok
|
95
|
+
|
96
|
+
<%- @model.associations.select{|a| a.has_and_belongs_to_many? and a.composition?}.each do |association| -%>
|
97
|
+
unless params[:<%= association.model2.plural_name %>].nil?
|
98
|
+
@<%= @model.singular_name %>.<%= association.model2.plural_name %>.clear
|
99
|
+
params[:<%= association.model2.plural_name %>].each do |<%= association.model2.singular_name.foreign_key %>|
|
100
|
+
@<%= @model.singular_name %>.<%= association.model2.plural_name %>.push <%= association.model2.klass %>.find <%= association.model2.singular_name.foreign_key %>
|
101
|
+
end
|
102
|
+
end
|
103
|
+
<%- end -%>
|
104
|
+
|
105
|
+
respond_to do |format|
|
106
|
+
<%- if @entity.ajax? -%>
|
107
|
+
format.js
|
108
|
+
<%- else -%>
|
109
|
+
if saved_ok
|
110
|
+
format.html { redirect_to <%= @model.object_name.pluralize %>_path, notice: @system_notice }
|
111
|
+
else
|
112
|
+
format.html { render action: "new" }
|
113
|
+
end
|
114
|
+
<%- end -%>
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def update
|
119
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.find(params[:id])
|
120
|
+
<%- if @entity.user? -%>
|
121
|
+
# if password is blank, delete from params
|
122
|
+
if params[:<%= @model.object_name %>][:password].blank?
|
123
|
+
params[:<%= @model.object_name %>].delete :password
|
124
|
+
params[:<%= @model.object_name %>].delete :password_confirmation
|
125
|
+
end
|
126
|
+
<%- end -%>
|
127
|
+
@<%= @model.singular_name %>.attributes = params[:<%= @model.to_params %>]
|
128
|
+
saved_ok = @<%= @model.singular_name %>.save
|
129
|
+
@system_notice = t('<%= @model.plural_name %>.notice.update') if saved_ok
|
130
|
+
|
131
|
+
<%- @model.associations.select{|a| a.has_and_belongs_to_many? and a.composition?}.each do |association| -%>
|
132
|
+
unless params[:<%= association.model2.plural_name %>].nil?
|
133
|
+
@<%= @model.singular_name %>.<%= association.model2.plural_name %>.clear
|
134
|
+
params[:<%= association.model2.plural_name %>].each do |<%= association.model2.singular_name.foreign_key %>|
|
135
|
+
@<%= @model.singular_name %>.<%= association.model2.plural_name %>.push <%= association.model2.klass %>.find <%= association.model2.singular_name.foreign_key %>
|
136
|
+
end
|
137
|
+
end
|
138
|
+
<%- end -%>
|
139
|
+
|
140
|
+
respond_to do |format|
|
141
|
+
<%- if @entity.ajax? -%>
|
142
|
+
format.js
|
143
|
+
<%- else -%>
|
144
|
+
if saved_ok
|
145
|
+
format.html { redirect_to <%= @model.object_name.pluralize %>_path, notice: @system_notice }
|
146
|
+
else
|
147
|
+
format.html { render action: "edit" }
|
148
|
+
end
|
149
|
+
<%- end -%>
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def destroy
|
154
|
+
@<%= @model.singular_name %> = <%= @model.klass %>.find(params[:id])
|
155
|
+
@system_notice = t('<%= @model.plural_name %>.notice.destroy') if @<%= @model.singular_name %>.destroy
|
156
|
+
|
157
|
+
respond_to do |format|
|
158
|
+
<%- if @entity.ajax? -%>
|
159
|
+
format.js
|
160
|
+
<%- else -%>
|
161
|
+
format.html { redirect_to <%= @model.object_name.pluralize %>_path, notice: @system_notice }
|
162
|
+
<%- end -%>
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
|
167
|
+
end
|