hancock_cms 2.0.0.2 → 2.0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +4 -0
  3. data/app/assets/images/{devices → hancock/devise}/login-bg.jpg +0 -0
  4. data/app/assets/images/{rails-admin → hancock/rails_admin}/hancock_logo.svg +0 -0
  5. data/app/assets/javascripts/hancock/cms.coffee +1 -1
  6. data/app/assets/javascripts/hancock/rails_admin/cms.ui.coffee +11 -37
  7. data/app/assets/javascripts/hancock/rails_admin/en_ru_switcher.coffee +90 -0
  8. data/app/assets/javascripts/hancock/rails_admin/enum_with_custom.coffee +42 -0
  9. data/app/assets/javascripts/hancock/rails_admin/form_controls_fixed.coffee +44 -0
  10. data/app/assets/javascripts/hancock/rails_admin/leftside_hider.coffee +106 -0
  11. data/app/assets/javascripts/hancock/rails_admin/multiselect.coffee +8 -0
  12. data/app/assets/javascripts/hancock/rails_admin/navigation_dropdown.coffee +25 -0
  13. data/app/assets/javascripts/hancock/rails_admin/navigation_filter.coffee +108 -0
  14. data/app/assets/javascripts/hancock/rails_admin/navigation_scroll.coffee +12 -0
  15. data/app/assets/javascripts/hancock/rails_admin/plugins.coffee.erb +16 -0
  16. data/app/assets/javascripts/jquery.placeholder.js +3 -2
  17. data/app/assets/javascripts/rails_admin/custom/ui.coffee +1 -0
  18. data/app/assets/stylesheets/hancock/cms/devise.sass +4 -1
  19. data/app/assets/stylesheets/hancock/rails_admin/cms.theming.sass +354 -147
  20. data/app/assets/stylesheets/hancock/rails_admin/fieldsets.sass +198 -0
  21. data/app/assets/stylesheets/hancock/rails_admin/plugins.sass.erb +6 -0
  22. data/app/assets/stylesheets/rails_admin/custom/theming.sass +1 -1
  23. data/app/controllers/concerns/hancock/decorators/home.rb +1 -1
  24. data/app/controllers/concerns/hancock/errors.rb +5 -7
  25. data/app/controllers/hancock/registrations_controller.rb +2 -7
  26. data/app/controllers/hancock/sessions_controller.rb +3 -7
  27. data/app/helpers/hancock/powered_helper.rb +3 -3
  28. data/app/helpers/hancock/settings_helper.rb +44 -0
  29. data/app/helpers/rails_admin/application/hancock_helper.rb +19 -0
  30. data/app/helpers/rails_admin/hancock/form_builder.rb +44 -0
  31. data/app/helpers/rails_admin/main/hancock_helper.rb +51 -0
  32. data/app/models/concerns/hancock/boolean_field.rb +7 -2
  33. data/app/models/concerns/hancock/decorators/embedded_element.rb +1 -9
  34. data/app/models/concerns/hancock/enableable.rb +1 -0
  35. data/app/models/concerns/hancock/hash_field.rb +9 -8
  36. data/app/models/concerns/hancock/html_field.rb +6 -3
  37. data/app/models/concerns/hancock/insertion_field.rb +115 -0
  38. data/app/models/concerns/hancock/mappable.rb +1 -0
  39. data/app/models/concerns/hancock/master_collection.rb +31 -0
  40. data/app/models/concerns/hancock/model_localizeable.rb +4 -1
  41. data/app/models/concerns/hancock/rails_admin_patch.rb +22 -3
  42. data/app/models/concerns/hancock/sort_field.rb +26 -3
  43. data/app/models/concerns/hancock/sortable.rb +3 -0
  44. data/app/models/concerns/hancock/user_defined.rb +53 -0
  45. data/app/views/blocks/_footer.html.slim +1 -1
  46. data/app/views/devise/passwords/edit.html.slim +0 -2
  47. data/app/views/devise/passwords/new.html.slim +0 -2
  48. data/app/views/devise/registrations/edit.html.slim +0 -2
  49. data/app/views/devise/registrations/new.html.slim +0 -2
  50. data/app/views/devise/sessions/new.html.slim +0 -2
  51. data/app/views/hancock/home/index.html.slim +4 -1
  52. data/app/views/layouts/application.html.slim +1 -11
  53. data/app/views/layouts/hancock/_assets.html.slim +15 -0
  54. data/app/views/layouts/hancock/devise/confirmations.html.slim +7 -4
  55. data/app/views/layouts/hancock/devise/passwords.html.slim +7 -4
  56. data/app/views/layouts/hancock/devise/registrations.html.slim +7 -4
  57. data/app/views/layouts/hancock/devise/sessions.html.slim +7 -4
  58. data/app/views/layouts/hancock/devise/unlocks.html.slim +7 -4
  59. data/app/views/layouts/rails_admin/_footer.html.slim +2 -2
  60. data/app/views/layouts/rails_admin/_footer_navigation.html.slim +20 -4
  61. data/app/views/layouts/rails_admin/_navigation.html.slim +13 -47
  62. data/app/views/layouts/rails_admin/_secondary_navigation.html.slim +5 -12
  63. data/app/views/layouts/rails_admin/_sidebar_navigation.html.slim +2 -0
  64. data/app/views/layouts/rails_admin/_sidebar_navigation_filter.html.slim +3 -0
  65. data/app/views/layouts/rails_admin/application.html.haml +3 -38
  66. data/app/views/rails_admin/main/_enum_for_settings_kinds.html.slim +24 -0
  67. data/app/views/rails_admin/main/_form_hancock_enum.html.slim +18 -0
  68. data/app/views/rails_admin/main/_form_hancock_enum_with_custom.slim +20 -0
  69. data/app/views/rails_admin/main/_hancock_html.html.slim +2 -2
  70. data/app/views/rails_admin/main/_hancock_html_ml.html.slim +31 -34
  71. data/app/views/rails_admin/main/edit.html.haml +18 -0
  72. data/app/views/rails_admin/main/new.html.haml +17 -0
  73. data/app/views/shared/_admin_link.html.slim +4 -2
  74. data/config/initializers/nested_set_patch.rb +76 -73
  75. data/config/initializers/rails_admin_mongoid_patch.rb +27 -0
  76. data/config/initializers/sprockets_patch.rb +159 -0
  77. data/config/locales/en.hancock.yml +1 -0
  78. data/config/locales/ru.devise.yml +22 -18
  79. data/config/locales/ru.hancock.yml +5 -5
  80. data/config/locales/ru.rails_admin.yml +3 -0
  81. data/hancock_cms.gemspec +7 -2
  82. data/lib/filename_to_slug.rb +0 -20
  83. data/lib/generators/hancock/cms/ability_generator.rb +1 -0
  84. data/lib/generators/hancock/cms/admin_generator.rb +1 -0
  85. data/lib/generators/hancock/cms/application_generator.rb +1 -0
  86. data/lib/generators/hancock/cms/assets_generator.rb +1 -0
  87. data/lib/generators/hancock/cms/layout_generator.rb +1 -0
  88. data/lib/generators/hancock/cms/model_generator.rb +1 -0
  89. data/lib/generators/hancock/cms/models/templates/embedded_element.erb +2 -2
  90. data/lib/generators/hancock/cms/rack_generator.rb +1 -0
  91. data/lib/generators/hancock/cms/raven_generator.rb +13 -0
  92. data/lib/generators/hancock/cms/robots_generator.rb +1 -0
  93. data/lib/generators/hancock/cms/scripts_generator.rb +1 -0
  94. data/lib/generators/hancock/cms/setup_generator.rb +146 -33
  95. data/lib/generators/hancock/cms/templates/Gemfile.erb +4 -5
  96. data/lib/generators/hancock/cms/templates/ability.erb +1 -1
  97. data/lib/generators/hancock/cms/templates/admin.erb +12 -4
  98. data/lib/generators/hancock/cms/templates/hancock_cms.erb +6 -3
  99. data/lib/generators/hancock/cms/templates/model.erb +5 -6
  100. data/lib/generators/hancock/cms/templates/raven.erb +13 -0
  101. data/lib/generators/hancock/cms/templates/robots.txt.erb +6 -2
  102. data/lib/generators/hancock/cms/templates/scripts/db_dump.sh.erb +1 -1
  103. data/lib/generators/hancock/cms/unicorn_god_generator.rb +1 -0
  104. data/lib/generators/hancock/cms/utils.rb +2 -0
  105. data/lib/hancock/admin.rb +153 -21
  106. data/lib/hancock/admin/embedded_element.rb +7 -2
  107. data/lib/hancock/configuration.rb +49 -4
  108. data/lib/hancock/controller.rb +1 -1
  109. data/lib/hancock/engine.rb +32 -36
  110. data/lib/hancock/model.rb +10 -0
  111. data/lib/hancock/models/embedded_element.rb +2 -0
  112. data/lib/hancock/models/mongoid/embedded_element.rb +17 -0
  113. data/lib/hancock/plugin_configuration.rb +1 -1
  114. data/lib/hancock/rails_admin_ext/config.rb +21 -4
  115. data/lib/hancock/rails_admin_ext/hancock_array.rb +19 -0
  116. data/lib/hancock/rails_admin_ext/hancock_enum.rb +33 -0
  117. data/lib/hancock/rails_admin_ext/hancock_enum_with_custom.rb +34 -0
  118. data/lib/hancock/rails_admin_ext/hancock_hash.rb +8 -1
  119. data/lib/hancock/rails_admin_ext/hancock_html.rb +17 -2
  120. data/lib/hancock/rails_admin_ext/hancock_multiselect.rb +1 -5
  121. data/lib/hancock/rails_admin_ext/hancock_slugs.rb +2 -6
  122. data/lib/hancock/rails_admin_ext/patches/field_patch.rb +2 -1
  123. data/lib/hancock/rails_admin_ext/patches/fieldset_patch.rb +14 -0
  124. data/lib/hancock/rails_admin_ext/patches/group_patch.rb +9 -0
  125. data/lib/hancock/rails_admin_ext/patches/hancock_cms_group.rb +2 -0
  126. data/lib/hancock/rails_admin_ext/patches/has_fields.rb +27 -0
  127. data/lib/hancock/rails_admin_ext/patches/navigation_patch.rb +25 -0
  128. data/lib/hancock/rails_admin_settings_patch.rb +219 -0
  129. data/lib/hancock/version.rb +1 -1
  130. data/lib/hancock_cms.rb +12 -9
  131. data/lib/manual_slug/active_record.rb +8 -8
  132. data/lib/manual_slug/mongoid.rb +6 -1
  133. data/lib/rails_admin/custom_show_in_app.rb +21 -32
  134. data/template.rb +19 -20
  135. metadata +104 -12
  136. data/app/controllers/concerns/hancock/no_cache.rb +0 -12
  137. data/app/models/concerns/hancock/cacheable.rb +0 -51
