etabliocms_pages 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ //= require jquery.uploadify.v2.1.4
2
+ //= require swfobject
3
+ //= require jquery.zclip
4
+ //= require pages
@@ -0,0 +1,13 @@
1
+ var AdminPages = function() {
2
+
3
+ return {
4
+ initCopyPaste : function() {
5
+ $('.icon-copypaste').zclip({
6
+ path:'/uploadify/ZeroClipboard.swf',
7
+ copy: $(this).parent().find(".url").text,
8
+ clickAfter: false
9
+ }
10
+ );
11
+ }
12
+ }
13
+ }();
@@ -0,0 +1,4 @@
1
+ /*
2
+ *= require pages
3
+ *= require uploadify
4
+ */
@@ -0,0 +1,10 @@
1
+ #data-submit { float: none; margin-top: 15px; }
2
+ #attachments { width: 698px; overflow: hidden; margin: 0 0 15px 0;
3
+ ul { margin-left: 1em; }
4
+ li { padding-bottom: 10px; }
5
+ }
6
+
7
+ .attachment { float: left; clear:left;
8
+ .icon { float: right; }
9
+
10
+ }
@@ -11,7 +11,7 @@ module EtabliocmsPages
11
11
  @page = Page.new(params[:etabliocms_pages_page])
12
12
  if @page.save
13
13
  flash[:notice] = t('page.created')
14
- redirect_to :action => 'index'
14
+ redirect_to params[:save_and_continue].present? ? {:action => 'edit'} : {:action => 'index'}
15
15
  else
16
16
  @page.build_contents_for_available_locales
17
17
  render :action => 'new'
@@ -20,21 +20,27 @@ module EtabliocmsPages
20
20
 
21
21
  def edit
22
22
  @page = Page.find(params[:id])
23
+ @page.build_contents_for_available_locales
23
24
  end
24
25
 
25
26
  def update
26
27
  @page = Page.find(params[:id])
27
28
  if @page.update_attributes(params[:etabliocms_pages_page])
28
29
  flash[:notice] = t('page.updated')
29
- redirect_to :action => 'index'
30
+ redirect_to params[:save_and_continue].present? ? {:action => 'edit'} : {:action => 'index'}
30
31
  else
31
32
  render :action => 'edit'
32
33
  end
33
34
  end
34
35
 
35
36
  def destroy
36
- Page.find(params[:id]).destroy
37
- flash[:notice] = t('page.destroyed')
37
+ @page = Page.find(params[:id])
38
+ unless @page.locked
39
+ @page.destroy
40
+ flash[:notice] = t('page.destroyed')
41
+ else
42
+ flash[:notice] = t('page.locked')
43
+ end
38
44
  redirect_to :action => 'index'
39
45
  end
40
46
 
@@ -49,6 +55,16 @@ module EtabliocmsPages
49
55
  redirect_to :action => 'index'
50
56
  end
51
57
 
58
+ def update_attachments
59
+ @page = Page.find(params[:attachable_id])
60
+ @attachment = @page.attachments.create(:data => params[:Filedata])
61
+ render :partial => "attachments", :layout => false
62
+ end
63
+
64
+ def destroy_attachment
65
+ @page = Page.find(params[:id])
66
+ @page.attachments.find(params[:attachment_id]).destroy
67
+ end
52
68
  end
53
69
  end
54
70
  end
@@ -0,0 +1,17 @@
1
+ module EtabliocmsPages
2
+ class Attachment < ActiveRecord::Base
3
+
4
+ belongs_to :attachable, :polymorphic => true
5
+
6
+ has_attached_file :data,
7
+ :path => ":rails_root/public/system/:class/:attachment/:id/:style/:filename",
8
+ :url => "/system/:class/:attachment/:id/:style/:filename",
9
+ :styles => {
10
+ :large => EtabliocmsPages.try(:paperclip_large) || "800x800>",
11
+ :medium => EtabliocmsPages.try(:paperclip_medium) || "400x400>",
12
+ :thumbnail => EtabliocmsPages.try(:paperclip_thumbnail) || "100x100>"}
13
+
14
+ validates_attachment_presence :data
15
+
16
+ end
17
+ end
@@ -9,6 +9,7 @@ module EtabliocmsPages
9
9
  serialize :areas, Hash
