enjoy_cms 0.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +249 -0
- data/LICENSE.txt +22 -0
- data/README.md +137 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/enjoy_cms.coffee +6 -0
- data/app/assets/javascripts/enjoy_cms/flash.js.coffee +3 -0
- data/app/assets/javascripts/enjoy_cms/map.js.coffee +22 -0
- data/app/assets/javascripts/head.load.js +707 -0
- data/app/assets/javascripts/jquery.placeholder.js +157 -0
- data/app/assets/stylesheets/enjoy_cms.sass +5 -0
- data/app/assets/stylesheets/enjoy_cms/flash.sass +63 -0
- data/app/assets/stylesheets/enjoy_cms/normalize.scss +406 -0
- data/app/assets/stylesheets/enjoy_cms/powered.sass +18 -0
- data/app/controllers/concerns/enjoy/errors.rb +93 -0
- data/app/controllers/concerns/enjoy/fancybox.rb +14 -0
- data/app/controllers/concerns/enjoy/localizeable.rb +33 -0
- data/app/controllers/concerns/enjoy/nav_menu.rb +64 -0
- data/app/controllers/concerns/enjoy/no_cache.rb +12 -0
- data/app/controllers/concerns/enjoy/seo_pages.rb +83 -0
- data/app/controllers/enjoy/contacts_controller.rb +5 -0
- data/app/controllers/enjoy/home_controller.rb +6 -0
- data/app/controllers/enjoy/news_controller.rb +5 -0
- data/app/controllers/enjoy/pages_controller.rb +5 -0
- data/app/controllers/enjoy/search_controller.rb +6 -0
- data/app/helpers/enjoy/gzip_helper.rb +27 -0
- data/app/helpers/enjoy/powered_helper.rb +12 -0
- data/app/mailers/enjoy/contact_mailer.rb +17 -0
- data/app/models/concerns/enjoy/boolean_field.rb +17 -0
- data/app/models/concerns/enjoy/enableable.rb +8 -0
- data/app/models/concerns/enjoy/geocodeable.rb +4 -0
- data/app/models/concerns/enjoy/mappable.rb +95 -0
- data/app/models/concerns/enjoy/mongoid_paperclip.rb +37 -0
- data/app/models/concerns/enjoy/seoable.rb +36 -0
- data/app/models/concerns/enjoy/sitemap_data.rb +23 -0
- data/app/models/concerns/enjoy/sort_field.rb +20 -0
- data/app/models/concerns/enjoy/sortable.rb +8 -0
- data/app/models/enjoy/contact_message.rb +12 -0
- data/app/models/enjoy/embedded_element.rb +15 -0
- data/app/models/enjoy/embedded_gallery_image.rb +15 -0
- data/app/models/enjoy/gallery.rb +10 -0
- data/app/models/enjoy/gallery_image.rb +10 -0
- data/app/models/enjoy/menu.rb +12 -0
- data/app/models/enjoy/news.rb +12 -0
- data/app/models/enjoy/page.rb +12 -0
- data/app/models/enjoy/seo.rb +13 -0
- data/app/views/blocks/_favicon.html.slim +21 -0
- data/app/views/blocks/_footer.html.slim +1 -0
- data/app/views/blocks/_seo_block.html.slim +18 -0
- data/app/views/blocks/_seo_block_with_obj.html.slim +27 -0
- data/app/views/devise/registrations/edit.html.slim +21 -0
- data/app/views/devise/registrations/new.html.slim +21 -0
- data/app/views/devise/sessions/new.html.slim +22 -0
- data/app/views/devise/shared/_links.html.slim +11 -0
- data/app/views/enjoy/contact_mailer/new_message_email.html.slim +15 -0
- data/app/views/enjoy/contacts/index.html.slim +10 -0
- data/app/views/enjoy/contacts/new.html.slim +10 -0
- data/app/views/enjoy/contacts/sent.html.slim +4 -0
- data/app/views/enjoy/home/index.html.slim +1 -0
- data/app/views/enjoy/news/index.html.slim +9 -0
- data/app/views/enjoy/news/show.html.slim +8 -0
- data/app/views/enjoy/pages/show.html.slim +1 -0
- data/app/views/enjoy/search/index.html.slim +19 -0
- data/app/views/errors/_base.html.slim +3 -0
- data/app/views/errors/error_403.html.slim +1 -0
- data/app/views/errors/error_404.html.slim +1 -0
- data/app/views/errors/error_500.html.slim +1 -0
- data/app/views/layouts/application.html.slim +25 -0
- data/app/views/rails_admin/main/_check_boxes.html.slim +27 -0
- data/app/views/rails_admin/main/_enum_check_boxes.html.slim +5 -0
- data/app/views/rails_admin/main/_enum_radio_buttons.html.slim +5 -0
- data/app/views/rails_admin/main/_form_raw.html.slim +1 -0
- data/app/views/shared/_admin_link.html.slim +3 -0
- data/app/views/shared/_messages.html.slim +7 -0
- data/app/views/shared/_meta.html.slim +19 -0
- data/app/views/shared/_obj.html.slim +21 -0
- data/app/views/shared/_og.html.slim +4 -0
- data/app/views/simple_captcha/_simple_captcha.html.slim +12 -0
- data/config/initializers/simple_captcha.rb +29 -0
- data/config/locales/en.enjoy.yml +29 -0
- data/config/locales/en.enjoy_admin.yml +6 -0
- data/config/locales/ru.cancan.yml +4 -0
- data/config/locales/ru.devise.yml +65 -0
- data/config/locales/ru.enjoy.yml +39 -0
- data/config/locales/ru.enjoy_admin.yml +6 -0
- data/config/locales/ru.kaminari.yml +17 -0
- data/config/locales/ru.models.yml +103 -0
- data/config/locales/ru.mongoid.yml +450 -0
- data/config/locales/ru.rails_admin.yml +148 -0
- data/config/locales/ru.simple_captcha.yml +3 -0
- data/config/locales/ru.simple_form.yml +9 -0
- data/config/routes.rb +14 -0
- data/enjoy_cms.gemspec +53 -0
- data/lib/enjoy/admin.rb +350 -0
- data/lib/enjoy/admin/contact_message.rb +36 -0
- data/lib/enjoy/admin/embedded_element.rb +11 -0
- data/lib/enjoy/admin/embedded_gallery_image.rb +15 -0
- data/lib/enjoy/admin/gallery.rb +20 -0
- data/lib/enjoy/admin/gallery_image.rb +18 -0
- data/lib/enjoy/admin/menu.rb +27 -0
- data/lib/enjoy/admin/news.rb +57 -0
- data/lib/enjoy/admin/page.rb +81 -0
- data/lib/enjoy/admin/seo.rb +17 -0
- data/lib/enjoy/configuration.rb +73 -0
- data/lib/enjoy/controller.rb +31 -0
- data/lib/enjoy/controllers/contacts.rb +70 -0
- data/lib/enjoy/controllers/news.rb +36 -0
- data/lib/enjoy/controllers/pages.rb +22 -0
- data/lib/enjoy/controllers/search.rb +62 -0
- data/lib/enjoy/elastic_search.rb +31 -0
- data/lib/enjoy/engine.rb +46 -0
- data/lib/enjoy/migration.rb +34 -0
- data/lib/enjoy/model.rb +22 -0
- data/lib/enjoy/models/active_record/contact_message.rb +14 -0
- data/lib/enjoy/models/active_record/menu.rb +17 -0
- data/lib/enjoy/models/active_record/news.rb +26 -0
- data/lib/enjoy/models/active_record/page.rb +20 -0
- data/lib/enjoy/models/active_record/seo.rb +17 -0
- data/lib/enjoy/models/contact_message.rb +37 -0
- data/lib/enjoy/models/embedded_element.rb +12 -0
- data/lib/enjoy/models/embedded_gallery_image.rb +16 -0
- data/lib/enjoy/models/gallery.rb +29 -0
- data/lib/enjoy/models/gallery_image.rb +23 -0
- data/lib/enjoy/models/menu.rb +28 -0
- data/lib/enjoy/models/mongoid/contact_message.rb +20 -0
- data/lib/enjoy/models/mongoid/embedded_element.rb +13 -0
- data/lib/enjoy/models/mongoid/embedded_gallery_image.rb +19 -0
- data/lib/enjoy/models/mongoid/gallery.rb +23 -0
- data/lib/enjoy/models/mongoid/gallery_image.rb +21 -0
- data/lib/enjoy/models/mongoid/menu.rb +15 -0
- data/lib/enjoy/models/mongoid/news.rb +29 -0
- data/lib/enjoy/models/mongoid/page.rb +25 -0
- data/lib/enjoy/models/mongoid/seo.rb +28 -0
- data/lib/enjoy/models/news.rb +58 -0
- data/lib/enjoy/models/page.rb +90 -0
- data/lib/enjoy/models/seo.rb +22 -0
- data/lib/enjoy/patch.rb +58 -0
- data/lib/enjoy/rails_admin_menu.rb +145 -0
- data/lib/enjoy/simple_form_patch.rb +12 -0
- data/lib/enjoy/tasks.rb +13 -0
- data/lib/enjoy/version.rb +3 -0
- data/lib/enjoy_cms.rb +109 -0
- data/lib/filename_to_slug.rb +34 -0
- data/lib/generators/enjoy/ability_generator.rb +14 -0
- data/lib/generators/enjoy/admin_generator.rb +21 -0
- data/lib/generators/enjoy/capify_generator.rb +39 -0
- data/lib/generators/enjoy/layout_generator.rb +14 -0
- data/lib/generators/enjoy/migration_generator.rb +18 -0
- data/lib/generators/enjoy/templates/Capfile +17 -0
- data/lib/generators/enjoy/templates/ability.erb +26 -0
- data/lib/generators/enjoy/templates/admin.erb +89 -0
- data/lib/generators/enjoy/templates/deploy.erb +47 -0
- data/lib/generators/enjoy/templates/dl.erb +30 -0
- data/lib/generators/enjoy/templates/migration_contact_messages.rb +15 -0
- data/lib/generators/enjoy/templates/migration_news.rb +26 -0
- data/lib/generators/enjoy/templates/migration_pages.rb +45 -0
- data/lib/generators/enjoy/templates/migration_seos.rb +14 -0
- data/lib/generators/enjoy/templates/production.erb +8 -0
- data/lib/generators/enjoy/templates/unicorn.erb +66 -0
- data/lib/generators/enjoy/utils.rb +21 -0
- data/lib/manual_slug.rb +10 -0
- data/lib/manual_slug/active_record.rb +32 -0
- data/lib/manual_slug/mongoid.rb +36 -0
- data/lib/rails_admin/custom_show_in_app.rb +43 -0
- data/release.sh +13 -0
- data/template.rb +824 -0
- metadata +579 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
module Enjoy
|
2
|
+
module Admin
|
3
|
+
module ContactMessage
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include Enjoy::Model
|
6
|
+
include Enjoy.orm_specific('ContactMessage')
|
7
|
+
|
8
|
+
included do
|
9
|
+
|
10
|
+
apply_simple_captcha message: Enjoy.configuration.contacts_captcha_error_message
|
11
|
+
|
12
|
+
validates_email_format_of :email, unless: 'email.blank?'
|
13
|
+
if Enjoy.config.contacts_message_required
|
14
|
+
validates_presence_of :content
|
15
|
+
end
|
16
|
+
validate do
|
17
|
+
if email.blank? && phone.blank?
|
18
|
+
errors.add(:email, I18n.t('rs.no_contact_info'))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
after_create do
|
23
|
+
mailer_class.send(mailer_method, self).deliver
|
24
|
+
end
|
25
|
+
|
26
|
+
def mailer_class
|
27
|
+
Enjoy::ContactMailer
|
28
|
+
end
|
29
|
+
|
30
|
+
def mailer_method
|
31
|
+
:new_message_email
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Enjoy
|
2
|
+
module Admin
|
3
|
+
module EmbeddedGalleryImage
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include Enjoy::Model
|
6
|
+
include Enjoy::Enableable
|
7
|
+
include Enjoy::Sortable
|
8
|
+
include Enjoy.orm_specific('EmbeddedGalleryImage')
|
9
|
+
|
10
|
+
included do
|
11
|
+
validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/, if: :image?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Enjoy
|
2
|
+
module Admin
|
3
|
+
module Gallery
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include Enjoy::Model
|
6
|
+
include ManualSlug
|
7
|
+
include Enjoy::Enableable
|
8
|
+
include Enjoy::SitemapData
|
9
|
+
include Enjoy.orm_specific('Gallery')
|
10
|
+
|
11
|
+
included do
|
12
|
+
|
13
|
+
has_many :gallery_images, class_name: "Enjoy::GalleryImage"
|
14
|
+
field :name, type: String, localize: Enjoy.configuration.localize
|
15
|
+
|
16
|
+
validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/, if: :image?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Enjoy
|
2
|
+
module Admin
|
3
|
+
module GalleryImage
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include Enjoy::Model
|
6
|
+
include Enableable
|
7
|
+
include Enjoy.orm_specific('GalleryImage')
|
8
|
+
|
9
|
+
included do
|
10
|
+
|
11
|
+
belongs_to :gallery, class_name: "Enjoy::Gallery"
|
12
|
+
field :name, type: String, localize: Enjoy.configuration.localize
|
13
|
+
|
14
|
+
validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/, if: :image?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Enjoy
|
2
|
+
module Admin
|
3
|
+
module Menu
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include Enjoy::Model
|
6
|
+
include Enableable
|
7
|
+
include ManualSlug
|
8
|
+
include Enjoy.orm_specific('Menu')
|
9
|
+
|
10
|
+
included do
|
11
|
+
|
12
|
+
field :name, type: String
|
13
|
+
manual_slug :name
|
14
|
+
|
15
|
+
after_save do
|
16
|
+
Rails.cache.delete 'menus'
|
17
|
+
end
|
18
|
+
after_destroy do
|
19
|
+
Rails.cache.delete 'menus'
|
20
|
+
end
|
21
|
+
|
22
|
+
has_and_belongs_to_many :pages, inverse_of: :menus, class_name: "Enjoy::Page"
|
23
|
+
alias_method :items, :pages
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Enjoy
|
2
|
+
module Admin
|
3
|
+
module News
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include Enjoy::Model
|
6
|
+
include Seoable
|
7
|
+
include Enableable
|
8
|
+
include ManualSlug
|
9
|
+
include SitemapData
|
10
|
+
include Enjoy.orm_specific('News')
|
11
|
+
|
12
|
+
if Enjoy.config.search_enabled
|
13
|
+
include Enjoy::ElasticSearch
|
14
|
+
end
|
15
|
+
|
16
|
+
included do
|
17
|
+
|
18
|
+
unless Enjoy.config.news_image_styles.nil?
|
19
|
+
validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/, if: :image?
|
20
|
+
end
|
21
|
+
|
22
|
+
validates_presence_of :name
|
23
|
+
if Enjoy.config.news_content_required
|
24
|
+
validates_presence_of :content
|
25
|
+
end
|
26
|
+
|
27
|
+
before_validation do
|
28
|
+
self.time = Time.now if self.time.blank?
|
29
|
+
end
|
30
|
+
scope :recent, ->(count = 5) { enabled.after_now.by_date.limit(count) }
|
31
|
+
unless Enjoy.config.news_per_page.nil?
|
32
|
+
paginates_per Enjoy.config.news_per_page
|
33
|
+
end
|
34
|
+
smart_excerpt :excerpt, :content, Enjoy.config.news_excerpt
|
35
|
+
manual_slug :report_slug
|
36
|
+
|
37
|
+
Enjoy.apply_patches self
|
38
|
+
end
|
39
|
+
|
40
|
+
def report_slug
|
41
|
+
if time.blank?
|
42
|
+
name
|
43
|
+
elsif name.blank?
|
44
|
+
time.strftime('%Y-%m-%d')
|
45
|
+
else
|
46
|
+
time.strftime('%Y-%m-%d') + '-' + name[0..20]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
def html5_date
|
50
|
+
time.strftime('%Y-%m-%d')
|
51
|
+
end
|
52
|
+
def format_date
|
53
|
+
time.strftime(I18n.t('rs.format_time'))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Enjoy
|
2
|
+
module Admin
|
3
|
+
module Page
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include Enjoy::Model
|
6
|
+
include Enableable
|
7
|
+
include Seoable
|
8
|
+
include ManualSlug
|
9
|
+
include SitemapData
|
10
|
+
|
11
|
+
include Enjoy.orm_specific('Page')
|
12
|
+
|
13
|
+
if Enjoy.config.search_enabled
|
14
|
+
include Enjoy::ElasticSearch
|
15
|
+
end
|
16
|
+
|
17
|
+
included do
|
18
|
+
|
19
|
+
has_and_belongs_to_many :menus, inverse_of: :pages, class_name: "Enjoy::Menu"
|
20
|
+
validates_uniqueness_of :fullpath
|
21
|
+
validates_presence_of :name
|
22
|
+
manual_slug :name
|
23
|
+
before_validation do
|
24
|
+
self.fullpath = "/pages/#{slug}" if self.fullpath.blank?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_fullpath
|
29
|
+
redirect.blank? ? fullpath : redirect
|
30
|
+
end
|
31
|
+
|
32
|
+
def has_content?
|
33
|
+
@content_used.nil? && !content.blank?
|
34
|
+
end
|
35
|
+
|
36
|
+
def page_content
|
37
|
+
if @content_used.nil?
|
38
|
+
@content_used = true
|
39
|
+
if content.nil?
|
40
|
+
''
|
41
|
+
else
|
42
|
+
content.gsub(/\{\{(.*?)\}\}/) do
|
43
|
+
Settings ? Settings.get($1).val : "" #temp
|
44
|
+
end
|
45
|
+
end
|
46
|
+
else
|
47
|
+
''
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def is_current?(url)
|
52
|
+
if fullpath == '/'
|
53
|
+
url == '/'
|
54
|
+
else
|
55
|
+
url.match(clean_regexp)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def regexp_prefix
|
60
|
+
""
|
61
|
+
end
|
62
|
+
|
63
|
+
def clean_regexp
|
64
|
+
if regexp.blank?
|
65
|
+
/^#{regexp_prefix}#{Regexp.escape(fullpath)}$/
|
66
|
+
else
|
67
|
+
begin
|
68
|
+
/#{regexp}/
|
69
|
+
rescue
|
70
|
+
# not a valid regexp - treat as literal search string
|
71
|
+
/#{Regexp.escape(regexp)}/
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def nav_options
|
77
|
+
{highlights_on: clean_regexp}
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Enjoy
|
2
|
+
module Admin
|
3
|
+
module Seo
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include Enjoy::Model
|
6
|
+
include Enableable
|
7
|
+
include Enjoy.orm_specific('Seo')
|
8
|
+
include Enjoy::SeoHelpers
|
9
|
+
|
10
|
+
included do
|
11
|
+
|
12
|
+
Enjoy.apply_patches self
|
13
|
+
validates_attachment_content_type :og_image, content_type: /\Aimage\/.*\Z/, if: :og_image?
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Enjoy
|
2
|
+
def self.configuration
|
3
|
+
@configuration ||= Configuration.new
|
4
|
+
end
|
5
|
+
def self.config
|
6
|
+
@configuration ||= Configuration.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.configure
|
10
|
+
yield configuration
|
11
|
+
end
|
12
|
+
|
13
|
+
class Configuration
|
14
|
+
attr_accessor :news_image_styles
|
15
|
+
attr_accessor :news_per_page
|
16
|
+
attr_accessor :news_excerpt
|
17
|
+
attr_accessor :news_content_required
|
18
|
+
|
19
|
+
attr_accessor :error_layout
|
20
|
+
attr_accessor :menu_max_depth
|
21
|
+
|
22
|
+
attr_accessor :search_enabled
|
23
|
+
attr_accessor :search_per_page
|
24
|
+
attr_accessor :search_models
|
25
|
+
|
26
|
+
attr_accessor :contacts_captcha
|
27
|
+
attr_accessor :contacts_fields
|
28
|
+
attr_accessor :contacts_message_required
|
29
|
+
attr_accessor :contacts_captcha_error_message
|
30
|
+
|
31
|
+
attr_accessor :separate_seo_table
|
32
|
+
|
33
|
+
attr_accessor :localize
|
34
|
+
|
35
|
+
attr_accessor :recreate_contact_message_action
|
36
|
+
|
37
|
+
def initialize
|
38
|
+
@news_image_styles = {
|
39
|
+
main: '400x200>',
|
40
|
+
thumb: '200x100>',
|
41
|
+
}
|
42
|
+
@news_per_page = 10
|
43
|
+
@news_excerpt = 12
|
44
|
+
@news_content_required = true
|
45
|
+
|
46
|
+
@error_layout = 'application'
|
47
|
+
@menu_max_depth = 2
|
48
|
+
|
49
|
+
@search_enabled = false
|
50
|
+
@search_per_page = 10
|
51
|
+
@search_models = []
|
52
|
+
|
53
|
+
@contacts_captcha = false
|
54
|
+
@contacts_fields = {}
|
55
|
+
@contacts_message_required = true
|
56
|
+
|
57
|
+
@contacts_captcha_error_message = "Код проверки введен неверно"
|
58
|
+
@recreate_contact_message_action = "new"
|
59
|
+
|
60
|
+
@localize = false
|
61
|
+
|
62
|
+
@separate_seo_table = false
|
63
|
+
end
|
64
|
+
|
65
|
+
def search_enabled=(val)
|
66
|
+
@search_enabled = val
|
67
|
+
if @search_enabled
|
68
|
+
@search_models << 'Page'
|
69
|
+
@search_models << 'News'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Enjoy::Controller
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
included do
|
4
|
+
include Enjoy::Errors
|
5
|
+
include Enjoy::SeoPages
|
6
|
+
include Enjoy::NavMenu
|
7
|
+
include Enjoy::Fancybox
|
8
|
+
protect_from_forgery with: :exception
|
9
|
+
helper_method :page_title
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def page_title
|
15
|
+
if @seo_page.nil?
|
16
|
+
Settings ? Settings.default_title : "" #temp
|
17
|
+
else
|
18
|
+
@seo_page.page_title
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def ckeditor_authenticate
|
23
|
+
redirect_to '/' unless user_signed_in? && current_user.has_role?('admin')
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def hide_ym_ga
|
28
|
+
false
|
29
|
+
end
|
30
|
+
helper_method :hide_ym_ga
|
31
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Enjoy
|
2
|
+
module Controllers
|
3
|
+
module Contacts
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
def index
|
6
|
+
@contact_message = model.new
|
7
|
+
after_initialize
|
8
|
+
end
|
9
|
+
|
10
|
+
def new
|
11
|
+
@contact_message = model.new
|
12
|
+
after_initialize
|
13
|
+
end
|
14
|
+
|
15
|
+
def create
|
16
|
+
@contact_message = model.new(message_params)
|
17
|
+
after_initialize
|
18
|
+
if Enjoy.config.contacts_captcha
|
19
|
+
meth = :save_with_captcha
|
20
|
+
else
|
21
|
+
meth = :save
|
22
|
+
end
|
23
|
+
if @contact_message.send(meth)
|
24
|
+
after_create
|
25
|
+
if request.xhr? && process_ajax
|
26
|
+
ajax_success
|
27
|
+
else
|
28
|
+
redirect_after_done
|
29
|
+
end
|
30
|
+
else
|
31
|
+
render_contacts_error
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def sent
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def render_contacts_error
|
40
|
+
if request.xhr? && process_ajax
|
41
|
+
render json: {errors: @contact_message.errors}, status: 422
|
42
|
+
else
|
43
|
+
flash.now[:alert] = @contact_message.errors.full_messages.join("\n")
|
44
|
+
render action: Enjoy.configuration.recreate_contact_message_action, status: 422
|
45
|
+
end
|
46
|
+
end
|
47
|
+
def process_ajax
|
48
|
+
true
|
49
|
+
end
|
50
|
+
def ajax_success
|
51
|
+
render json: {ok: true}
|
52
|
+
end
|
53
|
+
def redirect_after_done
|
54
|
+
redirect_to :contacts_sent
|
55
|
+
end
|
56
|
+
def after_initialize
|
57
|
+
# overrideable hook for updating message
|
58
|
+
end
|
59
|
+
def after_create
|
60
|
+
# overrideable hook for updating message
|
61
|
+
end
|
62
|
+
def model
|
63
|
+
Enjoy::ContactMessage
|
64
|
+
end
|
65
|
+
def message_params
|
66
|
+
params.require(:contact_message).permit(Enjoy.config.contacts_fields.keys + [:name, :email, :phone, :content, :captcha, :captcha_key])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|