activeadmin-selleo-cms 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ ActiveAdmin.register ActiveadminSelleoCms::Asset, { as: 'Asset' } do
2
+ config.batch_actions = false
3
+
4
+ belongs_to :page
5
+
6
+ controller do
7
+ respond_to :html, :js
8
+
9
+ def destroy
10
+ @page = ActiveadminSelleoCms::Page.find(params[:page_id])
11
+ super do |format|
12
+ format.js { render nothing: true }
13
+ end
14
+ end
15
+ end
16
+
17
+ end
@@ -1,15 +1,15 @@
1
1
  ActiveAdmin.register ActiveadminSelleoCms::Page, as: "Page", sort_order: "lft_asc" do
2
2
  config.batch_actions = false
3
3
 
4
- scope :all, default: true
4
+ #scope :all, default: true
5
5
 
6
- -> {
7
- ActiveadminSelleoCms::Page.roots.each do |page|
8
- scope page.title do
9
- ActiveadminSelleoCms::Page.where(parent_id: page.id)
10
- end
11
- end
12
- }
6
+ #-> {
7
+ # ActiveadminSelleoCms::Page.roots.each do |page|
8
+ # scope page.title do
9
+ # ActiveadminSelleoCms::Page.where(parent_id: page.id)
10
+ # end
11
+ # end
12
+ #}
13
13
 
14
14
  form :partial => "form"
15
15
 
@@ -17,7 +17,7 @@ ActiveAdmin.register ActiveadminSelleoCms::Page, as: "Page", sort_order: "lft_as
17
17
 
18
18
  index do
19
19
  column :title do |page|
20
- "#{'—' * page.depth} #{page.title}".html_safe
20
+ "#{'     ' * page.depth + '»'} #{page.title}".html_safe
21
21
  end
22
22
  column :show_in_menu do |page|
23
23
  check_box_tag "activeadmin_selleo_cms_page[show_in_menu][#{page.id}]", 1, page.show_in_menu, data: { route: admin_page_path(page.id), id: page.id, resource: 'page', attribute: 'show_in_menu' }
@@ -16,6 +16,17 @@ var slug = function(str) {
16
16
  return str;
17
17
  };
18
18
 
