rails_admin_cms 0.0.2 → 0.0.3

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/rails_admin_cms/all.js.coffee +4 -1
  3. data/app/assets/javascripts/rails_admin_cms/cms.js.coffee +95 -13
  4. data/app/controllers/cms/forms_controller.rb +0 -3
  5. data/app/helpers/cms/form_helper.rb +3 -0
  6. data/app/helpers/cms/javascript_helper.rb +7 -0
  7. data/app/helpers/cms/view_helper.rb +1 -1
  8. data/app/helpers/cms/viewable_helper.rb +2 -2
  9. data/app/models/admin/form/row/as_header.rb +15 -0
  10. data/app/models/admin/viewable/form.rb +1 -1
  11. data/app/models/form.rb +5 -10
  12. data/app/models/form/row.rb +4 -0
  13. data/app/models/form/row/as_header.rb +19 -0
  14. data/app/models/form/static.rb +4 -0
  15. data/app/models/form/structure.rb +5 -3
  16. data/app/models/naming/form.rb +13 -0
  17. data/app/models/naming/viewable.rb +13 -0
  18. data/app/models/naming/viewable/block.rb +29 -0
  19. data/app/models/naming/viewable/form.rb +15 -0
  20. data/app/models/naming/viewable/page.rb +11 -0
  21. data/app/models/viewable.rb +1 -23
  22. data/app/models/viewable/block.rb +0 -24
  23. data/app/models/viewable/form.rb +11 -10
  24. data/app/models/viewable/page.rb +0 -6
  25. data/app/presenters/viewable/form_presenter.rb +1 -6
  26. data/app/presenters/viewable/view_presenter.rb +5 -1
  27. data/app/presenters/viewable_list_presenter.rb +2 -2
  28. data/app/presenters/viewable_presenter.rb +10 -2
  29. data/app/views/cms/forms/create.js.erb +2 -2
  30. data/app/views/cms/shared/_flash_messages.js.erb +1 -1
  31. data/config/routes.rb +2 -2
  32. data/lib/active_type/virtual_attributes_decorator.rb +27 -0
  33. data/lib/generators/cms/install/templates/app/views/cms/forms/contact/_form.html.erb +0 -7
  34. data/lib/generators/cms/install/templates/app/views/cms/forms/contact/new.html.erb +5 -0
  35. data/lib/generators/cms/install/templates/app/views/cms/pages/page.html.erb +3 -3
  36. data/lib/generators/cms/install/templates/config/initializers/rails_admin.rb +5 -5
  37. data/lib/rails_admin_cms.rb +1 -0
  38. data/lib/rails_admin_cms/version.rb +1 -1
  39. metadata +11 -5
  40. data/app/assets/javascripts/rails_admin_cms/cms/flashes.js.coffee +0 -2
  41. data/app/assets/javascripts/rails_admin_cms/cms/with_scope/forms.js.coffee +0 -4
  42. data/app/assets/javascripts/rails_admin_cms/cms/with_scope/viewables.js.coffee +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f4ab2a876fced32bee134b71d05c7f197eff9d8
4
- data.tar.gz: 591c16de5bb08f0d191debcc2d84f16996f8c551
3
+ metadata.gz: aca625467f4115ced159d95b214b2f6122102f59
4
+ data.tar.gz: 5a7620fc1c7846cfdc0c7a4aaf7b7b8b9fdd89b1
5
5
  SHA512:
6
- metadata.gz: 2af4b0b5c9d21228d16daedf9a139af1789dcda75211a74b68a9dc3a08bcf2c343a8276e99f9a3957543f1de50bf5f8a2959cde761515ca9dffe1ba42ab36622
7
- data.tar.gz: 39f1f65e47c0f08cdf1d21c4f9a8c4cccbcd35f8cad20bb7b4b9ad64477fe5deba1f8e64ce862a83a81b39d32dac69018be2c76eb17bb577e89e4b2714748d8b
6
+ metadata.gz: 3d1d94efde4c1c8a0ccb665a8a71cf878d11b2d7316b59516cc6fdbfd81a36be89de1da854bbce6f1dbf6da03540c42a598e32d4e889dc11f1e3f55e181de788
7
+ data.tar.gz: 0fe2ddbd1f4c55f816af3f2b528712e721801448ceedaa0eb6f9d5424deaee49274f4e31aad608035ac4e64c083a7187d83fd8aa64ff8164d11eafb8bd94acd7
@@ -1,2 +1,5 @@
1
+ #= require jquery
2
+ #= require jquery_ujs
3
+ #= require jquery.form-validator
4
+ #= require jquery-ui/sortable
1
5
  #= require ./cms
2
- #= require_tree ./cms
@@ -1,18 +1,100 @@
1
- window.CMS ||= {}
1
+ $.fn.extend
2
+ cms_data: (name = null) ->
3
+ if name?
4
+ $(this).data("js-#{ name }")
5
+ else
6
+ for key, value of $(this).data()
7
+ if key.match /^js/
8
+ return value
2
9
 
3
- CMS.with_scope = (body_class, callback) ->
4
- if $('body').hasClass(body_class)
5
- callback()
10
+ class CMS
11
+ @start: =>
12
+ @ready =>
13
+ @clear_event_handlers()
14
+ @flash_messages()
6
15
 
7
- CMS.ready = (callback) ->
8
- $(document).on 'ready page:change', ->
9
- callback()
16
+ @ready_with_scope 'cms-forms', =>
17
+ @validate()
10
18
 
11
- CMS.ready_with_scope = (body_class, callback) ->
12
- CMS.ready ->
13
- CMS.with_scope(body_class, callback)
19
+ @ready_with_scope 'cms-edit-mode', =>
20
+ @element('cms-sortable').each ->
21
+ $(this).sortable
22
+ update: (event, ui) ->
23
+ url = $(this).cms_data()['url']
14
24
 
15
- #------------------------------------------------------------------------------#
25
+ target = $(ui.item)
26
+ id = target.cms_data('cms-sortable-id')
27
+ unique_key = { position: target.index() + 1 }
28
+ payload = $.param(id: id, unique_key: unique_key)
16
29
 
17
- CMS.ready ->
18
- CMS.flash_messages()
30
+ $.post(url, payload)
31
+
32
+
33
+ # https://github.com/gemgento/rails_script/blob/master/lib/generators/rails_script/install/templates/base.js.coffee
34
+ @clear_event_handlers: =>
35
+ $(document).on 'page:before-change', ->
36
+ for element in [window, document]
37
+ for event, handlers of ($._data(element, 'events') || {})
38
+ for handler in handlers
39
+ if handler? && handler.namespace == ''
40
+ $(element).off event, handler.handler
41
+
42
+ @flash_messages: =>
43
+ @element('cms-flash').fadeIn().delay(3500).fadeOut(800)
44
+
45
+ @validate: =>
46
+ $.validate(validateOnBlur: false)
47
+
48
+ @with_scope_any: (body_classes..., handler) =>
49
+ for body_class in body_classes
50
+ if @with_scope(body_class, handler)
51
+ return
52
+
53
+ @with_scope_all: (body_classes..., handler) =>
54
+ for body_class in body_classes
55
+ if !$('body').hasClass(body_class)
56
+ return
57
+ handler()
58
+
59
+ @with_scope_none: (body_classes..., handler) =>
60
+ without_scope = true
61
+ for body_class in body_classes
62
+ if $('body').hasClass(body_class)
63
+ without_scope = false
64
+ if without_scope
65
+ handler()
66
+
67
+ @with_scope: (body_class, handler) =>
68
+ if $('body').hasClass(body_class)
69
+ handler()
70
+ true
71
+ else
72
+ false
73
+
74
+ @ready_with_scope_any: (body_classes..., handler) =>
75
+ @ready =>
76
+ @with_scope_any(body_classes..., handler)
77
+
78
+ @ready_with_scope_all: (body_classes..., handler) =>
79
+ @ready =>
80
+ @with_scope_all(body_classes..., handler)
81
+
82
+ @ready_with_scope_none: (body_classes..., handler) =>
83
+ @ready =>
84
+ @with_scope_none(body_classes..., handler)
85
+
86
+ @ready_with_scope: (body_class, handler) =>
87
+ @ready =>
88
+ @with_scope(body_class, handler)
89
+
90
+ @ready: (handler) =>
91
+ $(document).on 'ready page:change', ->
92
+ handler()
93
+
94
+ @element_on: (name, events, handler) =>
95
+ $(document).on(events, "[data-js-#{ name }]", handler)
96
+
97
+ @element: (name) =>
98
+ $("[data-js-#{ name }]")
99
+
100
+ window.CMS = CMS
@@ -13,9 +13,6 @@ module CMS
13
13
  load_form
14
14
 
15
15
  if cms_form_instance.save
16
- if cms_form_instance.with_email?
17
- FormsMailer.send_email(cms_form_instance).deliver_now
18
- end
19
16
  reset_form
20
17
  flash_now!(:success)
21
18
  else
@@ -4,6 +4,9 @@ module CMS
4
4
  simple_form_for(cms_form_instance, cms_form_options(options)) do |f|
5
5
  concat f.invisible_captcha(:_subtitle)
6
6
  yield f
7
+ if @cms_view
8
+ concat f.input(:structure_id, as: :hidden, input_html: { value: cms_form_instance.structure_id })
9
+ end
7
10
  end
8
11
  end
9
12
 
@@ -0,0 +1,7 @@
1
+ module CMS
2
+ module JavascriptHelper
3
+ def cms_js_element(name, data = true, options = {})
4
+ { "data-js-#{name}" => data.to_json }.merge(options)
5
+ end
6
+ end
7
+ end
@@ -14,7 +14,7 @@ module CMS
14
14
  end
15
15
 
16
16
  def cms_flash_messages(*args)
17
- content_tag :div, class: 'cms-flash-messages', 'data-cms-flash' => true do
17
+ content_tag :div, cms_js_element('cms-flash', true, class: 'cms-flash-messages') do
18
18
  flash_messages(*args)
19
19
  end
20
20
  end
@@ -8,7 +8,7 @@ module CMS
8
8
  end
9
9
  end
10
10
 
11
- Viewable::Block.names.each do |type|
11
+ Naming::Viewable::Block.names.each do |type|
12
12
  define_cms_view_helper(type)
13
13
 
14
14
  define_method "cms_#{type}" do |name = 'cms', min = 1, max = nil| # max = FLOAT::INFINITY
@@ -18,7 +18,7 @@ module CMS
18
18
  end
19
19
  end
20
20
 
21
- Viewable.names.each do |type|
21
+ Naming::Viewable.names.each do |type|
22
22
  define_cms_view_helper(type)
23
23
 
24
24
  define_method "cms_#{type}" do |name = 'cms', min = 1, max = nil| # max = FLOAT::INFINITY
@@ -0,0 +1,15 @@
1
+ module Admin
2
+ module Form
3
+ module Row
4
+ module AsHeader
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ rails_admin do
9
+ visible false
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -12,7 +12,7 @@ module Admin
12
12
  field :structure do
13
13
  pretty_value do
14
14
  h, name = bindings[:view], value.name
15
- path = "#{h.dashboard_path}form~row?model_name=form~row&scope#{name}"
15
+ path = "#{ h.dashboard_path }form~row?#{ { model_name: 'form~row', scope: name }.to_query }"
16
16
  h.link_to name, path
17
17
  end
18
18
 
data/app/models/form.rb CHANGED
@@ -7,6 +7,7 @@ module Form
7
7
  validates :_subtitle, invisible_captcha: true
8
8
 
9
9
  before_save :set_locale
10
+ after_save :send_email, if: :with_email?
10
11
 
11
12
  delegate :virtual?, :has_attachments?, :has_collections?, to: :class
12
13
  end
@@ -33,16 +34,6 @@ module Form
33
34
  end
34
35
  end
35
36
 
36
- class << self
37
- def structure_models
38
- %w[
39
- Form::Structure
40
- Form::Field
41
- Form::Email
42
- ]
43
- end
44
- end
45
-
46
37
  private
47
38
 
48
39
  def set_locale
@@ -50,4 +41,8 @@ module Form
50
41
  self.locale = I18n.locale
51
42
  end
52
43
  end
44
+
45
+ def send_email
46
+ CMS::FormsMailer.send_email(self).deliver_later
47
+ end
53
48
  end
@@ -14,6 +14,10 @@ module Form
14
14
  delegate :with_email?, :send_to, :subject, :body, :email_column_key, :header, to: :structure
15
15
  delegate :form_name, to: :viewable
16
16
 
17
+ def js_form_selector
18
+ "#new_form_#{model_name.element}"
19
+ end
20
+
17
21
  def send_from
18
22
  send(email_column_key) if email_column_key
19
23
  end