@@ -8,7 +8,7 @@ gem 'sass-rails'
8
8
  gem 'compass-rails'
9
9
  gem 'compass'
10
10
 
11
- #{if mongoid then "gem 'hancock_cms_mongoid'" else "gem 'hancock_cms_activerecord'" end}, path: '/home/ack/www/hancock_cms' #'~> 0.3.7'
11
+ #{if mongoid then "gem 'hancock_cms_mongoid'" else "gem 'hancock_cms_activerecord'" end}
12
12
 
13
13
  gem 'devise'
14
14
 
@@ -20,9 +20,6 @@ gem 'cancancan'
20
20
  gem 'unicorn'
21
21
  gem 'x-real-ip'
22
22
 
23
- #temp
24
- #gem 'sentry-raven'
25
-
26
23
  group :development do
27
24
  gem 'better_errors'
28
25
  gem 'binding_of_caller'
@@ -57,7 +54,7 @@ group :test do
57
54
  gem 'factory_girl_rails'
58
55
  end
59
56
 
60
- #{if mongoid then "gem 'mongo_session_store-rails4'" else "gem 'activerecord-session_store'" end}
57
+ #{if mongoid then "gem 'mongo_session_store-rails5'" else "gem 'activerecord-session_store'" end}
61
58
 
62
59
  gem 'slim'
