From c6111460f529abda6124654bc5a58ca14d832f55 Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 7 Jan 2013 00:40:43 +0800 Subject: [PATCH] Fix album widget options --- app/controllers/admin/page_parts_controller.rb | 10 ++++------ app/controllers/orbit_widget_controller.rb | 7 ------- app/models/page_part.rb | 4 ---- .../admin/page_parts/_widget_options.html.erb | 4 ++++ lib/parsers/parser_common.rb | 2 +- lib/parsers/parser_front_end.rb | 2 +- .../panel/gallery/widget/albums_controller.rb | 17 ++++++++--------- 7 files changed, 18 insertions(+), 28 deletions(-) diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb index 58af08af..da2de827 100644 --- a/app/controllers/admin/page_parts_controller.rb +++ b/app/controllers/admin/page_parts_controller.rb @@ -39,9 +39,8 @@ class Admin::PagePartsController < ApplicationController when 'announcement' @categories = BulletinCategory.all @tags = AnnouncementTag.all - when 'news' - @categories = NewsBulletinCategory.all - @tags = NewsTag.all + when 'gallery' + @albums = GalleryAlbum.all when 'web_resource' @categories = WebLinkCategory.all @tags = WebResourceTag.all @@ -102,9 +101,8 @@ class Admin::PagePartsController < ApplicationController when 'announcement' @categories = BulletinCategory.all @tags = AnnouncementTag.all - when 'news' - @categories = NewsBulletinCategory.all - @tags = NewsTag.all + when 'gallery' + @albums = GalleryAlbum.all when 'web_resource' @categories = WebLinkCategory.all @tags = WebResourceTag.all diff --git a/app/controllers/orbit_widget_controller.rb b/app/controllers/orbit_widget_controller.rb index 8f4b25da..47e24fe0 100644 --- a/app/controllers/orbit_widget_controller.rb +++ b/app/controllers/orbit_widget_controller.rb @@ -1,10 +1,3 @@ class OrbitWidgetController< OrbitFrontendComponentController -before_filter :get_wiget_options - def get_wiget_options - @wiget_options = {} - if params[:widget_options] - @wiget_options = (eval('{'+ params[:widget_options] +'}') rescue {}) - end - end end \ No newline at end of file diff --git a/app/models/page_part.rb b/app/models/page_part.rb index a36c498a..ebaac684 100644 --- a/app/models/page_part.rb +++ b/app/models/page_part.rb @@ -23,10 +23,6 @@ class PagePart before_save :delete_empty_widget_field after_save :update_parent - def widget_options_uri - self.widget_options.map{|t| "#{t[0]}: #{t[1]}"}.join(',') rescue '' - end - protected diff --git a/app/views/admin/page_parts/_widget_options.html.erb b/app/views/admin/page_parts/_widget_options.html.erb index 731fdc38..f3438058 100644 --- a/app/views/admin/page_parts/_widget_options.html.erb +++ b/app/views/admin/page_parts/_widget_options.html.erb @@ -1,5 +1,9 @@ <% if (@module_app && @module_app.widget_options) %> <%= label_tag('widget_options') %> + <% if @module_app.key.eql?('gallery') %> + <%= t('gallery.gallery') %> + <%= select_tag "page_part[widget_options][album_id]", options_from_collection_for_select(@albums, :id, :name, :selected => (@part.widget_options[key] rescue nil)) %> + <% end %> <% if @module_app.widget_options.has_key? @part.widget_path%> <% @module_app.widget_options[@part.widget_path].each do |key,options| %> <%= label_tag(t(@module_app.widget_options_fields_i18n[@part.widget_path][key]))%> diff --git a/lib/parsers/parser_common.rb b/lib/parsers/parser_common.rb index c0a8315d..1f996cec 100644 --- a/lib/parsers/parser_common.rb +++ b/lib/parsers/parser_common.rb @@ -210,7 +210,7 @@ module ParserCommon when 'default_widget' "/panel/orbit_app/widget/#{part.widget_style}?inner=true" else - "/panel/#{part.module_app.key}/widget/#{part.widget_path}?inner=true&widget_options=#{part.widget_options_uri}" + "/panel/#{part.module_app.key}/widget/#{part.widget_path}?inner=true" end options = "&part_id=#{part.id}&category_id=#{!part[:category].blank? ? part[:category].blank? : category}&tag_id=#{!part[:tag].blank? ? part[:tag] : tag}&page=#{params[:page]}&search_query=#{params[:search_query]}&part_title=#{Rack::Utils.escape(part_title).gsub("+", "%20") rescue nil}" ret << "
" diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index 1175c527..246e6c20 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -114,7 +114,7 @@ module ParserFrontEnd when 'default_widget' "/panel/orbit_app/widget/\#{part.widget_style}?inner=true" else - "/panel/\#{part.module_app.key}/widget/\#{part.widget_path}?inner=true&widget_options=\#{part.widget_options_uri}" + "/panel/\#{part.module_app.key}/widget/\#{part.widget_path}?inner=true" end options = "&part_id=\#{part.id}&category_id=\#{!part[:category].blank? ? part[:category].blank? : category}&tag_id=\#{!part[:tag].blank? ? part[:tag] : tag}&page=\#{params[:page]}&search_query=\#{params[:search_query]}&part_title=\#{Rack::Utils.escape(part_title).gsub(\"\+\", \"\%20\") rescue nil}" ret << "" diff --git a/vendor/built_in_modules/gallery/app/controllers/panel/gallery/widget/albums_controller.rb b/vendor/built_in_modules/gallery/app/controllers/panel/gallery/widget/albums_controller.rb index 6a57b47b..8f880eb3 100644 --- a/vendor/built_in_modules/gallery/app/controllers/panel/gallery/widget/albums_controller.rb +++ b/vendor/built_in_modules/gallery/app/controllers/panel/gallery/widget/albums_controller.rb @@ -1,27 +1,26 @@ class Panel::Gallery::Widget::AlbumsController < OrbitWidgetController def widget1 - vertical = 2 - horizontal = 6 + @part = PagePart.find(params[:part_id]) - vertical = @wiget_options[:vertical] if (@wiget_options.has_key?(:vertical) && @wiget_options[:vertical] < vertical) - horizontal = @wiget_options[:horizontal] if (@wiget_options.has_key?(:horizontal) && @wiget_options[:horizontal] < horizontal) + vertical = @part.widget_options['vertical'].to_i rescue 0 + horizontal = @part.widget_options['horizontal'].to_i rescue 0 + @album = GalleryAlbum.find(@part.widget_options['album_id']) rescue nil + @album_images = @album.gallery_images if @album + @settings = {"vertical"=>vertical,"horizontal"=>horizontal} #[note] horizontal has it's limitation from 2 to 6 @class = "c" + @settings["horizontal"].to_s @total = @settings["vertical"] * @settings["horizontal"] @rnd = Random.new @images = [] for i in 0..@total-1 - @sn = @rnd.rand(0...GalleryImage.count) - if @sn < 0 - @sn = @sn * -1 - end - image = GalleryImage.skip(@sn).limit(1).first + image = @album_images[@rnd.rand(0...@album_images.count)] values = {"show_link"=>theater_panel_gallery_front_end_album_path(image),"thumb"=>image.file.thumb.url} @images << values end end + def widget2 end