@@ -0,0 +1,19 @@
1
+ module Form
2
+ class Row::AsHeader < Row
3
+ include Admin::Form::Row::AsHeader
4
+
5
+ before_save :set_label
6
+
7
+ alias_attribute :label, :locale
8
+
9
+ def with_email?
10
+ false
11
+ end
12
+
13
+ private
14
+
15
+ def set_label
16
+ self.label = I18n.t('cms.form.header', locale: I18n.default_locale)
17
+ end
18
+ end
19
+ end
@@ -13,5 +13,9 @@ module Form
13
13
  def form_name
14
14
  model_name.element
15
15
  end
16
+
17
+ def js_form_selector
18
+ "#new_form_#{form_name}"
19
+ end
16
20
  end
17
21
  end
@@ -10,6 +10,8 @@ module Form
10
10
  belongs_to :email, dependent: :destroy
11
11
 
12
12
  validates :fields, length: { maximum: RailsAdminCMS::Config.custom_form_max_size }
13
+ validates :viewable, presence: true, on: :create
14
+ validates :email, presence: true, on: :create
13
15
 
14
16
  after_create :create_header
15
17
  after_update :expire_cache
@@ -30,17 +32,17 @@ module Form
30
32
  end
31
33
 
32
34
  def header
33
- rows.first
35
+ rows.first.becomes Row::AsHeader
34
36
  end
35
37
 
36
38
  private
37
39
 
38
40
  def create_header
39
- rows.create!(locale: I18n.t('cms.form.header', locale: I18n.default_locale))
41
+ Row::AsHeader.create!(structure: self)
40
42
  end
41
43
 
42
44
  def expire_cache
43
- viewable.touch
45
+ viewable.try(:touch)
44
46
  end
45
47
 
46
48
  module Splitter
@@ -0,0 +1,13 @@
1
+ module Naming
2
+ module Form
3
+ class << self
4
+ def structure_models
5
+ %w[
6
+ Form::Structure
7
+ Form::Field
8
+ Form::Email
9
+ ]
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Naming
2
+ module Viewable
3
+ class << self
4
+ def names
5
+ @_names ||= CMS.rb_all_names 'app/models/viewable'
6
+ end
7
+
8
+ def models
9
+ @_models ||= Naming::Viewable.names.map{ |name| "Viewable::#{name.camelize}" }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ module Naming
2
+ module Viewable
3
+ module Block
4
+ class << self
5
+ def restricted_names
6
+ @_restricted_names ||= Naming::Viewable.names + begin
7
+ CMS.constants.grep(/Helper$/).map{ |name|
8
+ "CMS::#{name}".constantize.instance_methods.grep(/^cms_/)
9
+ }.flatten.map{ |name|
10
+ name.to_s.sub(/^cms_/, '')
11
+ }
12
+ end
13
+ end
14
+
15
+ def names
16
+ @_names ||= begin
17
+ names = CMS.html_names 'app/views/cms/blocks'
18
+ names.each do |name|
19
+ if name.in? restricted_names
20
+ raise ArgumentError, "'cms/blocks/_#{name}.html' partial should be called otherwise, '#{name}' taken"
21
+ end
22
+ end
23
+ names
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ module Naming
2
+ module Viewable
3
+ module Form
4
+ class << self
5
+ def names
6
+ @_names ||= CMS.dir_names 'app/views/cms/forms'
7
+ end
8
+
9
+ def static_names
10
+ @_static_names ||= CMS.rb_names 'app/models/form'
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Naming
2
+ module Viewable
3
+ module Page
4
+ class << self
5
+ def names
6
+ @_names ||= CMS.html_names 'app/views/cms/pages'
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -21,7 +21,7 @@ module Viewable
21
21
  scope :localized, -> { includes(:unique_key).where(unique_keys: { locale: I18n.locale }) }
22
22
  scope :other_locale, ->(locale) { includes(:unique_key).where(unique_keys: { locale: locale }) }
23
23
 
24
- delegate :has_unlocalized_fields?, :unlocalized_fields, :viewable_type, :dashed_name, :underscored_name, to: :class
24
+ delegate :has_unlocalized_fields?, :unlocalized_fields, :viewable_type, to: :class
25
25
  end
26
26
 
27
27
  class_methods do
@@ -42,18 +42,6 @@ module Viewable
42
42
  def viewable_type
43
43
  name
44
44
  end
