activeadmin-selleo-cms 0.0.20 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,6 @@
1
1
  ActiveAdmin.register ActiveadminSelleoCms::Asset, { as: 'Asset' } do
2
2
  config.batch_actions = false
3
-
4
- #belongs_to :page
3
+ menu false
5
4
 
6
5
  controller do
7
6
  respond_to :html, :js
@@ -0,0 +1,9 @@
1
+ ActiveAdmin.register ActiveadminSelleoCms::RelatedItem, { as: 'RelatedItem' } do
2
+ config.batch_actions = false
3
+ menu false
4
+
5
+ controller do
6
+ respond_to :html, :js
7
+ end
8
+
9
+ end
@@ -20,13 +20,20 @@ function delete_asset(page_id, asset_id) {
20
20
  $.ajax({
21
21
  url: '/admin/assets/' + asset_id + '.js',
22
22
  type: 'DELETE'
23
- }).success(function(){
24
- $('[data-attachment-id="' + asset_id + '"]').remove();
25
23
  }).error(function(){
26
24
  alert('Could not delete attachment');
27
25
  });
28
26
  }
29
27
 
28
+ function delete_related(page_id, related_item_id) {
29
+ $.ajax({
30
+ url: '/admin/related_items/' + related_item_id + '.js',
31
+ type: 'DELETE'
32
+ }).error(function(){
33
+ alert('Could not delete related item');
34
+ });
35
+ }
36
+
30
37
  function update_positions(pagesArray) {
31
38
  $('.update-positions-button').attr('disabled', true).attr('value', 'Saving...')
32
39
  $.ajax({
@@ -19,19 +19,13 @@ module PagesHelper
19
19
  return "#" unless page
20
20
  _locale = I18n.locale
21
21
  I18n.locale = locale
22
- _url = if page.is_link_url
23
- page.link_url
24
- elsif page.redirect_to_first_sub_page
25
- page.children.published.any? ? url_to_page(page.children.published.first) : "#"
26
- else
27
- page_path(locale, page)
28
- end
22
+ _url = page.url
29
23
  I18n.locale = _locale
30
24
  return _url
31
25
  end
32
26
 
33
27
  def link_to_page(page, link_name=nil)
34
- link_to (link_name || page.title), url_to_page(page)
28
+ link_to (link_name || page.title), page.url
35
29
  end
36
30
 
37
31
  def s(name)
@@ -1,17 +1,25 @@
1
1
  module ActiveadminSelleoCms
2
2
  class Asset < ActiveRecord::Base
3
3
  attr_protected :id
4
+ attr_accessor :cover_width, :cover_height, :cover_resize_method
4
5
 
5
6
  belongs_to :assetable, polymorphic: true
6
7
 
7
8
  has_attached_file :cover,
8
9
  :url => "/system/cms/covers/:id/:style_:basename.:extension",
9
- :path => ":rails_root/public/system/cms/covers/:id/:style_:basename.:extension"
10
+ :path => ":rails_root/public/system/cms/covers/:id/:style_:basename.:extension",
11
+ :styles => Proc.new{ |attachment| attachment.instance.image_sizes },
12
+ :default_style => :normal
10
13
 
11
14
  validates_attachment_size :cover, :less_than => 10.megabytes
12
15
 
13
16
  def url(format=nil)
14
17
  data.url(format)
15
18
  end
19
+
20
+ def image_sizes
21
+ { :normal => "#{cover_width || 120}x#{cover_height || 90}#{cover_resize_method || ">"}" }
22
+ end
23
+
16
24
  end
17
25
  end
@@ -1,6 +1,6 @@
1
1
  module ActiveadminSelleoCms
2
2
  class Image < ActiveadminSelleoCms::Asset
3
- attr_accessor :image_width, :image_height, :resize_method
3
+ attr_accessor :image_width, :image_height, :resize_method, :cover_width, :cover_height
4
4
 
5
5
  has_attached_file :data,
6
6
  :url => "/system/cms/images/:id/:style_:basename.:extension",
@@ -37,37 +37,45 @@ module ActiveadminSelleoCms
37
37
  end
38
38
 
39
39
  class Section
40
- attr_accessor :name, :type, :toolbar, :width, :height, :resize_method
40
+ attr_accessor :name, :type, :toolbar, :width, :height, :resize_method, :cover_width, :cover_height, :cover_resize_method
41
41
 
42
42
  def initialize(node)
43
43
  @name = node.attributes["name"].content
44
44
  @type = node.attributes["data-type"] ? node.attributes["data-type"].content : 'ckeditor'
45
- @attachments = (['files'].include?(@type) or node.attributes["data-attachments"]) ? true : false
46
- @attachment = (['file'].include?(@type) or node.attributes["data-attachment"]) ? true : false
45
+ @attachments = node.attributes["data-attachments"] ? node.attributes["data-attachments"].content.eql?("true") : false
46
+ @attachment = node.attributes["data-attachment"] ? node.attributes["data-attachment"].content.eql?("true") : false
47
+ @related = node.attributes["data-related"] ? node.attributes["data-related"].content.eql?("true") : false
47
48
  @toolbar = node.attributes["data-toolbar"] ? node.attributes["data-toolbar"].content : 'Minimal'
48
49
  @width = node.attributes["data-width"] ? node.attributes["data-width"].content : 640
49
50
  @height = node.attributes["data-height"] ? node.attributes["data-height"].content : 480
50
51
  @resize_method = node.attributes["data-resize-method"] ? node.attributes["data-resize-method"].content : "#"
52
+ @cover_width = node.attributes["data-cover-width"] ? node.attributes["data-cover-width"].content : 140
53
+ @cover_height = node.attributes["data-cover-height"] ? node.attributes["data-cover-height"].content : 199
54
+ @cover_resize_method = node.attributes["data-cover-resize-method"] ? node.attributes["data-cover-resize-method"].content : ">"
51
55
  end
52
56
 
53
57
  def text?
54
- ['ckeditor', 'text'].include? @type
58
+ ['ckeditor', 'text', 'string'].include? @type.downcase
55
59
  end
56
60
 
57
61
  def image?
58
- ['image'].include? @type
62
+ ['image'].include? @type.downcase
59
63
  end
60
64
 
61
65
  def images?
62
- ['images'].include? @type
66
+ ['images'].include? @type.downcase
63
67
  end
64
68
 
65
69
  def attachments?
66
- @attachments == true
70
+ ['files'].include?(@type.downcase) or @attachments
67
71
  end
68
72
 
69
73
  def attachment?
70
- @attachment == true
74
+ ['file'].include?(@type.downcase) or @attachment
75
+ end
76
+
77
+ def related?
78
+ ['related'].include?(@type.downcase) or @related
71
79
  end
72
80
 
73
81
  end
@@ -10,19 +10,14 @@ module ActiveadminSelleoCms
10
10
 
11
11
  attr_protected :id
12
12
 
13
- has_many :sections, as: :sectionable
14
- has_many :attachments, as: :assetable
15
- has_many :assets, as: :assetable
16
- has_many :searches, as: :searchable
17
- # ZUO
18
- #has_many :translations, class_name: 'ActiveadminSelleoCms::Page::Translation', foreign_key: :activeadmin_selleo_cms_page_id, dependent: :destroy, before_add: :set_nest
13
+ has_many :sections, as: :sectionable, dependent: :destroy
14
+ has_many :searches, as: :searchable, dependent: :destroy
15
+ has_many :related_items, as: :related
19
16
 
20
- accepts_nested_attributes_for :translations, :sections, :children, :attachments
17
+ accepts_nested_attributes_for :translations, :sections, :children
21
18
 
22
19
  validates_format_of :link_url, with: /^http/i, allow_blank: false, if: ->(page) { page.is_link_url }
23
20
  validates_presence_of :layout_name
24
- # ZUO
25
- #validates_associated :translations, :sections
26
21
 
27
22
  scope :show_in_menu, where(show_in_menu: true)
28
23
  scope :published, where(is_published: true)
@@ -39,8 +34,8 @@ module ActiveadminSelleoCms
39
34
  end
40
35
 
41
36
  before_save do
42
- if is_published_changed?
43
- self.published_at = is_published ? Time.now : nil
37
+ if is_published_changed? and is_published and published_at.blank?
38
+ self.published_at = Time.now
44
39
  end
45
40
  end
46
41
 
@@ -79,6 +74,10 @@ module ActiveadminSelleoCms
79
74
  title
80
75
  end
81
76
 
77
+ def to_label
78
+ "#{'- ' * depth} #{title}"
79
+ end
80
+
82
81
  def section_names
83
82
  @section_names ||= layout.section_names
84
83
  end
@@ -124,6 +123,10 @@ module ActiveadminSelleoCms
124
123
  end
125
124
  end
126
125
 
126
+ #def method_missing(sym, *args)
127
+ # sections.with_name(sym).first
128
+ #end
129
+
127
130
  class Translation
128
131
  attr_protected :id
129
132
 
@@ -0,0 +1,20 @@
1
+ module ActiveadminSelleoCms
2
+ class RelatedItem < ActiveRecord::Base
3
+ attr_protected :id
4
+
5
+ belongs_to :relatable, polymorphic: true
6
+ belongs_to :page
7
+
8
+ validates_presence_of :page_id, if: ->(ri){ ri.related_url.blank? }
9
+ validates :related_url, presence: true, format: { with: /^http/i }, if: ->(ri){ ri.page_id.blank? }
10
+
11
+ def target_title
12
+ title.present? ? title : (page.present? ? page.title : related_url)
13
+ end
14
+
15
+ def target_url
16
+ related_url.present? ? related_url : page.url
17
+ end
18
+
19
+ end
20
+ end
@@ -55,15 +55,17 @@ module ActiveadminSelleoCms
55
55
  class Translation
56
56
  attr_protected :id
57
57
 
58
- has_many :attachments, as: :assetable
59
- has_many :images, as: :assetable
60
- has_one :attachment, as: :assetable
61
- has_one :image, as: :assetable
58
+ has_many :attachments, as: :assetable, dependent: :destroy
59
+ has_many :images, as: :assetable, dependent: :destroy
60
+ has_one :attachment, as: :assetable, dependent: :destroy
61
+ has_one :image, as: :assetable, dependent: :destroy
62
+ has_many :related_items, as: :relatable, dependent: :destroy
62
63
 
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? }
64
+ accepts_nested_attributes_for :attachments, reject_if: lambda{ |a| a[:data].blank? }
65
+ accepts_nested_attributes_for :attachment, reject_if: lambda{ |a| a[:data].blank? }
65
66
  accepts_nested_attributes_for :image, reject_if: lambda{ |i| i[:data].blank? }
66
67
  accepts_nested_attributes_for :images, reject_if: lambda{ |i| i[:data].blank? }
68
+ accepts_nested_attributes_for :related_items, reject_if: lambda{ |ri| ri[:related_url].blank? and ri[:page_id].blank? }
67
69
  end
68
70
  end
69
71
  end
@@ -11,6 +11,7 @@
11
11
  = form.input :layout_name, collection: ActiveadminSelleoCms::Layout.all.sort, include_blank: false, hint: "The form will reload on change"
12
12
  = form.input :parent_id, as: :select, collection: nested_set_options(ActiveadminSelleoCms::Page, @page) {|i| "#{'-' * i.level} #{i.title}" }
13
13
  = form.input :is_published, as: :boolean, input_html: { checked: @page.published_at.present? }
14
+ = form.input :published_at, as: :datetimepicker
14
15
  = form.input :redirect_to_first_sub_page, as: :boolean
15
16
  = form.input :is_link_url, as: :boolean, input_html: { checked: @page.link_url.present? }
16
17
  = form.input :link_url, hint: "Enter remote URL including the http part at the beginning"
@@ -24,6 +24,7 @@
24
24
  = image_form.input :image_height, as: :hidden, value: section.height
25
25
  = image_form.input :resize_method, as: :hidden, value: section.resize_method
26
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
+ = image_form.input :caption
27
28
 
28
29
  - elsif section.images?
29
30
  = section_form_translated.inputs section.name.titleize, for: [:images, ActiveadminSelleoCms::Image.new] do |image_form|
@@ -31,6 +32,7 @@
31
32
  = image_form.input :image_height, as: :hidden, value: section.height
32
33
  = image_form.input :resize_method, as: :hidden, value: section.resize_method
33
34
  = image_form.input :data, label: "File to upload", input_html: { multiple: false }
35
+ = image_form.input :caption
34
36
  - unless section_form_translated.object.new_record?
35
37
  - section_form_translated.object.images.each do |image|
36
38
  %li{"data-asset-id" => image.id}
@@ -41,24 +43,50 @@
41
43
  - elsif section.attachment?
42
44
  = section_form_translated.inputs section.name.titleize, for: [:attachment, section_form_translated.object.image || ActiveadminSelleoCms::Attachment.new] do |attachment_form|
43
45
  = 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" )
46
+ = attachment_form.input :cover_width, as: :hidden, value: section.cover_width
47
+ = attachment_form.input :cover_height, as: :hidden, value: section.cover_height
48
+ = attachment_form.input :cover_resize_method, as: :hidden, value: section.cover_resize_method
44
49
  = attachment_form.input :cover, label: "Cover image"
45
50
  = attachment_form.input :caption
46
51
 
47
52
  = section_form_translated.input :locale, :as => :hidden, :label => false
53
+
48
54
  - if section.attachments?
49
- = section_form_translated.inputs "#{section.name.titleize} attachments", for: [:attachments, ActiveadminSelleoCms::Attachment.new] do |attachment_form|
55
+ = section_form_translated.inputs "#{section.name.titleize} attachments", for: [:attachments, section_form_translated.object.attachments.detect{|a| a.new_record?} || ActiveadminSelleoCms::Attachment.new] do |attachment_form|
50
56
  = attachment_form.input :data, label: "File to upload"
57
+ = attachment_form.input :cover_image_width, as: :hidden, value: section.cover_width
58
+ = attachment_form.input :cover_image_height, as: :hidden, value: section.cover_height
59
+ = attachment_form.input :cover_resize_method, as: :hidden, value: section.cover_resize_method
51
60
  = attachment_form.input :cover, label: "Cover image"
52
61
  = attachment_form.input :caption
53
62
  - if section_form_translated.object.attachments.any? and !section_form_translated.object.new_record?
54
63
  %li Existing files
55
64
  - 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})"
