forked from sbmsuite/radiant-asset_gallery-extension
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stefan Husch
committed
Aug 20, 2010
1 parent
236e345
commit 47f4fe3
Showing
20 changed files
with
562 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
h1. Asset Gallery | ||
|
||
This extension allows you to create galleries of Paperclipped Assets. Provides an admin interface to add, sort and remove assets from a Gallery with drag and drop, and radius tags to easily include the Galleries in your site. | ||
|
||
("sbmsuite":http://github.com/sbmsuite) modified the views from zapnap/radiant-flash-gallery-extension to use in the new extension. However THIS IS NOT A FORK. It is a newly created extension. "jfqd":http://github.com/jfqd modified the extension to support ujs drag and drop and globalize2-paperclipped compatibility. | ||
|
||
Tested with radiant 0.9.1 | ||
|
||
h2. Installation | ||
|
||
Install the "Paperclipped Extension":http://github.com/kbingman/paperclipped/ before the Asset Gallery Extension: | ||
|
||
<pre> | ||
git clone http://github.com/kbingman/paperclipped.git vendor/extensions/paperclipped | ||
|
||
rake production db:migrate:extensions | ||
rake production radiant:extensions:paperclipped:update | ||
</pre> | ||
|
||
Now install the Asset Gallery Extension: | ||
|
||
<pre> | ||
git clone http://github.com/jfqd/radiant-asset_gallery-extension vendor/extensions/asset_gallery | ||
|
||
rake production db:migrate:extensions | ||
rake production radiant:extensions:asset_gallery:update | ||
</pre> | ||
|
||
Be careful about the extensions load order: | ||
|
||
config.extensions = [ :paperclipped, :all ] | ||
|
||
h2. Tag Examples | ||
|
||
h3. List of galleries | ||
|
||
<pre><code> | ||
<r:gallery:each> | ||
<div> | ||
<div><r:gallery:first_image size="thumbnail" /> | ||
<div><r:gallery:name /></div> | ||
</div> | ||
</r:gallery:each> | ||
</code></pre> | ||
|
||
h3. Images of a gallery with caption | ||
|
||
<pre><code> | ||
<r:gallery:items name="my-gallery"> | ||
<div class="slide"> | ||
<r:gallery_item:image size="normal" /> | ||
<p><r:gallery_item:caption /></p> | ||
</div> | ||
</r:gallery:items> | ||
</code></pre> | ||
|
||
h2. Compatibility | ||
|
||
This extension is compatible with the "Globalize2-Paperclipped Extension":http://github.com/Aissac/radiant-globalize2-paperclipped-extension. You need to install the Globalize2-Paperclipped Extension before the Asset Gallery Extension. | ||
|
||
<pre> | ||
git clone http://github.com/Aissac/radiant-globalize2-paperclipped-extension.git vendor/extensions/globalize2_paperclipped | ||
</pre> | ||
|
||
Be careful about the extensions load order: | ||
|
||
config.extensions = [ :paperclipped, :globalize2, :globalize2_paperclipped, :all ] | ||
|
||
h2. Contributors | ||
|
||
"sbmsuite":http://github.com/sbmsuite | ||
"jfqd":http://github.com/jfqd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
class Admin::GalleryItemsController < ApplicationController | ||
|
||
# add an item to the gallery | ||
def create | ||
asset_id = (params[:gallery_item][:asset_id]).gsub("gallery_item_", "") | ||
gallery = Gallery.find(params[:gallery_id]) | ||
unless gallery.gallery_items.exists?(:asset_id => asset_id) | ||
gallery.gallery_items.create(:asset_id => asset_id) | ||
end | ||
respond_to do |format| | ||
format.html { render :nothing => true } | ||
format.js { | ||
render :update, :status => 200 do |page| | ||
page << 'Asset.SortItems();' | ||
end | ||
} | ||
end | ||
end | ||
|
||
# remove an item from the gallery | ||
def destroy | ||
asset_id = params[:id].gsub("gallery_item_", "") | ||
item = GalleryItem.find_by_gallery_id_and_asset_id(params[:gallery_id], asset_id) | ||
item.destroy | ||
respond_to do |format| | ||
format.html { render :nothing => true } | ||
format.js { | ||
gallery = Gallery.find(params[:gallery_id]) | ||
items = gallery.gallery_items # remove items from assets view! | ||
@assets = Asset.quick_search('', items) | ||
render :update, :status => 200 do |page| | ||
page.replace_html "asset_items", :partial => 'admin/galleries/assets.html.haml', :locals => { :assets => @assets } | ||
page << 'Asset.MakeDraggables();' | ||
end | ||
} | ||
end | ||
end | ||
|
||
# sort gallery items | ||
def sort | ||
gallery = Gallery.find(params[:gallery_id]) | ||
items = CGI::parse(params[:items])['gallery_items[]'] | ||
items.each_with_index do |id, index| | ||
gallery.gallery_items.update_all(['position=?', index+1], ['asset_id=?', id]) | ||
end | ||
respond_to do |format| | ||
format.html { render :nothing => true } | ||
format.js { render :nothing => true, :status => 200 } | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
class Gallery < ActiveRecord::Base | ||
belongs_to :user | ||
has_many :gallery_items, :dependent => :destroy | ||
has_many :gallery_items, :order => :position, :dependent => :destroy | ||
|
||
validates_uniqueness_of :name | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- assets.each do |asset| | ||
%li.asset-list-item{:id => "gallery_item_#{asset.id}"} | ||
= image_tag(asset.thumbnail(:thumbnail), :alt => asset.asset_file_name, :title => asset.title) | ||
%span= h asset.title[0..75] | ||
%span.delete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- items.each do |item| | ||
%li.asset-list-item{:id => "gallery_item_#{item.asset.id}"} | ||
= image_tag(item.asset.thumbnail(:thumbnail), :alt => item.asset.asset_file_name, :title => item.asset.title) | ||
%span= h item.asset.title[0..75] | ||
%span.delete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,49 @@ | ||
- content_for 'page_css' do | ||
:sass | ||
p.title | ||
margin: 10px 0 !important | ||
- @stylesheets << 'admin/gallery' | ||
- include_javascript 'admin/dragdrop' | ||
- include_javascript 'admin/gallery' | ||
|
||
#content .form-area div.error-with-field | ||
input.textbox | ||
font-family: Georgia,Palatino,"Times New Roman",Times,serif | ||
font-size: 200% | ||
width: 100% | ||
|
||
textarea.textarea | ||
height: 150px !important | ||
width: 100% | ||
display: block | ||
|
||
input.file | ||
margin: 50px 0 | ||
|
||
img.asset | ||
margin: 5px 0 | ||
border: 2px solid #fff | ||
|
||
a.asset | ||
display: block | ||
margin: 5px 0 | ||
|
||
div.asset-list-container | ||
overflow: auto | ||
width: 100% | ||
height: 300px | ||
border: 2px solid #cccccc | ||
|
||
div.asset-list-item-container | ||
display: inline-block | ||
|
||
div.asset-list-item | ||
border: 1px solid #cccccc | ||
text-align: center | ||
padding: 5px | ||
margin: 5px | ||
|
||
%h1= @gallery.new_record? ? 'New Gallery' : 'Edit Gallery' | ||
%h1= 'Edit Gallery' | ||
|
||
- form_for [:admin, @gallery], :html => {:multipart => true} do |f| | ||
.form-area | ||
%p.title | ||
%label Title | ||
= f.text_field :name, :class => 'textbox' | ||
%p.title | ||
%label Description | ||
= f.text_area :caption, :class => 'textarea' | ||
%p.title | ||
%label Select Assets For Gallery | ||
.asset-list-container | ||
- Asset.all.each do |asset| | ||
.asset-list-item-container | ||
.asset-list-item | ||
= image_tag(asset.thumbnail(:thumbnail)) | ||
%h5= asset.title | ||
- if @gallery.gallery_items.exists?(:asset_id => asset.id) | ||
= check_box "checked", asset.id, {:checked => true} | ||
- else | ||
= check_box "checked", asset.id | ||
|
||
|
||
%p.buttons | ||
#gallery_panel | ||
.form-area | ||
|
||
%p.title | ||
%label Title | ||
= f.text_field :name, :class => 'textbox' | ||
|
||
.drawer | ||
.drawer_contents#attributes | ||
%table.fieldset | ||
%tr | ||
%th.label | ||
%label Description | ||
%td.field= f.text_area :caption, :class => 'textarea' | ||
.drawer_handle | ||
%a.toggle{:href=>'#attributes', :rel=>"toggle[attributes]", :class=>"#{(meta_errors? ? 'less' : 'more')}"}= meta_label | ||
|
||
%p.title | ||
%label Selected Assets <small>(Drag around for ordering)</small> | ||
%ul.asset-list-container#gallery_items= render :partial => 'items', :locals => { :items => @items } | ||
|
||
#assets_panel | ||
%p.title#asset-selection | ||
%label Assets Overview | ||
%span.asset_filters | ||
- form_tag(admin_assets_path,:id => 'filesearchform', :method => 'get') do | ||
%input{ :type => "search", :id => "search", :name => "search" , :value => params[:search] } | ||
= observe_field 'search', :frequency => 1, :url => { :controller => 'galleries', :action=> 'search' }, :method => 'get', :with => "'search=' + escape(value) + '&id=' + #{@gallery.id}" | ||
%ul.asset-list-container#asset_items= render :partial => 'assets', :locals => { :assets => @assets } | ||
|
||
%p.note Drag your images to the Selected Assets area | ||
|
||
%p.buttons#submit_buttons | ||
- button_text = @gallery.new_record? ? 'Create' : 'Save Changes' | ||
= submit_tag button_text, :class => 'button' | ||
or | ||
= link_to 'Cancel', admin_galleries_url | ||
|
||
#routes{:style => 'display:none'} | ||
= hidden_field_tag 'admin_gallery_items_path', admin_gallery_items_path(@gallery) | ||
= hidden_field_tag 'admin_gallery_items_sort_path', admin_gallery_items_sort_path(@gallery) | ||
|
Oops, something went wrong.