activeadmin-selleo-cms 0.0.18 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/app/admin/active_admin/views_helper.rb +4 -0
  2. data/app/admin/activeadmin_selleo_cms/page.rb +42 -6
  3. data/app/assets/javascripts/activeadmin-selleo-cms/custom.js +35 -0
  4. data/app/assets/javascripts/activeadmin-selleo-cms/jquery-ui-timepicker-addon.js +1902 -0
  5. data/app/assets/javascripts/ckeditor/config.js +12 -1
  6. data/app/assets/stylesheets/activeadmin-selleo-cms/custom.css +5 -1
  7. data/app/assets/stylesheets/activeadmin-selleo-cms/jquery-ui-timepicker-addon.css +10 -0
  8. data/app/controllers/pages_controller.rb +9 -4
  9. data/app/controllers/searches_controller.rb +1 -1
  10. data/app/helpers/pages_helper.rb +9 -5
  11. data/app/models/activeadmin_selleo_cms/asset.rb +7 -1
  12. data/app/models/activeadmin_selleo_cms/attachment.rb +2 -0
  13. data/app/models/activeadmin_selleo_cms/image.rb +21 -0
  14. data/app/models/activeadmin_selleo_cms/layout.rb +27 -3
  15. data/app/models/activeadmin_selleo_cms/page.rb +33 -33
  16. data/app/models/activeadmin_selleo_cms/search.rb +1 -0
  17. data/app/models/activeadmin_selleo_cms/section.rb +33 -1
  18. data/app/views/admin/pages/_form.html.haml +2 -8
  19. data/app/views/admin/pages/_translated_fields.html.haml +52 -15
  20. data/app/views/admin/pages/reorder.html.haml +6 -0
  21. data/app/views/admin/pages/update_positions.js.erb +6 -0
  22. data/app/views/searches/show.html.haml +1 -1
  23. data/config/initializers/active_admin.rb +3 -0
  24. data/config/initializers/formtastic.rb +7 -0
  25. data/config/routes.rb +2 -7
  26. data/db/migrate/20130206173233_change_activeadmin_selleo_cms_searches.rb +29 -0
  27. data/db/migrate/20130207213528_change_activeadmin_selleo_cms_assets.rb +12 -0
  28. data/lib/activeadmin-selleo-cms/version.rb +1 -1
  29. data/lib/generators/activeadmin_selleo_cms/templates/cms.html.erb +7 -3
  30. data/spec/dummy/app/views/layouts/cms.html.erb +1 -1
  31. data/spec/dummy/db/snapshots/test_database.sql +1 -1
  32. data/spec/dummy/log/test.log +79024 -0
  33. data/spec/dummy/tmp/cache/assets/BEF/CA0/sprockets%2F3335c73d91157a627611592700a9654e +0 -0
  34. data/spec/dummy/tmp/cache/assets/C5A/610/sprockets%2Fbe898195780d802c102d152255d9e477 +0 -0
  35. data/spec/dummy/tmp/cache/assets/CB7/190/sprockets%2F136a9350fa75f3336af293952861ed6d +0 -0
  36. data/spec/dummy/tmp/cache/assets/CBA/D70/sprockets%2F8c5e2f7ea6f160a6792a442f01378479 +0 -0
  37. data/spec/dummy/tmp/cache/assets/CCF/2E0/sprockets%2Fde5b2bd811d24557c940a2239b7e3130 +0 -0
  38. data/spec/dummy/tmp/cache/assets/CD3/3E0/sprockets%2F373fa62090ab111ae606b963e1b8c793 +0 -0
  39. data/spec/dummy/tmp/cache/assets/CD6/930/sprockets%2Fb62a24129369fea572b674303a7fa12f +0 -0
  40. data/spec/dummy/tmp/cache/assets/CE2/D80/sprockets%2F28a4d5b1a75700c7579e3773f34ccd71 +0 -0
  41. data/spec/dummy/tmp/cache/assets/CE3/720/sprockets%2F8c9e2817b83ec580831f21b0c352c9c7 +0 -0
  42. data/spec/dummy/tmp/cache/assets/CED/FB0/sprockets%2Fa675d17ed83804639ec0264b624d98ed +0 -0
  43. data/spec/dummy/tmp/cache/assets/D2C/2E0/sprockets%2Fa031c32e27ced12f81d4326f8b52fb23 +0 -0
  44. data/spec/dummy/tmp/cache/assets/D5C/1D0/sprockets%2F0671a22da74f433700c99e13bfaaf0ce +0 -0
  45. data/spec/dummy/tmp/cache/assets/D63/6C0/sprockets%2F1ae1f1cf9d92d0e61b7006171a39fd4d +0 -0
  46. data/spec/dummy/tmp/cache/assets/D64/060/sprockets%2F3b86cba556132a40a7e49a7b4c7e17ad +0 -0
  47. data/spec/dummy/tmp/cache/assets/D92/B20/sprockets%2F871f050bda629a18e11ea8db7c1aca77 +0 -0
  48. data/spec/dummy/tmp/cache/assets/DB2/EA0/sprockets%2Ffead656b8b83fbae9f69435c33b4649d +0 -0
  49. data/spec/dummy/tmp/cache/assets/E37/3E0/sprockets%2F9e6d2d17ed6da64a2f1876d4cdfefcd1 +0 -0
  50. data/spec/dummy/tmp/capybara/capybara-201301312228138539754304.html +152 -0
  51. data/spec/dummy/tmp/capybara/capybara-201301312228185417992211.html +152 -0
  52. data/spec/dummy/tmp/capybara/capybara-201301312228232926906843.html +152 -0
  53. data/spec/dummy/tmp/capybara/capybara-201301312228302851745933.html +176 -0
  54. data/spec/dummy/tmp/capybara/capybara-20130131222835626927814.html +152 -0
  55. data/spec/dummy/tmp/capybara/capybara-201301312228403892930584.html +152 -0
  56. data/spec/dummy/tmp/capybara/capybara-201301312228491329185040.html +152 -0
  57. data/spec/dummy/tmp/capybara/capybara-201301312232412606495803.html +182 -0
  58. data/spec/dummy/tmp/capybara/capybara-201301312232508358940406.html +242 -0
  59. data/spec/dummy/tmp/capybara/capybara-201301312233036556441968.html +182 -0
  60. data/spec/dummy/tmp/capybara/capybara-201301312233093002404474.html +182 -0
  61. data/spec/models/activeadmin_selleo_cms/page_spec.rb +9 -0
  62. data/spec/support/pages_helper.rb +4 -4
  63. metadata +46 -5
  64. data/app/models/activeadmin_selleo_cms/header_image.rb +0 -12
  65. data/app/models/activeadmin_selleo_cms/icon.rb +0 -12
  66. data/app/modules/active_admin/views/index_as_list.rb +0 -28
