From 1e4d534908fe60f2daa547c3feda46849ba37190 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 23 Aug 2012 01:36:39 +0800 Subject: [PATCH] frontend updates --- .../app/assets/javascripts/galleryAPI.js.erb | 23 +- .../javascripts/galleryAPI_frontend.js.erb | 617 ++++++++++++++++++ .../back_end/orbit_galleries_controller.rb | 22 +- .../front_end/orbit_galleries_controller.rb | 228 +++++++ .../orbit_galleries/edit_album.html.erb | 2 +- .../orbit_galleries/add_album.html.erb | 34 + .../orbit_galleries/categorylist.html.erb | 89 +++ .../orbit_galleries/edit_album.html.erb | 74 +++ .../front_end/orbit_galleries/index.html.erb | 166 +++++ .../orbit_galleries/theater.html.erb | 34 + .../orbit_galleries/upload_panel.html.erb | 108 +++ .../built_in_modules/gallery/config/routes.rb | 4 + 12 files changed, 1380 insertions(+), 21 deletions(-) create mode 100644 vendor/built_in_modules/gallery/app/assets/javascripts/galleryAPI_frontend.js.erb create mode 100644 vendor/built_in_modules/gallery/app/controllers/panel/gallery/front_end/orbit_galleries_controller.rb create mode 100644 vendor/built_in_modules/gallery/app/views/panel/gallery/front_end/orbit_galleries/add_album.html.erb create mode 100644 vendor/built_in_modules/gallery/app/views/panel/gallery/front_end/orbit_galleries/categorylist.html.erb create mode 100644 vendor/built_in_modules/gallery/app/views/panel/gallery/front_end/orbit_galleries/edit_album.html.erb create mode 100644 vendor/built_in_modules/gallery/app/views/panel/gallery/front_end/orbit_galleries/index.html.erb create mode 100755 vendor/built_in_modules/gallery/app/views/panel/gallery/front_end/orbit_galleries/theater.html.erb create mode 100755 vendor/built_in_modules/gallery/app/views/panel/gallery/front_end/orbit_galleries/upload_panel.html.erb 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 856140590..ebd9ae5f0 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,4 +1,7 @@ <%# encoding: utf-8 %> +// refresh the imagesArray +// viewonly tags + $.extend($.expr[':'], { 'containsi': function (elem, i, match, array) { return (elem.textContent || elem.innerText || '').toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0; @@ -160,9 +163,9 @@ var galleryAPI = function(){ $.each(categories,function(x,category){ $.each(category,function(i,album){ if(album.cover == "default") - var $img = $("
"+album.name+"
"); + var $img = $("
"+album.name+""+album.category_name+"
"); else - var $img = $("
"+album.name+"
"); + var $img = $("
"+album.name+""+album.category_name+"
"); var tag_string = ""; for(tag in album.tag_names){ tag_string+= '' + album.tag_names[tag] + ''; @@ -514,20 +517,26 @@ var galleryAPI = function(){ // }) }) + var tag_panel_hidden = true; + var last_clicked = null; $('.bt-tag').click(function(){ - $(this).toggleClass("active"); + var $tag_panel = $('#tag_panel'), tag_panel_position = 0; - - if( $tag_panel.css('right') == '0px' ){ - tag_panel_position = -200; - } + if( $tag_panel.css('right') == '0px' ){ + tag_panel_position = -200; + } + if(last_clicked == $(this)) + alert("same") + else + alert("no") $tag_panel.animate({'right':tag_panel_position}, 300); g.albumArea .delay(200) .animate({'margin-right':tag_panel_position+200},300); + return false; }); g.albumArea.find("#tag_search_box").keyup(function(e){ diff --git a/vendor/built_in_modules/gallery/app/assets/javascripts/galleryAPI_frontend.js.erb b/vendor/built_in_modules/gallery/app/assets/javascripts/galleryAPI_frontend.js.erb new file mode 100644 index 000000000..4f7a068a2 --- /dev/null +++ b/vendor/built_in_modules/gallery/app/assets/javascripts/galleryAPI_frontend.js.erb @@ -0,0 +1,617 @@ +<%# 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 = 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(){ + if(!$(this).hasClass("active")){ + $(this).addClass("active"); + if(g.urlVars.length == 0) + window.location = "orbit_gallery?" + $(this).attr("href"); + else + window.location = window.location.href +"&"+ $(this).attr("href"); + }else{ + $(this).removeClass("active"); + var loc = window.location.href; + var url = loc.replace($(this).attr("href")+"&",""); + if(url == loc) + url = loc.replace($(this).attr("href"),""); + + if(url.charAt(url.length-1)=="&" || url.charAt(url.length-1)=="?") + url = url.substr(0,url.length-1); + window.location = url; + } + }) + + } + $("#filter .filter-clear a").click(function(){ + var loc = window.location.href; + var url = null; + var forwhat = $(this).attr("for"); + $("#filter ."+forwhat+" a.active").each(function(){ + $(this).removeClass("active"); + url = loc.replace($(this).attr("href")+"&",""); + if(url == loc) + url = loc.replace($(this).attr("href"),""); + + if(url.charAt(url.length-1)=="&" || url.charAt(url.length-1)=="?") + url = url.substr(0,url.length-1); + loc = url; + }) + window.location = url; + }) + } + this.makeNewAlbum = function(){ + $.get("add_album",function(html){ + rcom.modalWindow({loadHtml:html,width:400,height:320,"closeBtn":false},function(dom){ + dom.find("#album_name_save_btn").click(function(){ + var options ={ + cid : dom.find("select#category_list").val(), + albumname : { + "en" : dom.find("#name_en").val(), + "zh_tw" : dom.find("#name_zh_tw").val() + }, + albumdesc : { + "en" : dom.find("#desc_en").val(), + "zh_tw" : dom.find("#desc_zh_tw").val() + } + } + if(options.cid){ + $.post("create_album",options,function(response){ + if(g.loadArea == "albums") + g.loadAlbums("all"); + rcom.modalWindowClose(); + }) + } + }) + dom.find("#album_name_close_btn").click(function(){ + rcom.modalWindowClose(); + }) + }) + + }) + } + this.deleteAlbum = function(id){ + if(confirm("<%= I18n.t('gallery.del_album?') %>")){ + $.post("delete_album",{aid:id},function(){ + window.location = "orbit_gallery"; + }) + } + } + + this.loadAlbums = function(id){ + g.loadFooterPanel(g.loadArea,id,function(headbtn){ + headbtn = $(headbtn); + headbtn.click(function(){g.makeNewAlbum();}) + g.albumArea.find(".rghead .rgfn").html(headbtn); + }) + + g.albumArea.addClass('o_gallery'); + g.albumArea.find("#imgholder").empty(); + // var $addsign = $('
Add Album
'); + // $addsign.find("a").click(function(){g.makeNewAlbum();}) + + if(id!="all"){ + 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(category,function(i,album){ + if(album.cover == "default") + var $img = $("
"+album.name+""+album.category_name+"
"); + else + var $img = $("
"+album.name+""+album.category_name+"
"); + var tag_string = ""; + for(tag in album.tag_names){ + tag_string+= '' + album.tag_names[tag] + ''; + } + $img.find(".tagnames").html(tag_string); + g.albumArea.find("#imgholder").append($img); + }) + }) + // 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; + + 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; + }); + 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)))){ + $("#gallery_tag_list li span:not(:contains("+sval+"))").parent().slideUp(); + }else{ + $("#gallery_tag_list li span:not(:containsi("+sval+"))").parent().slideUp(); + } + }else{ + $("#gallery_tag_list li").slideDown(); + } + }) + g.albumArea.find("#tag_panel .bt-save").click(function(){ + g.saveTags(id,g.loadArea); + }) + g.albumArea.find(".rghead .rgfn .bt-add").click(function(){ + showUploadPanel(); + }) + g.albumArea.find(".rghead .rgfn .bt-del").click(function(){ + g.deleteAlbum(id); + }) + }) + var uploadpanel = $('
'); + var frame = $(''); + uploadpanel.find(".bt-cls").click(function(){ + uploadpanel.hide("slide"); + frame.remove(); + g.loadImages(id); + panelopen = false; + }) + var showUploadPanel = function(){ + if(!panelopen){ + uploadpanel.prepend(frame); + uploadpanel.show("slide"); + panelopen = true; + } + } + + g.albumArea.addClass('o_album'); + g.albumArea.find(".rghead .rgfn").append(uploadpanel); + g.albumArea.find("#imgholder").empty(); + $("#filter").remove(); + g.albumArea.css("margin-top",""); + // var $addsign = $('
Add Album
'); + // $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.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); + // tag + + } + this.loadTheater = function(id){ + var imageArray; + var imagecount = 0; + var picHeight = 0; + var bindHandlers = function(){ + var $slidelist = $('.slidelist'), + $rslide = $('.rslide'), + $rslidenav = $('.rslidenav'), + $img = $("#main_pic img"), + wHeight = $(window).height(); + + $("#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)))){ + $("#gallery_tag_list li span:not(:contains("+sval+"))").parent().slideUp(); + }else{ + $("#gallery_tag_list li span:not(:containsi("+sval+"))").parent().slideUp(); + } + + }else{ + $("#gallery_tag_list li").slideDown(); + } + }) + g.albumArea.find("#tag_panel .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 ){ + $slidelist.stop().animate({'height':rslide_h - 30}, 300); + $slidelist.find("ul").show(); + } else { + $slidelist.stop().animate({'height':'0px'}, 300); + $slidelist.find("ul").hide(); + } + }) + $(".slidectrl .togglescreen").click(function(){ + toggleFullscreen(); + }) + $(".slidectrl .browserfullscreen").click(function(){ + browserFullScreen(); + }) + $slidelist.find(".list_element").click(function(){ + imagecount = parseInt($(this).parent().attr("for")); + changeImage($(this)); + }) + $rslidenav.find(".navN").click(function(){ + nextpic($(this)); + }) + $rslidenav.find("a.navP").click(function(){ + prevpic($(this)); + }) + $("#nextpic").click(function(){ + nextpic($(this)); + }) + + $(document).keydown(function(e){ + if (e.keyCode == 37){ + prevpic($rslidenav.find(".navP")); + return false; + } + if(e.keyCode == 39){ + nextpic($rslidenav.find(".navN")); + return false; + } + if(e.keyCode == 27){ + toggleFullscreen(); + $rslide.removeClass('browserFullScreen'); + return false; + } + if(e.keyCode == 70 || e.keyCode == 102){ + if($rslide.hasClass("fullscreen")) + browserFullScreen(); + } + }); + var browserFullScreen = function(){ + var el = document.documentElement, + rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen; + rfs.call(el); + $rslide.addClass('browserFullScreen'); + } + var nextpic = function(dom){ + if(imagecount == imageArray.length - 1) + imagecount = 0; + else + imagecount++; + changeImage(dom); + } + var prevpic = function(dom){ + if(imagecount == 0) + imagecount = imageArray.length - 1 + else + imagecount--; + changeImage(dom); + } + var toggleFullscreen = function(){ + if($rslide.hasClass("fullscreen")){ + $rslide.css("position","relative"); + $rslide.removeClass("fullscreen"); + $(".slidectrl .browserfullscreen").hide(); + $img.css({"padding":""}) + $("#main_pic").height(picHeight ); + }else{ + $("#main_pic").height(wHeight); + // $img.height("100%"); + $rslide.css("position",""); + $rslide.addClass("fullscreen"); + $img.css({"padding":($rslide.height()-$img.height())/2}) + $(".slidectrl .browserfullscreen").show(); + } + } + var changeImage = function(dom){ + var pageurl = dom.attr('href'); + $img.fadeOut(200,function(){ + $img.attr({"src":dom.attr("data-content"),"height":picHeight+"px"}); + $img.fadeIn(200); + if($rslide.hasClass("fullscreen")){ + $img.css({"padding":($rslide.height()-$img.height())/2}) + } + $slidelist.stop().animate({'height':'0px'}, 300); + $slidelist.find("ul").hide(); + if(pageurl!=window.location){ + window.history.pushState({path:pageurl},'',pageurl); + } + // $(".slideinfo b.info").text(imageArray[imagecount].title); + if($('.bt-tag').hasClass("active")) + updatePhotoTag(); + $(".slideinfo .info").text(imageArray[imagecount].description); + if(imageArray.length > 1) + updateNavigation(); + }) + + } + var updateNavigation = function(){ + var next, prev; + if(imagecount == 0){ + next = 1; + prev = imageArray.length - 1; + }else if(imagecount == imageArray.length - 1){ + next = 0 + prev = imageArray.length - 2; + }else{ + 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}); + }; + if(imageArray.length > 1) + updateNavigation(); + } + + var preparestage = function(albumid){ + $.getJSON("get_images",{aid:albumid},function(album){ + imageArray = eval(album.images); + $.each(album.images,function(i,image){ + if(image._id == id) + imagecount = i; + }) + 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.loadFooterPanel(g.loadArea,id,function(head){ + head = $(head); + g.albumArea.find(".rghead .rgfn").html(head); + g.albumArea.find(".bt-back").attr("href","orbit_gallery?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); + + }); + } + + 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"); + $(this).addClass("setcover"); + $.post("set_cover",{"imageid":$(this).attr("href"),"aid":id},function(){}) + }) + $(".description_loader .edit_fn .bt-dels").click(function(){ + $(this) + .toggleClass("setdelete btn-danger active") + .find('span').toggleClass('icon-white'); + 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 .en .txtchange").each(function(){ + // var thisid = $(this).attr("for"); + // dataArray.push({"id":thisid,"text":{"en":$(this).val(),"zh_tw":$(".description_loader .zh_tw .txtchange[for="+thisid+"]").val()}}); + // }) + // var albumnm = Array(); + // $(".albumname_edit .txtchange").each(function(){ + // albumnm.push($(this).val()) + // }) + // var dataArray = $("form#edit_album").serialize(); + // $.post("update_album",{"data":dataArray},function(){ + + // }) + + }) + $('.bt-tag').click(function(){ + + $(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; + }); + 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)))){ + $("#gallery_tag_list li span:not(:contains("+sval+"))").parent().slideUp(); + }else{ + $("#gallery_tag_list li span:not(:containsi("+sval+"))").parent().slideUp(); + } + + }else{ + $("#gallery_tag_list li").slideDown(); + } + }) + g.albumArea.find("#tag_panel .bt-save").click(function(){ + g.saveTags(imageArray[imagecount]._id,g.loadArea); + }) + var tempval; + $(".txtchange").focus(function(){ + tempval = $(this).val(); + }).keyup(function(){ + if($(this).val() != tempval) + g.albumArea.find(".rghead .rgfn .bt-save").show(); + }) + g.albumArea.find(".rghead .rgfn .bt-delete").click(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(){ + if($(this).hasClass("setdelete")){ + images_to_delete.push($(this).attr("href")); + doms_to_delete.push($(this).parent().parent()); + if(thiscover == $(this).attr("href")) + delete_cover = true; + } + }) + if(confirm("Deleting "+images_to_delete.length+" image(s)?")){ + $.post("delete_images",{"images":images_to_delete,"delete_cover":delete_cover,"aid":id},function(response){ + if(response.success){ + for(dom in doms_to_delete){ + doms_to_delete[dom].hide("slide",function(){$(this).remove();}) + } + } + g.albumArea.find(".rghead .rgfn .bt-delete").hide(); + }) + } + }) + } + $("#filter").remove(); + g.albumArea.addClass('o_album_edit'); + g.albumArea.css("margin-top",""); + var head ='"><%= I18n.t("gallery.back_to_photos") %>'; + head+=''; + head+=''; + g.albumArea.find(".rghead .rgfn").html(head); + g.albumArea.find("#imgholder").load("edit_album?aid="+id,function(data,response,xhr){ + if(xhr.status == 404){ + $(this).text("<%= I18n.t('gallery.album_not_found') %>"); + return false; + } + 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/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 2bd9a94a5..dcd99cb0b 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 @@ -90,24 +90,20 @@ include AdminHelper end end end - i = 0 + @output = Array.new @albums.each do |album| + @albs = Array.new 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 + values.tag_ids.each do |tag| + 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} end - i = i + 1 + @output << @albs end - # @albums = GalleryAlbum.find("5017a7babd98eb049900000a") - # @albums.update_attributes({:tag_ids =>["501ba786bd98eb0232000126"]}) - - render :json=>@albums.to_json + render :json=>@output.to_json end def upload_image diff --git a/vendor/built_in_modules/gallery/app/controllers/panel/gallery/front_end/orbit_galleries_controller.rb b/vendor/built_in_modules/gallery/app/controllers/panel/gallery/front_end/orbit_galleries_controller.rb new file mode 100644 index 000000000..5f47d6927 --- /dev/null +++ b/vendor/built_in_modules/gallery/app/controllers/panel/gallery/front_end/orbit_galleries_controller.rb @@ -0,0 +1,228 @@ +class Panel::Gallery::FrontEnd::OrbitGalleriesController < OrbitWidgetController +include AdminHelper + def index + @authenticated = false + @categorylist = GalleryCategory.all + @cid = params['cat'] + @tags = GalleryTag.all + end + + def new_category + names = params['category'] + category = GalleryCategory.new + I18n.locale = :en + category.name = names['en'] + I18n.locale = :zh_tw + category.name = names['zh_tw'] + category.save! + render :json=>{"success"=>true,"id"=>category.id}.to_json + end + + def categorylist + @categorylist = GalleryCategory.all + #render :layout => false + end + + def gallery_category_delete + @category = GalleryCategory.find(params['id']) + @category.delete + render :json=>{"success"=>"true"}.to_json + end + + def add_album + if is_manager? || is_admin? + @categorylist = GalleryCategory.all + elsif is_sub_manager? + @categorylist = GalleryCategory.authed_for_user(current_user,"new_album") + end + render :layout => false + end + + def create_album + category = GalleryCategory.find(params['cid']) + albumnames = params["albumname"] + albumdescs = params["albumdesc"] + album = category.gallery_albums.new + I18n.locale = :en + album.name = albumnames["en"] + album.description = albumdescs["en"] + I18n.locale = :zh_tw + 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 + + def get_albums + @categoryids = params["cid"] + @tags = params["tid"] + @albums = Array.new + if @categoryids == "all" + if @tags + if @tags.kind_of?(Array) + @tags.each do |tag| + @albums << GalleryAlbum.where(tag_ids: tag) + end + else + @albums << GalleryAlbum.where(tag_ids: @tags) + end + else + @albums << GalleryAlbum.all + end + else + @categoryids.each do |id| + category = GalleryCategory.find(id) + if @tags + if @tags.kind_of?(Array) + @tags.each do |tag| + @albums << category.gallery_albums.where(tag_ids: tag) + end + else + @albums << category.gallery_albums.where(tag_ids: @tags) + end + else + @albums << category.gallery_albums.all + 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"]}) + + render :json=>@albums.to_json + end + + def upload_image + albumid = params['aid']; + @album = GalleryAlbum.find(albumid) + @files = params['files'] + a = Array.new + @files.each do |file| + @image = @album.gallery_images.new + @image.file = file + @image.save! + a << {"thumbnail_url"=>@image.file.thumb.url} + end + render :json=>a.to_json + end + + def upload_panel + render :layout => false + end + + def get_images + @album = GalleryAlbum.find(params["aid"]) + render :json=>{"images" => @album.gallery_images.all, "tags" => @album.tag_ids}.to_json + end + + def theater + picid = params["pic"] + @image = GalleryImage.find(picid) + @albumid = @image.gallery_album_id + album = GalleryAlbum.find(@albumid) + @images = album.gallery_images.all + render :layout=>false + end + + def delete_album + aid = params['aid'] + album = GalleryAlbum.find(aid) + album.delete + render :json =>{"success"=>true}.to_json + end + + def edit_album + if is_manager? || is_admin? || is_sub_manager? + aid = params['aid'] + album = GalleryAlbum.find(aid) + @images = album.gallery_images.all + @album_name = album.name_translations + @cover = album.cover + render :layout => false + end + end + + def set_cover + aid = params['aid'] + album = GalleryAlbum.find(aid) + image = GalleryImage.find(params[:imageid]) + album.update_attributes({:cover_path => image.file.thumb.url, :cover=>params[:imageid]}) + render :json =>{"success"=>true}.to_json + end + + def delete_images + images = params['images'] + images.each do |image| + img = GalleryImage.find(image) + img.delete + end + if params['delete_cover'] == "true" + album = GalleryAlbum.find(params['aid']) + album.update_attributes(:cover=>"default") + end + render :json =>{"success"=>true}.to_json + 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) + album_names = params[:albumnm] + data = params[:data] + aid =params[:aid] + debugger + data.each do |d| + image = GalleryImage.find(d[1][:id]) + @site_valid_locales.each do |locale| + image.description_translations[locale] = d[1][:text][locale] + end + image.save! + end + + album = GalleryAlbum.find(aid) + + @site_valid_locales.each_with_index do |locale,i| + album.name_translations[locale] = album_names[i] + end + album.save! + + 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/views/panel/gallery/back_end/orbit_galleries/edit_album.html.erb b/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/orbit_galleries/edit_album.html.erb index 3291942fe..3cef35446 100644 --- a/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/orbit_galleries/edit_album.html.erb +++ b/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/orbit_galleries/edit_album.html.erb @@ -27,7 +27,7 @@
- +
<% if image.id.to_s == @cover %> diff --git a/vendor/built_in_modules/gallery/app/views/panel/gallery/front_end/orbit_galleries/add_album.html.erb b/vendor/built_in_modules/gallery/app/views/panel/gallery/front_end/orbit_galleries/add_album.html.erb new file mode 100644 index 000000000..7af4f761f --- /dev/null +++ b/vendor/built_in_modules/gallery/app/views/panel/gallery/front_end/orbit_galleries/add_album.html.erb @@ -0,0 +1,34 @@ +