10
10
 
11
11
  has_slug :to_param => "path"
12
+ has_paper_trail
12
13
 
13
14
  end
14
15
  end
@@ -7,14 +7,20 @@ module EtabliocmsPages
7
7
  end
8
8
 
9
9
  acts_as_nested_set
10
- attr_accessor :child_of
10
+ attr_accessor :child_of, :attachment_data
11
11
  after_save :update_position
12
12
 
13
13
  has_many :contents, :class_name => "EtabliocmsPages::Content", :inverse_of => :page, :order => "locale asc", :dependent => :destroy
14
14
  accepts_nested_attributes_for :contents, :reject_if => proc { |attributes| attributes['title'].blank? }
15
15
 
16
+ has_many :attachments, :dependent => :destroy, :as => :attachable
17
+ accepts_nested_attributes_for :attachments
18
+
16
19
  validate :at_least_one_content_has_title
17
20
 
21
+ has_paper_trail
22
+
23
+
18
24
  def path
19
25
  self_and_ancestors.map{|p| p.slug }.join("/")
20
26
  end
@@ -39,7 +45,7 @@ module EtabliocmsPages
39
45
 
40
46
  def build_contents_for_available_locales
41
47
  I18n.available_locales.each do |available_locale|
42
- contents.build(:locale => available_locale) unless contents.detect { |c| c.locale == available_locale.to_s }
48
+ contents.build(:locale => available_locale) unless contents.map(&:locale).include?(available_locale.to_s)
43
49
  end
44
50
  end
45
51
 
@@ -0,0 +1,19 @@
1
+ <ul>
2
+ <% @page.attachments.each do |attachment| %>
3
+ <li class="attachment">
4
+
5
+ <%= link_to attachment.data.url(:default, false), attachment.data.url(:default, false), :class => "url" %>
6
+ : <%= link_to attachment.data_file_name, attachment.data.url(:default, false) %>
7
+
8
+ <%= link_to t('admin.attachments.copypaste'), "#", :class => "icon icon-copypaste", :title => t('admin.attachments.copypaste') %>
9
+
10
+ <%= link_to I18n.t('admin.attachments.destroy'),
11
+ destroy_attachment_admin_page_path(@page.id, :attachment_id => attachment.id),
12
+ {:method => :delete,
13
+ :confirm => t("admin.attachments.destroy_confirmation"),
14
+ :remote => true,
15
+ :class => 'icon icon-destroy', :title => I18n.t('admin.attachments.destroy')} %>
16
+
17
+ </li>
18
+ <% end %>
19
+ </ul>
@@ -21,9 +21,9 @@
21
21
 
22
22
  <% if !@page.new_record? && respond_to?(:page_path) %>
23
23
  <p>
24
- <% I18n.locale = content.locale %>
25
24
  <strong>Náhled: </strong>
26
- <%= link_to @page.title, page_path(@page.locale, @page), :"data-popup" => "true" %>
25
+ <% path = I18n.available_locales.size == 1 ? page_path(@page) : page_path(@page.locale, @page) %>
26
+ <%= link_to @page.title, path, :"data-popup" => "true" %> : <%= path %>
27
27
  </p>
28
28
  <% end %>
29
29
 
@@ -26,29 +26,81 @@
26
26
 
27
27
  <div id="contents">
28
28
  <ul>
29
- <%@page.contents.sort_by{|a| a.locale.to_s }.each do |content| %>
29
+ <% @page.contents.sort_by { |a| a.locale.to_s }.each do |content| %>
30
30
  <li><a href="#tabs-<%= content.object_id %>"><%= t("admin.locales.#{content.locale}") %></a></li>
