etabliocms_galleries 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
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.
data/README.textile ADDED
@@ -0,0 +1,3 @@
1
+ h1. EtabliocmsGalleries
2
+
3
+ This rocksssssssss!
@@ -0,0 +1,61 @@
1
+ module EtabliocmsGalleries
2
+ module Admin
3
+ class GalleriesController < EtabliocmsCore::Admin::BaseController
4
+
5
+ def index
6
+ @galleries = Gallery.order(params[:order] || "created_at DESC")
7
+ end
8
+
9
+ def new
10
+ @gallery = Gallery.new
11
+ end
12
+
13
+ def create
14
+ @gallery = Gallery.new(params[:etabliocms_galleries_gallery])
15
+ if @gallery.save
16
+ flash[:notice] = t('gallery.created')
17
+ redirect_to params[:save_and_continue].present? ? edit_admin_gallery_path(@gallery.id) : {:action => 'index'}
18
+ else
19
+ render :action => 'new'
20
+ end
21
+ end
22
+
23
+ def edit
24
+ @gallery = Gallery.find(params[:id])
25
+ end
26
+
27
+ def update
28
+ @gallery = Gallery.find(params[:id])
29
+ if @gallery.update_attributes(params[:etabliocms_galleries_gallery])
30
+ flash[:notice] = t('gallery.updated')
31
+ redirect_to params[:save_and_continue].present? ? edit_admin_gallery_path(@gallery.id) : {:action => 'index'}
32
+ else
33
+ render :action => 'edit'
34
+ end
35
+ end
36
+
37
+ def destroy
38
+ Gallery.find(params[:id]).destroy
39
+ flash[:notice] = t('gallery.destroyed')
40
+ redirect_to :action => 'index'
41
+ end
42
+
43
+ def sort
44
+ Gallery.all.each do |gallery|
45
+ gallery.position = params['etabliocms_galleries_gallery'].index(gallery.id.to_s) + 1
46
+ gallery.save
47
+ end
48
+ render :nothing => true
49
+ end
50
+
51
+ def sort_pictures
52
+ @gallery = Gallery.find(params[:id])
53
+ @gallery.pictures.all.each do |picture|
54
+ picture.position = params['etabliocms_galleries_picture'].index(picture.id.to_s) + 1
55
+ picture.save
56
+ end
57
+ render :nothing => true
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,38 @@
1
+ module EtabliocmsGalleries
2
+ class Gallery < ActiveRecord::Base
3
+
4
+ default_scope :order => "position asc"
5
+
6
+ attr_accessor :attachable_temp
7
+ belongs_to :attachable, :polymorphic => true
8
+ before_save :set_attachable
9
+
10
+ scope :visible, where(:visible => true)
11
+
12
+ validates :title, :presence => true
13
+
14
+ has_slug
15
+ has_paper_trail
16
+
17
+ has_many :pictures, :order => 'position asc', :dependent => :destroy, :class_name => 'EtabliocmsGalleries::Picture'
18
+ accepts_nested_attributes_for :pictures, :allow_destroy => true
19
+
20
+
21
+ def self.attachables_for_select
22
+ sum = []
23
+ sum += EtabliocmsPages::Page.all if defined?(EtabliocmsPages)
24
+ sum.map { |item| ["#{I18n.t("activerecord.attributes.#{item.class.to_s.underscore}.class_name")}: #{item.title}", "#{item.class}##{item.id}"] }
25
+ end
26
+
27
+ private
28
+ def set_attachable
29
+ attachable_type, attachable_id = attachable_temp.split("#")
30
+ if attachable_type.present? and attachable_id.present?
31
+ self.attachable_type = attachable_type
32
+ self.attachable_id = attachable_id
33
+ else
34
+ self.attachable = nil
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,20 @@
1
+ module EtabliocmsGalleries
2
+ class Picture < ActiveRecord::Base
3
+
4
+ default_scope :order => 'position asc'
5
+
6
+ has_paper_trail
7
+
8
+ belongs_to :gallery, :class_name => 'EtabliocmsGalleries::Gallery', :foreign_key => 'gallery_id'
9
+
10
+ has_attached_file :data,
11
+ :path => ":rails_root/public/system/:class/:attachment/:id/:style/:filename",
12
+ :url => "/system/:class/:attachment/:id/:style/:filename",
13
+ :styles => {
14
+ :large => EtabliocmsGalleries.try(:paperclip_large) || "800x800>",
15
+ :medium => EtabliocmsGalleries.try(:paperclip_medium) || "400x400>",
16
+ :thumbnail => EtabliocmsGalleries.try(:paperclip_thumbnail) || "100x100>"
17
+ }
18
+
19
+ end
20
+ end
@@ -0,0 +1,90 @@
1
+ <fieldset>
2
+ <legend><%= t('gallery.admin_legend') %></legend>
3
+
4
+ <%= render "layouts/errors", :target => @gallery %>
5
+
6
+ <p>
7
+ <%= f.label :title, t('activerecord.attributes.etabliocms_galleries/gallery.title'), :id => "gallery_title_label" %>
8
+ <%= f.text_field :title, :class => 'text-field' %>
9
+ </p>
10
+
11
+ <p>
12
+ <%= f.label :text, t('activerecord.attributes.etabliocms_galleries/gallery.text'), :id => "gallery_text_label" %>
13
+ <%= f.textile_text_area :text %>
14
+ </p>
15
+
16
+ <p>
17
+ <%= f.label :attachable_temp, t('activerecord.attributes.etabliocms_galleries/gallery.attachable_temp'), :id => "gallery_text_label" %>
18
+ <%= f.select :attachable_temp,
19
+ EtabliocmsGalleries::Gallery.attachables_for_select,
20
+ {:selected => "#{@gallery.attachable_type}##{@gallery.attachable_id}",:include_blank => true }%>
21
+ </p>
22
+
23
+ <p>
24
+ <%= f.label :visible, t('activerecord.attributes.etabliocms_galleries/gallery.visible'), :id => "page_visible_label" %>
25
+ <%= f.boolean_yes_no_select :visible %>
26
+ </p>
27
+
28
+ </fieldset>
29
+
30
+ <fieldset>
31
+
32
+ <legend><%= t('pictures.admin_legend') %></legend>
33
+ <table id="pictures-table" class="nested-fields-table">
34
+ <thead>
35
+ <tr>
36
+ <th style="width:15px;"><%= t('admin.order') %></th>
37
+ <th><%= t('activerecord.attributes.etabliocms_galleries/picture.thumbnail') %></th>
38
+ <th><%= t('activerecord.attributes.etabliocms_galleries/picture.title') %></th>
39
+ <th><%= t('activerecord.attributes.etabliocms_galleries/picture.data') %></th>
40
+ <th><%= t('admin.actions') %></th>
41
+ </tr>
42
+ </thead>
43
+
44
+ <tbody id="pictures">
45
+ <%= f.fields_for :pictures do |builder| %>
46
+ <%= render :partial => "picture_fields", :locals => {:builder => builder} %>
47
+ <% end %>
48
+ </tbody>
49
+ </table>
50
+
51
+ <%= link_to_add_fields(t('pictures.add'), f, :pictures, '#pictures', :class => 'text-icon icon-add') %>
52
+
53
+ </fieldset>
54
+
55
+ <fieldset>
56
+
57
+ <p class="submit-box">
58
+ <%= submit_tag t('admin.save'), :class => 'submit' %>
59
+ <span class="or"><%= t('admin.or') %></span>
60
+ <%= submit_tag t('admin.save_and_continue'), :class => 'submit', :name => "save_and_continue" %>
61
+ </p>
62
+
63
+ </fieldset>
64
+
65
+ <% unless @gallery.new_record? %>
66
+ <script>
67
+ $(document).ready(function() {
68
+ $('#pictures').sortable({
69
+ axis: 'y',
70
+ dropOnEmpty: false,
71
+ handle: '.handle',
72
+ cursor: 'hand',
73
+ items: 'tr',
74
+ opacity: 0.4,
75
+ scroll: true,
76
+ update: function() {
77
+ $.ajax({
78
+ type: 'post',
79
+ data: $('#pictures').sortable('serialize'),
80
+ dataType: 'script',
81
+ complete: function(request) {
82
+ $('#pictures').effect('highlight');
83
+ },
84
+ url: '<%= sort_pictures_admin_gallery_path(@gallery.id) %>'})
85
+ }
86
+ });
87
+ });
88
+ </script>
89
+
90
+ <% end %>
@@ -0,0 +1,21 @@
1
+ <%= content_tag_for :tr, builder.object, :class => 'fields' do %>
2
+
3
+ <td class="handle"><%= image_tag("icons/icon-refresh.gif") %></td>
4
+
5
+ <td class="thumbnail">
6
+ <%= link_to(image_tag(builder.object.data.url(:thumbnail)), builder.object.data.url) if builder.object && !builder.object.new_record? %>
7
+ </td>
8
+
9
+ <td>
10
+ <%= builder.text_field :title, :placeholder => t('activerecord.attributes.etabliocms_galleries/gallery.title') %>
11
+ </td>
12
+
13
+ <td>
14
+ <%= builder.file_field :data %>
15
+ </td>
16
+
17
+ <td class="centered">
18
+ <%= link_to_remove_fields image_tag("icons/icon-delete.gif"), builder %>
19
+ </td>
20
+
21
+ <% end %>
@@ -0,0 +1,7 @@
1
+ <% set_title_and_breadcrumb t('gallery.edit', :title => @gallery.title) %>
2
+
3
+ <h1><%= @gallery.title %></h1>
4
+
5
+ <%= form_for @gallery, :url => admin_gallery_path(@gallery.id), :html => {:method => :put, :id => "admin-form", :multipart => true} do |f| -%>
6
+ <%= render :partial => 'form', :locals => { :f => f } %>
7
+ <% end %>
@@ -0,0 +1,62 @@
1
+ <% set_title_and_breadcrumb t('gallery.galleries') %>
2
+
3
+ <h1><%= t('gallery.galleries') %></h1>
4
+
5
+ <div class="strap">
6
+ <%= link_to "#{t('gallery.add')} &raquo;".html_safe, new_admin_gallery_path, :class => 'text-icon icon-add' %>
7
+ <%= link_to "#{t('admin.refresh')} &raquo;".html_safe, admin_galleries_path, :class => 'text-icon icon-refresh' %>
8
+ <%= link_to "#{t('admin.back_to_admin')} &raquo;".html_safe, admin_path, :class => 'text-icon icon-backward' %>
9
+ </div>
10
+
11
+ <table class="admin-table">
12
+ <thead>
13
+ <tr>
14
+ <th style="width:30px;"><%= t('admin.order') %></th>
15
+ <th><%= t('activerecord.attributes.etabliocms_galleries/gallery.title') %> </th>
16
+ <th><%= t('activerecord.attributes.etabliocms_galleries/gallery.pictures_count') %> </th>
17
+ <th><%= t('admin.actions') %></th>
18
+ </tr>
19
+ </thead>
20
+ <tbody id="galleries">
21
+
22
+ <% for item in @galleries %>
23
+ <%= content_tag_for :tr, item, :class => cycle("odd-row", "even-row") do %>
24
+ <td class="handle"><%= image_tag("icons/icon-refresh.gif") %></td>
25
+ <td><%= link_to item.title, edit_admin_gallery_url(item.id) %></td>
26
+ <td class="centered"><%= item.pictures.count %></td>
27
+ <td>
28
+ <%= link_to t('admin.edit'), edit_admin_gallery_url(item.id), :class => 'icon icon-edit', :title => t('admin.edit') %>
29
+ <%= link_to t('admin.destroy'), admin_gallery_url(item.id),
30
+ :method => :delete,
31
+ :confirm => t('gallery.destroy_confirmation'),
32
+ :class => 'icon icon-destroy',
33
+ :title => t('admin.destroy') %>
34
+ </td>
35
+ <% end %>
36
+ <% end %>
37
+ </tbody>
38
+ </table>
39
+
40
+ <script>
41
+ $(document).ready(function() {
42
+ $('#galleries').sortable({
43
+ axis: 'y',
44
+ dropOnEmpty: false,
45
+ handle: '.handle',
46
+ cursor: 'hand',
47
+ items: 'tr',
48
+ opacity: 0.4,
49
+ scroll: true,
50
+ update: function() {
51
+ $.ajax({
52
+ type: 'post',
53
+ data: $('#galleries').sortable('serialize'),
54
+ dataType: 'script',
55
+ complete: function(request) {
56
+ $('#galleries').effect('highlight');
57
+ },
58
+ url: '<%= sort_admin_galleries_path %>'})
59
+ }
60
+ });
61
+ });
62
+ </script>
@@ -0,0 +1,7 @@
1
+ <% set_title_and_breadcrumb t('gallery.new') %>
2
+
3
+ <h1><%= t('gallery.new') %></h1>
4
+
5
+ <%= form_for @gallery, :url => admin_galleries_path, :html => {:method => :post, :id => "admin-form", :multipart => true} do |f| -%>
6
+ <%= render :partial => 'form', :locals => { :f => f } %>
7
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <h3><%= image_tag asset_path("admin/sidebar-galleries.png"), :alt => t('gallery.galleries') %><%= t('gallery.galleries') %></h3>
2
+ <ul>
3
+ <li><%= link_to_unless_current I18n.t('gallery.galleries_count', :count => EtabliocmsGalleries::Gallery.count), admin_galleries_path %></li>
4
+ <li><%= link_to_unless_current t('gallery.add'), new_admin_gallery_path %></li>
5
+ </ul>
@@ -0,0 +1,33 @@
1
+ cs:
2
+ admin:
3
+ order: Pořadí
4
+ gallery:
5
+ galleries: Galerie
6
+ galleries_count: "Galerie (%{count})"
7
+ add: Přidat galerii
8
+ created: Galerie byla úspěšně vytvořena.
9
+ updated: Galerie byla úspěšně upravena.
10
+ destroyed: Galerie byla úspěšně odstraněna.
11
+ destroy_confirmation: Skutečně chcete smazat tuto galerii?
12
+ admin_legend: Základní údaje o galerii
13
+ edit: "Editace galerie %{title}"
14
+ new: Nová galerie
15
+ pictures:
16
+ add: Přidat obrázek
17
+ destroy: Smazat
18
+ admin_legend: Obrázky
19
+ activerecord:
20
+ attributes:
21
+ "etabliocms_galleries/gallery":
22
+ class_name: Galerie
23
+ title: Nadpis
24
+ text: Text
25
+ visible: Viditelné
26
+ attachable_temp: Připojit k
27
+ pictures_count: Obrázků
28
+ "etabliocms_galleries/picture":
29
+ class_name: Obrázek
30
+ thumbnail: Náhled
31
+ title: Popisek
32
+ text: Text
33
+ visible: Viditelné
data/config/routes.rb ADDED
@@ -0,0 +1,12 @@
1
+ Rails.application.routes.draw do
2
+
3
+ scope :module => "etabliocms_galleries" do
4
+ namespace :admin do
5
+ resources :galleries do
6
+ post :sort, :on => :collection
7
+ post :sort_pictures, :on => :member
8
+ end
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,18 @@
1
+ class CreateGalleries < ActiveRecord::Migration
2
+
3
+ def change
4
+ create_table :galleries do |t|
5
+ t.string :title, :null => false
6
+ t.string :slug, :null => false
7
+ t.text :text
8
+
9
+ t.boolean :visible
10
+ t.integer :position, :default => 0
11
+
12
+ t.timestamps
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+
@@ -0,0 +1,22 @@
1
+ class CreatePictures < ActiveRecord::Migration
2
+
3
+ def change
4
+ create_table :pictures do |t|
5
+ t.string :title, :null => false
6
+ t.text :text
7
+
8
+ t.string :data_file_name
9
+ t.string :data_content_type
10
+ t.integer :data_file_size
11
+ t.datetime :data_updated_at
12
+
13
+ t.integer :gallery_id, :null => false
14
+ t.integer :position, :default => 0
15
+
16
+ t.timestamps
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+
@@ -0,0 +1,8 @@
1
+ class AddAttachableToGalleries < ActiveRecord::Migration
2
+
3
+ def change
4
+ add_column :galleries, :attachable_type, :string
5
+ add_column :galleries, :attachable_id, :integer
6
+ end
7
+
8
+ end
@@ -0,0 +1,16 @@
1
+ require "active_support/dependencies"
2
+
3
+ module EtabliocmsGalleries
4
+
5
+ mattr_accessor :paperclip_large
6
+ mattr_accessor :paperclip_medium
7
+ mattr_accessor :paperclip_thumbnail
8
+
9
+ def self.setup
10
+ yield self
11
+ end
12
+
13
+ end
14
+
15
+ require "etabliocms_galleries/engine"
16
+ require "form_helper"
@@ -0,0 +1,14 @@
1
+ module EtabliocmsGalleries
2
+
3
+ class Engine < ::Rails::Engine
4
+
5
+ initializer "etabliocms_core.initialize" do |app|
6
+ EtabliocmsCore.setup do |config|
7
+ config.modules ||= []
8
+ config.modules << :galleries
9
+ end
10
+ end
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,3 @@
1
+ module EtabliocmsGalleries
2
+ VERSION = "0.0.3"
3
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: etabliocms_galleries
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - papricek
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &5437140 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *5437140
25
+ - !ruby/object:Gem::Dependency
26
+ name: etabliocms_core
27
+ requirement: &5436620 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *5436620
36
+ - !ruby/object:Gem::Dependency
37
+ name: paperclip
38
+ requirement: &5436140 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *5436140
47
+ - !ruby/object:Gem::Dependency
48
+ name: sqlite3
49
+ requirement: &5435640 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *5435640
58
+ description: Small CMS - module for galleries
59
+ email:
60
+ - patrikjira@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - app/views/etabliocms_galleries/admin/galleries/_picture_fields.html.erb
66
+ - app/views/etabliocms_galleries/admin/galleries/_form.html.erb
67
+ - app/views/etabliocms_galleries/admin/galleries/new.html.erb
68
+ - app/views/etabliocms_galleries/admin/galleries/edit.html.erb
69
+ - app/views/etabliocms_galleries/admin/galleries/index.html.erb
70
+ - app/views/layouts/_sidebar_galleries.html.erb
71
+ - app/assets/images/admin/sidebar-galleries.png
72
+ - app/controllers/etabliocms_galleries/admin/galleries_controller.rb
73
+ - app/models/etabliocms_galleries/picture.rb
74
+ - app/models/etabliocms_galleries/gallery.rb
75
+ - config/routes.rb
76
+ - config/locales/galleries.cs.yml
77
+ - db/migrate/20120316190255_add_attachable_to_galleries.etabliocms_galleries_engine.rb
78
+ - db/migrate/20120316132855_create_galleries.etabliocms_galleries_engine.rb
79
+ - db/migrate/20120316153055_create_pictures.etabliocms_galleries_engine.rb
80
+ - lib/etabliocms_galleries/version.rb
81
+ - lib/etabliocms_galleries/engine.rb
82
+ - lib/etabliocms_galleries.rb
83
+ - MIT-LICENSE
84
+ - README.textile
85
+ homepage: https://github.com/papricek/etabliocms_galleries
86
+ licenses: []
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 1.8.5
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: Small CMS - module for galleries
109
+ test_files: []