65
+ - unless attachment.new_record?
66
+ %li{"data-asset-id" => attachment.id}
67
+ %label File
68
+ .attachment
69
+ .cover-image= image_tag(attachment.cover.url) if attachment.cover.exists?
70
+ .file-name= attachment.data_file_name
71
+ .caption= attachment.caption
72
+ .delete-link= link_to_function "Delete", "delete_asset(#{@page.id}, #{attachment.id})"
73
+
74
+ - if section.related?
75
+ = section_form_translated.inputs "#{section.name.titleize}", for: [:related_items, section_form_translated.object.related_items.detect{|ri| ri.new_record?} || ActiveadminSelleoCms::RelatedItem.new] do |related_form|
76
+ = related_form.input :title
77
+ = related_form.input :related_url
78
+ %li or
79
+ = related_form.input :page, collection: ActiveadminSelleoCms::Page.published.reorder("lft"), label: 'Related page'
80
+ - if section_form_translated.object.related_items.any? and !section_form_translated.object.new_record?
81
+ %li Related links
82
+ - section_form_translated.object.related_items.each do |related_item|
83
+ - unless related_item.new_record?
84
+ %li{"data-related-item-id" => related_item.id}
85
+ %label Link
86
+ .related
87
+ .related-item= link_to related_item.target_title, related_item.target_url, target: '_blank'
88
+ .delete-link= link_to_function "Delete", "delete_related(#{@page.id}, #{related_item.id})"
89
+
62
90
  - else
63
91
  = ""
64
92
 
@@ -0,0 +1 @@
1
+ $('li[data-related-item-id="<%= @related_item.id %>"]').remove();
@@ -0,0 +1,16 @@
1
+ class CreateActiveadminSelleoCmsRelatedItems < ActiveRecord::Migration
2
+ def change
3
+ create_table :activeadmin_selleo_cms_related_items do |t|
4
+ t.integer :relatable_id
5
+ t.string :relatable_type
6
+
7
+ t.belongs_to :page
8
+
9
+ t.string :related_url
10
+
11
+ t.string :title
12
+
13
+ t.timestamps
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveadminSelleoCms
2
- VERSION = "0.0.20"
2
+ VERSION = "0.0.21"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin-selleo-cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.20
4
+ version: 0.0.21
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-07 00:00:00.000000000 Z
12
+ date: 2013-02-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -361,11 +361,13 @@ files:
361
361
  - app/admin/translation.rb
362
362
  - app/admin/activeadmin_selleo_cms/section.rb
363
363
  - app/admin/activeadmin_selleo_cms/locale.rb
364
+ - app/admin/activeadmin_selleo_cms/related_item.rb
364
365
  - app/admin/activeadmin_selleo_cms/page.rb
365
366
  - app/admin/activeadmin_selleo_cms/asset.rb
