diff --git a/vendor/built_in_modules/gallery/app/assets/javascripts/galleryAPI.js.erb b/vendor/built_in_modules/gallery/app/assets/javascripts/galleryAPI.js.erb index bc1221db..f7909d69 100644 --- a/vendor/built_in_modules/gallery/app/assets/javascripts/galleryAPI.js.erb +++ b/vendor/built_in_modules/gallery/app/assets/javascripts/galleryAPI.js.erb @@ -1,3 +1,4 @@ +<%# encoding: utf-8 %> $.extend($.expr[':'], { 'containsi': function (elem, i, match, array) { return (elem.textContent || elem.innerText || '').toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0; @@ -9,41 +10,9 @@ var galleryAPI = function(){ this.albumArea = $("#orbit_gallery"); this.loadArea = null; this.tagList = $("ul#gallery_tag_list"); - // this.authenticated = false; this.initialize = function(callbackFn){ $(document).ready(function(){ bindHandlers(); - var passid = null; - // if(typeof g.urlVars['cat']!= "undefined"){ - // g.loadArea = "albums"; - // passid = g.urlVars['cat']; - // g.loadAlbums(g.urlVars['cat']); - // }else if(typeof g.urlVars['album']!= "undefined"){ - // g.loadArea = "images"; - // passid = g.urlVars['album']; - // g.loadImages(g.urlVars['album']); - // }else if(typeof g.urlVars['theater']!= "undefined"){ - // g.loadArea = "theater"; - // passid = g.urlVars['theater']; - // g.loadTheater(g.urlVars['theater']); - // }else if(typeof g.urlVars['edit']!= "undefined"){ - // g.loadArea = "edit"; - // passid = g.urlVars['edit']; - // g.editAlbum(g.urlVars['edit']); - // }else if(typeof g.urlVars['tag']!= "undefined"){ - // g.loadArea = "albums"; - // passid = g.urlVars['tag']; - // g.loadAlbums(g.urlVars['tag']); - // }else if(g.urlVars["locale"]){ - // g.loadArea = "albums"; - // g.loadAlbums("all"); - // }else if(g.urlVars.length == 0) { - // g.loadArea = "albums"; - // g.loadAlbums("all"); - // } - // if(typeof callbackFn == "function"){ - // callbackFn.call(this,g.loadArea,passid); - // } }) var bindHandlers = function(){ $("#filter .filter_btns a").click(function(){ @@ -84,8 +53,8 @@ var galleryAPI = function(){ window.location = url; }) } - this.makeNewAlbum = function(){ - $.get("albums/new",function(html){ + this.makeNewAlbum = function(path){ + $.get(path,function(html){ rcom.modalWindow({loadHtml:html,width:400,height:320,"closeBtn":false},function(dom){ dom.find("#album_name_save_btn").click(function(){ var options ={ @@ -127,7 +96,7 @@ var galleryAPI = function(){ } this.loadAlbums = function(id){ - g.albumArea.find(".rghead .rgfn a").click(function(){g.makeNewAlbum()}); + g.albumArea.find(".rghead .rgfn a").click(function(){g.makeNewAlbum($(this).attr("href"))}); g.albumArea.addClass('o_gallery'); g.albumArea.find("#imgholder").empty(); if(id!="all"){ @@ -155,9 +124,9 @@ var galleryAPI = function(){ $.each(categories,function(x,category){ $.each(category,function(i,album){ if(album.cover == "default") - var $img = $("
"); + var $img = $(""); else - var $img = $(""); + var $img = $(""); var tag_string = ""; for(tag in album.tag_names){ @@ -167,7 +136,6 @@ var galleryAPI = function(){ g.albumArea.find("#imgholder").append($img); }) }) - // g.albumArea.find("#imgholder").append($addsign); }) } this.loadImages = function(id){ @@ -205,7 +173,7 @@ var galleryAPI = function(){ } }) g.albumArea.find("#tag_panel .bt-save").click(function(){ - g.saveTags(id,g.loadArea); + g.saveTags(id,"album"); }) g.albumArea.find(".rghead .rgfn .bt-add").click(function(){ showUploadPanel(); @@ -235,10 +203,10 @@ var galleryAPI = function(){ g.albumArea.find("#imgholder").empty(); $("#filter").remove(); g.albumArea.css("margin-top",""); - $.getJSON(id+"/get_images",function(album){ + $.getJSON(id+"/imgs",function(album){ $.each(album.images,function(i,image){ var thumb = image.file.thumb.url; - var $img = $(""); + var $img = $(""); g.albumArea.find("#imgholder").append($img); }) g.tagList.find("input").attr("checked",false); @@ -252,11 +220,8 @@ var galleryAPI = function(){ g.tagList.append($li); }) } - // g.albumArea.find("#imgholder").append($addsign); + }) - // g.albumArea.find("#imgholder").append($addsign); - // tag - } this.loadTheater = function(id){ var imageArray; @@ -329,7 +294,7 @@ var galleryAPI = function(){ } }) g.albumArea.find("#tag_panel .bt-save").click(function(){ - g.saveTags(imageArray[imagecount]._id,g.loadArea) + g.saveTags(imageArray[imagecount]._id,"pic") var tagids = new Array(); g.tagList.find("li input:checked").each(function(){ tagids.push($(this).parent().attr("data-content")); @@ -461,15 +426,15 @@ var galleryAPI = function(){ next = imagecount + 1; prev = imagecount - 1; } - $(".navN").attr({"href":"orbit_gallery?theater="+imageArray[next]._id,"data-content":imageArray[next].file.url}); - $(".navP").attr({"href":"orbit_gallery?theater="+imageArray[prev]._id,"data-content":imageArray[prev].file.url}); + $(".navN").attr({"href":imageArray[next]._id,"data-content":imageArray[next].file.url}); + $(".navP").attr({"href":imageArray[prev]._id,"data-content":imageArray[prev].file.url}); }; if(imageArray.length > 1) updateNavigation(); } var preparestage = function(albumid){ - $.getJSON("get_images",{aid:albumid},function(album){ + $.getJSON("../albums/"+albumid+"/imgs",function(album){ imageArray = eval(album.images); $.each(album.images,function(i,image){ if(image._id == id) @@ -478,36 +443,28 @@ var galleryAPI = function(){ bindHandlers(); }) } - g.albumArea.find("#imgholder").load("theater?pic="+id,function(theater,response,xhr){ - if(xhr.status == 404){ - $(this).text("<%= I18n.t('gallery.pic_not_found') %>."); - return false; - } - $("#filter").remove(); - g.albumArea.css("margin-top",""); - var albumid = $(theater).find("#main_pic").attr("data-content"); - g.albumArea.find(".bt-back").attr("href","album_images?album="+albumid); - g.albumArea.find(".bt-edit").attr("href","orbit_gallery?edit="+albumid); - - g.albumArea.css("margin-bottom","0"); - picHeight = $(window).height() - ($("#orbit-bar").outerHeight() + $("#orbit_gallery .form-actions").outerHeight()); - preparestage(albumid); - - }); + + + var albumid = $("#main_pic").attr("data-content"); + g.albumArea.find(".bt-back").attr("href","../albums/"+albumid); + g.albumArea.find(".bt-edit").attr("href","../albums/"+albumid+"/edit"); + g.albumArea.css("margin-bottom","0"); + picHeight = $(window).height() - ($("#orbit-bar").outerHeight() + $("#orbit_gallery .form-actions").outerHeight()); + preparestage(albumid); + } this.editAlbum = function(id){ var bindHandlers = function(){ $(".nav .nav-tabs a").click(function(){ $(".tab_content .tab-pane").hide(); - }) $(".description_loader .edit_fn .bt-cover").click(function(){ $(".bt-cover").removeClass("setcover active btn-primary"); - $(".bt-cover span").removeClass("icon-white icon-star").addClass("icon-star-empty") + $(".bt-cover span").removeClass("icon-white icon-star").addClass("icon-star-empty"); $(".bt-cover[for="+$(this).attr("for")+"]").addClass("setcover active btn-primary"); $(".bt-cover[for="+$(this).attr("for")+"]").find("span").removeClass("icon-star-empty").addClass("icon-white icon-star"); - $.post("set_cover",{"imageid":$(this).attr("for")},function(){}) + $.post("set_cover",{"imageid":$(this).attr("for")}); }) $(".description_loader .edit_fn .bt-dels").click(function(){ $(this) @@ -535,13 +492,23 @@ var galleryAPI = function(){ // }) }) + var current_element_for_tags = null; $('.bt-tag').click(function(){ + var has_class = false; + if($(this).hasClass("active")) + has_class = true; + + $('.bt-tag').removeClass("active"); $(this).toggleClass("active"); var count = 0; $('.bt-tag').each(function(){ if($(this).hasClass("active")) count++; }) + if(has_class){ + $(this).removeClass("active"); + count = 0; + } var $tag_panel = $('#tag_panel'), tag_panel_position = 0; if(count == 1) @@ -557,7 +524,17 @@ var galleryAPI = function(){ g.albumArea .delay(200) .animate({'margin-right':tag_panel_position+200},300); - + + current_element_for_tags = $(this).attr("href"); + if(count == 1){ + var no = $(this).parent().attr("no"); + if(imageTagArray[no].id == current_element_for_tags){ + g.tagList.find("input").attr("checked",false); + for(tag in imageTagArray[no].tags){ + g.tagList.find("li[data-content="+imageTagArray[no].tags[tag]+"] input").attr("checked",true); + } + } + } return false; }); g.albumArea.find("#tag_search_box").keyup(function(e){ @@ -578,7 +555,7 @@ var galleryAPI = function(){ } }) g.albumArea.find("#tag_panel .bt-save").click(function(){ - g.saveTags(imageArray[imagecount]._id,g.loadArea); + g.saveTags(current_element_for_tags,"pic"); }) var tempval; $(".txtchange").focus(function(){ @@ -615,17 +592,15 @@ var galleryAPI = function(){ g.albumArea.find(".rghead .rgfn .bt-delete").hide(); } }) - // $.post("delete",{"images":images_to_delete,"delete_cover":delete_cover,"aid":id},function(response){ - // if(response.success){ - - // } - // }) } }) } $("#filter").remove(); g.albumArea.addClass('o_album_edit'); - g.albumArea.css("margin-top",""); + var imageTagArray = null; + $.getJSON("images_tags",function(data){ + imageTagArray = eval(data); + }) bindHandlers(); } this.saveTags = function(id,tagsfor){ @@ -633,15 +608,7 @@ var galleryAPI = function(){ g.tagList.find("li input:checked").each(function(){ tagids.push($(this).parent().attr("data-content")); }) - var tag = null; - if(g.loadArea == "images") - tag = "album"; - else if(g.loadArea == "theater") - tag = "pic"; - - $.post("save_tags",{"id":id,"tag":tag,"tids":tagids},function(){ - - }) + $.post("../save_tags",{"id":id,"tag":tagsfor,"tids":tagids}) } } galleryAPI.prototype.locale = "en"; diff --git a/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/album_images_controller.rb b/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/album_images_controller.rb index e7086276..acf2c260 100644 --- a/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/album_images_controller.rb +++ b/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/album_images_controller.rb @@ -1,15 +1,21 @@ class Panel::Gallery::BackEnd::AlbumImagesController < OrbitBackendController include AdminHelper - def theater - picid = params["pic"] - @image = GalleryImage.find(picid) + def show + if is_manager? || is_admin? || is_sub_manager? + @authenticated = true #turn this value to false for view only + else + @authenticated = false + end + @tags = GalleryTag.all + @image = GalleryImage.find(params[:id]) @albumid = @image.gallery_album_id - album = GalleryAlbum.find(@albumid) - @images = album.gallery_images.all - render :layout=>false + @album = GalleryAlbum.find(@albumid) + @images = @album.gallery_images.all + end + def destroy images = params['images'] images.each do |image| @@ -57,15 +63,5 @@ class Panel::Gallery::BackEnd::AlbumImagesController < OrbitBackendController render :json =>{"success"=>true}.to_json end - def save_tags - case params[:tag] - when "album" - @object = GalleryAlbum.find(params[:id]) - when "pic" - @object = GalleryImage.find(params[:id]) - end - @object.update_attributes({:tag_ids => params[:tids]}) - render :json => {"success"=> "true"}.to_json - end end diff --git a/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/albums_controller.rb b/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/albums_controller.rb index d4f53d1c..41c5c186 100644 --- a/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/albums_controller.rb +++ b/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/albums_controller.rb @@ -18,7 +18,7 @@ include AdminHelper else @authenticated = false end - @categorylist = GalleryCategory.all + @album = GalleryAlbum.find(params[:id]) @tags = GalleryTag.all end @@ -43,7 +43,6 @@ include AdminHelper album.name = albumnames["zh_tw"] album.description = albumdescs["zh_tw"] album.save! - #x = category.gallery_albums.create({name: params['albumname'],description: params['albumdesc']}) render :json=>{"success"=>true,"id"=>album.id}.to_json end @@ -88,7 +87,7 @@ include AdminHelper tags << GalleryTag.find(tag)[I18n.locale] end category = GalleryCategory.find(values.gallery_category_id).name - @albs << {"_id"=>values.id,"cover"=>values.cover,"cover_path"=>values.cover_path,"description"=>values.description,"category_name"=>category,"gallery_category_id" => values.gallery_category_id,"name"=>values.name,"tag_ids"=>values.tag_ids,"tag_names"=>tags} + @albs << {"_id"=>values.id,"show_path"=>panel_gallery_back_end_album_path(values),"cover"=>values.cover,"cover_path"=>values.cover_path,"description"=>values.description,"category_name"=>category,"gallery_category_id" => values.gallery_category_id,"name"=>values.name,"tag_ids"=>values.tag_ids,"tag_names"=>tags} end @output << @albs end @@ -118,7 +117,7 @@ include AdminHelper render :json =>{"success"=>true}.to_json end - def get_images + def imgs @album = GalleryAlbum.find(params[:album_id]) @tag_names = Array.new @images = @album.gallery_images.all @@ -128,7 +127,7 @@ include AdminHelper values.tag_ids.each do |tag| tags << GalleryTag.find(tag)[I18n.locale] end - @output << {"_id"=>values.id,"description"=>values.description,"title"=>values.title,"file"=>values.file,"gallery_album_id"=>values.gallery_album_id,"tag_ids"=>values.tag_ids,"tag_names"=>tags} + @output << {"_id"=>values.id,"theater_link"=>panel_gallery_back_end_album_image_path(values),"description"=>values.description,"title"=>values.title,"file"=>values.file,"gallery_album_id"=>values.gallery_album_id,"tag_ids"=>values.tag_ids,"tag_names"=>tags} end if is_manager? || is_admin? || is_sub_manager? @authenticated = true #turn this value to false for view only @@ -160,6 +159,15 @@ include AdminHelper end render :json=>a.to_json end + def images_tags + album = GalleryAlbum.find(params[:album_id]) + tags = Array.new + images = album.gallery_images.all + images.each do |image| + tags << {"id"=>image.id, "tags" => image.tag_ids} + end + render :json=>tags.to_json + end end diff --git a/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/tags_controller.rb b/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/tags_controller.rb index 520c866a..907e2388 100644 --- a/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/tags_controller.rb +++ b/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/tags_controller.rb @@ -1,8 +1,18 @@ class Panel::Gallery::BackEnd::TagsController < Admin::TagsController - def initialize - super - @app_title = 'gallery' - end + def initialize + super + @app_title = 'gallery' + end + def save_tags + case params[:tag] + when "album" + @object = GalleryAlbum.find(params[:id]) + when "pic" + @object = GalleryImage.find(params[:id]) + end + @object.update_attributes({:tag_ids => params[:tids]}) + render :json => {"success"=> "true"}.to_json + end end diff --git a/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/album_images/show.html.erb b/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/album_images/show.html.erb index 26c844e2..398aee35 100644 --- a/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/album_images/show.html.erb +++ b/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/album_images/show.html.erb @@ -4,7 +4,30 @@