camaleon_cms 2.5.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of camaleon_cms might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/apps/plugins/front_cache/front_cache_helper.rb +1 -1
- data/app/assets/config/camaleon-cms.js +0 -1
- data/app/assets/images/camaleon_cms/language/md.png +0 -0
- data/app/assets/javascripts/camaleon_cms/bootstrap.min.js +4 -5
- data/app/assets/stylesheets/camaleon_cms/bootstrap.min.css +6 -0
- data/app/assets/{fonts/camaleon_cms → stylesheets/camaleon_cms/fonts}/glyphicons-halflings-regular.eot +0 -0
- data/app/assets/{fonts/camaleon_cms → stylesheets/camaleon_cms/fonts}/glyphicons-halflings-regular.svg +0 -0
- data/app/assets/{fonts/camaleon_cms → stylesheets/camaleon_cms/fonts}/glyphicons-halflings-regular.ttf +0 -0
- data/app/assets/{fonts/camaleon_cms → stylesheets/camaleon_cms/fonts}/glyphicons-halflings-regular.woff +0 -0
- data/app/assets/{fonts/camaleon_cms → stylesheets/camaleon_cms/fonts}/glyphicons-halflings-regular.woff2 +0 -0
- data/app/controllers/camaleon_cms/admin/sessions_controller.rb +1 -1
- data/app/controllers/camaleon_cms/frontend_controller.rb +4 -1
- data/app/helpers/camaleon_cms/admin/breadcrumb_helper.rb +1 -1
- data/app/helpers/camaleon_cms/camaleon_helper.rb +4 -4
- data/app/helpers/camaleon_cms/frontend/seo_helper.rb +2 -1
- data/app/helpers/camaleon_cms/frontend/site_helper.rb +1 -6
- data/app/helpers/camaleon_cms/short_code_helper.rb +3 -3
- data/app/helpers/camaleon_cms/uploader_helper.rb +3 -2
- 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 -226
- 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/models/concerns/camaleon_cms/user_methods.rb +1 -1
- data/app/validators/camaleon_cms/post_uniq_validator.rb +28 -0
- data/app/validators/camaleon_cms/uniq_validator.rb +9 -0
- data/app/views/camaleon_cms/shortcode_templates/widget.html.erb +1 -1
- data/config/initializers/assets.rb +1 -1
- data/config/initializers/non_digest_assets.rb +3 -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/config/routes/admin.rb +1 -1
- data/lib/camaleon_cms/version.rb +1 -1
- data/lib/generators/camaleon_cms/theme_template/views/layouts/index.html.erb +19 -16
- data/lib/plugin_routes.rb +1 -26
- data/spec/dummy/config/application.rb +15 -3
- data/spec/features/admin/not_found_spec.rb +10 -0
- metadata +132 -123
- data/app/assets/stylesheets/camaleon_cms/bootstrap.min.css.scss +0 -6799
- data/config/locales/camaleon_cms/admin/js.yml +0 -435
- data/config/locales/camaleon_cms/common.yml +0 -784
- 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 -233
- data/spec/dummy/log/test.log +0 -46368
- 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
@@ -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
|
@@ -1,27 +1,29 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module CamaleonCms
|
2
|
+
class CustomFieldsRelationship < ActiveRecord::Base
|
3
|
+
self.table_name = "#{PluginRoutes.static_system_info['db_prefix']}custom_fields_relationships"
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
# attr_accessible :objectid, :custom_field_id, :term_order, :value, :object_class,
|
6
|
+
# :custom_field_slug, :group_number
|
7
|
+
default_scope { order("#{CamaleonCms::CustomFieldsRelationship.table_name}.term_order ASC") }
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
# relations
|
10
|
+
belongs_to :custom_field
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
# validates :objectid, :custom_field_id, presence: true
|
13
|
+
validates :custom_field_id, presence: true # error on clone model
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
after_save :set_parent_slug
|
16
|
+
after_save :update_model_owner # TODO: convert this model into polymorphic
|
16
17
|
|
17
|
-
|
18
|
+
private
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
def set_parent_slug
|
21
|
+
# self.update_column('custom_field_slug', self.custom_fields.slug)
|
22
|
+
end
|
23
|
+
|
24
|
+
# touch owner model
|
25
|
+
def update_model_owner
|
26
|
+
"CamaleonCms::#{object_class}".constantize.find(objectid).touch rescue nil # owner model
|
27
|
+
end
|
26
28
|
end
|
27
29
|
end
|
@@ -1,54 +1,58 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
validates :name, uniqueness: {
|
5
|
-
scope: [:site_id, :is_folder, :folder_path, :is_public],
|
6
|
-
message: 'Duplicates not allowed'
|
7
|
-
}
|
8
|
-
scope :only_folder, ->{ where(is_folder: true) }
|
9
|
-
scope :only_file, ->{ where(is_folder: false) }
|
10
|
-
default_scope { order(is_folder: :asc, name: :asc) }
|
11
|
-
before_save :create_parent_folders
|
12
|
-
before_destroy :delete_folder_items
|
1
|
+
module CamaleonCms
|
2
|
+
class Media < ActiveRecord::Base
|
3
|
+
self.table_name = "#{PluginRoutes.static_system_info['db_prefix']}media"
|
13
4
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
5
|
+
belongs_to :site
|
6
|
+
validates :name, uniqueness: {
|
7
|
+
scope: [:site_id, :is_folder, :folder_path, :is_public],
|
8
|
+
message: 'Duplicates not allowed'
|
9
|
+
}
|
10
|
+
scope :only_folder, ->{ where(is_folder: true) }
|
11
|
+
scope :only_file, ->{ where(is_folder: false) }
|
12
|
+
default_scope { order(is_folder: :asc, name: :asc) }
|
13
|
+
|
14
|
+
before_save :create_parent_folders
|
15
|
+
before_destroy :delete_folder_items
|
16
|
+
|
17
|
+
def self.search(search_expression = '', folder = nil)
|
18
|
+
if search_expression.blank?
|
19
|
+
where(folder_path: folder)
|
20
|
+
else
|
21
|
+
where('name like ?', "%#{search_expression}%")
|
22
|
+
end
|
19
23
|
end
|
20
|
-
end
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
# search file or folder by key
|
26
|
+
def self.find_by_key(key)
|
27
|
+
key = key.cama_fix_media_key
|
28
|
+
if key == '/'
|
29
|
+
where(folder_path: File.dirname(key))
|
30
|
+
else
|
31
|
+
where(folder_path: File.dirname(key), name: File.basename(key))
|
32
|
+
end
|
29
33
|
end
|
30
|
-
end
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
# return all items of current folder
|
36
|
+
def items
|
37
|
+
coll = is_public ? site.public_media : site.private_media
|
38
|
+
coll.where(folder_path: "#{folder_path}/#{name}".cama_fix_media_key)
|
39
|
+
end
|
37
40
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
private
|
42
|
+
# recover folder or file format
|
43
|
+
def create_parent_folders
|
44
|
+
coll = is_public ? site.public_media : site.private_media
|
45
|
+
_p = []
|
46
|
+
folder_path.split('/').each do |f_name|
|
47
|
+
_path = ('/'+_p.join('/')).cama_fix_media_key
|
48
|
+
coll.only_folder.where(name: f_name, folder_path: _path).first_or_create if "#{_path}/#{f_name}".cama_fix_media_key != '/'
|
49
|
+
_p.push(f_name)
|
50
|
+
end
|
47
51
|
end
|
48
|
-
end
|
49
52
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
+
# return all children items
|
54
|
+
def delete_folder_items
|
55
|
+
items.destroy_all if is_folder
|
56
|
+
end
|
53
57
|
end
|
54
58
|
end
|