63
60
  gem 'sprockets'
@@ -65,5 +62,7 @@ gem 'sprockets'
65
62
  gem 'uglifier'
66
63
 
67
64
  group :production do
65
+ #temp
66
+ #gem 'sentry-raven'
68
67
  gem "god"
69
68
  end
@@ -14,7 +14,7 @@ class Ability
14
14
 
15
15
  can :index, :all
16
16
  can :read, :all
17
- can :history, :all
17
+ can :history, :all if Hancock.config.history_tracking
18
18
  can :export, :all
19
19
  can :toggle, :all
20
20
 
@@ -1,7 +1,12 @@
1
1
  require 'rails_admin/custom_show_in_app'
2
2
 
3
+ require_relative 'hancock_cms'
4
+ # Add `require_relative '%hancock_plugin_name%'` here for configure it.
5
+ # `require_relative 'hancock_cms'` reconfigure it by default.
6
+ # So u need do it again. If u have some changes.
7
+
3
8
  <% if Hancock.mongoid? %>
4
- RailsAdminSettings.track_history!
9
+ RailsAdminSettings.track_history! if Hancock.config.history_tracking
5
10
  <% end %>
6
11
 
7
12
  RailsAdmin.config do |config|
@@ -39,8 +44,10 @@ RailsAdmin.config do |config|
39
44
  edit
