diff --git a/app/controllers/ad_banners_controller.rb b/app/controllers/ad_banners_controller.rb index 8970625..7727c17 100644 --- a/app/controllers/ad_banners_controller.rb +++ b/app/controllers/ad_banners_controller.rb @@ -1,7 +1,7 @@ class AdBannersController < ApplicationController def widget adbanner = Banner.find(OrbitHelper.widget_custom_value) - images = adbanner.ad_images.can_display.desc(:created_at).collect.with_index do |b,i| + images = adbanner.ad_images.can_display.asc(:sort_number,:created_at).collect.with_index do |b,i| image_link = OrbitHelper.is_mobile_view ? b.file.mobile.url : b.file.url klass = i == 0 ? "active" : "" caption = i == 0 ? '
' : "" diff --git a/app/controllers/admin/ad_banners_controller.rb b/app/controllers/admin/ad_banners_controller.rb index 395f6a4..38f6388 100644 --- a/app/controllers/admin/ad_banners_controller.rb +++ b/app/controllers/admin/ad_banners_controller.rb @@ -12,14 +12,18 @@ class Admin::AdBannersController < OrbitAdminController .with_categories(filters("category")) @banners = search_data(@banners,[:title]).page(params[:page]).per(6) - if request.xhr? + if request.xhr? render :partial => "index_table" end end def show @banner = Banner.find(params[:id]) - @images = @banner.ad_images.desc(:created_at).page(params[:page]).per(10) + if params[:show] == "expired" + @images = @banner.ad_images.is_expired.asc(:sort_number).page(params[:page]).per(10) + else + @images = @banner.ad_images.not_expired.asc(:sort_number).page(params[:page]).per(10) + end @table_fields = [:banner, :title, "ad_banner.duration", :link] end @@ -52,6 +56,18 @@ class Admin::AdBannersController < OrbitAdminController ad_banner.destroy redirect_to admin_ad_banners_path(:page => params[:page]) end + + def save_image_order + ids = params[:ids] + ids.each_with_index do |id,index| + image = AdImage.find(id) rescue nil + if !image.nil? + image.sort_number = index + image.save + end + end + render :json => {"success" => true}.to_json + end private diff --git a/app/models/ad_image.rb b/app/models/ad_image.rb index cb93691..92e8dee 100644 --- a/app/models/ad_image.rb +++ b/app/models/ad_image.rb @@ -13,6 +13,8 @@ class AdImage field :link_open, type: String field :postdate , :type => DateTime, :default => Time.now field :deadline , :type => DateTime + field :sort_number, :type => Integer + LINK_OPEN_TYPES = ["local", "new_window"] belongs_to :banner @@ -23,6 +25,8 @@ class AdImage # validates :title, presence: true scope :can_display, ->{self.and(AdImage.or({:postdate.lte=>Time.now},{:postdate=>nil}).selector,AdImage.or({:deadline.gte=>Time.now},{:deadline=>nil}).selector)} + scope :is_expired, ->{self.and(AdImage.or({:deadline.lte=>Time.now}).selector)} + scope :not_expired, ->{self.and(AdImage.or({:deadline.gte=>Time.now},{:deadline=>nil}).selector)} def expired? self.deadline