From 2a66b89d339136bd04b57c950b77b1ccc7e51f03 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Fri, 31 Aug 2012 22:01:19 +0800 Subject: [PATCH] Modifications in ruby --- .../app/assets/javascripts/galleryAPI.js.erb | 104 +++++++++-------- .../gallery/back_end/albums_controller.rb | 34 +++--- .../back_end/gallery_categories_controller.rb | 36 +++--- .../gallery/app/models/gallery_album.rb | 1 + .../back_end/album_images/index.html.erb | 95 ---------------- .../back_end/album_images/theater.html.erb | 34 ------ .../gallery/back_end/albums/create.js.erb | 3 + .../gallery/back_end/albums/edit.html.erb | 31 +++-- .../gallery/back_end/albums/new.html.erb | 53 ++++++--- .../gallery_categories/_category.html.erb | 13 +++ .../back_end/gallery_categories/create.js.erb | 2 + .../back_end/gallery_categories/edit.html.erb | 10 ++ .../gallery_categories/index.html.erb | 107 ++++++------------ .../back_end/gallery_categories/update.js.erb | 2 + .../gallery/config/locales/en.yml | 1 + .../built_in_modules/gallery/config/routes.rb | 4 + 16 files changed, 225 insertions(+), 305 deletions(-) delete mode 100644 vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/album_images/index.html.erb delete mode 100755 vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/album_images/theater.html.erb create mode 100644 vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/create.js.erb create mode 100644 vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/gallery_categories/_category.html.erb create mode 100644 vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/gallery_categories/create.js.erb create mode 100644 vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/gallery_categories/edit.html.erb create mode 100644 vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/gallery_categories/update.js.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 57d13bc5..80c21c4b 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 @@ -56,26 +56,26 @@ var galleryAPI = function(){ 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(); - }) - } - }) + // 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(); + // }) + // } + // }) dom.find("#album_name_close_btn").click(function(){ rcom.modalWindowClose(); }) @@ -87,9 +87,9 @@ var galleryAPI = function(){ if(confirm("<%= I18n.t('gallery.del_album?') %>")){ $.ajax({ type: "DELETE", - url : "albums/"+id, + url : id, success : function(){ - window.location = "albums"; + window.location = "../albums"; } }) } @@ -200,8 +200,6 @@ var galleryAPI = function(){ g.albumArea.addClass('o_album'); g.albumArea.find(".rghead .rgfn").append(uploadpanel); g.albumArea.find("#imgholder").empty(); - $("#filter").remove(); - g.albumArea.css("margin-top",""); $.getJSON(id+"/imgs",function(album){ $.each(album.images,function(i,image){ var thumb = image.file.thumb.url; @@ -390,6 +388,7 @@ var galleryAPI = function(){ } 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); @@ -398,9 +397,13 @@ var galleryAPI = function(){ } $slidelist.stop().animate({'height':'0px'}, 300); $slidelist.find("ul").hide(); - if(pageurl!=window.location){ - window.history.pushState({path:pageurl},'',pageurl); - } + if(rcom.getInternetExplorerVersion() == -1){ + if(pageurl!=window.location){ + window.history.pushState({path:pageurl},'',pageurl); + } + }else{ + window.location.hash = pageurl; + } // $(".slideinfo b.info").text(imageArray[imagecount].title); if($('.bt-tag').hasClass("active")) updatePhotoTag(); @@ -439,7 +442,19 @@ var galleryAPI = function(){ bindHandlers(); }) } - + if(rcom.getInternetExplorerVersion()!=-1){ + var url_constructor = window.location.href.split("/"); + var url = ""; + for(x=0;x<=url_constructor.length-1;x++){ + if(x == url_constructor.length-1){ + url+="#!/"+url_constructor[x]; + }else{ + url+=url_constructor[x]+"/"; + } + } + + window.location.href = url; + } var albumid = $("#main_pic").attr("data-content"); g.albumArea.find(".bt-back").attr("href","../albums/"+albumid); @@ -466,28 +481,23 @@ var galleryAPI = 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(); + if($(".description_loader .edit_fn .setdelete").length > 0) + g.albumArea.find(".rghead .rgfn .bt-save").show(); + + if($(this).hasClass("active")){ + $(this).parent().parent().find("input.del_field").val(true); }else{ - g.albumArea.find(".rghead .rgfn .bt-delete").hide(); + $(this).parent().parent().find("input.del_field").val(false); } + delete_cover(); }) - 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(){ - - // }) - - }) + var delete_cover = function(){ + if($(".description_loader .setcover").parent().find(".bt-dels").hasClass("active")){ + $("input.del_cover").val(true); + }else{ + $("input.del_cover").val(false); + } + } var current_element_for_tags = null; var current_element_no = null; $('.bt-tag').click(function(){ 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 e3441fad..28b20150 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 @@ -28,22 +28,27 @@ include AdminHelper elsif is_sub_manager? @categorylist = GalleryCategory.authed_for_user(current_user,"new_album") end + @album = GalleryAlbum.new render :layout => false end def create - 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"] + # 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 = GalleryAlbum.new(params[:gallery_album]) album.save! - render :json=>{"success"=>true,"id"=>album.id}.to_json + # render :json=>{"success"=>true,"id"=>album.id}.to_json + respond_to do |h| + h.js + end end def get_albums @@ -170,15 +175,16 @@ include AdminHelper end def update - debugger @album = GalleryAlbum.find(params[:id]) - #album.update_attributes(params[:gallery_album]) + @album.update_attributes(params[:gallery_album]) if is_manager? || is_admin? || is_sub_manager? @authenticated = true #turn this value to false for view only else @authenticated = false end - + if params['delete_cover'] == "true" + @album.update_attributes(:cover=>"default") + end @tags = GalleryTag.all render :action => :show end diff --git a/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/gallery_categories_controller.rb b/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/gallery_categories_controller.rb index 06432b1b..9c2e1c34 100644 --- a/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/gallery_categories_controller.rb +++ b/vendor/built_in_modules/gallery/app/controllers/panel/gallery/back_end/gallery_categories_controller.rb @@ -2,24 +2,32 @@ class Panel::Gallery::BackEnd::GalleryCategoriesController < OrbitBackendControl def index @categorylist = GalleryCategory.all - #render :layout => false + @new_category = GalleryCategory.new + end + def edit + @category = GalleryCategory.find(params[:id]) + render :layout => false + end + def create + @category = GalleryCategory.new(params[:gallery_category]) + @category.save! + respond_to do |h| + h.js + end + end + def update + @category = GalleryCategory.find(params[:id]) + @category.update_attributes(params[:gallery_category]) + respond_to do |h| + h.js + end end - def new - 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 delete + def destroy @category = GalleryCategory.find(params['id']) @category.delete render :json=>{"success"=>"true"}.to_json end -end \ No newline at end of file +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 b16e3289..03daa383 100644 --- a/vendor/built_in_modules/gallery/app/models/gallery_album.rb +++ b/vendor/built_in_modules/gallery/app/models/gallery_album.rb @@ -11,5 +11,6 @@ class GalleryAlbum belongs_to :gallery_category has_and_belongs_to_many :tags, :class_name => "GalleryTag" has_many :gallery_images, :autosave => true, :dependent => :destroy + accepts_nested_attributes_for :gallery_images, :allow_destroy => true end \ No newline at end of file diff --git a/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/album_images/index.html.erb b/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/album_images/index.html.erb deleted file mode 100644 index 1ad6b10b..00000000 --- a/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/album_images/index.html.erb +++ /dev/null @@ -1,95 +0,0 @@ - -<%= stylesheet_link_tag "gallery" %> - - - -<% content_for :page_specific_javascript do %> - <%= javascript_include_tag "galleryAPI" %> -<% end %> - - - - - - - diff --git a/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/album_images/theater.html.erb b/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/album_images/theater.html.erb deleted file mode 100755 index b1c62ae0..00000000 --- a/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/album_images/theater.html.erb +++ /dev/null @@ -1,34 +0,0 @@ - -
-
-
-
- Prev - Next -
-
-
- -
-
- Screen - List - F -
- - <%= @image.description %> -
-
-
\ No newline at end of file diff --git a/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/create.js.erb b/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/create.js.erb new file mode 100644 index 00000000..36cfe297 --- /dev/null +++ b/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/create.js.erb @@ -0,0 +1,3 @@ +var gal = new galleryAPI(); +gal.loadAlbums("all"); +rcom.modalWindowClose(); 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 0a396785..1052609e 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 @@ -15,19 +15,20 @@ <%= 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 %> -
- <% else %> -
- <% end %> -
<%= f.fields_for :name_translations do |name| %> <%= f.label t("gallery.album_name") %>
+ <% @site_valid_locales.each_with_index do |locale, i| %> + <% if i == 0 %> +
+ <% else %> +
+ <% end %> <%= name.text_field locale, :value => (@album_name[locale]), :class => "txtchange" %>
+ <% end %> +
<% end %>
@@ -38,10 +39,19 @@ <% end %>
- <%= f.fields_for :gallery_images do |j| %> + <%= f.fields_for :gallery_images, image do |j| %> <%= j.hidden_field :id, :value => (image.id) %> + <%= j.hidden_field :_destroy, :value => false, :class => "del_field" %> <%= j.fields_for :description_translations do |desc| %> + <% @site_valid_locales.each_with_index do |locale, i| %> + <% if i == 0 %> +
+ <% else %> +
+ <% end %> <%= desc.text_area locale, :value => (image.description_translations[locale] rescue nil), :class => "txtchange" %> +
+ <% end %> <% end %> <% end %>
@@ -57,12 +67,11 @@
<% end %>
-
- <% end %> + +
"><%= I18n.t("gallery.back_to_photos") %> - <%= f.submit t('gallery.save'), :class=>'bt-save icon-ok btn btn-primary pull-right', :style=>"display:none;" %>
diff --git a/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/new.html.erb b/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/new.html.erb index 7af4f761..10855947 100644 --- a/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/new.html.erb +++ b/vendor/built_in_modules/gallery/app/views/panel/gallery/back_end/albums/new.html.erb @@ -2,33 +2,50 @@ + <%= form_for @album, :url => {:action => "create"}, :remote => true do |f| %>