rails_admin_cms 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +36 -0
  4. data/Rakefile +26 -0
  5. data/app/assets/javascripts/rails_admin_cms/all.js.coffee +2 -0
  6. data/app/assets/javascripts/rails_admin_cms/cms.js.coffee +18 -0
  7. data/app/assets/javascripts/rails_admin_cms/cms/flashes.js.coffee +2 -0
  8. data/app/assets/javascripts/rails_admin_cms/cms/with_scope/forms.js.coffee +4 -0
  9. data/app/assets/javascripts/rails_admin_cms/cms/with_scope/viewables.js.coffee +14 -0
  10. data/app/assets/stylesheets/rails_admin_cms/all.css.sass +0 -0
  11. data/app/controllers/cms/attachments_controller.rb +20 -0
  12. data/app/controllers/cms/files_controller.rb +19 -0
  13. data/app/controllers/cms/forms_controller.rb +89 -0
  14. data/app/controllers/cms/pages_controller.rb +13 -0
  15. data/app/controllers/cms/viewables_controller.rb +49 -0
  16. data/app/controllers/concerns/cms/editing.rb +21 -0
  17. data/app/controllers/concerns/cms/localize.rb +15 -0
  18. data/app/helpers/cms/cache_helper.rb +26 -0
  19. data/app/helpers/cms/form_helper.rb +67 -0
  20. data/app/helpers/cms/locale_helper.rb +34 -0
  21. data/app/helpers/cms/view_helper.rb +37 -0
  22. data/app/helpers/cms/viewable_helper.rb +155 -0
  23. data/app/helpers/rails_admin/form_builder_decorator.rb +11 -0
  24. data/app/helpers/rails_admin/navigation_helper.rb +77 -0
  25. data/app/mailers/cms/forms_mailer.rb +48 -0
  26. data/app/models/admin/form/email.rb +41 -0
  27. data/app/models/admin/form/field.rb +25 -0
  28. data/app/models/admin/form/row.rb +36 -0
  29. data/app/models/admin/form/static/object.rb +15 -0
  30. data/app/models/admin/form/structure.rb +18 -0
  31. data/app/models/admin/setting.rb +21 -0
  32. data/app/models/admin/unique_key.rb +15 -0
  33. data/app/models/admin/viewable/block.rb +25 -0
  34. data/app/models/admin/viewable/form.rb +36 -0
  35. data/app/models/admin/viewable/image.rb +18 -0
  36. data/app/models/admin/viewable/link.rb +21 -0
  37. data/app/models/admin/viewable/page.rb +27 -0
  38. data/app/models/admin/viewable/select.rb +15 -0
  39. data/app/models/admin/viewable/text.rb +16 -0
  40. data/app/models/callbacks/form/field_after_create.rb +16 -0
  41. data/app/models/callbacks/form/field_after_destroy.rb +16 -0
  42. data/app/models/callbacks/form/field_before_update.rb +29 -0
  43. data/app/models/callbacks/restrictor.rb +30 -0
  44. data/app/models/callbacks/unique_key_before_update.rb +46 -0
  45. data/app/models/callbacks/viewable_after_destroy.rb +27 -0
  46. data/app/models/callbacks/viewable_before_update.rb +15 -0
  47. data/app/models/form.rb +43 -0
  48. data/app/models/form/email.rb +21 -0
  49. data/app/models/form/field.rb +75 -0
  50. data/app/models/form/row.rb +30 -0
  51. data/app/models/form/static.rb +17 -0
  52. data/app/models/form/static/attachment.rb +62 -0
  53. data/app/models/form/static/base.rb +10 -0
  54. data/app/models/form/static/email.rb +23 -0
  55. data/app/models/form/static/object.rb +12 -0
  56. data/app/models/form/structure.rb +90 -0
  57. data/app/models/setting.rb +85 -0
  58. data/app/models/unique_key.rb +62 -0
  59. data/app/models/viewable.rb +93 -0
  60. data/app/models/viewable/block.rb +39 -0
  61. data/app/models/viewable/field/url.rb +45 -0
  62. data/app/models/viewable/field/uuid.rb +61 -0
  63. data/app/models/viewable/form.rb +67 -0
  64. data/app/models/viewable/image.rb +6 -0
  65. data/app/models/viewable/link.rb +10 -0
  66. data/app/models/viewable/page.rb +24 -0
  67. data/app/models/viewable/select.rb +6 -0
  68. data/app/models/viewable/text.rb +6 -0
  69. data/app/presenters/base_list_presenter.rb +42 -0
  70. data/app/presenters/base_presenter.rb +17 -0
  71. data/app/presenters/viewable/block_presenter.rb +10 -0
  72. data/app/presenters/viewable/form_presenter.rb +15 -0
  73. data/app/presenters/viewable/image_presenter.rb +11 -0
  74. data/app/presenters/viewable/link_list_presenter.rb +44 -0
  75. data/app/presenters/viewable/link_presenter.rb +64 -0
  76. data/app/presenters/viewable/page_presenter.rb +4 -0
  77. data/app/presenters/viewable/select_list_presenter.rb +7 -0
  78. data/app/presenters/viewable/select_presenter.rb +15 -0
  79. data/app/presenters/viewable/text_presenter.rb +11 -0
  80. data/app/presenters/viewable/view_presenter.rb +38 -0
  81. data/app/presenters/viewable_list_presenter.rb +54 -0
  82. data/app/presenters/viewable_presenter.rb +27 -0
  83. data/app/views/cms/forms/create.js.erb +3 -0
  84. data/app/views/cms/shared/_flash_messages.js.erb +2 -0
  85. data/app/views/cms/viewables/update.js.erb +1 -0
  86. data/app/views/layouts/rails_admin/_secondary_navigation.html.haml +10 -0
  87. data/config/initializers/assets.rb +6 -0
  88. data/config/initializers/route_translator.rb +3 -0
  89. data/config/locales/cms.en.yml +32 -0
  90. data/config/locales/cms.fr.yml +32 -0
  91. data/config/locales/flash.en.yml +43 -0
  92. data/config/locales/flash.fr.yml +43 -0
  93. data/config/locales/routes.en.yml +3 -0
  94. data/config/locales/routes.fr.yml +3 -0
  95. data/config/routes.rb +36 -0
  96. data/config/spring.rb +1 -0
  97. data/db/migrate/20151226023652_create_unique_key.rb +19 -0
  98. data/db/migrate/20151226054335_create_viewable_link.rb +14 -0
  99. data/db/migrate/20151227064933_create_viewable_text.rb +10 -0
  100. data/db/migrate/20151227072412_create_rich_rich_images.rich.rb +18 -0
  101. data/db/migrate/20151227072413_add_uri_cache_to_rich_image.rich.rb +6 -0
  102. data/db/migrate/20151227072414_refactor_image_to_file.rich.rb +13 -0
  103. data/db/migrate/20151228231201_create_viewable_image.rb +10 -0
  104. data/db/migrate/20151230050603_create_setting.rb +13 -0
  105. data/db/migrate/20151230072904_add_cms_mail_from_and_bcc_settings.rb +14 -0
  106. data/db/migrate/20151230085947_create_viewable_select.rb +10 -0
  107. data/db/migrate/20151231054310_create_viewable_block.rb +9 -0
  108. data/db/migrate/20151231102148_create_viewable_page.rb +13 -0
  109. data/db/migrate/20160101124428_create_viewable_form.rb +15 -0
  110. data/db/migrate/20160101140244_create_form_structure.rb +9 -0
  111. data/db/migrate/20160101141844_create_form_row.rb +13 -0
  112. data/db/migrate/20160102010317_create_form_field.rb +17 -0
  113. data/db/migrate/20160103120544_create_form_email.rb +18 -0
  114. data/lib/generators/cms/install/USAGE +8 -0
  115. data/lib/generators/cms/install/install_generator.rb +14 -0
  116. data/lib/generators/cms/install/templates/Gemfile +47 -0
  117. data/lib/generators/cms/install/templates/app/assets/javascripts/application.js +19 -0
  118. data/lib/generators/cms/install/templates/app/assets/stylesheets/application.css +17 -0
  119. data/lib/generators/cms/install/templates/app/controllers/application_controller.rb +9 -0
  120. data/lib/generators/cms/install/templates/app/controllers/cms/authenticate.rb +34 -0
  121. data/lib/generators/cms/install/templates/app/models/form/contact.rb +20 -0
  122. data/lib/generators/cms/install/templates/app/views/cms/blocks/_example.html.erb +13 -0
  123. data/lib/generators/cms/install/templates/app/views/cms/forms/contact/_form.html.erb +30 -0
  124. data/lib/generators/cms/install/templates/app/views/cms/forms/contact/new.html.erb +19 -0
  125. data/lib/generators/cms/install/templates/app/views/cms/forms_mailer/contact.html.erb +6 -0
  126. data/lib/generators/cms/install/templates/app/views/cms/forms_mailer/contact.text.erb +6 -0
  127. data/lib/generators/cms/install/templates/app/views/cms/pages/page.html.erb +29 -0
  128. data/lib/generators/cms/install/templates/app/views/layouts/application.html.erb +23 -0
  129. data/lib/generators/cms/install/templates/config/application.rb +36 -0
  130. data/lib/generators/cms/install/templates/config/initializers/rails_admin.rb +97 -0
  131. data/lib/generators/cms/install/templates/config/initializers/rich.rb +142 -0
  132. data/lib/generators/cms/install/templates/config/initializers/simple_form.rb +165 -0
  133. data/lib/generators/cms/install/templates/config/initializers/simple_form_bootstrap.rb +149 -0
  134. data/lib/generators/cms/install/templates/config/locales/routes.en.yml +4 -0
  135. data/lib/generators/cms/install/templates/config/locales/simple_form.en.yml +31 -0
  136. data/lib/generators/cms/install/templates/config/routes.rb +61 -0
  137. data/lib/generators/cms/install/templates/vendor/assets/javascripts/rails_admin/custom/ui.js.coffee +1 -0
  138. data/lib/generators/cms/install/templates/vendor/assets/stylesheets/rails_admin/custom/mixins.sass +0 -0
  139. data/lib/generators/cms/install/templates/vendor/assets/stylesheets/rails_admin/custom/theming.sass +1 -0
  140. data/lib/generators/cms/install/templates/vendor/assets/stylesheets/rails_admin/custom/variables.sass +0 -0
  141. data/lib/generators/cms/install/templates/vendor/assets/stylesheets/rich/editor.css +20 -0
  142. data/lib/rails_admin_cms.rb +28 -0
  143. data/lib/rails_admin_cms/config.rb +45 -0
  144. data/lib/rails_admin_cms/core_ext/boolean.rb +29 -0
  145. data/lib/rails_admin_cms/engine.rb +11 -0
  146. data/lib/rails_admin_cms/inflections.rb +4 -0
  147. data/lib/rails_admin_cms/utils.rb +30 -0
  148. data/lib/rails_admin_cms/version.rb +3 -0
  149. data/lib/tasks/rails_admin_cms_tasks.rake +4 -0
  150. metadata +669 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 64532329456176e9cc5b085b1a7e174d7bdcd7d5
4
+ data.tar.gz: 26b4fd42b12511578a06360edec4511e0b5f54d1
5
+ SHA512:
6
+ metadata.gz: 08c544696542dd45900978dc4a265c0f1568b0cbaf4a0b99c89632ec6a3609b284effe01321562536388dc8b4b3248ff242ab0f660d5abb6b1e1a3f0e42e12c9
7
+ data.tar.gz: 015ff341e2aa59dc9d0fe2add4d4a538bd404db57c34cbb8f5a3aff34d62206c426a0b884cb7e11e97f4e188f0352e3a619a81c997801997471a6bb28be7d3b2
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Patrice Lebel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ # RailsAdminCMS
2
+
3
+ *Flexible Content Management Framework for RailsAdmin*
4
+
5
+ ## Overview
6
+
7
+ RailsAdmin...
8
+
9
+ ## View helpers
10
+
11
+ Seamlessly adds some useful classes to the body tag within your layout in order to scope your css/js : `cms-template-name`, `controller-name`, `controller-name-action-name`, `locale` and `edit-mode`.
12
+
13
+ ```ruby
14
+ # ...
15
+ </head>
16
+ <body class="<%= cms_body_class 'other-class', 'etc' %>">
17
+ # ...
18
+ </body>
19
+ </html>
20
+ ```
21
+
22
+ ## TODO
23
+
24
+ * Documentation
25
+ * Generators
26
+ * Published Pages/Forms
27
+ * Keep the Locale within the DB after form submission
28
+ * Mailchimp integration
29
+ * More Specs
30
+
31
+ ## Notes
32
+
33
+ gem 'dalli-delete-matched' needed if Memcached is used
34
+
35
+
36
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,26 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'RailsAdminCMS'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
@@ -0,0 +1,2 @@
1
+ #= require ./cms
2
+ #= require_tree ./cms
@@ -0,0 +1,18 @@
1
+ window.CMS ||= {}
2
+
3
+ CMS.with_scope = (body_class, callback) ->
4
+ if $('body').hasClass(body_class)
5
+ callback()
6
+
7
+ CMS.ready = (callback) ->
8
+ $(document).on 'ready page:change', ->
9
+ callback()
10
+
11
+ CMS.ready_with_scope = (body_class, callback) ->
12
+ CMS.ready ->
13
+ CMS.with_scope(body_class, callback)
14
+
15
+ #------------------------------------------------------------------------------#
16
+
17
+ CMS.ready ->
18
+ CMS.flash_messages()
@@ -0,0 +1,2 @@
1
+ CMS.flash_messages = ->
2
+ $('[data-cms-flash]').fadeIn().delay(3500).fadeOut(800);
@@ -0,0 +1,4 @@
1
+ #= require jquery.form-validator
2
+
3
+ CMS.ready_with_scope 'cms-forms', ->
4
+ $.validate(validateOnBlur: false)
@@ -0,0 +1,14 @@
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)
@@ -0,0 +1,20 @@
1
+ module CMS
2
+ class AttachmentsController < RailsAdminCMS::Config.parent_controller
3
+ before_action :authenticate_admin_user!
4
+
5
+ def show
6
+ name, format = params[:file].sub(/\?.+$/, ''), params[:format]
7
+ file_name = "#{name}.#{format}"
8
+ content_type = Mime::Type.lookup_by_extension(format)
9
+
10
+ send_file(
11
+ "#{Rails.root}/private/attachments/#{params[:directory]}/#{file_name}",
12
+ type: content_type,
13
+ filename: file_name,
14
+ disposition: 'inline',
15
+ x_sendfile: !Rails.env.development?,
16
+ stream: true
17
+ )
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ module CMS
2
+ class FilesController < RailsAdminCMS::Config.parent_controller
3
+ def show
4
+ file_path = Viewable::Link.find(params[:id]).file
5
+ file_name = File.basename(file_path)
6
+ ext = File.extname(file_name).sub('.', '')
7
+ content_type = Mime::Type.lookup_by_extension(ext)
8
+
9
+ send_file(
10
+ "#{Rails.root}/public#{file_path}",
11
+ type: content_type,
12
+ filename: file_name,
13
+ disposition: 'inline',
14
+ x_sendfile: !Rails.env.development?,
15
+ stream: true
16
+ )
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,89 @@
1
+ module CMS
2
+ class FormsController < RailsAdminCMS::Config.parent_controller
3
+ attr_internal :cms_form_instance
4
+ helper_method :cms_form_instance, :cms_form_instance=
5
+
6
+ def new
7
+ load_form
8
+
9
+ render new_template
10
+ end
11
+
12
+ def create
13
+ load_form
14
+
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
+ reset_form
20
+ flash_now!(:success)
21
+ else
22
+ flash_now!(error: cms_form_instance.errors.full_messages.first)
23
+ end
24
+
25
+ respond_to do |format|
26
+ format.js {}
27
+ format.html do
28
+ render new_template
29
+ end
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def load_form
36
+ @cms_view = Viewable::Form.find(params[:id]) if params[:id].present?
37
+ attributes = form_params if params.has_key?(form_key)
38
+ self.cms_form_instance = form_class.new(attributes)
39
+ end
40
+
41
+ def reset_form
42
+ self.cms_form_instance = form_object
43
+ end
44
+
45
+ def new_template
46
+ "cms/forms/#{params[:cms_view_type]}/new"
47
+ end
48
+
49
+ def form_params
50
+ if form_class.has_collections?
51
+ form_class.collections.each do |collection|
52
+ params[form_key][collection] = "[#{params[form_key][collection].reject(&:blank?).join('][')}]"
53
+ end
54
+ end
55
+ params.require(form_key).permit(form_attributes)
56
+ end
57
+
58
+ def form_attributes
59
+ attributes = form_object.attributes.keys
60
+ attributes = attributes.reject{ |key| %w[ id ].include? key } << '_subtitle'
61
+ if form_class.has_attachments?
62
+ attributes = attributes.concat(form_class.attachments)
63
+ end
64
+ attributes
65
+ end
66
+
67
+ def form_key
68
+ @_form_key ||= "form_#{form_class_name}"
69
+ end
70
+
71
+ def form_object
72
+ @_form_object ||= form_class.new
73
+ end
74
+
75
+ def form_class
76
+ @_form_class ||= "Form::#{form_class_name.camelize}".constantize
77
+ end
78
+
79
+ def form_class_name
80
+ return @_form_class_name if @_form_class_name
81
+
82
+ if Viewable::Form.static? params[:cms_view_type]
83
+ @_form_class_name = params[:cms_view_type]
84
+ else
85
+ @_form_class_name = 'row'
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,13 @@
1
+ module CMS
2
+ class PagesController < RailsAdminCMS::Config.parent_controller
3
+ def show
4
+ @cms_view = Viewable::Page.find(params[:id]) if params[:id].present?
5
+
6
+ if @cms_view
7
+ render @cms_view.view_path
8
+ else
9
+ render "cms/pages/#{params[:cms_view_type]}"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,49 @@
1
+ module CMS
2
+ class ViewablesController < RailsAdminCMS::Config.parent_controller
3
+ before_action :authenticate_admin_user!
4
+
5
+ def create
6
+ current_count = UniqueKey.where(list_key_params).count
7
+
8
+ if params[:max] == 'Infinity' || current_count < params[:max].to_i
9
+ unique_key = list_key_params.merge(position: current_count + 1)
10
+
11
+ viewable = UniqueKey.create_localized_viewable!(unique_key)
12
+
13
+ if unique_key[:viewable_type] != 'Viewable::Block'
14
+ path = rails_admin.edit_path(model_name: unique_key[:viewable_type].to_s.underscore.gsub('/', '~'), id: viewable.id)
15
+
16
+ redirect_to path
17
+ else
18
+ redirect_to :back
19
+ end
20
+ else
21
+ redirect_to :back
22
+ end
23
+ end
24
+
25
+ def update
26
+ unique_key = UniqueKey.find(params[:id])
27
+
28
+ if unique_key.update(unique_key_params)
29
+ flash_now!(:success)
30
+ else
31
+ flash_now!(error: unique_key.errors.full_messages.first)
32
+ end
33
+
34
+ respond_to do |format|
35
+ format.js {}
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def list_key_params
42
+ params.require(:list_key).permit(:viewable_type, :view_path, :name, :locale)
43
+ end
44
+
45
+ def unique_key_params
46
+ params.require(:unique_key).permit(:position)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,21 @@
1
+ module CMS
2
+ module Editing
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_action :set_edit_mode
7
+
8
+ helper_method :cms_edit_mode?
9
+ end
10
+
11
+ def cms_edit_mode?
12
+ @_editing ||= current_admin? && session[:edit_mode].to_b
13
+ end
14
+
15
+ private
16
+
17
+ def set_edit_mode
18
+ session[:edit_mode] = params[:edit_mode] || session[:edit_mode]
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ module CMS
2
+ module Localize
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_action :set_locale
7
+ end
8
+
9
+ private
10
+
11
+ def set_locale
12
+ I18n.locale = session[:locale] = params[:locale] || session[:locale] || I18n.default_locale
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ module CMS
2
+ module CacheHelper
3
+ def cms_cache(name = nil)
4
+ cache_unless no_cache, cache_key(name) do
5
+ yield
6
+ end
7
+ end
8
+
9
+ private
10
+
11
+ def no_cache
12
+ cms_edit_mode? || forms_create?
13
+ end
14
+
15
+ def forms_create?
16
+ controller_name == 'forms' && action_name == 'create'
17
+ end
18
+
19
+ def cache_key(name)
20
+ key = [@virtual_path, locale]
21
+ key << @cms_view.uuid if @cms_view
22
+ key << name if name
23
+ key
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,67 @@
1
+ module CMS
2
+ module FormHelper
3
+ def cms_form_for(options = {})
4
+ simple_form_for(cms_form_instance, cms_form_options(options)) do |f|
5
+ concat f.invisible_captcha(:_subtitle)
6
+ yield f
7
+ end
8
+ end
9
+
10
+ def cms_form_options(options = {})
11
+ if @cms_view
12
+ url = @cms_view.url
13
+ else
14
+ url = main_app.__send__("#{cms_form_instance.form_name}_path")
15
+ end
16
+ options.reverse_merge! url: url
17
+ if cms_form_instance.has_attachments?
18
+ options[:multipart] = true
19
+ else
20
+ options[:remote] = true
21
+ end
22
+ options
23
+ end
24
+
25
+ def cms_form_partial
26
+ "cms/forms/#{params[:cms_view_type]}/form"
27
+ end
28
+
29
+ def cms_validates(options = {})
30
+ type, required = options.extract!(*Form::Field::TYPES.map(&:to_sym)).first
31
+ unless type
32
+ return cms_validate_presence(options)
33
+ end
34
+ unless required
35
+ return options
36
+ end
37
+ case type
38
+ when :check_boxes
39
+ cms_validate_check_boxes(options)
40
+ when :email
41
+ cms_validate_email(options)
42
+ else
43
+ cms_validate_presence(options)
44
+ end
45
+ end
46
+
47
+ def cms_validate_presence(options = {})
48
+ { 'data-validation' => 'required', 'data-validation-error-msg' => t('errors.messages.blank') }.merge(options)
49
+ end
50
+
51
+ def cms_validate_email(options = {})
52
+ { 'data-validation' => 'email', 'data-validation-error-msg' => t('errors.messages.invalid') }.merge(options)
53
+ end
54
+
55
+ def cms_validate_check_boxes(options = {})
56
+ { 'data-validation' => 'checkbox_group', 'data-validation-qty' => 'min1', 'data-validation-error-msg' => t('errors.messages.blank') }.merge(options)
57
+ end
58
+
59
+ def cms_form_send
60
+ t('cms.form.submit.send')
61
+ end
62
+
63
+ def cms_form_sending(options = {})
64
+ { 'data-disable-with' => t('cms.form.submit.sending') }.merge(options)
65
+ end
66
+ end
67
+ end