31
31
  <% end %>
32
+ <li><a href="#tabs-attachments"><%= t("admin.attachments.attachments") %></a></li>
32
33
  </ul>
33
34
 
34
35
  <%= f.fields_for :contents do |builder| %>
35
36
  <%= render "content_fields", :f => builder %>
36
37
  <% end %>
38
+
39
+ <div id="tabs-attachments">
40
+
41
+ <% unless @page.new_record? %>
42
+
43
+ <div id="attachments">
44
+ <%= render "attachments" %>
45
+ </div>
46
+
47
+ <%= f.file_field :attachment_data %>
48
+ <%= f.submit t('admin.attachments.upload'), :id => 'data-submit', :class => "submit" %>
49
+
50
+ <% else %>
51
+
52
+ <p><%= t('admin.attachments.page_must_be_saved') %></p>
53
+
54
+ <% end %>
55
+
56
+ </div>
37
57
  </div>
38
58
 
39
59
  </fieldset>
40
60
 
41
61
  <fieldset>
42
62
 
43
- <% I18n.locale = I18n.default_locale %>
44
- <p>
63
+ <p class="submit-box">
45
64
  <%= submit_tag t('admin.save'), :class => 'submit' %>
65
+ <span class="or"><%= t('admin.or') %></span>
66
+ <%= submit_tag t('admin.save_and_continue'), :class => 'submit', :name => "save_and_continue" %>
46
67
  </p>
47
68
 
48
69
  </fieldset>
49
70
 
71
+ <%- session_key_name = Rails.application.config.session_options[:key] -%>
72
+
50
73
  <script>
51
74
  $(function() {
52
75
  $("#contents").tabs();
76
+ AdminPages.initCopyPaste();
77
+
78
+ $('#etabliocms_pages_page_attachment_data').click(function(event) {
79
+ event.preventDefault();
80
+ });
81
+ $('#etabliocms_pages_page_attachment_data').uploadify({
82
+
83
+ uploader : '/uploadify/uploadify.swf',
84
+ script : '<%= update_attachments_admin_page_path(@page) %>',
85
+ multi : true,
86
+ cancelImg : '/uploadify/cancel.png',
87
+ buttonText: '<%= t('admin.attachments.select_files') %>',
88
+ scriptData : { 'format' : 'js',
89
+ '<%= session_key_name %>' : encodeURIComponent('<%= u cookies[session_key_name] %>'),
90
+ 'authenticity_token' : encodeURIComponent('<%= u form_authenticity_token if protect_against_forgery? %>'),
91
+ 'attachable_id' : '<%= @page.id %>'},
92
+ onComplete: function(event, queueID, fileObj, response, data) {
93
+ $('#attachments').html(response);
94
+ AdminPages.initCopyPaste();
95
+ }
96
+
97
+ });
98
+ $('#data-submit').click(function(event) {
99
+ event.preventDefault();
100
+ $('#etabliocms_pages_page_attachment_data').uploadifyUpload();
101
+ });
102
+
53
103
  });
104
+
105
+
54
106
  </script>
@@ -0,0 +1,2 @@
1
+ $("#attachments").html("<%= escape_javascript(render("attachments")) %>");
2
+ console.log("fasfds");
@@ -2,6 +2,6 @@
2
2
 
3
3
  <h1><%= @page.title %></h1>
4
4
 
5
- <%= form_for @page, :url => admin_page_path(@page.id), :html => {:method => :put, :id => "admin-form"} do |f| -%>
5
+ <%= form_for @page, :url => admin_page_path(@page.id), :html => {:method => :put, :id => "admin-form", :multipart => true} do |f| -%>
6
6
  <%= render :partial => 'form', :locals => { :f => f } %>
7
7
  <% end %>
