fixed gallery frontend for category display

This commit is contained in:
Harry Bomrah 2013-11-07 03:06:43 +08:00 committed by saurabhbhatia
parent 49217d4705
commit 8c532e7241
4 changed files with 10 additions and 66 deletions

View File

@ -41,32 +41,11 @@ var galleryAPI = function(){
} }
this.loadAlbums = function(id){ this.loadAlbums = function(cids){
g.albumArea.find(".rghead .rgfn a").click(function(){g.makeNewAlbum($(this).attr("href"))}); g.albumArea.find(".rghead .rgfn a").click(function(){g.makeNewAlbum($(this).attr("href"))});
g.albumArea.addClass('o_gallery'); g.albumArea.addClass('o_gallery');
g.albumArea.find("#imgholder").empty(); g.albumArea.find("#imgholder").empty();
if(id!="all"){ $.getJSON("/panel/gallery/front_end/get_albums",{"cid":cids,"inner":true},function(categories){
var cids = [];
var tids = [];
var href = null;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++){
hash = hashes[i].split('=');
if(hash[0]=="cat"){
cids.push(hash[1]);
href = "cat="+hash[1];
}else if(hash[0]=="tag"){
tids.push(hash[1]);
href = "tag="+hash[1];
}
$("#filter .filter_btns a[href='"+href+"']").addClass("active");
}
if(cids.length == 0)
cids = "all";
}else{
var cids = "all";
}
$.getJSON("/panel/gallery/front_end/get_albums",{"cid":cids,"tid":tids,"inner":true},function(categories){
$.each(categories,function(x,category){ $.each(categories,function(x,category){
$.each(category,function(i,album){ $.each(category,function(i,album){
album.description = (album.description?album.description:"<%= I18n.t('gallery.no_description') %>") album.description = (album.description?album.description:"<%= I18n.t('gallery.no_description') %>")

View File

@ -1,5 +1,6 @@
class Panel::Gallery::FrontEnd::AlbumsController < OrbitWidgetController class Panel::Gallery::FrontEnd::AlbumsController < OrbitWidgetController
def index def index
@categories = params[:category_id]
end end
def show def show
@ -9,36 +10,10 @@ class Panel::Gallery::FrontEnd::AlbumsController < OrbitWidgetController
def get_albums def get_albums
@categoryids = params["cid"] @categoryids = params["cid"]
@tags = params["tid"]
@albums = Array.new @albums = Array.new
if @categoryids == "all" @albums << GalleryAlbum.where(:category_id.in => @categoryids)
if @tags
if @tags.kind_of?(Array)
@tags.each do |tag|
@albums << GalleryAlbum.where(tagged_ids: tag)
end
else
@albums << GalleryAlbum.where(tagged_ids: @tags)
end
else
@albums << GalleryAlbum.all
end
else
@categoryids.each do |id|
category = Category.find(id)
if @tags
if @tags.kind_of?(Array)
@tags.each do |tag|
@albums << category.gallery_albums.where(tagged_ids: tag)
end
else
@albums << category.gallery_albums.where(tagged_ids: @tags)
end
else
@albums << category.gallery_albums.all
end
end
end
@output = Array.new @output = Array.new
@albums.each do |album| @albums.each do |album|
@albs = Array.new @albs = Array.new

View File

@ -27,16 +27,9 @@
<script type="text/javascript"> <script type="text/javascript">
galleryAPI.prototype.locale = "<%= I18n.locale %>"; galleryAPI.prototype.locale = "<%= I18n.locale %>";
var gallery = new galleryAPI(); var gallery = new galleryAPI();
var categories = <%= @categories.to_json.html_safe %>;
gallery.initialize(); gallery.initialize();
if(typeof gallery.urlVars['cat']!= "undefined"){ gallery.loadArea = "albums";
gallery.loadArea = "albums"; gallery.loadAlbums(categories);
gallery.loadAlbums(gallery.urlVars['cat']);
}else if(typeof gallery.urlVars['tag']!= "undefined"){
gallery.loadArea = "albums";
gallery.loadAlbums(gallery.urlVars['tag']);
}else{
gallery.loadArea = "albums";
gallery.loadAlbums("all");
}
</script> </script>

View File

@ -18,10 +18,7 @@
</ul> </ul>
</div> </div>
<!-- tag end --> <!-- tag end -->
<div class="form-actions form-fixed pagination-right rghead"> <!-- -->
<div class="rgfn">
<a class="bt-back rgbt" title="<%= I18n.t("gallery.back_to_albums") %>" href="<%= panel_gallery_front_end_albums_path %>"><i class="icon-arrow-left"></i> <%= I18n.t("gallery.back_to_albums") %></a>
</div>
</div> </div>
</div> </div>