40
45
  delete
41
46
 
42
- history_index
43
- history_show
47
+ if Hancock.config.history_tracking
48
+ history_index
49
+ history_show
50
+ end
44
51
 
45
52
  toggle
46
53
  # toggle_menu # for Hancock::Pages
@@ -54,10 +61,11 @@ RailsAdmin.config do |config|
54
61
  config.excluded_models ||= []
55
62
  config.excluded_models << [
56
63
  'RailsAdmin::CustomShowInApp', 'HistoryTracker',
57
- 'Ckeditor::Asset', 'Ckeditor::AttachmentFile', 'Ckeditor::Picture',
64
+ 'Ckeditor::Asset', 'Ckeditor::AttachmentFile', 'Ckeditor::Picture', 'Ckeditor::Folder',
58
65
  'Hancock::EmbeddedElement'
59
66
  ]
60
67
  config.excluded_models.flatten!
68
+ config.excluded_models.uniq!
61
69
  end
62
70
 
63
71
  # [required] fix for timezones to be displayed in local time instead of UTC
@@ -3,7 +3,8 @@ Hancock.configure do |config|
3
3
  # config.main_index_layout = 'application'
4
4
  # config.error_layout = 'application'
5
5
  #
6
- # config.localize = false
6
+ # config.localize = !!defined?(RailsAdminMongoidLocalizeField) #false
7
+ # config.raven_support = !!defined?(Raven)
7
8
  #
8
9
  # config.ability_manager_config = []
9
10
  ### example ###
@@ -20,8 +21,8 @@ Hancock.configure do |config|
20
21
  # actions: :manage
21
22
  # }
22
23
  #
23
- # config.recaptcha_support = defined?(Recaptcha)
24
- # config.simple_captcha_support = defined?(SimpleCaptcha)
24
+ # config.recaptcha_support = !!defined?(Recaptcha)
25
+ # config.simple_captcha_support = !!defined?(SimpleCaptcha)
25
26
  #
26
27
  # config.admin_enter_captcha = config.recaptcha_support or config.simple_captcha_support
27
28
  # config.registration_captcha = config.admin_enter_captcha
@@ -29,4 +30,6 @@ Hancock.configure do |config|
29
30
  # config.captcha_on_development = false
30
31
  #
31
32
  # config.history_tracking = false
33
+ #
34
+ # config.mongoid_single_collection = nil # or set colection_name or `true` for default (:hancock_master_collection)
32
35
  end
@@ -1,19 +1,19 @@
1
1
  class <%= camelcased_class_name %>
2
2
  include Hancock::Model
3
3
  # include Hancock::Enableable
4
- # include Hancock::Cacheable
5
4
  # include ManualSlug
6
5
 