@@ -0,0 +1,16 @@
1
+ require 'rack/utils'
2
+ class FlashSessionCookieMiddleware
3
+ def initialize(app, session_key = '_session_id')
4
+ @app = app
5
+ @session_key = session_key
6
+ end
7
+
8
+ def call(env)
9
+ if env['HTTP_USER_AGENT'] =~ /^(Adobe|Shockwave) Flash/
10
+ req = Rack::Request.new(env)
11
+ env['HTTP_COOKIE'] = "#{@session_key}=#{req.params[@session_key]}".freeze unless req.params[@session_key].nil?
12
+ end
13
+ @app.call(env)
14
+ end
15
+ end
16
+
@@ -1,4 +1,13 @@
1
1
  cs:
2
+ admin:
3
+ attachments:
4
+ attachments: Přílohy
5
+ page_must_be_saved: Pro přikládání souborů musíte stránku nejprve uložit.
6
+ upload: Uploadovat
7
+ select_files: Vybrat soubor
8
+ copypaste: Zkopírovat do schránky
9
+ destroy: Odstranit
10
+ destroy_confirmation: Skutečně chcete smazat tuto přílohu?
2
11
  page:
3
12
  pages: Stránky
4
13
  pages_count: "Stránky (%{count})"
@@ -8,6 +17,7 @@ cs:
8
17
  destroyed: Stránka byla úspěšně odstraněna.
9
18
  moved: Stránka byla úspěšně přesunuta.
10
19
  not_moved: Stránka nebyla přesunuta.
20
+ locked: Stránka je uzamčená, nemůže být odstraněna.
11
21
  destroy_confirmation: Skutečně chcete smazat tuto stránku?
12
22
  admin_legend_basic: Základní údaje o stránce
13
23
  admin_legend_contents: Obsah stránky
@@ -31,6 +41,7 @@ cs:
31
41
  at_least_one_content_has_title: Alespoň jedna jazyková mutace musí mít nadpis.
32
42
  attributes:
33
43
  "etabliocms_pages/page":
44
+ class_name: Stránka
34
45
  title: Nadpis
35
46
  child_of: Rodič
36
47
  text: Text
data/config/routes.rb CHANGED
@@ -5,6 +5,8 @@ Rails.application.routes.draw do
5
5
  resources :pages do
6
6
  member do
7
7
  put :move
8
+ post :update_attachments
9
+ delete :destroy_attachment
8
10
  end
9
11
  end
10
12
  end
@@ -0,0 +1,7 @@
1
+ class AddLockedToPages < ActiveRecord::Migration
2
+
3
+ def change
4
+ add_column :pages, :locked, :boolean, :default => false
5
+ end
6
+
7
+ end
@@ -0,0 +1,17 @@
1
+ class CreateAttachments < ActiveRecord::Migration
2
+
3
+ def change
4
+ create_table :attachments do |t|
5
+ t.string :title
6
+
7
+ t.string :data_file_name
8
+ t.string :data_content_type
9
+ t.integer :data_file_size
10
+ t.datetime :data_updated_at
11
+
12
+ t.references :attachable, :polymorphic => {:default => 'Page'}
13
+ t.timestamps
14
+ end
15
+ end
16
+
17
+ end
@@ -1,4 +1,5 @@
1
1
  require 'awesome_nested_set'
2
+ require 'paperclip'
2
3
 
3
4
  module EtabliocmsPages
4
5
 
@@ -15,6 +16,19 @@ module EtabliocmsPages
15
16
  EtabliocmsPages.setup do |config|
16
17
  config.areas ||= [:text]
17
18
  end
19
+ Rails.application.config.assets.precompile += %w( admin-pages.js admin-pages.css )
20
+ end
21
+
22
+ initializer "etabliocms_pages.uploadify_middlerware" do |app|
23
+ app.config.middleware.insert_before(
24
+ ActionDispatch::Session::CookieStore,
25
+ FlashSessionCookieMiddleware,
26
+ Rails.application.config.session_options[:key]
27
+ )
28
+ end
29
+
30
+ initializer "etabliocms_pages.load_static_assets" do |app|
31
+ app.middleware.use ::ActionDispatch::Static, "#{root}/public"
18
32
  end