@@ -160,7 +160,6 @@ CKEDITOR.editorConfig = function( config )
160
160
 
161
161
  config.toolbar_Lite =
162
162
  [
163
- ['FontSize'],
164
163
  ['Cut', 'Copy', 'Paste'],
165
164
  ['Bold', 'Italic', 'Underline', 'StrikeThrough'],
166
165
  ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyFull'],
@@ -168,4 +167,16 @@ CKEDITOR.editorConfig = function( config )
168
167
  ['BulletedList', 'HorizontalRule']
169
168
  ];
170
169
 
170
+ config.toolbar_Minimal =
171
+ [
172
+ ['Cut', 'Copy', 'Paste'],
173
+ ['Bold', 'Italic', 'Underline', 'StrikeThrough'],
174
+ ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyFull']
175
+ ];
176
+
177
+ config.toolbar_Header =
178
+ [
179
+ ['Bold'],
180
+ ];
181
+
171
182
  };
@@ -56,4 +56,8 @@ div.translation > input {
56
56
 
57
57
  table#translations td.key {
58
58
  padding-top: 16px;
59
- }
59
+ }
60
+
61
+ .sortable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
62
+ .sortable li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.4em; height: 18px; }
63
+ .sortable li span { position: absolute; margin-left: -1.3em; }
@@ -0,0 +1,10 @@
1
+ .ui-timepicker-div .ui-widget-header { margin-bottom: 8px; }
2
+ .ui-timepicker-div dl { text-align: left; }
3
+ .ui-timepicker-div dl dt { height: 25px; margin-bottom: -25px; }
4
+ .ui-timepicker-div dl dd { margin: 0 10px 10px 65px; }
5
+ .ui-timepicker-div td { font-size: 90%; }
6
+ .ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; }
7
+
8
+ .ui-timepicker-rtl{ direction: rtl; }
9
+ .ui-timepicker-rtl dl { text-align: right; }
10
+ .ui-timepicker-rtl dl dd { margin: 0 65px 10px 10px; }
@@ -4,19 +4,24 @@ class PagesController < CmsController
4
4
  private