6
+ # include Hancock::Cache::Cacheable
7
+ # def self.default_cache_keys
8
+ # []
9
+ # end
10
+
7
11
  # acts_as_nested_set
8
12
  # scope :sorted, -> { order_by([:lft, :asc]) }
9
13
 
10
14
  field :name
11
15
  # manual_slug :name
12
16
 
13
- # def self.default_cache_keys
14
- # []
15
- # end
16
-
17
17
  ############# rails_admin ##############
18
18
  #
19
19
  # def self.admin_can_user_defined_actions
@@ -36,7 +36,6 @@ class <%= camelcased_class_name %>
36
36
  # field :enabled, :toggle
37
37
  field :name
38
38
  # group :url, &Hancock::Admin.url_block
39
- # group :cache, &Hancock::Admin.caching_block
40
39
  end
41
40
 
42
41
  end
@@ -0,0 +1,13 @@
1
+ if defined?(Raven)
2
+ Raven.configure do |config|
3
+ config.sanitize_fields = Rails.application.config.filter_parameters.map(&:to_s)
4
+
5
+ # config.dsn = 'https://%public%:%secret%@sentry.io/%id%'
6
+ config.environments = ['production']
7
+
8
+ config.async = lambda { |event|
9
+ Thread.new { Raven.send_event(event) }
10
+ }
11
+
12
+ end
13
+ end
@@ -1,5 +1,9 @@
1
- Host: <%= app_name.downcase %>.ru
1
+ Host: https://<%= app_name.downcase %>.ru
2
2
  User-Agent: *
3
3
  Allow: /
4
4
  Disallow: /admin
