From 51190a79cbc7f1647b378a263e19a2954fc1b802 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 17 Apr 2012 16:03:48 +0800 Subject: [PATCH] Preview now can be use at both ad_banner and ad_image,however it won't run correctly if user change its ad_banner at ad_image. --- app/assets/javascripts/inc/modal-preview.js | 2 +- app/controllers/admin/ad_banners_controller.rb | 2 +- app/models/ad_banner.rb | 1 + app/views/admin/ad_banners/_ad_banner_tab.html.erb | 3 +-- app/views/admin/ad_banners/_modal_ad_banner_form.html.erb | 3 --- app/views/admin/ad_banners/index.html.erb | 1 + app/views/admin/ad_images/_form.html.erb | 7 ++++--- config/routes.rb | 6 ++---- 8 files changed, 11 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/inc/modal-preview.js b/app/assets/javascripts/inc/modal-preview.js index 3453c096..fd62a95e 100644 --- a/app/assets/javascripts/inc/modal-preview.js +++ b/app/assets/javascripts/inc/modal-preview.js @@ -4,7 +4,7 @@ $(document).ready(function() { $("a.preview_trigger").click(function(){ - $(this).after("

"); + $(this).after(""); $.ajax({ type:"PUT", url:$(this).attr("href"), diff --git a/app/controllers/admin/ad_banners_controller.rb b/app/controllers/admin/ad_banners_controller.rb index 4d2ed213..c3d0cc58 100644 --- a/app/controllers/admin/ad_banners_controller.rb +++ b/app/controllers/admin/ad_banners_controller.rb @@ -40,7 +40,7 @@ class Admin::AdBannersController < ApplicationController end def realtime_preview - @ad_banner = AdBanner.find(params[:id]).preview_clone + @ad_banner = AdBanner.find(conditions: { title: params[:title] }).preview_clone #@ad_banner.update_attributes(params[:ad_banner]).update_attributes(params[:ad_images]) end diff --git a/app/models/ad_banner.rb b/app/models/ad_banner.rb index a2ac2096..0147c3d2 100644 --- a/app/models/ad_banner.rb +++ b/app/models/ad_banner.rb @@ -9,6 +9,7 @@ class AdBanner before_save :save_or_destroy validates_uniqueness_of :title + validates :title , :length => { :minimum => 2 } has_many :ad_images , dependent: :delete FX_TYPES = ["blindX","blindY","blindZ","cover","curtainX","curtainY","fade","fadeZoom","growX","growY","scrollUp","scrollDown","scrollLeft","scrollRight","scrollHorz","scrollVert","shuffle","slideX","slideY","toss","turnUp","turnDown","turnLeft","turnRight","uncover","wipe","zoom"] diff --git a/app/views/admin/ad_banners/_ad_banner_tab.html.erb b/app/views/admin/ad_banners/_ad_banner_tab.html.erb index 001726f4..47986323 100644 --- a/app/views/admin/ad_banners/_ad_banner_tab.html.erb +++ b/app/views/admin/ad_banners/_ad_banner_tab.html.erb @@ -1,4 +1,3 @@ -
" id=<%= ad_banner_tab.title %>>

<%= t("admin.ad.banner_best_size") %>:

@@ -13,7 +12,7 @@ <%= render :partial => "ad_image_update", :collection => ad_banner_tab.ad_images,:as => :ad_image,:locals=>{:ad_banner => ad_banner_tab} %> <%#= render :partial => 'new_add_banner_file', :object => ad_banner_tab.ad_images.build, :locals => { :field_name => "new_ad_images[]", :f => f, :classes => "r_destroy" } %> <%= link_to t("admin.ad.new_image"),new_admin_ad_banner_ad_image_path(ad_banner_tab) ,:class => "btn btn-primary"%> - <%= link_to t("modal.preview"), realtime_preview_admin_ad_banner_path(ad_banner_tab) , :class=>'preview_trigger btn btn-success'%> + <%= link_to t("modal.preview"), admin_realtime_preview_ad_banner_path(ad_banner_tab.title) , :class=>'preview_trigger btn btn-success'%>
<% end -%> diff --git a/app/views/admin/ad_banners/_modal_ad_banner_form.html.erb b/app/views/admin/ad_banners/_modal_ad_banner_form.html.erb index 8e8de1d9..66f8de2b 100644 --- a/app/views/admin/ad_banners/_modal_ad_banner_form.html.erb +++ b/app/views/admin/ad_banners/_modal_ad_banner_form.html.erb @@ -44,9 +44,6 @@ $('#new_ad_banner_tab_but').on('shown', function (e) { $('#new-a-banner').modal({show: true}); }) -$('#new-a-banner').on('shown', function (e) { - alert('show!'); -}) $('#new-a-banner').on('hidden', function (e) { $(".nav.nav-tabs a[id!='new_ad_banner_tab_but']:last").tab('show'); diff --git a/app/views/admin/ad_banners/index.html.erb b/app/views/admin/ad_banners/index.html.erb index 365d020d..4b7dfef2 100644 --- a/app/views/admin/ad_banners/index.html.erb +++ b/app/views/admin/ad_banners/index.html.erb @@ -2,6 +2,7 @@ <%#= stylesheet_link_tag "admin/ad_banner_preview" %> <% end -%> <% content_for :page_specific_css do -%> + <%= javascript_include_tag "/static/jquery.cycle.all.latest.js" %> <%= javascript_include_tag "inc/modal-preview" %> <% end -%> diff --git a/app/views/admin/ad_images/_form.html.erb b/app/views/admin/ad_images/_form.html.erb index ce17d490..c19b2cf4 100644 --- a/app/views/admin/ad_images/_form.html.erb +++ b/app/views/admin/ad_images/_form.html.erb @@ -5,6 +5,7 @@ <%= javascript_include_tag "lib/datepicker" %> <%= javascript_include_tag "lib/date.format" %> <%= javascript_include_tag "inc/modal-preview" %> + <%= javascript_include_tag "/static/jquery.cycle.all.latest.js" %> <% end %> @@ -182,9 +183,9 @@
- <%= link_to t("modal.preview"), realtime_preview_admin_ad_banner_path(@ad_image.ad_banner) ,:class=>"preview_trigger btn btn-success" rescue nil%> - - + <%= link_to t("modal.preview"), admin_realtime_preview_ad_banner_path(@ad_image.ad_banner.title) ,:class=>"preview_trigger btn btn-success" rescue nil%> + <%= f.submit t("submit"),:class=>"btn btn-primary" %> + <%= f.submit t("cancel"),:class=>"btn ",:type => 'reset' %>
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 0d440e83..9200492d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,15 +24,13 @@ Orbit::Application.routes.draw do end end - + + match 'ad_banner/:title/preivew' => 'ad_banners#realtime_preview',:as => :realtime_preview_ad_banner,:via => :put resources :ad_banners do collection do match 'new_ad_image' => 'ad_images#new',:as => :new_ad_image,:via => :get match 'new_ad_image' => 'ad_images#create',:as => :create_ad_image,:via => :post end - member do - match 'preivew' => 'ad_banners#realtime_preview',:as => :realtime_preview,:via => :put - end resources :ad_images ,:except => [:show,:index] end resources :dashboards