5
5
 
6
6
  def find_page
7
- page_scope = ActiveadminSelleoCms::Page
8
7
  root = ActiveadminSelleoCms::Page.root
9
8
 
10
9
  raise "Create at least one page" unless root
11
10
 
12
- if parent = ActiveadminSelleoCms::Page.find_by_slug(params[:page_id])
13
- page_scope = page_scope.where(parent_id: parent.id)
11
+ page_id = nil
12
+
13
+ 5.downto(1).each do |l|
14
+ if params["slug#{l}"] and page = ActiveadminSelleoCms::Page.where(parent_id: page_id).find_by_slug(params["slug#{l}"])
15
+ page_id = page.id
16
+ end
14
17
  end
15
18
 
16
- @page = page_scope.find_by_slug(params[:id])
19
+ @page = ActiveadminSelleoCms::Page.find_by_id(page_id)
17
20
 
18
21
  if !@page or (!@page.is_published? and @page != root)
19
22
  redirect_to page_path(I18n.locale, root)
23
+ elsif @page.redirect_to_first_sub_page
24
+ redirect_to page_path(I18n.locale, @page.children.first || root)
20
25
  end
21
26
  end
22
27
 
@@ -1,6 +1,6 @@
1
1
  class SearchesController < CmsController
2
2
  def show
3
- @results = ActiveadminSelleoCms::Search.current_locale.search_by_content(params[:id]).map(&:searchable).uniq
3
+ @results = ActiveadminSelleoCms::Search.current_locale.search_by_content(params[:id])
4
4
  render action: :show, layout: 'search'
5
5
  end
6
6
  end
@@ -1,7 +1,7 @@
1
1
  module PagesHelper
2
2
  def link_to_locale(link_name, locale, page=nil)
3
3
  if page
4
- link_to link_name, page_path(locale.code, page.translated_attribute(:slug, locale.code))
4
+ link_to link_name, url_to_page(page, locale.to_s)
5
5
  elsif request.fullpath.match(/^\/\w{2}\/.*/)
6
6
  link_to link_name, request.fullpath.gsub(/^\/(\w{2})\//, "/#{locale.code}/")
7
7
  else
@@ -11,19 +11,23 @@ module PagesHelper
11
11
 
12
12
  def link_to_search_result(result)
13
13
  if result.is_a? ActiveadminSelleoCms::Page
14
- link_to result, result.url
14
+ "#{link_to result.breadcrumb, result.url} #{link_to "(e)", edit_admin_page_path(result.id), target: '_blank' if current_user}".html_safe
15
15
  end
16
16
  end
17
17
 
18
- def url_to_page(page)
18
+ def url_to_page(page, locale=I18n.locale)
19
19
  return "#" unless page
20
- if page.is_link_url
20
+ _locale = I18n.locale
21
+ I18n.locale = locale
22
+ _url = if page.is_link_url
21
23
  page.link_url
22
24
  elsif page.redirect_to_first_sub_page
23
25
  page.children.published.any? ? url_to_page(page.children.published.first) : "#"
24
26
  else
25
- page_path(I18n.locale, page)
27
+ page_path(locale, page)
26
28
  end
29
+ I18n.locale = _locale
30
+ return _url
27
31
  end
28
32
 
29
33
  def link_to_page(page, link_name=nil)
@@ -1,9 +1,15 @@
1
1
  module ActiveadminSelleoCms
2
2
  class Asset < ActiveRecord::Base
3
- attr_accessible :data
3
+ attr_protected :id
4
4
 
5
5
  belongs_to :assetable, polymorphic: true
6
6
 
7
+ has_attached_file :cover,
8
+ :url => "/system/cms/covers/:id/:style_:basename.:extension",
9
+ :path => ":rails_root/public/system/cms/covers/:id/:style_:basename.:extension"
10
+
11
+ validates_attachment_size :cover, :less_than => 10.megabytes
12
+
7
13
  def url(format=nil)
8
14
  data.url(format)
9
15
  end
@@ -6,5 +6,7 @@ module ActiveadminSelleoCms
6
6
 
7
7
  validates_attachment_size :data, :less_than => 10.megabytes
8
8
  validates_attachment_presence :data
9
+
10
+ attr_protected :id
9
11
  end
10
12
  end
@@ -0,0 +1,21 @@
1
+ module ActiveadminSelleoCms
2
+ class Image < ActiveadminSelleoCms::Asset
3
+ attr_accessor :image_width, :image_height, :resize_method
4
+
5
+ has_attached_file :data,
6
+ :url => "/system/cms/images/:id/:style_:basename.:extension",
7
+ :path => ":rails_root/public/system/cms/images/:id/:style_:basename.:extension",
8
+ :styles => Proc.new{ |attachment| attachment.instance.image_sizes },
9
+ :default_style => :normal
10
+
11
+ validates_attachment_size :data, :less_than => 1.megabytes
12
+ validates_attachment_presence :data
13
+
14
+ attr_protected :id
15
+
16
+ def image_sizes
17
+ { :normal => "#{image_width || 640}x#{image_height || 480}#{resize_method || "#"}" }
18
+ end
19
+
20
+ end
21
+ end
@@ -37,13 +37,37 @@ module ActiveadminSelleoCms
37
37
  end
38
38
 
39
39
  class Section
40
- attr_accessor :name, :type, :toolbar, :attachments
40
+ attr_accessor :name, :type, :toolbar, :width, :height, :resize_method
41
41
 
42
42
  def initialize(node)
43
43
  @name = node.attributes["name"].content
44
- @attachments = node.attributes["attachments"] ? true : false
45
44
  @type = node.attributes["data-type"] ? node.attributes["data-type"].content : 'ckeditor'
46
- @toolbar = node.attributes["data-toolbar"] ? node.attributes["data-toolbar"].content : 'Easy'
45
+ @attachments = (['files'].include?(@type) or node.attributes["data-attachments"]) ? true : false
46
+ @attachment = (['file'].include?(@type) or node.attributes["data-attachment"]) ? true : false
47
+ @toolbar = node.attributes["data-toolbar"] ? node.attributes["data-toolbar"].content : 'Minimal'
48
+ @width = node.attributes["data-width"] ? node.attributes["data-width"].content : 640
49
+ @height = node.attributes["data-height"] ? node.attributes["data-height"].content : 480
50
+ @resize_method = node.attributes["data-resize-method"] ? node.attributes["data-resize-method"].content : "#"
51
+ end
52
+
53
+ def text?
54
+ ['ckeditor', 'text'].include? @type
55
+ end
56
+
57
+ def image?
58
+ ['image'].include? @type
59
+ end
60
+
61
+ def images?
62
+ ['images'].include? @type
63
+ end
64
+
65
+ def attachments?
66
+ @attachments == true
67
+ end
68
+
69
+ def attachment?
70
+ @attachment == true
47
71
  end
48
72
 
49
73
  end
@@ -11,15 +11,13 @@ module ActiveadminSelleoCms
11
11
  attr_protected :id
12
12
 
13
13
  has_many :sections, as: :sectionable
14
- has_one :icon, as: :assetable
15
- has_one :header_image, as: :assetable
16
14
  has_many :attachments, as: :assetable
17
15
  has_many :assets, as: :assetable
18
16
  has_many :searches, as: :searchable
19
17
  # ZUO
20
18
  #has_many :translations, class_name: 'ActiveadminSelleoCms::Page::Translation', foreign_key: :activeadmin_selleo_cms_page_id, dependent: :destroy, before_add: :set_nest
21
19
 
22
- accepts_nested_attributes_for :translations, :sections, :children, :icon, :header_image, :attachments
20
+ accepts_nested_attributes_for :translations, :sections, :children, :attachments
23
21
 
24
22
  validates_format_of :link_url, with: /^http/i, allow_blank: false, if: ->(page) { page.is_link_url }
25
23
  validates_presence_of :layout_name
@@ -32,8 +30,8 @@ module ActiveadminSelleoCms
32
30
  scope :latest, ->(n) { published.reorder("published_at DESC").limit(n) }
33
31
  scope :most_read, ->(n) { published.reorder("views DESC").limit(n) }
34
32
  scope :with_layout, ->(layout_name) { where(layout_name: layout_name) }
35
- scope :with_setting_value, ->(key, value) { where("activeadmin_selleo_cms_pages.settings ~ '#{key}: #{value}'") }
36
- scope :with_setting, ->(key) { where("activeadmin_selleo_cms_pages.settings ~ '#{key}: '") }
33
+ scope :with_setting_value, ->(key, value) { where("activeadmin_selleo_cms_pages.settings ~ '#{key}:\\s?\\W?#{value}\\W?\\s*$'") }
34
+ scope :with_setting, ->(key) { where("activeadmin_selleo_cms_pages.settings ~ '#{key}:\\s?'") }
37
35
 
38
36
  before_validation do
39
37
  self.slug = self.title.parameterize if title and slug.blank?
@@ -50,28 +48,25 @@ module ActiveadminSelleoCms
50
48
  self.layout_name = Layout.all.first if new_record? and layout_name.blank?
51
49
  end
52
50
 
53
- def set_nest(translation)
54
- translation.activeadmin_selleo_cms_page ||= self
51
+ after_initialize do
52
+ _settings = read_attribute(:settings) || {}
53
+ _settings.keys.each do |key|
54
+ eval "
55
+ def #{key}
56
+ (self.settings || {})[:#{key}]
57
+ end
58
+ def #{key}=(val)
59
+ self.settings ||= {}
60
+ val = true if val == '1'
61
+ val = false if val == '0'
62
+ self.settings[:#{key}] = val
63
+ end
64
+ "
65
+ end
55
66
  end
56
67
 
57
- def method_missing(method, *args, &block)
58
- _method = (method.to_s[/(.*)\=$/,1] || method).to_sym
59
- unless (self.settings || {})[_method].nil?
60
- eval "
61
- def #{_method}
62
- (self.settings || {})[:#{_method}]
63
- end
64
- def #{_method}=(val)
65
- self.settings ||= {}
66
- val = true if val == '1'
67
- val = false if val == '0'
68
- self.settings[:#{_method}] = val
69
- end
70
- "
71
- send(method, *args)
72
- else
73
- super
74
- end
68
+ def set_nest(translation)
69
+ translation.activeadmin_selleo_cms_page ||= self
75
70
  end
76
71
 
77
72
  def initialize_missing_sections
@@ -96,14 +91,6 @@ module ActiveadminSelleoCms
96
91
  parent ? "#{parent.to_param}/#{slug}" : slug
97
92
  end
98
93
 
99
- def icon_url
100
- icon ? icon.url : 'http://placehold.it/120x90'
101
- end
102
-
103
- def header_image_url
104
- header_image ? header_image.url : 'http://placehold.it/770x385'
105
- end
106
-
107
94
  def roots
108
95
  Page.published.roots
109
96
  end
@@ -124,6 +111,19 @@ module ActiveadminSelleoCms
124
111
  _url
125
112
  end
126
113
 
114
+ def self.update_positions(page_ids)
115
+ begin
116
+ ActiveRecord::Base.transaction do
117
+ page_ids.each_cons(2) do |pair|
118
+ Page.find(pair.last).move_to_right_of(Page.find(pair.first))
119
+ end
120
+ end
121
+ return true
122
+ rescue
123
+ return false
124
+ end
125
+ end
126
+
127
127
  class Translation
128
128
  attr_protected :id
129
129
 
@@ -6,5 +6,6 @@ module ActiveadminSelleoCms
6
6
  belongs_to :searchable, polymorphic: true
7
7
 
8
8
  scope :current_locale, -> { where(locale: I18n.locale) }
9
+ scope :published, -> { where(is_published: true) }
9
10
  end
10
11
  end
@@ -8,6 +8,8 @@ module ActiveadminSelleoCms
8
8
 
9
9
  belongs_to :sectionable, polymorphic: true
10
10
 
11
+ delegate :layout, to: :sectionable
12
+
11
13
  accepts_nested_attributes_for :translations
12
14
 
13
15
  validates_presence_of :name
@@ -26,12 +28,42 @@ module ActiveadminSelleoCms
26
28
  end
27
29
  end
28
30
 
31
+ def image
32
+ if current_translation = translations.with_locales(I18n.fallbacks[I18n.locale]).detect{|t| t.image}
33
+ current_translation.image
34
+ else
35
+ nil
36
+ end
37
+ end
38
+
39
+ def attachment
40
+ if current_translation = translations.with_locales(I18n.fallbacks[I18n.locale]).detect{|t| t.attachment}
41
+ current_translation.attachment
42
+ else
43
+ nil
44
+ end
45
+ end
46
+
47
+ def images
48
+ if current_translation = translations.with_locales(I18n.fallbacks[I18n.locale]).detect{|t| t.images.any? }
49
+ current_translation.images
50
+ else
51
+ []
52
+ end
53
+ end
54
+
29
55
  class Translation
30
56
  attr_protected :id
31
57
 
32
58
  has_many :attachments, as: :assetable
59
+ has_many :images, as: :assetable
60
+ has_one :attachment, as: :assetable
61
+ has_one :image, as: :assetable
33
62
 
34
- accepts_nested_attributes_for :attachments
63
+ accepts_nested_attributes_for :attachments, reject_if: lambda{ |i| i[:data].blank? }
64
+ accepts_nested_attributes_for :attachment, reject_if: lambda{ |i| i[:data].blank? }
65
+ accepts_nested_attributes_for :image, reject_if: lambda{ |i| i[:data].blank? }
66
+ accepts_nested_attributes_for :images, reject_if: lambda{ |i| i[:data].blank? }
35
67
  end
36
68
  end
37
69
  end
@@ -5,8 +5,9 @@
5
5
  - current_locale = ActiveadminSelleoCms::Locale.find_by_code(I18n.locale)
6
6
  - @page.initialize_missing_sections
7
7
  - @section_forms = []
8
+ -#= @page.errors.full_messages
8
9
 
9
- = form.inputs "General options" do
10
+ = form.inputs general_options(@page) do
10
11
  = form.input :layout_name, collection: ActiveadminSelleoCms::Layout.all.sort, include_blank: false, hint: "The form will reload on change"
11
12
  = form.input :parent_id, as: :select, collection: nested_set_options(ActiveadminSelleoCms::Page, @page) {|i| "#{'-' * i.level} #{i.title}" }
12
13
  = form.input :is_published, as: :boolean, input_html: { checked: @page.published_at.present? }
@@ -41,13 +42,6 @@
41
42
  - else
42
43
  = ""
43
44
 
44
- - unless @page.new_record?
45
- = form.inputs "Page icon", for: [:icon, form.object.icon || ActiveadminSelleoCms::Icon.new] do |icon_form|
46
- = icon_form.input :data, label: "Icon", hint: (form.object.icon ? icon_form.template.image_tag(form.object.icon_url) : "No icon uploaded yet" )
47
-
48
- = form.inputs "Header image", for: [:header_image, form.object.header_image || ActiveadminSelleoCms::HeaderImage.new] do |header_image_form|
49
- = header_image_form.input :data, label: "Header image", hint: (form.object.header_image ? header_image_form.template.image_tag(form.object.header_image_url) : "No header image uploaded yet" )
50
-
51
45
  = form.actions do
52
46
  = form.action :submit
53
47
  %li.cancel
@@ -8,20 +8,57 @@
8
8
  = form.input :meta_keywords, input_html: { class: 'link-url-hide' }
9
9
  = form.input :meta_description, input_html: { rows: 3, class: 'link-url-hide' }
10
10
  = form.input :locale, :as => :hidden, :label => false
11
+ -#- unless @page.new_record?
11
12
  - @section_forms.each do |section_form|
12
- = section_form.semantic_fields_for :translations do |section_form_translated|
13
- - if section_form_translated.object.locale.to_sym == locale.code
14
- - section = @page.layout.find_section(section_form.object.name)
15
- = section_form_translated.input :body, as: section.type, label: "#{section_form.object.name.titleize} part", input_html: { toolbar: section.toolbar }
16
- = section_form_translated.input :locale, :as => :hidden, :label => false
17
- - if !@page.new_record? and section.attachments
18
- = section_form_translated.inputs "Attachments", for: [:attachments, ActiveadminSelleoCms::Attachment.new] do |attachment_form|
19
- = attachment_form.input :data, label: "Attachment", input_html: { multiple: false }
20
- - section_form_translated.object.attachments.each do |attachment|
21
- %li{"data-asset-id" => attachment.id}
22
- %label File
23
- = attachment.data_file_name
24
- = link_to_function "Delete", "delete_asset(#{@page.id}, #{attachment.id})"
25
- - else
26
- = ""
13
+ %section{:name => section_form.object.name}
14
+ = section_form.semantic_fields_for :translations do |section_form_translated|
15
+ - if section_form_translated.object.locale.to_sym == locale.code
16
+ - section = @page.layout.find_section(section_form.object.name)
17
+
18
+ - if section.text?
19
+ = section_form_translated.input :body, as: section.type, label: section.name.titleize, input_html: { toolbar: section.toolbar }
20
+
21
+ - elsif section.image?
22
+ = section_form_translated.inputs section.name.titleize, for: [:image, section_form_translated.object.image || ActiveadminSelleoCms::Image.new] do |image_form|
23
+ = image_form.input :image_width, as: :hidden, value: section.width
24
+ = image_form.input :image_height, as: :hidden, value: section.height
25
+ = image_form.input :resize_method, as: :hidden, value: section.resize_method
26
+ = image_form.input :data, label: "File to upload", input_html: { multiple: false }, hint: (section_form_translated.object.image ? section_form_translated.template.image_tag(section_form_translated.object.image.url) : "No icon uploaded yet" )
27
+
28
+ - elsif section.images?
29
+ = section_form_translated.inputs section.name.titleize, for: [:images, ActiveadminSelleoCms::Image.new] do |image_form|
30
+ = image_form.input :image_width, as: :hidden, value: section.width
31
+ = image_form.input :image_height, as: :hidden, value: section.height
32
+ = image_form.input :resize_method, as: :hidden, value: section.resize_method
33
+ = image_form.input :data, label: "File to upload", input_html: { multiple: false }
34
+ - unless section_form_translated.object.new_record?
35
+ - section_form_translated.object.images.each do |image|
36
+ %li{"data-asset-id" => image.id}
37
+ %label Image
38
+ = image.data_file_name
39
+ = link_to_function "Delete", "delete_asset(#{@page.id}, #{image.id})"
40
+
41
+ - elsif section.attachment?
42
+ = section_form_translated.inputs section.name.titleize, for: [:attachment, section_form_translated.object.image || ActiveadminSelleoCms::Attachment.new] do |attachment_form|
43
+ = attachment_form.input :data, label: "File to upload", input_html: { multiple: false }, hint: (section_form_translated.object.image ? link_to(section_form_translated.object.image.url) : "No file uploaded yet" )
44
+ = attachment_form.input :cover, label: "Cover image"
45
+ = attachment_form.input :caption
46
+
47
+ = section_form_translated.input :locale, :as => :hidden, :label => false
48
+ - if section.attachments?
49
+ = section_form_translated.inputs "#{section.name.titleize} attachments", for: [:attachments, ActiveadminSelleoCms::Attachment.new] do |attachment_form|
50
+ = attachment_form.input :data, label: "File to upload"
51
+ = attachment_form.input :cover, label: "Cover image"
52
+ = attachment_form.input :caption
53
+ - if section_form_translated.object.attachments.any? and !section_form_translated.object.new_record?
54
+ %li Existing files
55
+ - section_form_translated.object.attachments.each do |attachment|
56
+ %li{"data-asset-id" => attachment.id}
57
+ %label File
58
+ = attachment.data_file_name
59
+ = image_tag(attachment.cover.url) if attachment.cover.exists?
60
+ = attachment.caption
61
+ = link_to_function "Delete", "delete_asset(#{@page.id}, #{attachment.id})"
62
+ - else
63
+ = ""
27
64