camaleon_cms 2.5.3.1 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of camaleon_cms might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/apps/plugins/front_cache/front_cache_helper.rb +1 -1
- data/app/assets/images/camaleon_cms/language/md.png +0 -0
- data/app/models/camaleon_cms/ability.rb +94 -92
- data/app/models/camaleon_cms/category.rb +45 -44
- data/app/models/camaleon_cms/custom_field.rb +26 -25
- data/app/models/camaleon_cms/custom_field_group.rb +115 -114
- data/app/models/camaleon_cms/custom_fields_relationship.rb +21 -19
- data/app/models/camaleon_cms/media.rb +48 -44
- data/app/models/camaleon_cms/meta.rb +5 -3
- data/app/models/camaleon_cms/nav_menu.rb +27 -24
- data/app/models/camaleon_cms/nav_menu_item.rb +58 -54
- data/app/models/camaleon_cms/plugin.rb +62 -60
- data/app/models/camaleon_cms/post.rb +205 -227
- data/app/models/camaleon_cms/post_comment.rb +44 -42
- data/app/models/camaleon_cms/post_default.rb +65 -62
- data/app/models/camaleon_cms/post_relationship.rb +1 -2
- data/app/models/camaleon_cms/post_tag.rb +9 -6
- data/app/models/camaleon_cms/post_type.rb +170 -163
- data/app/models/camaleon_cms/site.rb +211 -203
- data/app/models/camaleon_cms/term_relationship.rb +16 -14
- data/app/models/camaleon_cms/term_taxonomy.rb +49 -54
- data/app/models/camaleon_cms/theme.rb +24 -23
- data/app/models/camaleon_cms/user.rb +18 -13
- data/app/models/camaleon_cms/user_role.rb +130 -128
- data/app/models/camaleon_cms/widget/assigned.rb +25 -21
- data/app/models/camaleon_cms/widget/main.rb +40 -36
- data/app/models/camaleon_cms/widget/sidebar.rb +20 -16
- data/app/validators/camaleon_cms/post_uniq_validator.rb +28 -0
- data/app/validators/camaleon_cms/uniq_validator.rb +9 -0
- data/config/locales/camaleon_cms/admin/ar.yml +1 -0
- data/config/locales/camaleon_cms/admin/de.yml +1 -0
- data/config/locales/camaleon_cms/admin/en.yml +82 -21
- data/config/locales/camaleon_cms/admin/fr.yml +1 -0
- data/config/locales/camaleon_cms/admin/it.yml +1 -0
- data/config/locales/camaleon_cms/admin/js/de.yml +51 -0
- data/config/locales/camaleon_cms/admin/js/en.yml +51 -0
- data/config/locales/camaleon_cms/admin/js/es.yml +53 -0
- data/config/locales/camaleon_cms/admin/js/it.yml +44 -0
- data/config/locales/camaleon_cms/admin/js/nl.yml +42 -0
- data/config/locales/camaleon_cms/admin/js/pt-BR.yml +44 -0
- data/config/locales/camaleon_cms/admin/js/ru.yml +51 -0
- data/config/locales/camaleon_cms/admin/js/uk.yml +51 -0
- data/config/locales/camaleon_cms/admin/js/zh-CN.yml +51 -0
- data/config/locales/camaleon_cms/admin/nl.yml +1 -0
- data/config/locales/camaleon_cms/admin/ru.yml +1 -0
- data/config/locales/camaleon_cms/admin/uk.yml +2 -1
- data/config/locales/camaleon_cms/admin/zh-CH.yml +1 -0
- data/config/locales/camaleon_cms/common.md +3 -0
- data/config/locales/camaleon_cms/common/ar.yml +66 -0
- data/config/locales/camaleon_cms/common/de.yml +66 -0
- data/config/locales/camaleon_cms/common/en.yml +63 -0
- data/config/locales/camaleon_cms/common/es.yml +66 -0
- data/config/locales/camaleon_cms/common/fr.yml +66 -0
- data/config/locales/camaleon_cms/common/it.yml +63 -0
- data/config/locales/camaleon_cms/common/md.yml +60 -0
- data/config/locales/camaleon_cms/common/nl.yml +64 -0
- data/config/locales/camaleon_cms/common/pt-BR.yml +65 -0
- data/config/locales/camaleon_cms/common/pt.yml +65 -0
- data/config/locales/camaleon_cms/common/ru.yml +66 -0
- data/config/locales/camaleon_cms/common/uk.yml +64 -0
- data/config/locales/camaleon_cms/common/zh-CN.yml +66 -0
- data/config/locales/camaleon_cms/languages/ar.yml +16 -0
- data/config/locales/camaleon_cms/languages/de.yml +16 -0
- data/config/locales/camaleon_cms/languages/en.yml +16 -0
- data/config/locales/camaleon_cms/languages/es.yml +16 -0
- data/config/locales/camaleon_cms/languages/it.yml +16 -0
- data/config/locales/camaleon_cms/languages/md.yml +15 -0
- data/config/locales/camaleon_cms/languages/nl.yml +16 -0
- data/config/locales/camaleon_cms/languages/pt-BR.yml +16 -0
- data/config/locales/camaleon_cms/languages/pt.yml +16 -0
- data/config/locales/camaleon_cms/languages/ru.yml +16 -0
- data/config/locales/camaleon_cms/languages/uk.yml +16 -0
- data/config/locales/camaleon_cms/languages/zh-CN.yml +16 -0
- data/config/locales/camaleon_cms/routes/de.yml +8 -0
- data/config/locales/camaleon_cms/routes/es.yml +8 -0
- data/config/locales/camaleon_cms/routes/fr.yml +8 -0
- data/config/locales/camaleon_cms/routes/it.yml +8 -0
- data/config/locales/camaleon_cms/routes/md.yml +8 -0
- data/config/locales/camaleon_cms/routes/pt-BR.yml +8 -0
- data/config/locales/camaleon_cms/routes/pt.yml +8 -0
- data/config/locales/camaleon_cms/routes/ru.yml +8 -0
- data/config/locales/camaleon_cms/routes/uk.yml +8 -0
- data/config/locales/camaleon_cms/routes/zh-CN.yml +8 -0
- data/config/locales/md.yml +207 -0
- data/lib/camaleon_cms/version.rb +1 -1
- data/spec/dummy/config/application.rb +14 -2
- metadata +102 -109
- data/config/locales/camaleon_cms/admin/js.yml +0 -435
- data/config/locales/camaleon_cms/common.yml +0 -786
- data/config/locales/camaleon_cms/languages.yml +0 -167
- data/config/locales/camaleon_cms/routes.yml +0 -71
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -254
- data/spec/dummy/log/test.log +0 -46384
- data/spec/dummy/public/media/1/rails_tmp.png +0 -0
- data/spec/dummy/public/media/1/rails_tmp_1.png +0 -0
- data/spec/dummy/public/media/1/rails_tmp_2.png +0 -0
- data/spec/dummy/public/media/1/rails_tmp_3.png +0 -0
- data/spec/dummy/public/media/1/sample/rails_tmp.png +0 -0
- data/spec/dummy/public/media/1/sample/thumb/rails_tmp-png.png +0 -0
- data/spec/dummy/public/media/1/slide33.jpg +0 -0
- data/spec/dummy/public/media/1/thumb/rails_tmp-png.png +0 -0
- data/spec/dummy/public/media/1/thumb/rails_tmp-png_20x.png +0 -0
- data/spec/dummy/public/media/1/thumb/rails_tmp-png_300x300.png +0 -0
- data/spec/dummy/public/media/1/thumb/rails_tmp-png_505x350.png +0 -0
- data/spec/dummy/public/media/1/thumb/rails_tmp_1-png.png +0 -0
- data/spec/dummy/public/media/1/thumb/rails_tmp_2-png.png +0 -0
- data/spec/dummy/public/media/1/thumb/rails_tmp_3-png.png +0 -0
- data/spec/dummy/public/media/1/thumb/slide33-jpg.jpg +0 -0
- data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-19-13.472.html +0 -457
- data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-19-13.472.png +0 -0
- data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-19-28.693.html +0 -428
- data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-19-28.693.png +0 -0
- data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-22-45.502.html +0 -337
- data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-22-45.502.png +0 -0
- data/spec/support/fixtures/rails_tmp.png +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 397cc4329729b870190f21057d1d58a8cd9877479851c865953d41280fa88be1
|
4
|
+
data.tar.gz: c694f405c6161e611c6c21432e73f2d3e371efe55156196b0323674ac35832f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7eafee5524c10e26013ebaf8639759fda224c9611bc9143d455009d7b56568f80f108d5c678e740429d9e96aeff18fb65cde892d13d93affd901d1b4522eddef
|
7
|
+
data.tar.gz: c17d29772c58a438fb8374fdd1c0cc9ddadd83925bd5940839d1a8c96a00f89f63798973fd4088fa3ce828c997a3be673c4dd71fbe226c2292794c7d6c3646f8
|
@@ -95,7 +95,7 @@ module Plugins::FrontCache::FrontCacheHelper
|
|
95
95
|
@caches[:cache_counter] += 1
|
96
96
|
current_site.set_meta("front_cache_elements", @caches)
|
97
97
|
else
|
98
|
-
Rails.cache.clear
|
98
|
+
Rails.cache.clear
|
99
99
|
@caches[:cache_counter] = 0
|
100
100
|
current_site.set_meta("front_cache_elements", @caches)
|
101
101
|
end
|
Binary file
|
@@ -1,109 +1,111 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module CamaleonCms
|
2
|
+
class Ability
|
3
|
+
include CanCan::Ability
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
5
|
+
def initialize(user, current_site = nil)
|
6
|
+
# Define abilities for the passed in user here. For example:
|
7
|
+
#
|
8
|
+
user ||= CamaleonCms::User.new # guest user (not logged in)
|
9
|
+
if user.admin?
|
10
|
+
can :manage, :all
|
11
|
+
elsif user.client?
|
12
|
+
can :read, :all
|
13
|
+
else
|
14
|
+
# conditions:
|
15
|
+
current_user_role = user.get_role(current_site) || current_site.user_roles.new
|
16
|
+
@roles_manager ||= current_user_role.get_meta("_manager_#{current_site.id}", {}) || {}
|
17
|
+
@roles_post_type ||= current_user_role.get_meta("_post_type_#{current_site.id}", {}) || {}
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
ids_publish = @roles_post_type[:publish] || []
|
20
|
+
ids_edit = @roles_post_type[:edit] || []
|
21
|
+
ids_edit_other = @roles_post_type[:edit_other] || []
|
22
|
+
ids_edit_publish = @roles_post_type[:edit_publish] || []
|
23
|
+
ids_delete = @roles_post_type[:delete] || []
|
24
|
+
ids_delete_other = @roles_post_type[:delete_other] || []
|
25
|
+
ids_delete_publish = @roles_post_type[:delete_publish] || []
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
can :posts, CamaleonCms::PostType do |pt|
|
28
|
+
(ids_edit + ids_edit_other + ids_edit_publish).to_i.include?(pt.id) rescue false
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
31
|
+
can :create_post, CamaleonCms::PostType do |pt|
|
32
|
+
ids_edit.to_i.include?(pt.id) rescue false
|
33
|
+
end
|
34
|
+
can :publish_post, CamaleonCms::PostType do |pt|
|
35
|
+
ids_publish.to_i.include?(pt.id) rescue false
|
36
|
+
end
|
37
|
+
can :edit_other, CamaleonCms::PostType do |pt|
|
38
|
+
ids_edit_other.to_i.include?(pt.id) rescue false
|
39
|
+
end
|
40
|
+
can :edit_publish, CamaleonCms::PostType do |pt|
|
41
|
+
ids_edit_publish.to_i.include?(pt.id) rescue false
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
can :categories, CamaleonCms::PostType do |pt|
|
45
|
+
@roles_post_type[:manage_categories].to_i.include?(pt.id) rescue false
|
46
|
+
end
|
47
|
+
can :post_tags, CamaleonCms::PostType do |pt|
|
48
|
+
@roles_post_type[:manage_tags].to_i.include?(pt.id) rescue false
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
51
|
+
can :update, CamaleonCms::Post do |post|
|
52
|
+
pt_id = post.post_type.id
|
53
|
+
r = false
|
54
|
+
r ||= ids_edit.to_i.include?(pt_id) && post.user_id == user.id rescue false
|
55
|
+
r ||= ids_edit_publish.to_i.include?(pt_id) && post.published? rescue false
|
56
|
+
r ||= ids_edit_other.to_i.include?(pt_id) && post.user_id != user.id rescue false
|
57
|
+
r
|
58
|
+
end
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
60
|
+
can :destroy, CamaleonCms::Post do |post|
|
61
|
+
pt_id = post.post_type.id
|
62
|
+
r = false
|
63
|
+
r ||= ids_delete.to_i.include?(pt_id) && post.user_id == user.id rescue false
|
64
|
+
r ||= ids_delete_publish.to_i.include?(pt_id) && post.published? rescue false
|
65
|
+
r ||= ids_delete_other.to_i.include?(pt_id) && post.user_id != user.id rescue false
|
66
|
+
r
|
67
|
+
end
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
69
|
+
# support for custom abilities for each posttype
|
70
|
+
# sample: http://camaleon.tuzitio.com/documentation/category/40756-uncategorized/custom-models.html
|
71
|
+
@roles_post_type.each do |k , v|
|
72
|
+
next if ['edit', 'edit_other', 'edit_publish', 'publish', 'manage_categories'].include?(k.to_s)
|
73
|
+
can k.to_sym, CamaleonCms::PostType do |pt|
|
74
|
+
v.include?(pt.id.to_s) rescue false
|
75
|
+
end
|
74
76
|
end
|
75
|
-
end
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
78
|
+
# others
|
79
|
+
can :manage, :media if @roles_manager[:media] rescue false
|
80
|
+
can :manage, :comments if @roles_manager[:comments] rescue false
|
81
|
+
# can :manage, :forms if @roles_manager[:forms] rescue false
|
82
|
+
can :manage, :themes if @roles_manager[:themes] rescue false
|
83
|
+
can :manage, :widgets if @roles_manager[:widgets] rescue false
|
84
|
+
can :manage, :nav_menu if @roles_manager[:nav_menu] rescue false
|
85
|
+
can :manage, :plugins if @roles_manager[:plugins] rescue false
|
86
|
+
can :manage, :users if @roles_manager[:users] rescue false
|
87
|
+
can :manage, :settings if @roles_manager[:settings] rescue false
|
88
|
+
@roles_manager.try(:each) do |rol_manage_key, val_role|
|
89
|
+
can :manage, rol_manage_key.to_sym if val_role.to_s.cama_true? rescue false
|
90
|
+
end
|
91
|
+
end
|
92
|
+
cannot :impersonate, CamaleonCms::User do |u|
|
93
|
+
u.id == user.id
|
89
94
|
end
|
90
95
|
end
|
91
|
-
cannot :impersonate, CamaleonCms::User do |u|
|
92
|
-
u.id == user.id
|
93
|
-
end
|
94
|
-
end
|
95
96
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
97
|
+
# overwrite can method to support decorator class names
|
98
|
+
def can?(action, subject, *extra_args)
|
99
|
+
if subject.is_a?(Draper::Decorator)
|
100
|
+
super(action,subject.model,*extra_args)
|
101
|
+
else
|
102
|
+
super(action, subject, *extra_args)
|
103
|
+
end
|
102
104
|
end
|
103
|
-
end
|
104
105
|
|
105
|
-
|
106
|
-
|
107
|
-
|
106
|
+
# overwrite cannot method to support decorator class names
|
107
|
+
def cannot?(*args)
|
108
|
+
!can?(*args)
|
109
|
+
end
|
108
110
|
end
|
109
111
|
end
|
@@ -1,51 +1,52 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
inverse_of: :categories
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
1
|
+
module CamaleonCms
|
2
|
+
class Category < CamaleonCms::TermTaxonomy
|
3
|
+
alias_attribute :site_id, :term_group
|
4
|
+
alias_attribute :post_type_id, :status
|
5
|
+
|
6
|
+
default_scope { where(taxonomy: :category) }
|
7
|
+
scope :no_empty, -> { where('count > 0') } # return all categories that contains at least one post
|
8
|
+
scope :empty, -> { where(count: [0, nil]) } # return all categories that does not contain any post
|
9
|
+
# scope :parents, -> { where("term_taxonomy.parent_id IS NULL") }
|
10
|
+
|
11
|
+
cama_define_common_relationships('Category')
|
12
|
+
|
13
|
+
has_many :posts, foreign_key: :objectid, through: :term_relationships, source: :object
|
14
|
+
has_many :children, class_name: 'CamaleonCms::Category', foreign_key: :parent_id, dependent: :destroy
|
15
|
+
belongs_to :parent, class_name: 'CamaleonCms::Category', foreign_key: :parent_id
|
16
|
+
belongs_to :post_type_parent, class_name: 'CamaleonCms::PostType', foreign_key: :parent_id, inverse_of: :categories
|
17
|
+
belongs_to :site
|
18
|
+
|
19
|
+
before_save :set_site
|
20
|
+
before_destroy :set_posts_in_default_category
|
21
|
+
|
22
|
+
# return the post type of this category
|
23
|
+
def post_type
|
24
|
+
cama_fetch_cache('post_type') do
|
25
|
+
ctg = self
|
26
|
+
begin
|
27
|
+
pt = ctg.post_type_parent
|
28
|
+
ctg = ctg.parent
|
29
|
+
end while ctg
|
30
|
+
pt
|
31
|
+
end
|
31
32
|
end
|
32
|
-
end
|
33
33
|
|
34
|
-
|
34
|
+
private
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
def set_site
|
37
|
+
self.site_id ||= post_type.site_id
|
38
|
+
self.status ||= post_type.id
|
39
|
+
end
|
40
|
+
|
41
|
+
# rescue all posts to assign into default category if they don't have any category assigned
|
42
|
+
def set_posts_in_default_category
|
43
|
+
category_default = post_type.default_category
|
44
|
+
return if category_default == self
|
41
45
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
self.posts.each do |post|
|
47
|
-
if post.categories.where.not(id: id).blank?
|
48
|
-
post.assign_category(category_default.id)
|
46
|
+
posts.each do |post|
|
47
|
+
if post.categories.where.not(id: id).blank?
|
48
|
+
post.assign_category(category_default.id)
|
49
|
+
end
|
49
50
|
end
|
50
51
|
end
|
51
52
|
end
|
@@ -1,35 +1,36 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module CamaleonCms
|
2
|
+
class CustomField < ActiveRecord::Base
|
3
|
+
include CamaleonCms::Metas
|
3
4
|
|
4
|
-
|
5
|
-
|
5
|
+
self.primary_key = :id
|
6
|
+
self.table_name = "#{PluginRoutes.static_system_info['db_prefix']}custom_fields"
|
6
7
|
|
7
|
-
|
8
|
+
alias_attribute :label, :name
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
default_scope { order("#{CamaleonCms::CustomField.table_name}.field_order ASC") }
|
11
|
+
scope :configuration, -> { where(parent_id: -1) }
|
12
|
+
scope :visible_group, -> { where(status: nil) }
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
belongs_to :parent, class_name: 'CamaleonCms::CustomField', foreign_key: :parent_id
|
14
|
+
# status: nil -> visible on list group fields
|
15
|
+
# attr_accessible :object_class, :objectid, :description, :parent_id, :count, :name, :slug,
|
16
|
+
# :field_order, :status, :is_repeat
|
17
|
+
has_many :metas, -> { where(object_class: 'CustomField') }, foreign_key: :objectid, dependent: :destroy
|
18
|
+
has_many :values, class_name: 'CamaleonCms::CustomFieldsRelationship',
|
19
|
+
foreign_key: :custom_field_id, dependent: :destroy
|
20
|
+
belongs_to :custom_field_group
|
21
|
+
belongs_to :parent, class_name: 'CamaleonCms::CustomField', foreign_key: :parent_id
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
validates :name, :object_class, presence: true
|
24
|
+
validates_uniqueness_of :slug, scope: [:parent_id, :object_class],
|
25
|
+
unless: ->(o) { o.is_a?(CamaleonCms::CustomFieldGroup) }
|
26
26
|
|
27
|
-
|
27
|
+
before_validation :before_validating
|
28
28
|
|
29
|
-
|
29
|
+
private
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
def before_validating
|
32
|
+
self.slug ||= name
|
33
|
+
self.slug = slug.to_s.parameterize
|
34
|
+
end
|
34
35
|
end
|
35
36
|
end
|
@@ -1,135 +1,136 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module CamaleonCms
|
2
|
+
class CustomFieldGroup < CamaleonCms::CustomField
|
3
|
+
self.primary_key = :id
|
4
|
+
# attrs required: name, slug, description
|
5
|
+
alias_attribute :site_id, :parent_id
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
default_scope { where.not(object_class: '_fields')
|
8
|
+
.reorder("#{CamaleonCms::CustomField.table_name}.field_order ASC") }
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
belongs_to :site, class_name: 'CamaleonCms::Site', foreign_key: :parent_id
|
10
|
+
has_many :metas, -> { where(object_class: 'CustomFieldGroup') }, foreign_key: :objectid, dependent: :destroy
|
11
|
+
has_many :fields, -> { where(object_class: '_fields') }, class_name: 'CamaleonCms::CustomField',
|
12
|
+
foreign_key: :parent_id, dependent: :destroy
|
13
|
+
belongs_to :site, foreign_key: :parent_id
|
14
14
|
|
15
|
-
|
15
|
+
validates_uniqueness_of :slug, scope: [:object_class, :objectid, :parent_id]
|
16
16
|
|
17
|
-
|
17
|
+
before_validation :before_validating
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
19
|
+
# add fields to group
|
20
|
+
# item:
|
21
|
+
# - sample: {"name"=>"Label", "slug"=>"my_slug", "description"=>"my description (optional)"}
|
22
|
+
# - options (textbox sample): {"field_key":"text_box","multiple":"1","required":"1",
|
23
|
+
# "translate":"1"}
|
24
|
+
# * field_key (string) | translate (boolean) | default_value (unique value) |
|
25
|
+
# default_values (array - multiple values for this field) | label_eval (boolean) |
|
26
|
+
# multiple_options (array)
|
27
|
+
# * multiple_options (used for select, radio and checkboxes ): [{"title"=>"Option Title",
|
28
|
+
# "value"=>"2", "default"=>"1"}, {"title"=>"abcde", "value"=>"3"}]
|
29
|
+
# * label_eval: (Boolean, default false), true => will evaluate the label and description of
|
30
|
+
# current field using (eval('my_label')) to have translatable|dynamic labels
|
31
|
+
# ****** check all options for each case in Admin::CustomFieldsHelper ****
|
32
|
+
# SAMPLE: my_model.add_field({"name"=>"Sub Title", "slug"=>"subtitle"}, {"field_key"=>"text_box",
|
33
|
+
# "translate"=>true, default_value: "Get in Touch"})
|
34
|
+
def add_manual_field(item, options)
|
35
|
+
c = get_field(item[:slug] || item['slug'])
|
36
|
+
return c if c.present?
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
field_item = fields.new(item)
|
39
|
+
if field_item.save
|
40
|
+
field_item.set_options(options)
|
41
|
+
auto_save_default_values(field_item, options)
|
42
|
+
end
|
43
|
+
field_item
|
42
44
|
end
|
43
|
-
|
44
|
-
end
|
45
|
-
alias_method :add_field, :add_manual_field
|
45
|
+
alias_method :add_field, :add_manual_field
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
# return a field with slug = slug from current group
|
48
|
+
def get_field(slug)
|
49
|
+
fields.find_by(slug: slug)
|
50
|
+
end
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
52
|
+
# only used by form on admin panel (protected)
|
53
|
+
# return array of failed_fields and full_fields [[failed fields], [all fields]]
|
54
|
+
def add_fields(items, item_options)
|
55
|
+
fields.where.not(id: items.to_h.map { |_k, obj| obj['id'] }.uniq).destroy_all
|
56
|
+
cache_fields = []
|
57
|
+
order_index = 0
|
58
|
+
errors_saved = []
|
59
|
+
if items.present?
|
60
|
+
items.each do |i, item|
|
61
|
+
item[:field_order] = order_index
|
62
|
+
options = item_options[i] || {}
|
63
|
+
if item[:id].present? && (field_item = self.fields.find_by(id: item[:id])).present?
|
64
|
+
saved = field_item.update(item)
|
65
|
+
cache_fields << field_item
|
66
|
+
else
|
67
|
+
field_item = self.fields.new(item)
|
68
|
+
cache_fields << field_item
|
69
|
+
saved = field_item.save
|
70
|
+
auto_save_default_values(field_item, options) if saved
|
71
|
+
errors_saved << field_item unless saved
|
72
|
+
end
|
73
|
+
if saved
|
74
|
+
field_item.set_meta('_default', options)
|
75
|
+
order_index += 1
|
76
|
+
end
|
76
77
|
end
|
77
78
|
end
|
79
|
+
[errors_saved, cache_fields]
|
78
80
|
end
|
79
|
-
[errors_saved, cache_fields]
|
80
|
-
end
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
82
|
+
# generate the caption for this group
|
83
|
+
def get_caption
|
84
|
+
caption = ''
|
85
|
+
begin
|
86
|
+
case object_class
|
87
|
+
when 'PostType_Post'
|
88
|
+
caption = "Fields for Contents in <b>#{site.post_types.find(objectid).decorate.the_title}</b>"
|
89
|
+
when 'PostType_Category'
|
90
|
+
caption = "Fields for Categories in <b>#{site.post_types.find(objectid).decorate.the_title}</b>"
|
91
|
+
when 'PostType_PostTag'
|
92
|
+
caption = "Fields for Post tags in <b>#{site.post_types.find(objectid).decorate.the_title}</b>"
|
93
|
+
when 'Widget::Main'
|
94
|
+
caption = "Fields for Widget <b>(#{CamaleonCms::Widget::Main.find(objectid).name.translate})</b>"
|
95
|
+
when 'Theme'
|
96
|
+
caption = "Field settings for Theme <b>(#{site.themes.find(objectid).name rescue objectid})</b>"
|
97
|
+
when 'NavMenu'
|
98
|
+
caption = "Field settings for Menus <b>(#{CamaleonCms::NavMenu.find(objectid).name})</b>"
|
99
|
+
when 'Site'
|
100
|
+
caption = 'Field settings the site'
|
101
|
+
when 'PostType'
|
102
|
+
caption = 'Fields for all <b>Post_Types</b>'
|
103
|
+
when 'Post'
|
104
|
+
p = CamaleonCms::Post.find(objectid).decorate
|
105
|
+
caption = "Fields for content <b>(#{p.the_title})</b>"
|
106
|
+
else # 'Plugin' or other class
|
107
|
+
caption = "Fields for <b>#{object_class}</b>"
|
108
|
+
end
|
109
|
+
rescue => e
|
110
|
+
Rails.logger.debug "Camaleon CMS - Menu Item Error: #{e.message} ==> Attrs: #{self.attributes}"
|
108
111
|
end
|
109
|
-
|
110
|
-
Rails.logger.debug "Camaleon CMS - Menu Item Error: #{e.message} ==> Attrs: #{self.attributes}"
|
112
|
+
caption
|
111
113
|
end
|
112
|
-
caption
|
113
|
-
end
|
114
114
|
|
115
|
-
|
115
|
+
private
|
116
116
|
|
117
|
-
|
118
|
-
|
119
|
-
|
117
|
+
def before_validating
|
118
|
+
self.slug = "_group-#{name.to_s.parameterize}" unless slug.present?
|
119
|
+
end
|
120
120
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
121
|
+
# auto save the default field values
|
122
|
+
def auto_save_default_values(field, options)
|
123
|
+
class_name = object_class.split("_").first
|
124
|
+
if %w(Post Category Plugin Theme).include?(class_name) && objectid && (options[:default_value].present? || options[:default_values].present?)
|
125
|
+
if class_name == 'Theme'
|
126
|
+
owner = "CamaleonCms::#{class_name}".constantize.find(objectid) # owner model
|
127
|
+
else
|
128
|
+
owner = "CamaleonCms::#{class_name}".constantize.find(objectid) rescue "CamaleonCms::#{class_name}".constantize.find_by(slug: objectid) # owner model
|
129
|
+
end
|
130
|
+
(options[:default_values] || [options[:default_value]] || []).each do |value|
|
131
|
+
owner.custom_field_values.create!(custom_field_id: field.id, custom_field_slug: field.slug,
|
132
|
+
value: fix_meta_value(value)) if owner.present?
|
133
|
+
end
|
133
134
|
end
|
134
135
|
end
|
135
136
|
end
|