From d532ded8e4e8ddb723bea73638e5a81b7be06873 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Sat, 14 Sep 2013 18:01:15 +0800 Subject: [PATCH] widget code for gallery rewritten for new_ui --- .../gallery/app/assets/javascripts/gallery.js | 18 ++++++----- .../panel/gallery/widget/albums_controller.rb | 31 ++++++++++++++++--- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/vendor/built_in_modules/gallery/app/assets/javascripts/gallery.js b/vendor/built_in_modules/gallery/app/assets/javascripts/gallery.js index 9ac0b842..7bf7ce18 100644 --- a/vendor/built_in_modules/gallery/app/assets/javascripts/gallery.js +++ b/vendor/built_in_modules/gallery/app/assets/javascripts/gallery.js @@ -19,14 +19,16 @@ $(function () { 'use strict'; // Initialize the jQuery File Upload widget: - $('#fileupload').fileupload({ - maxFileSize: 5000000, - acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i, - dropZone: $('#dropzone'), - headers:{ - 'X-CSRF-Token': $('meta[name="csrf-token"]').attr("content") - } - }); + if($('#fileupload').length){ + $('#fileupload').fileupload({ + maxFileSize: 5000000, + acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i, + dropZone: $('#dropzone'), + headers:{ + 'X-CSRF-Token': $('meta[name="csrf-token"]').attr("content") + } + }); + } }); $(function() { 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 8f880eb3..439897eb 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 @@ -9,15 +9,38 @@ class Panel::Gallery::Widget::AlbumsController < OrbitWidgetController @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 - 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 + + if @album_images.count > @total + @randoms = [] + until @randoms.count == @total do + r = @rnd.rand(0...@album_images.count) + if !@randoms.include?r + @randoms << r + image = @album_images[r] + values = {"show_link"=>theater_panel_gallery_front_end_album_path(image),"thumb"=>image.file.thumb.url} + @images << values + end + end + elsif @album_images.count == @total + @album_images.each do |image| + values = {"show_link"=>theater_panel_gallery_front_end_album_path(image),"thumb"=>image.file.thumb.url} + @images << values + end + else + @album_images.each do |image| + values = {"show_link"=>theater_panel_gallery_front_end_album_path(image),"thumb"=>image.file.thumb.url} + @images << values + end + until @images.count == @total do + values = {"show_link"=>"javascript:void(0);","thumb"=>"assets/gallery/default.jpg"} + @images << values + end end end