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 80c21c4b..54f5371c 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 @@ -34,48 +34,40 @@ var galleryAPI = function(){ 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"),""); + $("#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; + if(url.charAt(url.length-1)=="&" || url.charAt(url.length-1)=="?") + url = url.substr(0,url.length-1); + loc = url; + }) + window.location = url; }) - window.location = url; - }) + } + } 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 ={ - // 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("albums/create",options,function(response){ - // if(g.loadArea == "albums") - // g.loadAlbums("all"); - // rcom.modalWindowClose(); - // }) - // } - // }) + $("form#new_gallery_album").submit(function(){ + var validated = true; + $(this).find(".error").removeClass("error"); + $(this).find(".validate").each(function(){ + if(!$(this).val()){ + validated = false; + $(this).parent().addClass("error"); + } + }) + if(!validated) + return false; + }) dom.find("#album_name_close_btn").click(function(){ rcom.modalWindowClose(); }) @@ -103,6 +95,7 @@ var galleryAPI = function(){ var cids = []; var tids = []; var href = null; + console.log(cids); var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); for(var i = 0; i < hashes.length; i++){ hash = hashes[i].split('='); @@ -123,6 +116,7 @@ var galleryAPI = function(){ $.getJSON("get_albums",{cid:cids,tid:tids},function(categories){ $.each(categories,function(x,category){ $.each(category,function(i,album){ + album.description = (album.description?album.description:"<%= I18n.t('gallery.no_description') %>") if(album.cover == "default") var $img = $("
"); else @@ -203,6 +197,7 @@ var galleryAPI = function(){ $.getJSON(id+"/imgs",function(album){ $.each(album.images,function(i,image){ var thumb = image.file.thumb.url; + image.description = (image.description?image.description:"<%= I18n.t('gallery.no_description') %>") var $img = $(""); g.albumArea.find("#imgholder").append($img); }) @@ -473,8 +468,8 @@ var galleryAPI = function(){ $(".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[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"); + $(this).addClass("setcover active btn-primary"); + $(this).find("span").removeClass("icon-star-empty").addClass("icon-white icon-star"); $.post("set_cover",{"imageid":$(this).attr("for")}); }) $(".description_loader .edit_fn .bt-dels").click(function(){ @@ -573,38 +568,37 @@ var galleryAPI = function(){ if($(this).val() != tempval) g.albumArea.find(".rghead .rgfn .bt-save").show(); }) - g.albumArea.find(".rghead .rgfn .bt-delete").click(function(){ - var deleteurl = $(this).attr("href"); - var images_to_delete = new Array(); - var delete_cover = false; - var doms_to_delete = new Array(); - var thiscover = $(".description_loader .edit_fn .setcover").attr("for"); - $(".description_loader .edit_fn .bt-dels").each(function(){ - if($(this).hasClass("setdelete")){ - images_to_delete.push($(this).attr("href")); - $(".tab_content .rgphoto_edit[data-content="+$(this).attr("href")+"]").each(function(){ - doms_to_delete.push($(this)); - }) - if(thiscover == $(this).attr("href")) - delete_cover = true; - } - }) - if(confirm("Deleting "+images_to_delete.length+" image(s)?")){ - $.ajax({ - data : {"images":images_to_delete,"delete_cover":delete_cover}, - type : "DELETE", - url : deleteurl+"/"+id, // have to ask chris about delete resource - success : function(){ - for(dom in doms_to_delete){ - doms_to_delete[dom].hide("slide",function(){$(this).remove();}) - } - g.albumArea.find(".rghead .rgfn .bt-delete").hide(); - } - }) - } - }) + // g.albumArea.find(".rghead .rgfn .bt-delete").click(function(){ + // var deleteurl = $(this).attr("href"); + // var images_to_delete = new Array(); + // var delete_cover = false; + // var doms_to_delete = new Array(); + // var thiscover = $(".description_loader .edit_fn .setcover").attr("for"); + // $(".description_loader .edit_fn .bt-dels").each(function(){ + // if($(this).hasClass("setdelete")){ + // images_to_delete.push($(this).attr("href")); + // $(".tab_content .rgphoto_edit[data-content="+$(this).attr("href")+"]").each(function(){ + // doms_to_delete.push($(this)); + // }) + // if(thiscover == $(this).attr("href")) + // delete_cover = true; + // } + // }) + // if(confirm("Deleting "+images_to_delete.length+" image(s)?")){ + // $.ajax({ + // data : {"images":images_to_delete,"delete_cover":delete_cover}, + // type : "DELETE", + // url : deleteurl+"/"+id, // have to ask chris about delete resource + // success : function(){ + // 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'); var imageTagArray = null; $.getJSON("images_tags",function(data){ 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 index a353b768..8c9ab040 100644 --- 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 @@ -9,130 +9,26 @@ var galleryAPI = function(){ this.urlVars = rcom.getUrlVars(); this.albumArea = $("#orbit_gallery"); this.loadArea = null; - this.tagList = $("ul#gallery_tag_list"); + this.tagList = $("ul#.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); - } + //bindHandlers(); }) var bindHandlers = function(){ - $("#filter .filter_btns a").click(function(){ - if(!$(this).hasClass("active")){ - $(this).addClass("active"); - if(g.urlVars.length == 0) - window.location = "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.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.find(".rghead").hide(); - }) - + g.albumArea.find(".rghead .rgfn a").click(function(){g.makeNewAlbum($(this).attr("href"))}); g.albumArea.addClass('o_gallery'); g.albumArea.find("#imgholder").empty(); - // var $addsign = $(''); - // $addsign.find("a").click(function(){g.makeNewAlbum();}) - if(id!="all"){ var cids = []; var tids = []; var href = null; + console.log(cids); var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); for(var i = 0; i < hashes.length; i++){ hash = hashes[i].split('='); @@ -153,107 +49,35 @@ var galleryAPI = function(){ $.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){ + album.description = (album.description?album.description:"<%= I18n.t('gallery.no_description') %>") if(album.cover == "default") - var $img = $(""); + var $img = $(""); else - var $img = $(""); + var $img = $(""); var tag_string = ""; for(tag in album.tag_names){ - tag_string+= ' '; + if(tag == album.tag_names.length-1) + tag_string+= ' '; + else + tag_string+= ' '; } $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 = $(''); - // $addsign.find("a").click(function(){showUploadPanel();}) - $.getJSON("panel/gallery/front_end/get_images",{aid:id,"inner":true},function(album){ + $.getJSON("panel/gallery/front_end/albums/"+id+"/imgs",function(album){ $.each(album.images,function(i,image){ var thumb = image.file.thumb.url; - var $img = $(""); + image.description = (image.description?image.description:"<%= I18n.t('gallery.no_description') %>") + 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; @@ -288,9 +112,23 @@ var galleryAPI = function(){ }); 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); + if(tags.length > 0 && g.tagList.find("li").length == 0){ + var tagnames = imageArray[imagecount].tag_names; + g.tagList.empty(); + for(i in tagnames){ + $li = $("+ <%= label_tag(locale, t("gallery.album_name")) %> + <%= name.text_field locale, :class => "validate" %> +
++ <%= label_tag(locale, t("gallery.album_desc")) %> + <%= desc.text_field locale %> +
+