constructor-pages 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -31,6 +31,23 @@ module ConstructorPages
31
31
  def update
32
32
  @field = Field.find params[:id]
33
33
 
34
+ if @field.type_value != params[:field][:type_value]
35
+ "constructor_pages/types/#{@field.type_value}_type".classify.constantize.where(:field_id => @field.id).each do |field|
36
+ new_field = "constructor_pages/types/#{params[:field][:type_value]}_type".classify.constantize.new(
37
+ :field_id => @field.id,
38
+ :page_id => field.page_id)
39
+
40
+ if @field.type_value != 'image' \
41
+ and params[:field][:type_value] != 'image' \
42
+ and not (@field.type_value == 'string' and field.value.strip == '')
43
+ new_field.value = field.value
44
+ end
45
+
46
+ new_field.save
47
+
48
+ field.destroy
49
+ end
50
+ end
34
51
  if @field.update_attributes params[:field]
35
52
  redirect_to edit_template_url(@field.template.id), :notice => "Поле «#{@field.name}» успешно обновлено."
36
53
  else
@@ -134,28 +134,37 @@ module ConstructorPages
134
134
  def update
135
135
  @page = Page.find params[:id]
136
136
 
137
- @page.template.fields.each do |field|
138
- f = "constructor_pages/types/#{field.type_value}_type".classify.constantize.where(
139
- :field_id => field.id,
140
- :page_id => @page.id).first_or_create
141
-
142
- if params[:fields]
143
- f.value = 0 if field.type_value == 'boolean'
144
-
145
- if params[:fields][field.type_value]
146
- if field.type_value == "date"
147
- value = params[:fields][field.type_value][field.id.to_s]
148
- f.value = Date.new(value["date(1i)"].to_i, value["date(2i)"].to_i, value["date(3i)"].to_i).to_s
149
- else
150
- f.value = params[:fields][field.type_value][field.id.to_s]
151
- end
152
- end
153
-
154
- f.save
137
+ if @page.template.id != params[:page][:template_id].to_i
138
+ @page.template.fields.each do |field|
139
+ "constructor_pages/types/#{field.type_value}_type".classify.constantize.destroy_all(
140
+ :field_id => field.id,
141
+ :page_id => @page.id)
155
142
  end
156
143
  end
157
144
 
158
145
  if @page.update_attributes params[:page]
146
+
147
+ @page.template.fields.each do |field|
148
+ f = "constructor_pages/types/#{field.type_value}_type".classify.constantize.where(
149
+ :field_id => field.id,
150
+ :page_id => @page.id).first_or_create
151
+
152
+ if params[:fields]
153
+ f.value = 0 if field.type_value == 'boolean'
154
+
155
+ if params[:fields][field.type_value]
156
+ if field.type_value == "date"
157
+ value = params[:fields][field.type_value][field.id.to_s]
158
+ f.value = Date.new(value["date(1i)"].to_i, value["date(2i)"].to_i, value["date(3i)"].to_i).to_s
159
+ else
160
+ f.value = params[:fields][field.type_value][field.id.to_s]
161
+ end
162
+ end
163
+
164
+ f.save
165
+ end
166
+ end
167
+
159
168
  redirect_to pages_url, :notice => "Страница «#{@page.name}» успешно обновлена."
160
169
  else
161
170
  render :action => "edit"
@@ -15,14 +15,15 @@
15
15
  .controls= f.text_field :code_name, :class => "span4"
16
16
  = f.hidden_field :template_id, :value => @field.template.id, :class => "span4"
17
17
 
18
- .control-group
19
- = f.label :type_value, :class => 'control-label'
20
- .controls
21
- = f.select :type_value, options_for_select(types_value, :selected => @field.type_value), :class => "span4"
18
+ - unless @field.type_value == 'image'
19
+ .control-group
20
+ = f.label :type_value, :class => 'control-label'
21
+ .controls
22
+ = f.select :type_value, options_for_select(types_value, :selected => @field.type_value), :class => "span4"
22
23
 
23
24
  .row-fluid
24
25
  .span12
25
26
  .form-actions
26
27
  .btn-group
27
28
  = f.submit :class => "btn btn-primary"
28
- = link_to "Отмена", template_url(@field.template), :class => "btn"
29
+ = link_to "Отмена", edit_template_url(@field.template), :class => "btn"
@@ -3,7 +3,7 @@
3
3
  Gem::Specification.new do |s|
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.name = %q{constructor-pages}
6
- s.version = '0.2.8'
6
+ s.version = '0.2.9'
7
7
  s.summary = %q{Pages for ConstructorCms}
8
8
  s.authors = ['Ivan Zotov']
9
9
  s.require_paths = %w(lib)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: constructor-pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: