alchemy-custom-model 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: 9fd3b1365def03b70994ef5cdba868f1fc415224
4
- data.tar.gz: 6433cd7510a5622b1c5edc7f0539082c2fc50cdb
3
+ metadata.gz: 8ed0ee1023ebbe7aa4406999e824b2cf0b23bc8e
4
+ data.tar.gz: 7d245b0a99f8ed1de3ecc347d03f7eeb79da2400
5
5
  SHA512:
6
- metadata.gz: d66df91e327ed0dd2e90c7961dc28f747bcda68de29ac6d65452f5a9fa14d85f53809b91b599e5d58c045ef4f7304aa05ec5fad86b2c7b4721651e4dc7664b68
7
- data.tar.gz: 65905483dbf78356fe8f20a749730c7f14b01295a855e98ded8e53a2e758b8133999f430215f39a818f5aba794ab7ff5c0f68d9f0c0956f9e30b16b51de267ce
6
+ metadata.gz: a174324f0a85e471597c66fd1602281cdd067915c897aed4b9815a73ee2012aaa4e4474960e3cc2bbd7da159925c567cb2bf4e80e24eb493f10bf16d5d5726da
7
+ data.tar.gz: 01fdb0b4e39999267464b77248c9cb81cef4e774165515323de6d62f797d16cf123007d44421f134cf9e0655725698270ccefe45efc5b9715c106244f74f42bb
@@ -5,8 +5,8 @@ module Alchemy
5
5
  class ClonesController < ::Alchemy::Custom::Model::Admin::BaseController
6
6
  def create
7
7
  @obj.assign_attributes clean_params
8
- if @parent.present? and @obj.respond_to?("#{parent_model_name_demodulized}=".to_sym)
9
- @obj.send "#{parent_model_name_demodulized}=", @parent
8
+ if @parent.present?
9
+ @obj.send("#{@obj.class.to_cloner_name}=",@parent)
10
10
  end
11
11
  @obj = yield @obj if block_given?
12
12
  if @obj.apply
@@ -19,8 +19,13 @@ module Alchemy::Custom::Model::Admin::OrdersHelper
19
19
  end
20
20
  end
21
21
 
22
- def update_order_path(options = {})
22
+ def update_order_path(obj=nil,options = {})
23
+ if obj.nil?
23
24
  polymorphic_path([:admin, base_class.to_s.pluralize.underscore, :order], options)
25
+ else
26
+ polymorphic_path([:admin, obj, :order], options)
27
+
28
+ end
24
29
  end
25
30
 
26
31
  def print_order_identify(el)
@@ -3,6 +3,8 @@ module Alchemy
3
3
  module Model
4
4
  class Cloner < ::ActiveType::Object
5
5
 
6
+
7
+
6
8
  attribute :language_id, :integer
7
9
  attribute :site_id, :integer
8
10
 
@@ -14,7 +16,7 @@ module Alchemy
14
16
  # ritorna true se il clone è andato a buon fine false altrimenti
15
17
  def apply
16
18
  if valid?
17
- cloned = self.category.clone_to_other_lang self.attributes.with_indifferent_access
19
+ cloned = self.send(self.to_cloner_name).clone_to_other_lang(get_attributes_for_clone.with_indifferent_access)
18
20
  if cloned.valid?
19
21
  true
20
22
  else
@@ -30,6 +32,27 @@ module Alchemy
30
32
 
31
33
 
32
34
 
35
+ private
36
+
37
+ class << self
38
+ def cloner_of(name,scope = nil, options={})
39
+ class_attribute :to_cloner_name
40
+ name = name.to_sym
41
+ if options[:foreign_key]
42
+ attribute options[:foreign_key]
43
+ else
44
+ attribute :"#{name}_id"
45
+ end
46
+ belongs_to name, scope, options
47
+ self.to_cloner_name = name
48
+ end
49
+ end
50
+
51
+ def get_attributes_for_clone
52
+ self.attributes
53
+ end
54
+
55
+
33
56
  protected
34
57
 
35
58
  def check_lang_in_site
@@ -22,7 +22,7 @@
22
22
  <%= t(:suggestion) %>
23
23
  </div>
24
24
  <div class="buttons">
25
- <button name="button" type="submit" id="save_order" data-url-update=<%= update_order_path %>><%= t(:save_order) %>
25
+ <button name="button" type="submit" id="save_order" data-url-update=<%= update_order_path(@obj) %>><%= t(:save_order) %>
26
26
  </button>
27
27
  </div>
28
28
  </div>
@@ -31,9 +31,14 @@ module Alchemy::Custom::Model
31
31
 
32
32
 
33
33
  def update
34
+ if !self.class.method_for_show.blank?
35
+ klass= klass_for_show_elements
36
+ else
37
+ klass= self.parent_klass
38
+ end
34
39
  updated_nodes = params[:ordered_data]
35
- self.parent_klass.transaction do
36
- process_nodes updated_nodes, self.parent_klass
40
+ klass.transaction do
41
+ process_nodes updated_nodes, klass
37
42
  end
38
43
  redirect_to polymorphic_path([:admin, self.parent_klass])
39
44
  end
@@ -44,6 +49,10 @@ module Alchemy::Custom::Model
44
49
  self.class.parent_klass
45
50
  end
46
51
 
52
+ def klass_for_show_elements
53
+ self.class.method_for_show.to_s.singularize.classify.constantize
54
+ end
55
+
47
56
  private
48
57
 
49
58
  def check_parent
@@ -1,7 +1,7 @@
1
1
  module Alchemy
2
2
  module Custom
3
3
  module Model
4
- VERSION = '2.0.1'
4
+ VERSION = '2.0.2'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alchemy-custom-model
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
  - Alessandro Baccanelli
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-05-10 00:00:00.000000000 Z
12
+ date: 2019-05-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: alchemy_cms
@@ -267,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
267
267
  version: '0'
268
268
  requirements: []
269
269
  rubyforge_project:
270
- rubygems_version: 2.4.8
270
+ rubygems_version: 2.6.12
271
271
  signing_key:
272
272
  specification_version: 4
273
273
  summary: A gem for semplify model implementation with Alchemy CMS