19
+ function delete_asset(page_id, asset_id) {
20
+ $.ajax({
21
+ url: '/admin/pages/' + page_id + '/assets/' + asset_id + '.js',
22
+ type: 'DELETE'
23
+ }).success(function(){
24
+ $('[data-attachment-id="' + asset_id + '"]').remove();
25
+ }).error(function(){
26
+ alert('Could not delete attachment');
27
+ });
28
+ }
29
+
19
30
  $(function(){
20
31
  $('#translations.index input').blur(function(evt){
21
32
  $.ajax({
@@ -1,5 +1,5 @@
1
1
  module ActiveadminSelleoCms
2
- class ApplicationController < ActionController::Base
2
+ class ApplicationController < ApplicationController
3
3
 
4
4
  before_filter do
5
5
  I18n.locale = params[:locale]
@@ -24,8 +24,8 @@ module ActiveadminSelleoCms
24
24
  end
25
25
  end
26
26
 
27
- def link_to_page(page)
28
- link_to page.title, url_to_page(page)
27
+ def link_to_page(page, link_name=nil)
28
+ link_to (link_name || page.title), url_to_page(page)
29
29
  end
30
30
  end
31
31
  end
@@ -0,0 +1,11 @@
1
+ module ActiveadminSelleoCms
2
+ class Asset < ActiveRecord::Base
3
+ attr_accessible :data
4
+
5
+ belongs_to :assetable, polymorphic: true
6
+
7
+ def url(format=nil)
8
+ data.url(format)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module ActiveadminSelleoCms
2
+ class Attachment < ActiveadminSelleoCms::Asset
3
+ has_attached_file :data,
4
+ :url => "/cms/attachments/:id/:style_:basename.:extension",
5
+ :path => ":rails_root/public/cms/attachments/:id/:style_:basename.:extension"
6
+
7
+ validates_attachment_size :data, :less_than => 10.megabytes
8
+ validates_attachment_presence :data
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ module ActiveadminSelleoCms
2
+ class HeaderImage < ActiveadminSelleoCms::Asset
3
+ has_attached_file :data,
4
+ :url => "/cms/header_images/:id/:style_:basename.:extension",
5
+ :path => ":rails_root/public/cms/header_images/:id/:style_:basename.:extension",
6
+ :styles => { :normal => "770x385#" },
7
+ :default_style => :normal
8
+
9
+ validates_attachment_size :data, :less_than => 1.megabytes
10
+ validates_attachment_presence :data
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module ActiveadminSelleoCms
2
+ class Icon < ActiveadminSelleoCms::Asset
3
+ has_attached_file :data,
4
+ :url => "/cms/icons/:id/:style_:basename.:extension",
5
+ :path => ":rails_root/public/cms/icons/:id/:style_:basename.:extension",
6
+ :styles => { :normal => "120x90#" },
7
+ :default_style => :normal
8
+
9
+ validates_attachment_size :data, :less_than => 1.megabytes
10
+ validates_attachment_presence :data
11
+ end
12
+ end
@@ -9,8 +9,12 @@ module ActiveadminSelleoCms
9
9
  attr_protected :id
10
10
 
11
11
  has_many :sections, as: :sectionable
12
+ has_one :icon, as: :assetable
13
+ has_one :header_image, as: :assetable
14
+ has_many :attachments, as: :assetable
15
+ has_many :assets, as: :assetable
12
16
 
13
- accepts_nested_attributes_for :translations, :sections, :children
17
+ accepts_nested_attributes_for :translations, :sections, :children, :icon, :header_image, :attachments
14
18
 
15
19
  validates_format_of :link_url, with: /^http/i, allow_blank: false, if: ->(page) { page.is_link_url }
16
20
  validates_presence_of :layout
@@ -57,6 +61,14 @@ module ActiveadminSelleoCms
57
61
  slug
58
62
  end
59
63
 
64
+ def icon_url
65
+ icon ? icon.url : 'http://placehold.it/120x90'
66
+ end
67
+
68
+ def header_image_url
69
+ header_image ? header_image.url : 'http://placehold.it/770x385'
70
+ end
71
+
60
72
  class Translation
61
73
  attr_protected :id
62
74
 
@@ -15,6 +15,20 @@
15
15
  = form.input :is_link_url, as: :boolean, input_html: { checked: @page.link_url.present? }
16
16
  = form.input :link_url, hint: "Enter remote URL including the http part at the beginning"
17
17
 
18
+ = form.inputs "Page icon", for: [:icon, form.object.icon || ActiveadminSelleoCms::Icon.new] do |icon_form|
19
+ = icon_form.input :data, label: "Icon", hint: (form.object.icon ? icon_form.template.image_tag(form.object.icon_url) : "No icon uploaded yet" )
20
+
21
+ = form.inputs "Header image", for: [:header_image, form.object.header_image || ActiveadminSelleoCms::HeaderImage.new] do |header_image_form|
22
+ = 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" )
23
+
24
+ = form.inputs "Attachments", for: [:attachments, ActiveadminSelleoCms::Attachment.new] do |attachment_form|
25
+ = attachment_form.input :data, label: "Attachment", input_html: { multiple: true, name: "page[attachments_attributes][][data]" }
26
+ - form.object.attachments.each do |attachment|
27
+ %li{"data-attachment-id" => attachment.id}
28
+ %label File
29
+ = attachment.data_file_name
30
+ = link_to_function "Delete", "delete_asset(#{@page.id}, #{attachment.id})"
31
+
18
32
  = form.semantic_fields_for :sections do |section_form|
19
33
  - if @page.section_names.include? section_form.object.name
20
34
  - @section_forms << section_form
@@ -0,0 +1,25 @@
1
+ class CreateActiveadminSelleoCmsAssets < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :activeadmin_selleo_cms_assets do |t|
4
+ t.string :data_file_name, :null => false
5
+ t.string :data_content_type
6
+ t.integer :data_file_size
7
+
8
+ t.integer :assetable_id
9
+ t.string :assetable_type
10
+ t.string :type
11
+
12
+ t.integer :width
13
+ t.integer :height
14
+
15
+ t.timestamps
16
+ end
17
+
18
+ add_index "activeadmin_selleo_cms_assets", ["assetable_type", "type", "assetable_id"], :name => "idx_activeadmin_selleo_cms_asset_assetable_type"
19
+ add_index "activeadmin_selleo_cms_assets", ["assetable_type", "assetable_id"], :name => "idx_activeadmin_selleo_cms_assets_assetable"
20
+ end
21
+
22
+ def self.down
23
+ drop_table :activeadmin_selleo_cms_assets
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveadminSelleoCms
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
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.8
4
+ version: 0.0.9
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-01-01 00:00:00.000000000 Z
12
+ date: 2013-01-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -217,6 +217,7 @@ files:
217
217
  - app/admin/translation.rb
218
218
  - app/admin/activeadmin_selleo_cms/locale.rb
219
219
  - app/admin/activeadmin_selleo_cms/page.rb
220
+ - app/admin/activeadmin_selleo_cms/asset.rb
220
221
  - app/views/layouts/activeadmin_selleo_cms/application.html.erb
221
222
  - app/views/admin/pages/_form.html.haml
222
223
  - app/views/admin/pages/_translated_fields.html.haml
@@ -227,10 +228,14 @@ files:
227
228
  - app/views/active_admin/resource/update.js
228
229
  - app/models/translation.rb
229
230
  - app/models/activeadmin_selleo_cms/section.rb
231
+ - app/models/activeadmin_selleo_cms/icon.rb
230
232
  - app/models/activeadmin_selleo_cms/locale.rb
233
+ - app/models/activeadmin_selleo_cms/attachment.rb
231
234
  - app/models/activeadmin_selleo_cms/layout.rb
232
235
  - app/models/activeadmin_selleo_cms/search.rb
236
+ - app/models/activeadmin_selleo_cms/header_image.rb
233
237
  - app/models/activeadmin_selleo_cms/page.rb
238
+ - app/models/activeadmin_selleo_cms/asset.rb
234
239
  - app/models/ckeditor/picture.rb
235
240
  - app/models/ckeditor/attachment_file.rb
236
241
  - app/models/ckeditor/asset.rb
@@ -255,6 +260,7 @@ files:
255
260
  - db/migrate/20121227222912_create_translations.rb
256
261
  - db/migrate/20121204112326_create_ckeditor_assets.rb
257
262
  - db/migrate/20121221164723_create_activeadmin_selleo_cms_searches.rb
263
+ - db/migrate/20130102113712_create_activeadmin_selleo_cms_assets.rb
258
264
  - lib/activeadmin-selleo-cms/application.rb
259
265
  - lib/activeadmin-selleo-cms/version.rb
260
266
  - lib/activeadmin-selleo-cms/engine.rb