19
33
 
20
34
  end
@@ -1,3 +1,3 @@
1
1
  module EtabliocmsPages
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -3,6 +3,9 @@ require "active_support/dependencies"
3
3
  module EtabliocmsPages
4
4
 
5
5
  mattr_accessor :areas
6
+ mattr_accessor :paperclip_large
7
+ mattr_accessor :paperclip_medium
8
+ mattr_accessor :paperclip_thumbnail
6
9
 
7
10
  def self.setup
8
11
  yield self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etabliocms_pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-06 00:00:00.000000000 Z
12
+ date: 2012-03-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &10373100 !ruby/object:Gem::Requirement
16
+ requirement: &13196120 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.2.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *10373100
24
+ version_requirements: *13196120
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: etabliocms_core
27
- requirement: &10307800 !ruby/object:Gem::Requirement
27
+ requirement: &13195700 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *10307800
35
+ version_requirements: *13195700
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: awesome_nested_set
38
- requirement: &9895800 !ruby/object:Gem::Requirement
38
+ requirement: &13195100 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - =
@@ -43,10 +43,21 @@ dependencies:
43
43
  version: 2.1.2
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *9895800
46
+ version_requirements: *13195100
47
+ - !ruby/object:Gem::Dependency
48
+ name: paperclip
49
+ requirement: &13194640 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *13194640
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: sqlite3
49
- requirement: &9739400 !ruby/object:Gem::Requirement
60
+ requirement: &13194060 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,7 +65,7 @@ dependencies:
54
65
  version: '0'
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *9739400
68
+ version_requirements: *13194060
58
69
  description: Small CMS - module for pages
59
70
  email:
60
71
  - patrikjira@gmail.com
@@ -64,18 +75,29 @@ extra_rdoc_files: []
64
75
  files:
65
76
  - app/views/layouts/_sidebar_pages.html.erb
66
77
  - app/views/etabliocms_pages/admin/pages/_form.html.erb
78
+ - app/views/etabliocms_pages/admin/pages/_attachments.html.erb
67
79
  - app/views/etabliocms_pages/admin/pages/_content_fields.html.erb
68
80
  - app/views/etabliocms_pages/admin/pages/new.html.erb
69
81
  - app/views/etabliocms_pages/admin/pages/edit.html.erb
70
82
  - app/views/etabliocms_pages/admin/pages/index.html.erb
83
+ - app/views/etabliocms_pages/admin/pages/destroy_attachment.js.erb
84
+ - app/assets/javascripts/pages.js
85
+ - app/assets/javascripts/admin-pages.js
86
+ - app/assets/stylesheets/admin-pages.css
87
+ - app/assets/stylesheets/pages.css.scss
71
88
  - app/assets/images/admin/sidebar-pages.png
89
+ - app/assets/images/icons/icon-copypaste.png
72
90
  - app/controllers/etabliocms_pages/admin/pages_controller.rb
73
91
  - app/models/etabliocms_pages/content.rb
92
+ - app/models/etabliocms_pages/attachment.rb
74
93
  - app/models/etabliocms_pages/page.rb
75
94
  - config/routes.rb
95
+ - config/initializers/flash_session_cookie_middleware.rb
76
96
  - config/locales/pages.cs.yml
77
97
  - db/migrate/20120223140555_create_pages.etabliocms_pages_engine.rb
98
+ - db/migrate/20120312181555_add_locked_to_pages.etabliocms_pages_engine.rb
78
99
  - db/migrate/20120301175455_create_contents.etabliocms_pages_engine.rb
100
+ - db/migrate/20120315114155_create_attachments.etabliocms_pages_engine.rb
79
101
  - lib/etabliocms_pages/version.rb
80
102
  - lib/etabliocms_pages/engine.rb
81
103
  - lib/etabliocms_pages.rb