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 f64f4587..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 @@ -10,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(){ @@ -85,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 ={ @@ -128,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"){ @@ -156,9 +124,9 @@ var galleryAPI = function(){ $.each(categories,function(x,category){ $.each(category,function(i,album){ if(album.cover == "default") - var $img = $("
"+album.name+""+album.category_name+"
"); + var $img = $("
"+album.name+""+album.category_name+"
"); else - var $img = $("
"+album.name+""+album.category_name+"
"); + var $img = $("
"+album.name+""+album.category_name+"
"); var tag_string = ""; for(tag in album.tag_names){ @@ -168,7 +136,6 @@ var galleryAPI = function(){ g.albumArea.find("#imgholder").append($img); }) }) - // g.albumArea.find("#imgholder").append($addsign); }) } this.loadImages = function(id){ @@ -206,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(); @@ -236,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); @@ -253,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; @@ -330,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")); @@ -462,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) @@ -479,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) @@ -536,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) @@ -558,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){ @@ -579,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(){ @@ -616,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){ @@ -634,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 @@ @@ -84,8 +99,8 @@ galleryAPI.prototype.locale = "<%= I18n.locale %>"; var gallery = new galleryAPI(); gallery.initialize(); - gallery.loadArea = "images"; - gallery.loadImages("<%= params[:id] %>"); + gallery.loadArea = "theater"; + gallery.loadTheater("<%= params[:id] %>"); diff --git a/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/edit.html.erb b/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/edit.html.erb index 621606aa..a3007000 100644 --- a/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/edit.html.erb +++ b/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/edit.html.erb @@ -13,7 +13,7 @@ <% end %> -<%= form_for @album, :url => panel_gallery_back_end_albums_path(@album), :html => {:class => 'clear'} do |f| %> +<%= form_for @album, :url => panel_gallery_back_end_album_path(@album), :html => {:class => 'clear'} do |f| %>
<% @site_valid_locales.each_with_index do |locale, i| %> <% if i == 0 %> @@ -30,16 +30,18 @@
<% @images.each_with_index do |image,x| %>
- + + <%= link_to panel_gallery_back_end_album_image_path(image) do %> + + <% end %>
- <%= f.fields_for :gallery_images do |j| %> <%= j.fields_for :description_translations do |desc| %> <%= desc.text_area locale, :value => (image.description_translations[locale] rescue nil ), :class => "txtchange" %> <% end %> <% end %>
-
+
<% if image.id.to_s == @cover %> " href="set_cover" for="<%= image.id %>"> <% else %> @@ -55,7 +57,7 @@ <% end %>
diff --git a/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/index.html.erb b/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/index.html.erb index b53218ce..b77fe0be 100644 --- a/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/index.html.erb +++ b/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/index.html.erb @@ -97,7 +97,7 @@ diff --git a/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/show.html.erb b/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/show.html.erb index 6462c219..434bf704 100644 --- a/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/show.html.erb +++ b/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/show.html.erb @@ -58,20 +58,14 @@ diff --git a/vendor/built_in_modules/gallery/config/routes.rb b/vendor/built_in_modules/gallery/config/routes.rb index 0a3e74cd..ca368b3a 100644 --- a/vendor/built_in_modules/gallery/config/routes.rb +++ b/vendor/built_in_modules/gallery/config/routes.rb @@ -2,37 +2,19 @@ Rails.application.routes.draw do namespace :panel do namespace :gallery do namespace :back_end do - # match "orbit_gallery" => "orbit_galleries#index" - - # match "add_album" => "orbit_galleries#add" - # match "create_album" => "orbit_galleries#create_album" match "get_albums" => "albums#get_albums" match "upload_image" => "albums#upload_image" - match "get_images" => "album_images#get_images" - match "theater" => "album_images#theater" - # match "delete_album" => "orbit_galleries#delete" - # match "edit_album" => "orbit_galleries#edit" - #match "set_cover" => "albums#set_cover" - # match "delete_images" => "orbit_galleries#delete_images" - # # match "update_album" => "orbit_galleries#update_album" - match "save_tags" => "album_images#save_tags" + match "save_tags" => "tags#save_tags" - # match "categories" => "orbit_gallery_categories#index" - # match "gallery_category_delete" => "orbit_gallery_categories#delete" - # match "gallery_category_save" => "orbit_gallery_categories#new" - - resources :albums do + resources :albums do match "set_cover" => "albums#set_cover" - match "get_images" => "albums#get_images" + match "imgs" => "albums#imgs" match "upload_panel" => "albums#upload_panel" - - end - resources :album_images do - # match "delete" => "album_images#destroy" + match "images_tags" => "albums#images_tags" end + resources :album_images resources :gallery_categories - resources :tags end namespace :front_end do