diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..97a708b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +config/gallery.yml \ No newline at end of file diff --git a/app/controllers/gallery_controller.rb b/app/controllers/gallery_controller.rb deleted file mode 100644 index cbdb268..0000000 --- a/app/controllers/gallery_controller.rb +++ /dev/null @@ -1,144 +0,0 @@ -class GalleryController < ApplicationController - - before_filter :find_gallery, :except => [:index, :list, :new, :create] - - def index - @galleries = Gallery.find(:all, :conditions => ["parent_id IS NULL"] ) - end - - def new - @gallery = Gallery.new - end - - def create - if request.post? - @gallery = Gallery.new(params[:gallery].merge({:parent_id => params[:parent_id]})) - if @gallery.save - flash[:notice] = "Your gallery has been saved below." - redirect_to( params[:continue] ? gallery_edit_url(:id => @gallery.id) : gallery_show_url(:id => @gallery.id)) - else - flash[:error] = "Validation errors occurred while processing this form. Please take a moment to review the form and correct any input errors before continuing." - render(:action => 'new') - end - else - redirect_to(gallery_index_url) - end - end - - def edit - end - - def update - if request.post? - if @gallery.update_attributes(params[:gallery]) - flash[:notice] = "Your gallery has been saved below." - redirect_to( params[:continue] ? gallery_edit_url(:id => @gallery.id) : gallery_show_url(:id => @gallery.id)) - else - flash[:error] = "Validation errors occurred while processing this form. Please take a moment to review the form and correct any input errors before continuing." - render(:action => 'edit') - end - else - redirect_to(gallery_edit_url(:id => @gallery)) - end - end - - def destroy - if request.post? - count = @gallery.items.count - @gallery.destroy - flash[:notice] = if count > 1 - "The gallery and its images were successfully destroyed from the site." - else - "The gallery and its image was successfully destroyed from the site." - end - redirect_to(gallery_index_url) - end - end - - def retrieve_file - @file_url = params[:file_url] - uri = URI.parse(@file_url) - raise "You can specify only HTTP and FTP url using file url mode." unless uri.is_a?(URI::HTTP) || uri.is_a?(URI::FTP) - temp_file_path = File.join(Technoweenie::AttachmentFu.tempfile_path, File.basename(@file_url.gsub(/\?.*$/, ''))) - open(@file_url) do |remote_file| - File.open(temp_file_path, 'w') do |file| - file.write(remote_file.read) - end - end - create_item(@gallery, temp_file_path) - flash[:notice] = "Your file has been saved below." - rescue Exception => e - flash[:error] = "I had troubles retrieving your file :( - #{e}" - ensure - redirect_to gallery_show_url(:id => @gallery) - end - - def clear_thumbs - @gallery.clear_thumbs - flash[:notice] = 'Thumbnails have been deleted correctly' - redirect_to(gallery_show_url(:id => @gallery)) - end - - def children - render(:layout => false) - end - - def import - @folders = import_folders - if request.post? && params[:file_path] - path = File.expand_path(File.join(galleries_absolute_path, params[:file_path])) - if path =~ /^#{import_path}/ and File.exists?(path) - create_item(@gallery, path) - @imported = true - end - render(:action => 'imported') - elsif request.post? - @files = [] - @selected_path = File.expand_path(File.join(galleries_absolute_path, params[:path])) - if @selected_path =~ /^#{import_path}/ - @files = Dir[File.join(@selected_path, '**', '*')].find_all{|file| file if File.file?(file)} - @files.collect!{|file| file.gsub(/^#{galleries_absolute_path}/, '')}.sort! - render(:action => 'import_files') - end - end - end - -private - - def find_gallery - @gallery = Gallery.find(params[:id]) - rescue ActiveRecord::RecordNotFound - redirect_to(gallery_index_url) - end - - def galleries_absolute_path - galleries_folder = Radiant::Config['gallery.path_prefix'] - galleries_path = File.expand_path(File.join(RAILS_ROOT, galleries_folder)) - end - - def create_item(gallery, temp_path) - item = GalleryItem.new - item.attributes = { - :gallery_id => gallery.id, - :temp_path => temp_path, - :filename => File.basename(temp_path), - :content_type => GalleryItem::KnownExtensions[File.extname(temp_path).gsub(/^\./, '')][:content_type] - } - item.save - FileUtils.rm(temp_path) - if item.thumbnailable? - [300, 500].each{|size| item.thumb(:width => size, :height => size, :prefix => 'admin')} - end - end - - def import_folders - folders = Dir[File.join(import_path, '**', '*')].find_all{|path| path if File.directory?(path) } - folders << import_path - folders.collect!{|path| path.gsub(/^#{galleries_absolute_path}/, '')}.sort! - end - - def import_path - File.join(galleries_absolute_path, 'import') - end - -end diff --git a/app/controllers/gallery_item_controller.rb b/app/controllers/gallery_item_controller.rb deleted file mode 100644 index cece2e5..0000000 --- a/app/controllers/gallery_item_controller.rb +++ /dev/null @@ -1,60 +0,0 @@ -class GalleryItemController < ApplicationController - - before_filter :find_item, :except => [ :create, :sort ] - - def create - @gallery = Gallery.find(params[:gallery_id]) - if params[:gallery_item][:uploaded_data].size > 0 - @gallery.items.create(params[:gallery_item]) - flash[:notice] = "Your file has been saved below." - else - flash[:error] = "I had troubles uploading your file :(" - end - redirect_to gallery_show_url(:id => @gallery) - rescue ActiveRecord::RecordNotFound - redirect_to(gallery_index_url) - end - - def edit - unless request.xhr? - redirect_to(gallery_show_url(:id => @item.gallery.id)) and return - end - end - - def update - if request.xhr? && request.post? - @item.update_attributes params[:item] - else - redirect_to(gallery_show_url(:id => @item.gallery.id)) and return - end - end - - def destroy - if request.xhr? && request.post? - @destroyed = @item.destroy - else - redirect_to(gallery_show_url(:id => @item.gallery.id)) and return - end - end - - def sort - old_position, new_position = params[:old_position].to_i, params[:new_position].to_i - @item = GalleryItem.find(:first, :conditions => ["id = ? AND position = ?", params[:id], old_position]) - if @item - x, y, z = old_position < new_position ? ["-", "<", ">"] : ["+", ">", "<"] - GalleryItem.update_all("position = (position #{x} 1)", ["parent_id IS NULL AND gallery_id = ? AND position #{y}= ? AND position #{z}= ?", @item.gallery_id, new_position, old_position]) - @item.update_attribute('position', new_position) - else - @error = true - end - end - -private - - def find_item - @item = GalleryItem.find(params[:id]) - rescue ActiveRecord::RecordNotFound - redirect_to(gallery_index_url) - end - -end diff --git a/app/helpers/gallery_helper.rb b/app/helpers/gallery_helper.rb deleted file mode 100644 index 903c36f..0000000 --- a/app/helpers/gallery_helper.rb +++ /dev/null @@ -1,94 +0,0 @@ -module GalleryHelper - - def gallery_toolbar - content = '
' - links = [] - links << link_to('Edit gallery', gallery_edit_url(:id => @gallery.id)) - links << link_to('Import files', gallery_import_url(:id => @gallery.id)) - links << link_to('Clear thumbs', gallery_clear_thumbs_url(:id => @gallery)) - links << link_to('Add Child Gallery', gallery_new_child_url(:parent_id => @gallery)) - links << link_to('Destroy gallery', gallery_destroy_url(:id => @gallery)) - content << links.join(" | ") - content << '
' - end - - def item_label(item) - "
#{item.name}
" - end - - def item_buttons(item) - content = '
' - content << item_show_button(item) - content << item_edit_button(item) - content << item_edit_image_button(item) - content << item_destroy_button(item) - content << '
' - end - - def item_show_button(item) - content = '' - if item.image? - content << link_to(image('gallery/show.png'), item.thumb(:width => 500, :height => 500, :prefix => :admin).public_filename, :rel => "lightbox[#{@gallery.name}]", :title => 'Show', :id => "item_#{item.id}_view_title" ) - else - content << link_to(image('gallery/show.png'), item.public_filename, :title => item.name) - end - end - - - def item_edit_image_button(item) - content = '' - #if item.image? - # content << link_to(image('gallery/edit-image.png'), gallery_item_edit_image_url(:id => item), :title => 'Edit image' ) - #end - content - end - - def item_destroy_button(item) - link_to(image('gallery/destroy.png', :id => "item_delete_#{item.id}"), - gallery_item_destroy_url(:id => item.id), { - :title => 'Destroy', - :onclick => "GalleryItems.delete_if_confirm(#{item.id}, '#{gallery_item_destroy_url(:id => item.id)}'); return false;" - } - ) - end - - def item_edit_button(item) - content = '' - content << link_to(image('gallery/edit.png'), '#', :title => 'Edit', :onclick => "GalleryItemPopup.open(#{item.id}); return false;") - end - - def item_preview(item) - content = "
" - if item.image? - thumb = item.thumb(:width => 300, :height => 300, :prefix => :admin) - width_perc, height_perc = proportional_resize(thumb.width, thumb.height, 100, 100) - margin_top = (100 - height_perc) / 2 - content << "" - else - width_perc, height_perc = proportional_resize(100, 100, 100, 100) - margin_top = (100 - height_perc) / 2 - content << "" - end - content << "
" - end - - def gallery_zoom_slider - %|
-
-
-
-
-
-
| - end - -private - - def proportional_resize(width, height, max_width, max_height) - aspectratio = max_width.to_f / max_height.to_f - picratio = width.to_f / height.to_f - scaleratio = picratio > aspectratio ? max_width.to_f / width : max_height.to_f / height - [width * scaleratio, height * scaleratio] - end - -end \ No newline at end of file diff --git a/app/helpers/gallery_item_helper.rb b/app/helpers/gallery_item_helper.rb deleted file mode 100644 index b08a379..0000000 --- a/app/helpers/gallery_item_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module GalleryItemHelper -end \ No newline at end of file diff --git a/app/views/gallery/_form.rhtml b/app/views/gallery/_form.rhtml deleted file mode 100644 index fd00f03..0000000 --- a/app/views/gallery/_form.rhtml +++ /dev/null @@ -1,31 +0,0 @@ - -
-

- - <%= g.text_field "name", :class => 'textbox', :maxlength => 255 %> -

-

- -

-
- <%= g.text_area "description", :class => 'textbox', :maxlength => 255 %> -
- -

- - Advanced options -

-   -
-

- <%= save_model_button(@gallery) %> <%= save_model_and_continue_editing_button(@gallery) %> or <%= link_to "Cancel", gallery_index_url %> -

\ No newline at end of file diff --git a/app/views/gallery/_gallery.rhtml b/app/views/gallery/_gallery.rhtml deleted file mode 100644 index 080b397..0000000 --- a/app/views/gallery/_gallery.rhtml +++ /dev/null @@ -1,36 +0,0 @@ -<% -count = gallery.children.count -children = count > 0 -level = gallery.ancestors.size -padding_left = (level * 22) + 4 -children_class = children ? ' children-visible' : ' no-children' -expanded = false -expander = children ? image((expanded ? "collapse" : "expand"), :class => "expander", :alt => 'toggle children', :title => '', :align => 'center', :id => "gallery-expander-#{gallery.id}") : "" -name = %{#{ gallery.name }} -icon = image('gallery/gallery', :class => "icon", :alt => 'gallery-icon', :title => '', :align => 'center') -spinner = image('spinner.gif', :class => 'busy', :id => "gallery-busy-#{gallery.id}", :alt => "", :title => "", :align => "center", :style => 'display: none;') --%> - - - - - - <%= expander %> - - <%= icon %> - <%= gallery.name %> - - (<%= gallery.items.size %> files) - <%= spinner %> - - - <%= gallery.id %> - <%= gallery.hidden ? 'hidden' : 'visible' %> - <%= link_to image('add-child', :alt => 'add child'), gallery_new_child_url(:parent_id => gallery) %> - <%= link_to image_tag('admin/remove', :alt => 'remove gallery'), gallery_destroy_url(:id => gallery) %> - - - - - - diff --git a/app/views/gallery/children.rhtml b/app/views/gallery/children.rhtml deleted file mode 100644 index 9e1d669..0000000 --- a/app/views/gallery/children.rhtml +++ /dev/null @@ -1,6 +0,0 @@ -<%= render :partial => 'gallery', :collection => @gallery.children %> - \ No newline at end of file diff --git a/app/views/gallery/destroy.rhtml b/app/views/gallery/destroy.rhtml deleted file mode 100644 index 235b9ce..0000000 --- a/app/views/gallery/destroy.rhtml +++ /dev/null @@ -1,25 +0,0 @@ -<% include_stylesheet 'admin/gallery/gallery' -%> -<% items = pluralize(@gallery.items.count, 'Item') -%> -<% items_question = @gallery.items.size > 0 ? " and #{items.downcase}" : "" -%> -

Remove <%= items %>

-

Are you sure you want to permanently remove the following gallery<%= items_question %>?

- - - - - - - -
- -
-

<%= submit_tag "Destroy gallery", :class => 'button' %> or <%= link_to 'Cancel', gallery_index_url %>

-
\ No newline at end of file diff --git a/app/views/gallery/edit.rhtml b/app/views/gallery/edit.rhtml deleted file mode 100644 index bd1684d..0000000 --- a/app/views/gallery/edit.rhtml +++ /dev/null @@ -1,12 +0,0 @@ -<% include_stylesheet 'admin/gallery/gallery' -%> -

Edit Gallery

- -<% form_for(:gallery, :url => {:action => 'update'}) do |g| -%> - <%= render :partial => 'form', :locals => {:g => g} %> -<% end -%> - - \ No newline at end of file diff --git a/app/views/gallery/import.rhtml b/app/views/gallery/import.rhtml deleted file mode 100644 index df85026..0000000 --- a/app/views/gallery/import.rhtml +++ /dev/null @@ -1,14 +0,0 @@ -<% include_stylesheet 'admin/gallery/gallery' -%> -<% include_javascript 'gallery' -%> - -

<%= @gallery.name %> / import

-

- Create a folder named import inside the galleries folder. - Upload your files in that folder using ftp, then select the import folder you created. - Click import and all your files will be imported. -

-
- <% options = options_for_select @folders -%> - <%= select_tag 'path', options %> -

<%= submit_tag "Import", :class => 'button' %> or <%= link_to 'Cancel', gallery_show_url(@gallery) %>

-
diff --git a/app/views/gallery/import_files.rhtml b/app/views/gallery/import_files.rhtml deleted file mode 100644 index 4202ea9..0000000 --- a/app/views/gallery/import_files.rhtml +++ /dev/null @@ -1,31 +0,0 @@ -<% include_stylesheet 'admin/gallery/gallery' -%> -<% include_javascript 'gallery' -%> - - -

<%= @gallery.name %> / import

-

The following files will be imported under <%= link_to @gallery.name, gallery_show_url(:id => @gallery) %> gallery. Click the Import button at the end of the page.

-

- - - - -

- -

\ No newline at end of file diff --git a/app/views/gallery/imported.rjs b/app/views/gallery/imported.rjs deleted file mode 100644 index 024c9bd..0000000 --- a/app/views/gallery/imported.rjs +++ /dev/null @@ -1,5 +0,0 @@ -if @imported - page.call "GalleryImporter.instance.next" -else - page.call "alert", "Error importing '#{params[:path]}'" -end \ No newline at end of file diff --git a/app/views/gallery/index.rhtml b/app/views/gallery/index.rhtml deleted file mode 100644 index 79279e9..0000000 --- a/app/views/gallery/index.rhtml +++ /dev/null @@ -1,33 +0,0 @@ -<% include_stylesheet 'admin/gallery/gallery' -%> -<% include_javascript 'lite_sortable' -%> -<% include_javascript 'gallery' -%> - -

Galleries

- - - - - - - - - - - -<% if @galleries.size > 0 -%> - <%= render :partial => 'gallery', :collection => @galleries %> - -<% else -%> - - - -<% end -%> - -
NameIDStatusActions
No Galleries
-

- <%= link_to image('gallery/new-gallery.png', :alt => 'New Gallery'), gallery_new_url %> -

\ No newline at end of file diff --git a/app/views/gallery/list.rhtml b/app/views/gallery/list.rhtml deleted file mode 100644 index 9a6f2d6..0000000 --- a/app/views/gallery/list.rhtml +++ /dev/null @@ -1,36 +0,0 @@ -<% include_stylesheet 'admin/gallery/gallery' -%> -<% include_javascript 'gallery' -%> - -

Galleries

- - - - - - - - - - - -<% if @galleries.size > 0 -%> - <%= render :partial => 'gallery', :collection => @galleries %> - -<% else -%> - - - -<% end -%> - -
NameIDStatusActions
No Galleries
-

- <%= link_to image('gallery/new-gallery.png', :alt => 'New Gallery'), gallery_new_url %> -

\ No newline at end of file diff --git a/app/views/gallery/new.rhtml b/app/views/gallery/new.rhtml deleted file mode 100644 index 1310991..0000000 --- a/app/views/gallery/new.rhtml +++ /dev/null @@ -1,12 +0,0 @@ -<% include_stylesheet 'admin/gallery/gallery' -%> -

New Gallery

- -<% form_for(:gallery, :url => {:action => 'create', :parent_id => params[:parent_id]}) do |g| -%> - <%= render :partial => 'form', :locals => {:g => g} %> -<% end -%> - - \ No newline at end of file diff --git a/app/views/gallery/show.rhtml b/app/views/gallery/show.rhtml deleted file mode 100644 index c8e8f07..0000000 --- a/app/views/gallery/show.rhtml +++ /dev/null @@ -1,90 +0,0 @@ -<% include_javascript 'dragdrop' %> -<% include_javascript 'slider' %> -<% include_javascript 'lightbox'%> -<% include_javascript 'lite_sortable'%> -<% include_javascript 'gallery'%> -<% include_stylesheet 'admin/gallery/gallery' -%> -<% include_stylesheet 'lightbox/lightbox' -%> - -

<%= @gallery.name %>

-<% if flash[:gallery_external_html] -%> -
<%= flash[:gallery_external_html] %>
-<% end -%> - -<%= gallery_toolbar %> -<%= gallery_zoom_slider %> - -
 
-
-
- <% form_for(:gallery_item, - :url => gallery_item_create_url(:gallery_id => @gallery), - :html => {:method => 'post', :multipart => true} - ) do |form| -%> -

Upload file:

-

- <%= form.file_field 'uploaded_data', :class => 'textbox' %> - <%= submit_tag "Upload", :id => nil, :class => 'button', :disable_with => "Uploading..." %> -

- <% end %> -
- -
- - Switch to url mode - - -
-
- -
- -
- -
- -
\ No newline at end of file diff --git a/app/views/gallery_item/destroy.rjs b/app/views/gallery_item/destroy.rjs deleted file mode 100644 index 9ec6c8e..0000000 --- a/app/views/gallery_item/destroy.rjs +++ /dev/null @@ -1,5 +0,0 @@ -if @destroyed - page.call "GalleryItemsPanel.instance.removeItem", @item.id -else - page.alert "Problem destroying this item" -end \ No newline at end of file diff --git a/app/views/gallery_item/edit.rhtml b/app/views/gallery_item/edit.rhtml deleted file mode 100644 index 7d1fd9d..0000000 --- a/app/views/gallery_item/edit.rhtml +++ /dev/null @@ -1,28 +0,0 @@ -
- -

Edit info

- <% form_remote_tag( - :url => gallery_item_update_url(:id => @item), - :id => 'update-item-popup-form', - :eval_scripts => true, - :before => "$('update-item-popup-save-button').disabled=true;$('update-item-popup-save-button').value='Saving...';", - :loading => "Element.show('update-item-popup-busy')", - :complete => "Element.hide('update-item-popup-busy')" - ) do %> -
- -
- <%= text_field "item", "name" %>
-
- <%= text_area "item", "description" %>
- <%= submit_tag "Save", :id => 'update-item-popup-save-button' %> -
-

<%= link_to_function 'Close', "GalleryPopup.close();", :class => 'close-link' %>

- <% end %> -
- - \ No newline at end of file diff --git a/app/views/gallery_item/edit_image.rhtml b/app/views/gallery_item/edit_image.rhtml deleted file mode 100644 index 01534cf..0000000 --- a/app/views/gallery_item/edit_image.rhtml +++ /dev/null @@ -1,42 +0,0 @@ -<% include_stylesheet 'admin/gallery/gallery' -%> -<% include_stylesheet 'admin/gallery/cropper' -%> -<% include_javascript 'builder' -%> -<% include_javascript 'cropper' -%> - - - - -

Edit image (beta)

-<% if @item.image? -%> -
- - - - - - -

- - or <%= link_to 'Cancel', gallery_show_url(:id => @item.gallery) %> -

-
-<% else %> -

You can not crop this item because it's not an image.

-<% end -%> -
-

<%= @item.name %>

- <%= @item.name %> -
\ No newline at end of file diff --git a/app/views/gallery_item/sort.rjs b/app/views/gallery_item/sort.rjs deleted file mode 100644 index c5e4b98..0000000 --- a/app/views/gallery_item/sort.rjs +++ /dev/null @@ -1,3 +0,0 @@ -if @error - page.alert "Error: maybe the selected item has been deleted or moved by someone else!" -end \ No newline at end of file diff --git a/app/views/gallery_item/update.rjs b/app/views/gallery_item/update.rjs deleted file mode 100644 index 6ffab98..0000000 --- a/app/views/gallery_item/update.rjs +++ /dev/null @@ -1,4 +0,0 @@ -page.call "GalleryItems.set_name", @item.id, @item.name -page.call "GalleryItems.set_description", @item.id, @item.description -page.call "GalleryItemPopup.close" -page.call "GalleryItemPopup.reset_button" \ No newline at end of file diff --git a/test/functional/gallery_controller_test.rb b/test/functional/gallery_controller_test.rb deleted file mode 100644 index 963f0c4..0000000 --- a/test/functional/gallery_controller_test.rb +++ /dev/null @@ -1,17 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -# Re-raise errors caught by the controller. -GalleryController.class_eval { def rescue_action(e) raise e end } - -class GalleryControllerTest < Test::Unit::TestCase - def setup - @controller = GalleryController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - end - - # Replace this with your real tests. - def test_truth - assert true - end -end diff --git a/test/functional/gallery_item_controller_test.rb b/test/functional/gallery_item_controller_test.rb deleted file mode 100644 index 44cb831..0000000 --- a/test/functional/gallery_item_controller_test.rb +++ /dev/null @@ -1,17 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -# Re-raise errors caught by the controller. -GalleryItemController.class_eval { def rescue_action(e) raise e end } - -class GalleryItemControllerTest < Test::Unit::TestCase - def setup - @controller = GalleryItemController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - end - - # Replace this with your real tests. - def test_truth - assert true - end -end