Commit 6db6c234 authored by jak4's avatar jak4
Browse files

Added to more fields to photo model: css_class and preview_type

Added config options for url, css_class and preview_type
Added preview_link method to photo model. Will either use the provided ext_type or the preview_type in the database. If there is an exception this will be catched and the version :error_wrong_preview_version will be delivered.
parent ef8cf3b4
...@@ -5,7 +5,7 @@ module Refinery ...@@ -5,7 +5,7 @@ module Refinery
mount_uploader :file, Refinery::PhotoGallery::Admin::FileUploader mount_uploader :file, Refinery::PhotoGallery::Admin::FileUploader
acts_as_indexed :fields => [:title, :description] acts_as_indexed :fields => [:title, :description]
attr_accessible :album_id, :title, :description, :longitude, :latitude, :url attr_accessible :album_id, :title, :description, :longitude, :latitude, :url, :css_class, :preview_type
validates :title, :presence => true validates :title, :presence => true
#TODO validate latitude/longitude - convert from nondecimal to decimal using inspiration from https://github.com/airblade/geo_tools/tree/master/lib/geo_tools #TODO validate latitude/longitude - convert from nondecimal to decimal using inspiration from https://github.com/airblade/geo_tools/tree/master/lib/geo_tools
...@@ -24,6 +24,15 @@ module Refinery ...@@ -24,6 +24,15 @@ module Refinery
self.url.blank? ? file.single.url : self.url self.url.blank? ? file.single.url : self.url
end end
def preview_link(ext_type = :album)
begin
type = self.preview_type.blank? ? ext_type : self.preview_type
file.url(type)
rescue Exception => e
file.url(:error_wrong_preview_version)
end
end
private private
def set_title def set_title
......
...@@ -47,6 +47,7 @@ module Refinery ...@@ -47,6 +47,7 @@ module Refinery
"thumbs/#{model.album.path}" "thumbs/#{model.album.path}"
end end
end end
version :preview do version :preview do
process :resize_to_fit => Refinery::PhotoGallery.preview_dimensions process :resize_to_fit => Refinery::PhotoGallery.preview_dimensions
process :auto_orient process :auto_orient
...@@ -54,8 +55,8 @@ module Refinery ...@@ -54,8 +55,8 @@ module Refinery
"thumbs/#{model.album.path}" "thumbs/#{model.album.path}"
end end
end end
version :single do
version :single do
process :resize_to_limit => Refinery::PhotoGallery.single_dimensions process :resize_to_limit => Refinery::PhotoGallery.single_dimensions
process :auto_orient process :auto_orient
...@@ -64,6 +65,11 @@ module Refinery ...@@ -64,6 +65,11 @@ module Refinery
end end
end end
version :error_wrong_preview_version do
def store_dir
"error/wrong_preview_version.png"
end
end
# Add a white list of extensions which are allowed to be uploaded, # Add a white list of extensions which are allowed to be uploaded,
def extension_white_list def extension_white_list
......
...@@ -15,10 +15,26 @@ ...@@ -15,10 +15,26 @@
<%= p.text_area :description, :rows => "5", :cols=> "57" %> <%= p.text_area :description, :rows => "5", :cols=> "57" %>
</div> </div>
<div class='field'> <% if Refinery::PhotoGallery.admin_options_show_url %>
<%= p.label :url %> <div class='field'>
<%= p.text_field :url, :class => "larger" %> <%= p.label :url %>
</div> <%= p.text_field :url, :class => "larger" %>
</div>
<% end %>
<% if Refinery::PhotoGallery.admin_options_show_css_class %>
<div class='field'>
<%= p.label :css_class %>
<%= p.text_field :css_class, :class => "larger" %>
</div>
<% end %>
<% if Refinery::PhotoGallery.admin_options_show_preview_type %>
<div class='field'>
<%= p.label :preview_type %>
<%= p.text_field :preview_type, :class => "larger" %>
</div>
<% end %>
<div class='field-group'> <div class='field-group'>
<%= p.label :longitude, :tooltip=> t('.use_decimal_format') %> <%= p.label :longitude, :tooltip=> t('.use_decimal_format') %>
......
...@@ -5,8 +5,12 @@ ...@@ -5,8 +5,12 @@
<ul id="gallery" class="clearfix"> <ul id="gallery" class="clearfix">
<% photos_for_page.each_with_index do |photo, index| %> <% photos_for_page.each_with_index do |photo, index| %>
<li> <% if photo.css_class.present? %>
<%= link_to (image_tag photo.file.url(:album), :width => Refinery::PhotoGallery.album_dimensions[0], :height => Refinery::PhotoGallery.album_dimensions[1] ), photo.link_url, { <li class="<%= photo.css_class %>" >
<% else %>
<li>
<% end %>
<%= link_to (image_tag photo.preview_link(:album), :width => Refinery::PhotoGallery.album_dimensions[0], :height => Refinery::PhotoGallery.album_dimensions[1] ), photo.link_url, {
:target=> "_blank", :target=> "_blank",
:class=>"fancybox", :class=>"fancybox",
:data =>{:title=> t('.image') + ' ' + (index + 1 ).to_s + '/' + photos_for_page.total_pages.to_s + ' ' + photo.title + '<br/><br/>' + photo.description}, :data =>{:title=> t('.image') + ' ' + (index + 1 ).to_s + '/' + photos_for_page.total_pages.to_s + ' ' + photo.title + '<br/><br/>' + photo.description},
......
class AddCssStylesAndShowOriginalFieldsToPhotos < ActiveRecord::Migration
def change
add_column :refinery_photo_gallery_photos, :css_class, :string
add_column :refinery_photo_gallery_photos, :preview_type, :string
end
end
...@@ -31,6 +31,7 @@ Refinery::PhotoGallery.configure do |config| ...@@ -31,6 +31,7 @@ Refinery::PhotoGallery.configure do |config|
# config.albums_per_page = <%= Refinery::PhotoGallery.albums_per_page.inspect %> # config.albums_per_page = <%= Refinery::PhotoGallery.albums_per_page.inspect %>
# config.photos_per_page = <%= Refinery::PhotoGallery.photos_per_page.inspect %> # config.photos_per_page = <%= Refinery::PhotoGallery.photos_per_page.inspect %>
# config.admin_options_show_url = <%= Refinery::PhotoGallery.admin_options_show_url.inspect %>
# config.admin_options_show_css_class = <%= Refinery::PhotoGallery.admin_options_show_css_class.inspect %>
# config.admin_options_show_preview_type = <%= Refinery::PhotoGallery.admin_options_show_preview_type.inspect %>
end end
...@@ -4,7 +4,9 @@ module Refinery ...@@ -4,7 +4,9 @@ module Refinery
config_accessor :runtimes, :max_file_size,:client_side_resize, :client_side_resize_params, :plupload_locale, :extension_white_list,:photo_gallery_dir, config_accessor :runtimes, :max_file_size,:client_side_resize, :client_side_resize_params, :plupload_locale, :extension_white_list,:photo_gallery_dir,
:delete_uploaded_file,:collection_dimensions, :album_dimensions, :preview_dimensions, :single_dimensions, :photo_gallery_dir_relative_to_root, :delete_uploaded_file,:collection_dimensions, :album_dimensions, :preview_dimensions, :single_dimensions, :photo_gallery_dir_relative_to_root,
:photos_per_page, :albums_per_page, :collections_per_page :photos_per_page, :albums_per_page, :collections_per_page,
:admin_options_show_url, :admin_options_show_css_class,
:admin_options_show_preview_type
...@@ -27,5 +29,9 @@ module Refinery ...@@ -27,5 +29,9 @@ module Refinery
self.albums_per_page = 10 self.albums_per_page = 10
self.collections_per_page = 10 self.collections_per_page = 10
self.photos_per_page = 10 self.photos_per_page = 10
self.admin_options_show_url = true
self.admin_options_show_css_class = true
self.admin_options_show_preview_type = true
end end
end end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment