From 53fb0e12ab799e60c65b2c1b26be4f749afd48d2 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 18 Dec 2014 20:00:46 +0800 Subject: [PATCH] youtube video added --- app/controllers/ad_banners_controller.rb | 72 +++++++++++++++---- .../admin/ad_banners_controller.rb | 1 + app/models/banner.rb | 1 + app/views/admin/ad_banners/_form.html.erb | 3 + app/views/admin/ad_banners/index.html.erb | 4 +- lib/ad_banner/engine.rb | 8 +++ 6 files changed, 75 insertions(+), 14 deletions(-) diff --git a/app/controllers/ad_banners_controller.rb b/app/controllers/ad_banners_controller.rb index 1f89adc..bf022c1 100644 --- a/app/controllers/ad_banners_controller.rb +++ b/app/controllers/ad_banners_controller.rb @@ -1,20 +1,57 @@ class AdBannersController < ApplicationController def widget adbanner = Banner.find(OrbitHelper.widget_custom_value) - images = adbanner.ad_images.can_display.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 ? '
' : "" + widget = OrbitHelper.get_current_widget + if widget.widget_type == "ad_banner_widget2_video" + return video_widget(adbanner) + else + return image_widget(adbanner) + end + end + + private + + def image_widget(adbanner) + images = adbanner.ad_images.can_display.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 ? '
' : "" { - "image_link" => image_link, - "title" => b.title, - "class" => klass, - "height" => adbanner.height, - "width" => adbanner.width, - "caption" => caption, - "context" => b.context, - "link" => b.out_link || "#" + "image_link" => image_link, + "title" => b.title, + "class" => klass, + "height" => adbanner.height, + "width" => adbanner.width, + "caption" => caption, + "context" => b.context, + "link" => b.out_link || "#" } + end + { + "extras" => { + "ad_fx" => adbanner.ad_fx, + "speed" => adbanner.speed, + "title" => adbanner.title, + "timeout" => adbanner.timeout, + "more" => "More" + }, + "images" => images + } + end + + def video_widget(adbanner) + images = adbanner.ad_images.can_display.collect.with_index do |ad_b,i| + image_link = OrbitHelper.is_mobile_view ? ad_b.file.mobile.url : ad_b.file.url + caption = i == 0 ? '
' : "" + klass = i == 0 ? "active" : "" + if ad_b.exchange_item == "1" + image_html = "
" + else ad_b.exchange_item == "2" + image_html = "
#{ad_b.title}
" + end + { + "html" => image_html + } end { "extras" => { @@ -27,4 +64,15 @@ class AdBannersController < ApplicationController "images" => images } end + + def format_url(url,index) + uri = URI.parse(url) + ps = uri.query.split("&") + url_params = {} + ps.each do |p| + x = p.split("=") + url_params[x.first] = x.last + end + url = "http://www.youtube.com/v/#{url_params["v"]}/?version=3&playerapiid=ytplayer#{index}" + end end diff --git a/app/controllers/admin/ad_banners_controller.rb b/app/controllers/admin/ad_banners_controller.rb index 8652ff6..1cb8fae 100644 --- a/app/controllers/admin/ad_banners_controller.rb +++ b/app/controllers/admin/ad_banners_controller.rb @@ -3,6 +3,7 @@ class Admin::AdBannersController < OrbitAdminController def index @banners = Banner.all + @categories = @module_app.categories.enabled.collect{|c|[c.title, c.id]} end def show diff --git a/app/models/banner.rb b/app/models/banner.rb index f776fbe..b44a374 100644 --- a/app/models/banner.rb +++ b/app/models/banner.rb @@ -2,6 +2,7 @@ class Banner include Mongoid::Document include Mongoid::Timestamps include OrbitTag::Taggable + include OrbitCategory::Categorizable field :ad_fx, type: String field :height, type: Integer diff --git a/app/views/admin/ad_banners/_form.html.erb b/app/views/admin/ad_banners/_form.html.erb index 7ed6e75..b59ce8a 100644 --- a/app/views/admin/ad_banners/_form.html.erb +++ b/app/views/admin/ad_banners/_form.html.erb @@ -10,3 +10,6 @@ <%= f.number_field :width, in: 10..1000, step: 10, class: 'input-mini', onkeypress: "if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;", id: 'width' %> <%= f.number_field :height, in: 10..1000, step: 10, class: 'input-mini', onkeypress: "if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;", id: 'height' %> + +<%= f.label :category_id, t('ad_banner.categories') %> +<%= f.select :category_id, @categories, {} %> diff --git a/app/views/admin/ad_banners/index.html.erb b/app/views/admin/ad_banners/index.html.erb index 5b79e3f..30aeb35 100644 --- a/app/views/admin/ad_banners/index.html.erb +++ b/app/views/admin/ad_banners/index.html.erb @@ -42,5 +42,5 @@ - <%= render 'layouts/delete_modal', delete_options: @delete_options %> -<% end %> \ No newline at end of file +<% end %> +<%= render 'layouts/delete_modal', delete_options: @delete_options %> \ No newline at end of file diff --git a/lib/ad_banner/engine.rb b/lib/ad_banner/engine.rb index 6f9b098..cfc045f 100644 --- a/lib/ad_banner/engine.rb +++ b/lib/ad_banner/engine.rb @@ -21,6 +21,14 @@ module AdBanner :priority=>1, :active_for_action=>{'admin/ad_banners'=>"index"}, :available_for => 'users' + + context_link 'categories', + :link_path=>"admin_module_app_categories_path" , + :link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'ad_banner').id}", + :priority=>3, + :active_for_action=>{'admin/ad_banners'=>'categories'}, + :active_for_category => 'AdBanner', + :available_for => 'managers' end end end