ordering added to albums

This commit is contained in:
Harry Bomrah 2015-04-16 23:10:25 +08:00
parent 7e432bd1ed
commit 8aead66ac5
8 changed files with 55 additions and 27 deletions

View File

@ -43,10 +43,10 @@ $(function() {
$img = $('.rgalbum img'); $img = $('.rgalbum img');
$('.rgalbum > a').rsImg(); $('.rgalbum > a').rsImg();
if($containerData.galleryId == 'gallery') { if($containerData.galleryId == 'gallery') {
$container.masonry({ // $container.masonry({
itemSelector : '.rgalbum', // itemSelector : '.rgalbum',
isAnimated: true, // isAnimated: true,
}); // });
$albumname.each(function(i) { $albumname.each(function(i) {
var $albumblock = $(this).closest('a').height(), var $albumblock = $(this).closest('a').height(),
$H = $(this).outerHeight(true); $H = $(this).outerHeight(true);
@ -69,12 +69,7 @@ $(function() {
}; };
}); });
$('#orbit_gallery').delegate('.icons-tag', clickEvent, function(){ $('#orbit_gallery').delegate('.icons-tag', clickEvent, function(){
$(this).parents('.gallery_info').nextAll('.albumtag').slideToggle(300, function() { $(this).parents('.gallery_info').nextAll('.albumtag').slideToggle(300);
$container.masonry({
itemSelector : '.rgalbum',
isAnimated: true,
});
});
}); });
}; };
}); });
@ -229,11 +224,12 @@ $(function() {
$container.data("order-edit","1"); $container.data("order-edit","1");
el.text("Save Order"); el.text("Save Order");
}else{ }else{
var temp = $container.sortable( "toArray", { attribute: "data-image-id" }); var temp = $container.sortable( "toArray", { attribute: "data-image-id" }),
type = $container.attr("id");
if(images_order.toString() != temp.toString()){ if(images_order.toString() != temp.toString()){
$.ajax({ $.ajax({
url : "/admin/galleries/order", url : "/admin/galleries/order",
data : {"imageids" : temp }, data : {"imageids" : temp, "type" : type},
type : "post", type : "post",
dataType : "json" dataType : "json"
}) })

View File

@ -4,10 +4,17 @@
list-style: none; list-style: none;
} }
#orbit_gallery .rgalbum { #orbit_gallery .rgalbum {
position: relative;
float: left;
margin: 5px; margin: 5px;
padding: 10px; padding: 5px;
width: 200px; width: 200px;
background: #FFFFFF; background: #FFFFFF;
overflow: hidden;
-webkit-box-shadow: 0px 0px 5px rgba(0, 0, 0, .1);
-moz-box-shadow: 0px 0px 5px rgba(0, 0, 0, .1);
box-shadow: 0px 0px 5px rgba(0, 0, 0, .1);
-o-box-shadow: 0px 0px 5px rgba(0, 0, 0, .1);
-webkit-transition-property: left, right, top; -webkit-transition-property: left, right, top;
-moz-transition-property: left, right, top; -moz-transition-property: left, right, top;
-ms-transition-property: left, right, top; -ms-transition-property: left, right, top;
@ -522,6 +529,7 @@
.order-edit-notification{ .order-edit-notification{
background-color: #ffffd5; background-color: #ffffd5;
z-index: 10;
display: none; display: none;
height: 25px; height: 25px;
margin-left: 40%; margin-left: 40%;

View File

@ -4,7 +4,7 @@ class Admin::GalleriesController < OrbitAdminController
before_action :log_user_action before_action :log_user_action
layout "back_end" layout "back_end"
def index def index
@albums = Album.all @albums = Album.all.asc(:order)
@tags = @module_app.tags @tags = @module_app.tags
end end

View File

@ -8,6 +8,8 @@ class Admin::ImagesController < OrbitAdminController
end end
def changeorder def changeorder
type = params[:type]
if type == "imgholder"
images = params[:imageids] images = params[:imageids]
images.each_with_index do |image, i| images.each_with_index do |image, i|
img = AlbumImage.find(image) rescue nil img = AlbumImage.find(image) rescue nil
@ -16,6 +18,16 @@ class Admin::ImagesController < OrbitAdminController
img.save img.save
end end
end end
elsif type == "orbit_gallery"
albums = params[:imageids]
albums.each_with_index do |albumid, i|
album = Album.find(albumid) rescue nil
if !album.nil?
album.order = i
album.save
end
end
end
render :json => {"success" => true}.to_json render :json => {"success" => true}.to_json
end end

View File

@ -1,6 +1,6 @@
class GalleriesController < ApplicationController class GalleriesController < ApplicationController
def index def index
albums = Album.filter_by_categories albums = Album.filter_by_categories.asc(:order)
galleries = albums.collect do |a| galleries = albums.collect do |a|
{ {
"album-name" => a.name, "album-name" => a.name,

View File

@ -13,6 +13,7 @@ class Album
field :tag_names field :tag_names
field :uid, type: String field :uid, type: String
field :rss2_id, type: String field :rss2_id, type: String
field :order, type: Integer, default: 0
# has_and_belongs_to_many :tags, :class_name => "GalleryTag" # has_and_belongs_to_many :tags, :class_name => "GalleryTag"
has_many :album_images, :autosave => true, :dependent => :destroy has_many :album_images, :autosave => true, :dependent => :destroy

View File

@ -1,4 +1,4 @@
<li class="rgalbum"> <li class="rgalbum" data-image-id="<%= album.id %>">
<a href="<%= admin_gallery_path(album.id) %>"> <a href="<%= admin_gallery_path(album.id) %>">
<% if album.cover == "default" %> <% if album.cover == "default" %>
<%= image_tag "gallery/default.jpg" %> <%= image_tag "gallery/default.jpg" %>

View File

@ -1,8 +1,19 @@
<ul id="orbit_gallery" class="gallery" data-gallery-id="gallery"> <div class="order-edit-notification">Albums re-ordering enabled.</div>
<div class="rgbody">
<ul id="orbit_gallery" class="gallery clearfix" data-gallery-id="gallery">
<% @albums.each do |album| %> <% @albums.each do |album| %>
<%= render :partial => "album", :object => album %> <%= render :partial => "album", :object => album %>
<% end %> <% end %>
</ul> </ul>
</div>
<div class="bottomnav clearfix">
<div class="action pull-right">
<% if can_edit_or_delete?(nil) %>
<a href="#" class="btn btn-small btn-info" id="edit-order-btn">Edit Order</a>
<% end %>
</div>
</div>
<% content_for :page_specific_css do %> <% content_for :page_specific_css do %>
<%= stylesheet_link_tag "gallery" %> <%= stylesheet_link_tag "gallery" %>