5
- Sitemap: http://<%= app_name.downcase %>.ru/sitemap.xml.gz
5
+ # Disallow: /account
6
+ Disallow: /ckeditor/*
7
+ # Disallow: /goto
8
+ # Disallow: /users
9
+ Sitemap: https://<%= app_name.downcase %>.ru/sitemap.xml.gz
@@ -1,3 +1,3 @@
1
1
  #!/bin/sh
2
2
 
3
- mongodump --db <%= app_name.downcase %>
3
+ mongodump --db <%= app_name.underscore %>
@@ -11,5 +11,6 @@ module Hancock::Cms
11
11
  template 'unicorn.erb', "config/unicorn.rb"
12
12
  template 'unicorn.god.erb', "config/unicorn.god"
13
13
  end
14
+
14
15
  end
15
16
  end
@@ -4,6 +4,7 @@ module Hancock::Cms
4
4
  module Generators
5
5
  module Utils
6
6
  module InstanceMethods
7
+
7
8
  def display(output, color = :green)
8
9
  say(" - #{output}", color)
9
10
  end
@@ -15,6 +16,7 @@ module Hancock::Cms
15
16
  ask(" ? #{wording} Press <enter> for [#{default_value}] >", :yellow).presence || default_value
16
17
  end
17
18
  end
19
+
18
20
  end
19
21
  end
20
22
  end
data/lib/hancock/admin.rb CHANGED
@@ -1,18 +1,67 @@
1
1
  module Hancock
2
2
  module Admin
3
- def self.map_config(is_active = false)
3
+ def self.map_config(is_active = false, options = {})
4
+ if is_active.is_a?(Hash)
5
+ is_active, options = (is_active[:active] || false), is_active
6
+ end
7
+ fields = (options[:fields] ||= {})
8
+ field_names = [:slugs, :text_slug]
9
+ field_showings = get_field_showings(fields, field_names)
10
+
4
11
  Proc.new {
5
12
  active is_active
6
- label I18n.t('hancock.map')
7
- field :address, :string
8
- field :map_address, :string
9
- field :map_hint, :string
13
+ label options[:label] || I18n.t('hancock.map')
14
+
15
+ field :address, :string do
16
+ searchable true
17
+ end if field_showings[:address]
18
+
19
+ field :map_address, :string do
20
+ searchable true
21
+ end if field_showings[:map_address]
22
+
23
+ field :map_hint, :string do
24
+ searchable true
25
+ end if field_showings[:map_hint]
26
+
10
27
  field :coordinates, :string do
28
+ searchable true
11
29
  read_only true
12
30
  formatted_value{ bindings[:object].coordinates.to_json }
31
+ end if field_showings[:coordinates]
32
+
33
+ field :lat do
34
+ searchable true
35
+ end if field_showings[:lat]
36
+
37
+ field :lon do
38
+ searchable true
39
+ end if field_showings[:lon]
40
+
41
+
42
+ Hancock::RailsAdminGroupPatch::hancock_cms_group(self, options[:fields])
43
+
44
+ if block_given?
45
+ yield self
13
46
  end
14
- field :lat
15
- field :lon
47
+ }
48
+ end
49
+
50
+ def self.url_block(is_active = false, options = {})
51
+ if is_active.is_a?(Hash)
52
+ is_active, options = (is_active[:active] || false), is_active
53
+ end
54
+ fields = (options[:fields] ||= {})
55
+ field_names = [:slugs, :text_slug]
56
+ field_showings = get_field_showings(fields, field_names)
57
+
58
+ Proc.new {
59
+ active is_active
60
+ label options[:label] || I18n.t('hancock.url')
61
+ field :slugs, :hancock_slugs if field_showings[:slugs]
62
+ field :text_slug if field_showings[:text_slug]
63
+
64
+ Hancock::RailsAdminGroupPatch::hancock_cms_group(self, options[:fields])
16
65
 
17
66
  if block_given?
18
67
  yield self
@@ -20,12 +69,21 @@ module Hancock
20
69
  }
21
70
  end
22
71
 
23
- def self.caching_block(is_active = false)
72
+ def self.content_block(is_active = false, options = {})
73
+ if is_active.is_a?(Hash)
74
+ is_active, options = (is_active[:active] || false), is_active
75
+ end
76
+ fields = (options[:fields] ||= {})
77
+ field_names = [:excerpt, :content]
78
+ field_showings = get_field_showings(fields, field_names)
79
+
24
80
  Proc.new {
25
81
  active is_active
26
- label I18n.t('hancock.cache')
27
- field :perform_caching, :toggle
28
- field :cache_keys_str, :text
82
+ label options[:label] || I18n.t('hancock.content')
83
+ field :excerpt, :hancock_html if field_showings[:excerpt]
84
+ field :content, :hancock_html if field_showings[:content]
85
+
86
+ Hancock::RailsAdminGroupPatch::hancock_cms_group(self, options[:fields] || {})
29
87
 
30
88
  if block_given?
31
89
  yield self
@@ -33,28 +91,102 @@ module Hancock
33
91
  }
34
92
  end
35
93
 
36
- def self.url_block(is_active = false)
94
+ def self.categories_block(is_active = false, options = {})
95
+ if is_active.is_a?(Hash)
96
+ is_active, options = (is_active[:active] || false), is_active
97
+ end
98
+ fields = (options[:fields] ||= {})
99
+ field_names = [:main_category, :categories]
100
+ field_showings = get_field_showings(fields, field_names)
101
+
37
102
  Proc.new {
38
103
  active is_active
39
- label I18n.t('hancock.url')
40
- field :slugs, :hancock_slugs
41
- field :text_slug
104
+ label options[:label] || I18n.t('hancock.categories')
105
+
106
+ field :main_category do
107
+ inline_add false
108
+ inline_edit false
109
+ end if field_showings[:main_category]
110
+ field :categories, :hancock_multiselect if field_showings[:categories]
111
+
112
+ Hancock::RailsAdminGroupPatch::hancock_cms_group(self, options[:fields] || {})
113
+
114
+ if block_given?
115
+ yield self
116
+ end
42
117
  }
43
118
  end
44
119
 
45
- def self.content_block(is_active = false, options = {})
120
+
121
+ def self.insertions_block(is_active = false, options = {})
46
122
  if is_active.is_a?(Hash)
47
- is_active, fields = (is_active[:active] || false), is_active
123
+ is_active, options = (is_active[:active] || false), is_active
48
124
  end
125
+ fields = (options[:fields] ||= {})
126
+ field_names = [:possible_insertions]
127
+ field_showings = get_field_showings(fields, field_names)
49
128
 
50
- _excluded_fields = options.delete(:excluded_fields) || []
51
129
  Proc.new {
52
130
  active is_active
53
- label I18n.t('hancock.content')
54
- field :excerpt, :hancock_html unless _excluded_fields.include?(:excerpt)
55
- field :content, :hancock_html unless _excluded_fields.include?(:content)
131
+ label options[:label] || I18n.t('hancock.insertions')
132
+ field :possible_insertions do
133
+ read_only true
134
+ pretty_value do
135
+ ("<dl class='possible_insertions_list'>" + bindings[:object].possible_insertions.map do |_ins|
136
+ "<dt>#{_ins}</dt><dd>#{bindings[:object].send(_ins)}</dd>"
137
+ end.join + "</dl>").html_safe
138
+ end
139
+ end if field_showings[:possible_insertions]
140
+
141
+ Hancock::RailsAdminGroupPatch::hancock_cms_group(self, options[:fields] || {})
142
+
143
+ if block_given?
144
+ yield self
145
+ end
56
146
  }
57
147
  end
58
148
 
149
+ def self.user_defined_field_block(field_name, is_active = false, options = {})
150
+ if field_name.is_a?(Hash)
151
+ field_name, is_active, options = (field_name[:field_name] || field_name[:field]), (field_name[:active] || false), field_name
152
+ elsif is_active.is_a?(Hash)
153
+ is_active, options = (is_active[:active] || false), is_active
154
+ end
155
+ field_name = field_name.to_sym
156
+ render_method = options[:render_method] || "render_#{field_name}"
157
+
158
+ fields = (options[:fields] ||= {})
159
+ field_names = [field_name, render_method]
160
+ field_showings = get_field_showings(fields, field_names)
161
+
162
+ Proc.new {
163
+ active is_active
164
+ label options[:label]# || I18n.t('hancock.user_defined_field')
165
+ field @abstract_model.model.user_defined_fields[field_name][:render_method], :toggle if field_showings[render_method]
166
+ field field_name, :ck_editor if field_showings[field_name]
167
+
168
+ Hancock::RailsAdminGroupPatch::hancock_cms_group(self, options[:fields] || {})
169
+
170
+ if block_given?
171
+ yield self
172
+ end
173
+ }
174
+ end
175
+
176
+ def self.get_field_showings(fields, field_names)
177
+ field_showings = field_names.map { |f| {f => true } }.inject(&:merge) || {}
178
+ if fields.is_a?(Hash)
179
+ field_names.each do |f|
180
+ field_showings[f] = (fields[f] != false)
181
+ end
182
+ elsif fields.is_a?(Array)
183
+ _fields = fields.map { |f| f[:fields] }.inject(&:merge) || {}
184
+ field_names.each do |f|
185
+ field_showings[f] = (_fields[f] != false)
186
+ end
187
+ end
188
+ field_showings
189
+ end
190
+
59
191
  end
60
192
  end
@@ -1,21 +1,25 @@
1
1
  module Hancock
2
2
  module Admin
3
3
  module EmbeddedElement
4
+
4
5
  def self.config(nav_label = nil, fields = {})
5
6
  if nav_label.is_a?(Hash)
6
7
  nav_label, fields = nav_label[:nav_label], nav_label
7
8
  elsif nav_label.is_a?(Array)
8
9
  nav_label, fields = nil, nav_label
9
10
  end
11
+ fields ||= {}
12
+ field_names = [:enabled, :name]
13
+ field_showings = Hancock::Admin.get_field_showings(fields, field_names)
10
14
 
11
15
  Proc.new {
12
16
  navigation_label(nav_label || I18n.t('hancock.cms'))
13
17
  field :enabled, :toggle do
14
18
  searchable false
15
- end
19
+ end if field_showings[:enabled]
16
20
  field :name, :string do
17
21
  searchable true
18
- end
22
+ end if field_showings[:name]
19
23
 
20
24
  Hancock::RailsAdminGroupPatch::hancock_cms_group(self, fields)
21
25
 
@@ -24,6 +28,7 @@ module Hancock
24
28
  end
25
29
  }
26
30
  end
31
+
27
32
  end
28
33
  end
29
34
  end