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 2d96ad4e..7b801874 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,31 +1,46 @@ <%# encoding: utf-8 %> +$.extend($.expr[':'], { + 'containsi': function (elem, i, match, array) { + return (elem.textContent || elem.innerText || '').toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0; + } +}); var galleryAPI = function(){ g = this; this.urlVars = rcom.getUrlVars(); this.albumArea = $("#orbit_gallery"); - this.loadArea = ""; + this.loadArea = null; + this.tagList = $("ul#gallery_tag_list"); // this.authenticated = false; - this.initialize = function(){ + 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']); - g.loadArea = "albums"; }else if(typeof g.urlVars['album']!= "undefined"){ - g.loadImages(g.urlVars['album']); g.loadArea = "images"; + passid = g.urlVars['album']; + g.loadImages(g.urlVars['album']); }else if(typeof g.urlVars['theater']!= "undefined"){ - g.loadTheater(g.urlVars['theater']); g.loadArea = "theater"; + passid = g.urlVars['theater']; + g.loadTheater(g.urlVars['theater']); }else if(typeof g.urlVars['edit']!= "undefined"){ - g.editAlbum(g.urlVars['edit']); 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.length == 0){ g.loadArea = "albums"; - }else{ g.loadAlbums("all"); - g.loadArea = "albums"; + } + if(typeof callbackFn == "function"){ + callbackFn.call(this,g.loadArea,passid); } }) var bindHandlers = function(){ @@ -48,6 +63,7 @@ var galleryAPI = function(){ window.location = url; } }) + } $("#filter .filter-clear a").click(function(){ var loc = window.location.href; @@ -105,12 +121,15 @@ var galleryAPI = function(){ } this.loadAlbums = function(id){ - var headbtn = $('" href="albums" onclick="return false;"><%= I18n.t("gallery.add_album") %>'); - headbtn.click(function(){g.makeNewAlbum();}) - g.albumArea.find(".rghead .rgfn").html(headbtn); + g.loadFooterPanel(g.loadArea,id,function(headbtn){ + headbtn = $(headbtn); + headbtn.click(function(){g.makeNewAlbum();}) + g.albumArea.find(".rghead .rgfn").html(headbtn); + }) + g.albumArea.find("#imgholder").empty(); - var $addsign = $('
'); - $addsign.find("a").click(function(){g.makeNewAlbum();}) + // var $addsign = $(''); + // $addsign.find("a").click(function(){g.makeNewAlbum();}) if(id!="all"){ var cids = []; @@ -137,16 +156,29 @@ 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){ + tag_string+=album.tag_names[tag] + " "; + } + $img.find("span.tagnames").text(tag_string); g.albumArea.find("#imgholder").append($img); }) }) - g.albumArea.find("#imgholder").append($addsign); + // g.albumArea.find("#imgholder").append($addsign); }) } this.loadImages = function(id){ + var panelopen = false; + g.loadFooterPanel(g.loadArea,id,function(headerPanel){ + headarea = $(headerPanel); + g.albumArea.find(".rghead .rgfn").html(headarea); + $('.bt-tag').click(function(){ + $(this).toggleClass("active"); + var $tag_panel = $('#tag_panel'), + tag_panel_position = 0; var headarea = '" href="orbit_gallery"><%= I18n.t("gallery.back_to_albums") %> '; headarea+='" href="images" onclick="return false;"><%= I18n.t("gallery.add_images") %> '; @@ -156,20 +188,12 @@ var galleryAPI = function(){ headarea = $(headarea); var uploadpanel = $(''); var frame = $(''); - g.albumArea.find(".rghead .rgfn").html(headarea); - g.albumArea.find(".rghead .rgfn a.bt-add").click(function(){ - showUploadPanel(); - }) - g.albumArea.find(".rghead .rgfn a.bt-del").click(function(){ - g.deleteAlbum(id); - }) uploadpanel.find("a.bt-cls").click(function(){ uploadpanel.hide("slide"); frame.remove(); g.loadImages(id); panelopen = false; }) - var panelopen = false; var showUploadPanel = function(){ if(!panelopen){ uploadpanel.prepend(frame); @@ -182,36 +206,24 @@ var galleryAPI = function(){ g.albumArea.find("#imgholder").empty(); $("#filter").remove(); g.albumArea.css("margin-top",""); - var $addsign = $(''); - $addsign.find("a").click(function(){showUploadPanel();}) - $.getJSON("get_images",{aid:id},function(images){ - $.each(images,function(i,image){ + // var $addsign = $(''); + // $addsign.find("a").click(function(){showUploadPanel();}) + $.getJSON("get_images",{aid:id},function(album){ + $.each(album.images,function(i,image){ var thumb = image.file.thumb.url; var $img = $(""); g.albumArea.find("#imgholder").append($img); }) - g.albumArea.find("#imgholder").append($addsign); + g.tagList.find("input").attr("checked",false); + $.each(album.tags,function(i,tag){ + + g.tagList.find("li[data-content="+tag+"] input").attr("checked",true); + }) + // g.albumArea.find("#imgholder").append($addsign); }) - g.albumArea.find("#imgholder").append($addsign); - - + // g.albumArea.find("#imgholder").append($addsign); // tag - $('.bt-tag').click(function(){ - var $tag_panel = $('#tag_panel'), - tag_panel_position = 0; - - if( $tag_panel.css('right') == '0px' ){ - tag_panel_position = -200; - } - $tag_panel.animate({'right':tag_panel_position}, 300); - - g.albumArea - .delay(200) - .animate({'margin-right':tag_panel_position+200},300); - return false; - }); - - + } this.loadTheater = function(id){ var imageArray; @@ -226,7 +238,52 @@ var galleryAPI = function(){ $("#main_pic").height(picHeight); $img.height("100%"); + + $('.bt-tag').click(function(){ + if(!$(this).hasClass("active")) + updatePhotoTag(); + $(this).toggleClass("active"); + var $tag_panel = $('#tag_panel'), + tag_panel_position = 0; + if( $tag_panel.css('right') == '0px' ){ + tag_panel_position = -200; + } + $tag_panel.animate({'right':tag_panel_position}, 300); + + g.albumArea + .delay(200) + .animate({'margin-right':tag_panel_position+200},300); + return false; + }); + var updatePhotoTag = function(){ + var tags = imageArray[imagecount].tag_ids; + g.tagList.find("input").attr("checked",false); + for(tag in tags){ + g.tagList.find("li[data-content="+tags[tag]+"] input").attr("checked",true); + } + } + g.albumArea.find("#tag_search_box").keyup(function(e){ + sval = $(this).val(); + if(sval == "<%= I18n.t('gallery.search_tags') %>") + sval = ""; + sval = sval.replace(/(^\s*)|(\s*$)/g,''); + if(sval){ + var re1 = new RegExp("^[\u4E00-\uFA29]*$"); //Chinese character range + var re2 = new RegExp("^[\uE7C7-\uE7F3]*$"); + if ((re1.test(sval) && (re2.test(sval)))){ + $("ul#gallery_tag_list li span:not(:contains("+sval+"))").parent().slideUp(); + }else{ + $("ul#gallery_tag_list li span:not(:containsi("+sval+"))").parent().slideUp(); + } + + }else{ + $("ul#gallery_tag_list li").slideDown(); + } + }) + g.albumArea.find("#tag_panel button.bt-save").click(function(){ + g.saveTags(imageArray[imagecount]._id,g.loadArea); + }) $(".slidectrl a.togglelist").click(function(){ var rslide_h = $rslide.outerHeight(); if ( $slidelist.height() < 1 ){ @@ -324,10 +381,13 @@ var galleryAPI = function(){ window.history.pushState({path:pageurl},'',pageurl); } // $(".slideinfo b.info").text(imageArray[imagecount].title); + if($('.bt-tag').hasClass("active")) + updatePhotoTag(); $(".slideinfo span.info").text(imageArray[imagecount].description); if(imageArray.length > 1) updateNavigation(); }) + } var updateNavigation = function(){ var next, prev; @@ -349,19 +409,15 @@ var galleryAPI = function(){ } var preparestage = function(albumid){ - $.getJSON("get_images",{aid:albumid},function(images){ - imageArray = eval(images); - $.each(images,function(i,image){ + $.getJSON("get_images",{aid:albumid},function(album){ + imageArray = eval(album.images); + $.each(album.images,function(i,image){ if(image._id == id) imagecount = i; }) bindHandlers(); }) } - - var head = $('"><%= I18n.t("gallery.back_to_photos") %>'); - var head1 = $('" href="" ><%= I18n.t("gallery.edit") %>'); - var head2 = $('" href="" ><%= I18n.t("gallery.photo_tag") %>'); g.albumArea.find("#imgholder").load("theater?pic="+id,function(theater,response,xhr){ if(xhr.status == 404){ $(this).text("<%= I18n.t('gallery.pic_not_found') %>."); @@ -370,16 +426,55 @@ var galleryAPI = function(){ $("#filter").remove(); g.albumArea.css("margin-top",""); var albumid = $(theater).find("#main_pic").attr("data-content"); - head.attr("href","orbit_gallery?album="+albumid); - head1.attr("href","orbit_gallery?edit="+albumid); - g.albumArea.find(".rghead .rgfn").html(head); - g.albumArea.find(".rghead .rgfn").append(head1,head2); - picHeight = $(window).height() - ($("#orbit-bar").outerHeight() + $("#orbit_gallery .rghead").outerHeight()); + g.loadFooterPanel(g.loadArea,id,function(head){ + head = $(head); + g.albumArea.find(".rghead .rgfn").html(head); + g.albumArea.find("a.bt-back").attr("href","orbit_gallery?album="+albumid); + g.albumArea.find("a.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); + + }); + } + this.editAlbum = function(id){ + var bindHandlers = function(){ + $(".nav .nav-tabs a").click(function(){ + $(".tab_content .tab-pane").hide(); - // tag + }) + $(".description_loader .edit_fn .bt-cover").click(function(){ + $(".bt-cover").removeClass("setcover"); + $(this).addClass("setcover"); + $.post("set_cover",{"imageid":$(this).attr("href"),"aid":id},function(){}) + }) + $(".description_loader .edit_fn .bt-dels").click(function(){ + $(this).toggleClass("setdelete"); + if($(".description_loader .edit_fn .setdelete").length > 0){ + g.albumArea.find(".rghead .rgfn .bt-delete").show(); + }else{ + g.albumArea.find(".rghead .rgfn .bt-delete").hide(); + } + }) + g.albumArea.find(".rghead .rgfn .bt-save").click(function(){ + // var dataArray = Array(); + // $(".description_loader .txtchange").each(function(){ + // dataArray.push({"id":$(this).attr("for"),"text": $(this).val()}); + // }) + // var albumnm = Array(); + // $(".albumname_edit .txtchange").each(function(){ + // albumnm.push($(this).val()) + // }) + var dataArray = $("form#edit_album").serialize(); + $.post("update_album",{"aid":id,"data":dataArray},function(){ + + }) + }) $('.bt-tag').click(function(){ + + $(this).toggleClass("active"); var $tag_panel = $('#tag_panel'), tag_panel_position = 0; @@ -393,33 +488,26 @@ var galleryAPI = function(){ .animate({'margin-right':tag_panel_position+200},300); return false; }); - }); - } - - this.editAlbum = function(id){ - var bindHandlers = function(){ - $("#description_loader .edit_fn .bt-cover").click(function(){ - $(".bt-cover").removeClass("setcover"); - $(this).addClass("setcover"); - $.post("set_cover",{"imageid":$(this).attr("href"),"aid":id},function(){}) - }) - $("#description_loader .edit_fn .bt-dels").click(function(){ - $(this).toggleClass("setdelete"); - if($("#description_loader .edit_fn .setdelete").length > 0){ - g.albumArea.find(".rghead .rgfn .bt-delete").show(); + g.albumArea.find("#tag_search_box").keyup(function(e){ + sval = $(this).val(); + if(sval == "<%= I18n.t('gallery.search_tags') %>") + sval = ""; + sval = sval.replace(/(^\s*)|(\s*$)/g,''); + if(sval){ + var re1 = new RegExp("^[\u4E00-\uFA29]*$"); //Chinese character range + var re2 = new RegExp("^[\uE7C7-\uE7F3]*$"); + if ((re1.test(sval) && (re2.test(sval)))){ + $("ul#gallery_tag_list li span:not(:contains("+sval+"))").parent().slideUp(); + }else{ + $("ul#gallery_tag_list li span:not(:containsi("+sval+"))").parent().slideUp(); + } + }else{ - g.albumArea.find(".rghead .rgfn .bt-delete").hide(); + $("ul#gallery_tag_list li").slideDown(); } }) - g.albumArea.find(".rghead .rgfn .bt-save").click(function(){ - var dataArray = Array(); - $("#description_loader .txtchange").each(function(){ - dataArray.push({"id":$(this).attr("for"),"text": $(this).val()}); - }) - albumnm = $(".albumname_edit #album_name_text").val(); - $.post("update_album",{data:dataArray,"aid":id,"name":albumnm},function(){ - - }) + g.albumArea.find("#tag_panel button.bt-save").click(function(){ + g.saveTags(imageArray[imagecount]._id,g.loadArea); }) var tempval; $(".txtchange").focus(function(){ @@ -432,8 +520,8 @@ var galleryAPI = function(){ var images_to_delete = new Array(); var delete_cover = false; var doms_to_delete = new Array(); - var thiscover = $("#description_loader .edit_fn .setcover").attr("href"); - $("#description_loader .edit_fn .bt-dels").each(function(){ + var thiscover = $(".description_loader .edit_fn .setcover").attr("href"); + $(".description_loader .edit_fn .bt-dels").each(function(){ if($(this).hasClass("setdelete")){ images_to_delete.push($(this).attr("href")); doms_to_delete.push($(this).parent().parent()); @@ -467,5 +555,20 @@ var galleryAPI = function(){ bindHandlers(); }) } -} + this.saveTags = function(id,tagsfor){ + var tagids = new Array(); + 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(){ + + }) + } +} +galleryAPI.prototype.locale = "en"; diff --git a/vendor/built_in_modules/gallery/app/assets/stylesheets/gallery.css b/vendor/built_in_modules/gallery/app/assets/stylesheets/gallery.css index 3f497110..3a54dc3f 100755 --- a/vendor/built_in_modules/gallery/app/assets/stylesheets/gallery.css +++ b/vendor/built_in_modules/gallery/app/assets/stylesheets/gallery.css @@ -549,6 +549,12 @@ body.fullscreen, .fullscreen #container, .fullscreen #container2, .fullscreen #m margin-left: 8px; margin-right: 8px; } +.tab_content .tab-pane{ + display: none; +} +.tab_content .active{ + display: block; +} #orbit_gallery .btn { margin: 0; } #orbit_gallery .rgfn .btn { margin-left: 8px; diff --git a/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/orbit_galleries_controller.rb b/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/orbit_galleries_controller.rb index 3a2a17f0..cb78c5f6 100644 --- a/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/orbit_galleries_controller.rb +++ b/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/orbit_galleries_controller.rb @@ -2,7 +2,7 @@ class Panel::Gallery::BackEnd::OrbitGalleriesController < OrbitBackendController include AdminHelper def index if is_manager? || is_admin? || is_sub_manager? - @authenticated = true + @authenticated = true #turn this value to false for view only else @authenticated = false end @@ -90,8 +90,20 @@ include AdminHelper end end end - - + i = 0 + @albums.each do |album| + album.each do |values| + # if values.tag_ids.kind_of?(Array) + tags = Array.new + values.tag_ids.each do |tag| + tags << GalleryTag.find(tag)[I18n.locale] + end + # end + values.tag_names = tags + values.save + end + i = i + 1 + end # @albums = GalleryAlbum.find("5017a7babd98eb049900000a") # @albums.update_attributes({:tag_ids =>["501ba786bd98eb0232000126"]}) @@ -118,8 +130,7 @@ include AdminHelper def get_images @album = GalleryAlbum.find(params["aid"]) - @images = @album.gallery_images.all - render :json=>@images.to_json + render :json=>{"images" => @album.gallery_images.all, "tags" => @album.tag_ids}.to_json end def theater @@ -143,7 +154,7 @@ include AdminHelper aid = params['aid'] album = GalleryAlbum.find(aid) @images = album.gallery_images.all - @album_name = album.name + @album_name = album.name_translations @cover = album.cover render :layout => false end @@ -171,16 +182,30 @@ include AdminHelper end def update_album + # data = params['data'] + # album_name = params['name'] + # aid = params['aid'] + # data.each do |d| + # image = GalleryImage.find(d[1][:id]) + # image.update_attributes(:description=>d[1][:text]) + # end + # album = GalleryAlbum.find(aid) + # album.update_attributes(:name => album_name) data = params['data'] - album_name = params['name'] - aid = params['aid'] - data.each do |d| - image = GalleryImage.find(d[1][:id]) - image.update_attributes(:description=>d[1][:text]) + debugger + + 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 - album = GalleryAlbum.find(aid) - album.update_attributes(:name => album_name) - render :json =>{"success"=>true}.to_json + @object.update_attributes({:tag_ids => params[:tids]}) + render :json => {"success"=> "true"}.to_json end end diff --git a/vendor/built_in_modules/gallery/app/models/gallery_album.rb b/vendor/built_in_modules/gallery/app/models/gallery_album.rb index f76f98af..b16e3289 100644 --- a/vendor/built_in_modules/gallery/app/models/gallery_album.rb +++ b/vendor/built_in_modules/gallery/app/models/gallery_album.rb @@ -6,6 +6,7 @@ class GalleryAlbum field :description, localize: true field :cover, default: "default" field :cover_path + field :tag_names belongs_to :gallery_category has_and_belongs_to_many :tags, :class_name => "GalleryTag" diff --git a/vendor/built_in_modules/gallery/app/models/gallery_image.rb b/vendor/built_in_modules/gallery/app/models/gallery_image.rb index e3dc5de1..8b958ddd 100644 --- a/vendor/built_in_modules/gallery/app/models/gallery_image.rb +++ b/vendor/built_in_modules/gallery/app/models/gallery_image.rb @@ -5,7 +5,7 @@ class GalleryImage mount_uploader :file, GalleryUploader field :title - field :description + field :description, localize: true has_and_belongs_to_many :tags, :class_name => "GalleryTag" diff --git a/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/orbit_galleries/categorylist.html.erb b/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/orbit_galleries/categorylist.html.erb index 1103206b..33f19760 100644 --- a/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/orbit_galleries/categorylist.html.erb +++ b/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/orbit_galleries/categorylist.html.erb @@ -2,9 +2,9 @@ <% @categorylist.each do |category| %>