366
367
  - app/admin/active_admin/views_helper.rb
367
368
  - app/views/layouts/activeadmin_selleo_cms/application.html.erb
368
369
  - app/views/admin/sections/_form.html.haml
370
+ - app/views/admin/related_items/destroy.js.erb
369
371
  - app/views/admin/pages/reorder.html.haml
370
372
  - app/views/admin/pages/_form.html.haml
371
373
  - app/views/admin/pages/_translated_fields.html.haml
@@ -380,6 +382,7 @@ files:
380
382
  - app/models/activeadmin_selleo_cms/section.rb
381
383
  - app/models/activeadmin_selleo_cms/image.rb
382
384
  - app/models/activeadmin_selleo_cms/locale.rb
385
+ - app/models/activeadmin_selleo_cms/related_item.rb
383
386
  - app/models/activeadmin_selleo_cms/attachment.rb
384
387
  - app/models/activeadmin_selleo_cms/layout.rb
385
388
  - app/models/activeadmin_selleo_cms/search.rb
@@ -414,6 +417,7 @@ files:
414
417
  - db/migrate/20121204112326_create_ckeditor_assets.rb
415
418
  - db/migrate/20130207213528_change_activeadmin_selleo_cms_assets.rb
416
419
  - db/migrate/20121221164723_create_activeadmin_selleo_cms_searches.rb
420
+ - db/migrate/20130211151210_create_activeadmin_selleo_cms_related_items.rb
417
421
  - db/migrate/20130102113712_create_activeadmin_selleo_cms_assets.rb
418
422
  - db/migrate/20130108153415_add_redirect_to_first_sub_page.rb
419
423
  - db/migrate/20130109132745_add_fields_to_page.rb