45
-
46
- def dashed_name
47
- @_dashed_name ||= underscored_name.dasherize
48
- end
49
-
50
- def underscored_name
51
- @_underscored_name ||= name.underscore.gsub('/', '_')
52
- end
53
- end
54
-
55
- def short_type
56
- viewable_type.demodulize.underscore
57
45
  end
58
46
 
59
47
  def list(locale = nil)
@@ -75,16 +63,6 @@ module Viewable
75
63
  .merge(locale: locale || self.locale)
76
64
  end
77
65
 
78
- class << self
79
- def models
80
- @_models ||= names.map{ |name| "Viewable::#{name.camelize}" }
81
- end
82
-
83
- def names
84
- @_names ||= CMS.rb_all_names 'app/models/viewable'
85
- end
86
- end
87
-
88
66
  private
89
67
 
90
68
  def expire_cache
@@ -11,29 +11,5 @@ module Viewable
11
11
  def partial_name
12
12
  @_partial_name ||= unique_key_name.partition('/').first
13
13
  end
14
-
15
- class << self
16
- def restricted_names
17
- @_restricted_names ||= Viewable.names + begin
18
- CMS.constants.grep(/Helper$/).map{ |name|
19
- "CMS::#{name}".constantize.instance_methods.grep(/^cms_/)
20
- }.flatten.map{ |name|
21
- name.to_s.sub(/^cms_/, '')
22
- }
23
- end
24
- end
25
-
26
- def names
27
- @_names ||= begin
28
- names = CMS.html_names 'app/views/cms/blocks'
29
- names.each do |name|
30
- if name.in? restricted_names
31
- raise ArgumentError, "'cms/blocks/_#{name}.html' partial should be called otherwise, '#{name}' taken"
32
- end
33
- end
34
- names
35
- end
36
- end
37
- end
38
14
  end
39
15
  end
@@ -13,16 +13,8 @@ module Viewable
13
13
  has_unlocalized_fields :structure
14
14
 
15
15
  class << self
16
- def names
17
- @_names ||= CMS.dir_names 'app/views/cms/forms'
18
- end
19
-
20
- def static_names
21
- @_static_names ||= CMS.rb_names 'app/models/form'
22
- end
23
-
24
16
  def static?(name)
25
- name.in? static_names
17
+ name.in? Naming::Viewable::Form.static_names
26
18
  end
27
19
 
28
20
  def not_static?(name)
@@ -35,13 +27,22 @@ module Viewable
35
27
  end
36
28
 
37
29
  def static?
38
- form_name.in? self.class.static_names
30
+ form_name.in? Naming::Viewable::Form.static_names
39
31
  end
40
32
 
41
33
  def not_static?
42
34
  !static?
43
35
  end
44
36
 
37
+ def fetch_row(form)
38
+ if structure.nil?
39
+ create_structure!(viewable: self, email: ::Form::Email.new)
40
+ end
41
+ attributes = form.attributes
42
+ attributes['structure_id'] = structure_id
43
+ rows.build(attributes)
44
+ end
45
+
45
46
  private
46
47
 
47
48
  def uuid_columns
@@ -5,12 +5,6 @@ module Viewable
5
5
  include Field::Url
6
6
  include Admin::Viewable::Page
7
7
 
8
- class << self
9
- def names
10
- @_names ||= CMS.html_names 'app/views/cms/pages'
11
- end
12
- end
13
-
14
8
  def view_name
15
9
  @_view_name ||= view_path.split('/').last
16
10
  end
@@ -3,12 +3,7 @@ module Viewable
3
3
  def initialize(model, context)
4
4
  super
5
5
  if m.not_static?
6
- if m.structure.nil?
7
- m.create_structure!(viewable: m, email: ::Form::Email.new)
8
- end
9
- attributes = h.cms_form_instance.attributes
10
- attributes['structure_id'] = m.structure_id
11
- h.cms_form_instance = m.rows.build(attributes)
6
+ h.cms_form_instance = m.fetch_row(h.cms_form_instance)
12
7
  end
13
8
  end
14
9
  end
@@ -32,7 +32,11 @@ module Viewable
32
32
  end
33
33
 
34
34
  def add_path
35
- h.main_app.new_viewable_url(list_key: h.cms_list_key(m.short_type, m.unique_key_name), max: Float::INFINITY)
35
+ h.main_app.new_viewable_url(list_key: h.cms_list_key(short_type, m.unique_key_name), max: Float::INFINITY)
36
+ end
37
+
38
+ def short_type
39
+ m.viewable_type.demodulize.underscore
36
40
  end
37
41
  end
38
42
  end
@@ -11,7 +11,7 @@ class ViewableListPresenter < BaseListPresenter
11
11
  h.content_tag(:ul, sortable(class: "cms-wrapped-edit")) do
12
12
  list.each.with_index(1) do |m, i|
13
13
  name = method_name ? m.__send__(method_name) : i
14
- h.concat(h.content_tag(:li, 'data-cms-sortable-id' => m.unique_key.id) do
14
+ h.concat(h.content_tag(:li, h.cms_js_element('cms-sortable-id', m.unique_key.id)) do
15
15
  m.edit_link(name)
16
16
  end)
17
17
  end
@@ -30,7 +30,7 @@ class ViewableListPresenter < BaseListPresenter
30
30
 
31
31
  def sortable(options = {})
32
32
  if h.cms_edit_mode?
33
- { 'data-cms-sortable' => { url: h.main_app.edit_viewable_url(format: :js) }.to_json }.merge(options)
33
+ h.cms_js_element('cms-sortable', { url: h.main_app.edit_viewable_url(format: :js) }, options)
34
34
  else
35
35
  options
36
36
  end
@@ -2,7 +2,7 @@ class ViewablePresenter < BasePresenter
2
2
  def edit_link(name = nil)
3
3
  return unless h.cms_edit_mode?
4
4
 
5
- h.link_to edit_path, class: "cms-edit cms-edit-#{m.dashed_name}", 'data-no-turbolink' => true do
5
+ h.link_to edit_path, class: "cms-edit cms-edit-#{dashed_name}", 'data-no-turbolink' => true do
6
6
  h.concat h.content_tag(:span, h.t('cms.edit'), class: "cms-edit-action")
7
7
  h.concat " "
8
8
  h.concat h.content_tag(:span, name, class: "cms-edit-name")
@@ -12,7 +12,7 @@ class ViewablePresenter < BasePresenter
12
12
  def li_sortable_tag(options = nil)
13
13
  options ||= {}
14
14
  if h.cms_edit_mode?
15
- options['data-cms-sortable-id'] = m.unique_key.id
15
+ options = h.cms_js_element('cms-sortable-id', m.unique_key.id, options)
16
16
  end
17
17
  h.content_tag :li, options do
18
18
  yield
@@ -24,4 +24,12 @@ class ViewablePresenter < BasePresenter
24
24
  def edit_path
25
25
  h.rails_admin.edit_path(model_name: m.class.name.underscore.gsub('/', '~'), id: m.id)
26
26
  end
27
+
28
+ def dashed_name
29
+ @_dashed_name ||= underscored_name.dasherize
30
+ end
31
+
32
+ def underscored_name
33
+ @_underscored_name ||= m.class.name.underscore.gsub('/', '_')
34
+ end
27
35
  end
@@ -1,3 +1,3 @@
1
- $('#new_form_<%= params[:cms_view_type] %>').replaceWith("<%= j render cms_form_partial %>");
2
- $.validate({validateOnBlur: false});
1
+ $('<%= cms_form_instance.js_form_selector %>').replaceWith("<%= j render cms_form_partial %>");
2
+ CMS.validate();
3
3
  <%= render 'cms/shared/flash_messages' %>
@@ -1,2 +1,2 @@
1
- $('[data-cms-flash]').replaceWith("<%= j cms_flash_messages %>");
1
+ CMS.element('cms-flash').replaceWith("<%= j cms_flash_messages %>");
2
2
  CMS.flash_messages();
data/config/routes.rb CHANGED
@@ -20,12 +20,12 @@ Rails.application.routes.draw do
20
20
  localized do
21
21
  resources :files, format: false, only: [:show]
22
22
 
23
- Viewable::Page.names.each do |name|
23
+ Naming::Viewable::Page.names.each do |name|
24
24
  get name => 'pages#show', format: false,
25
25
  defaults: { cms_view_type: name, cms_body_class: name }
26
26
  end
27
27
 
28
- Viewable::Form.names.each do |name|
28
+ Naming::Viewable::Form.names.each do |name|
29
29
  get name => 'forms#new', format: false,
30
30
  defaults: { cms_view_type: name, cms_body_class: name }
31
31
  post name => 'forms#create',
@@ -0,0 +1,27 @@
1
+ ActiveType::Object.class_eval do
2
+ def type_for_attribute(attribute)
3
+ virtual_columns_hash[attribute]
4
+ end
5
+ end
6
+
7
+ ActiveType::VirtualAttributes::VirtualColumn.class_eval do
8
+ def type
9
+ @type_caster.type
10
+ end
11
+
12
+ def klass
13
+ case type
14
+ when :integer then Fixnum
15
+ when :float then Float
16
+ when :decimal then BigDecimal
17
+ when :datetime, :timestamp, :time then Time
18
+ when :date then Date
19
+ when :text, :string, :binary then String
20
+ when :boolean then Object
21
+ end
22
+ end
23
+ end
24
+
25
+ ActiveType::TypeCaster.class_eval do
26
+ attr_reader :type
27
+ end
@@ -1,12 +1,7 @@
1
- <%# cms_form %>
2
-
3
1
  <% cms_cache do
4
2
  select = cms_select(1, Float::INFINITY)
5
3
  -%>
6
4
 
7
- <%#= @cms_view.edit_link %>
8
- <%#= @cms_view.add_link %>
9
-
10
5
  <%= cms_form_for do |f| %>
11
6
  <%= f.input :name, input_html: cms_validate_presence %>
12
7
  <%= f.input :email, input_html: cms_validate_email %>
@@ -22,8 +17,6 @@
22
17
  -%>
23
18
  <%# end %>
24
19
 
25
- <%#= f.input :structure_id, as: :hidden, input_html: { value: cms_form_instance.structure_id } %>
26
-
27
20
  <%= f.submit cms_form_send, cms_form_sending %>
28
21
  <% end %>
29
22
 
@@ -1,7 +1,12 @@
1
+ <%# view = cms_form %>
2
+
1
3
  <% cms_cache('top') do
2
4
  text = cms_text('top')
3
5
  -%>
4
6
 
7
+ <%#= view.edit_link %>
8
+ <%#= view.add_link %>
9
+
5
10
  <%= text.html %>
6
11
  <%= text.edit_link %>
7
12
 
@@ -1,4 +1,4 @@
1
- <%# cms_page %>
1
+ <%# view = cms_page %>
2
2
 
3
3
  <% cms_cache do
4
4
  menu = cms_link(0, Float::INFINITY)
@@ -8,8 +8,8 @@
8
8
  # view_block = cms_view_example
9
9
  -%>
10
10
 
11
- <%#= @cms_view.edit_link %>
12
- <%#= @cms_view.add_link %>
11
+ <%#= view.edit_link %>
12
+ <%#= view.add_link %>
13
13
 
14
14
  <%= menu.ul_sortable_tag do %>
15
15
  <% menu.each do |link| %>
@@ -23,7 +23,7 @@ RailsAdmin.config do |config|
23
23
  dashboard # mandatory
24
24
  index # mandatory
25
25
  new do
26
- except Viewable.models + Form.structure_models + %w[
26
+ except Naming::Viewable.models + Naming::Form.structure_models + %w[
27
27
  UniqueKey
28
28
  Setting
29
29
  Rich::RichFile
@@ -31,18 +31,18 @@ RailsAdmin.config do |config|
31
31
  ]
32
32
  end
33
33
  export do
34
- except Viewable.models + Form.structure_models + %w[
34
+ except Naming::Viewable.models + Naming::Form.structure_models + %w[
35
35
  UniqueKey
36
36
  ]
37
37
  end
38
38
  bulk_delete do
39
- except Viewable.models + Form.structure_models + %w[
39
+ except Naming::Viewable.models + Naming::Form.structure_models + %w[
40
40
  UniqueKey
41
41
  Setting
42
42
  ]
43
43
  end
44
44
  show do
45
- except Viewable.models + Form.structure_models + %w[
45
+ except Naming::Viewable.models + Naming::Form.structure_models + %w[
46
46
  UniqueKey
47
47
  ]
48
48
  end
@@ -52,7 +52,7 @@ RailsAdmin.config do |config|
52
52
  ]
53
53
  end
54
54
  delete do
55
- except Form.structure_models + %w[
55
+ except Naming::Form.structure_models + %w[
56
56
  UniqueKey
57
57
  Setting
58
58
  ]
@@ -11,6 +11,7 @@ require "rails_admin_jcrop"
11
11
 
12
12
  require "simple_form"
13
13
  require "active_type"
14
+ require "active_type/virtual_attributes_decorator"
14
15
  require "email_validator"
15
16
  require "country_select"
16
17
  require "i18n_country_select"
@@ -1,3 +1,3 @@
1
1
  module RailsAdminCMS
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_admin_cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrice Lebel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-06 00:00:00.000000000 Z
11
+ date: 2016-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -600,9 +600,6 @@ files:
600
600
  - Rakefile
601
601
  - app/assets/javascripts/rails_admin_cms/all.js.coffee
602
602
  - app/assets/javascripts/rails_admin_cms/cms.js.coffee
603
- - app/assets/javascripts/rails_admin_cms/cms/flashes.js.coffee
604
- - app/assets/javascripts/rails_admin_cms/cms/with_scope/forms.js.coffee
605
- - app/assets/javascripts/rails_admin_cms/cms/with_scope/viewables.js.coffee
606
603
  - app/assets/stylesheets/rails_admin_cms/all.css.sass
607
604
  - app/controllers/cms/attachments_controller.rb
608
605
  - app/controllers/cms/files_controller.rb
@@ -613,6 +610,7 @@ files:
613
610
  - app/controllers/concerns/cms/localize.rb
614
611
  - app/helpers/cms/cache_helper.rb
615
612
  - app/helpers/cms/form_helper.rb
613
+ - app/helpers/cms/javascript_helper.rb
616
614
  - app/helpers/cms/locale_helper.rb
617
615
  - app/helpers/cms/view_helper.rb
618
616
  - app/helpers/cms/viewable_helper.rb
@@ -622,6 +620,7 @@ files:
622
620
  - app/models/admin/form/email.rb
623
621
  - app/models/admin/form/field.rb
624
622
  - app/models/admin/form/row.rb
623
+ - app/models/admin/form/row/as_header.rb
625
624
  - app/models/admin/form/static/object.rb
626
625
  - app/models/admin/form/structure.rb
627
626
  - app/models/admin/setting.rb
@@ -644,12 +643,18 @@ files:
644
643
  - app/models/form/email.rb
645
644
  - app/models/form/field.rb
646
645
  - app/models/form/row.rb
646
+ - app/models/form/row/as_header.rb
647
647
  - app/models/form/static.rb
648
648
  - app/models/form/static/attachment.rb
649
649
  - app/models/form/static/base.rb
650
650
  - app/models/form/static/email.rb
651
651
  - app/models/form/static/object.rb
652
652
  - app/models/form/structure.rb
653
+ - app/models/naming/form.rb
654
+ - app/models/naming/viewable.rb
655
+ - app/models/naming/viewable/block.rb
656
+ - app/models/naming/viewable/form.rb
657
+ - app/models/naming/viewable/page.rb
653
658
  - app/models/setting.rb
654
659
  - app/models/unique_key.rb
655
660
  - app/models/viewable.rb
@@ -704,6 +709,7 @@ files:
704
709
  - db/migrate/20160101141844_create_form_row.rb
705
710
  - db/migrate/20160102010317_create_form_field.rb
706
711
  - db/migrate/20160103120544_create_form_email.rb
712
+ - lib/active_type/virtual_attributes_decorator.rb
707
713
  - lib/generators/cms/install/USAGE
708
714
  - lib/generators/cms/install/install_generator.rb
709
715
  - lib/generators/cms/install/templates/Gemfile
@@ -1,2 +0,0 @@
1
- CMS.flash_messages = ->
2
- $('[data-cms-flash]').fadeIn().delay(3500).fadeOut(800);
@@ -1,4 +0,0 @@
1
- #= require jquery.form-validator
2
-
3
- CMS.ready_with_scope 'cms-forms', ->
4
- $.validate(validateOnBlur: false)
@@ -1,14 +0,0 @@
1
- #= require jquery-ui/sortable
2
-
3
- CMS.ready_with_scope 'cms-edit-mode', ->
4
- $('[data-cms-sortable]').each ->
5
- $(this).sortable
6
- update: (event, ui) ->
7
- url = $(this).data('cms-sortable')['url']
8
-
9
- target = $(ui.item)
10
- id = target.data('cms-sortable-id')
11
- unique_key = { position: target.index() + 1 }
12
- payload = $.param(id: id, unique_key: unique_key)
13
-
14
- $.post(url, payload)