From c57ba305e9031d692b1098900bb4bfd8335fd2f4 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Mon, 23 Apr 2012 17:03:55 +0800 Subject: [PATCH] Fix ad_banner --- app/assets/javascripts/inc/modal-preview.js | 17 ++++++++++++----- app/models/ad_banner.rb | 10 +++++++++- .../admin/ad_banners/_ad_banner_tab.html.erb | 2 +- .../ad_banners/_modal_ad_banner_form.html.erb | 10 ++++++---- config/locales/en.yml | 1 + config/locales/zh_tw.yml | 1 + config/routes.rb | 2 +- 7 files changed, 31 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/inc/modal-preview.js b/app/assets/javascripts/inc/modal-preview.js index 2f915f6c..35195999 100644 --- a/app/assets/javascripts/inc/modal-preview.js +++ b/app/assets/javascripts/inc/modal-preview.js @@ -6,10 +6,17 @@ $(document).ready(function() { $("a.preview_trigger").click(function(){ $(this).after(""); $.ajax({ - type:"put", + type: 'PUT', + //async : true, url:$(this).attr("href"), - data:$(this).parents("form").serialize() - }).done(function(){ $("#"+start_modal_with_id).modal('show');}); - return false;} - ); + contentType: 'application/javascript; charset=utf-8', + data:$(this).parents("form").serialize(), + success: function (msg) { + $("#"+start_modal_with_id).modal('show'); }, + error: function(){ + alert("ERROR"); + } + }); + return false; + }); }); \ No newline at end of file diff --git a/app/models/ad_banner.rb b/app/models/ad_banner.rb index 0147c3d2..7377d852 100644 --- a/app/models/ad_banner.rb +++ b/app/models/ad_banner.rb @@ -4,7 +4,7 @@ class AdBanner include Mongoid::MultiParameterAttributes field :title - field :transition_sec,type: Integer + field :transition_msec,type: Integer field :ad_fx #TODO Design should explain before_save :save_or_destroy @@ -13,6 +13,14 @@ class AdBanner 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"] +attr_writer :transition_sec + def transition_sec + self.transition_msec/1000 + end + + def transition_sec=(sec) + self.transition_msec = sec.to_i*1000 + end def preview_clone preview_banner = self.clone 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 27047348..c1e406db 100644 --- a/app/views/admin/ad_banners/_ad_banner_tab.html.erb +++ b/app/views/admin/ad_banners/_ad_banner_tab.html.erb @@ -5,7 +5,7 @@ <%= f.label :ad_fx, t('admin.ad.ab_fx') %> <%= f.select :ad_fx ,AdBanner::FX_TYPES %> <%= f.label :transition_sec, t('admin.ad.transition_sec') %> - <%= f.text_field :transition_sec,:placeholder=>"3秒請輸入3000",:class=> "span3" %> <%= t("admin.ad.trans_unit_sec") %> + <%= f.text_field :transition_sec,:placeholder=>t('admin.ad.sec_place_holder'),:class=> "span3" %> <%= t("admin.ad.trans_unit_sec") %> <%= f.submit t("admin.ad.update_banner") %> <%= f.submit t("cancel"),:type=>'reset' %>
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 235e7e15..cac5f1a1 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 @@ -40,11 +40,13 @@ $('#new_ad_banner_tab_but').on('shown', function (e) { $('#new-a-banner').modal({show: true}); }); -<% if params[:action] == "new" -%> - $('#new-a-banner').modal({show: true}); -<% end -%> + $('#new-a-banner').on('hidden', function (e) { - $(".nav.nav-tabs a[id!='new_ad_banner_tab_but']:last").tab('show'); + $('#post-body-content').find(".nav.nav-tabs").children('li.active').removeClass("active"); + + $('#post-body-content').find(".nav.nav-tabs").children('li[id!="new_ad_banner_tab_but"]').last().addClass("active"); + $('.tab-pane').find(".nav.nav-tabs").children('li[id!="new_ad_banner_tab_but"]').last().addClass("active"); + }); diff --git a/config/locales/en.yml b/config/locales/en.yml index de58faa7..46c86825 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -44,6 +44,7 @@ en: action: Action ad_banner: AD Banner ad: + sec_place_holder: Enter 3 if 3 sec ab_fx: FX all_banners: AdBanner list banner_best_size: Banner Best Size diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index cc185ab5..bb3fa5ca 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -41,6 +41,7 @@ zh_tw: action: 操作 ad_banner: 廣告輪播 ad: + sec_place_holder: 3秒請輸入3 ab_fx: 轉場特效 all_banners: 輪播清單 banner_best_size: Banner 尺寸 diff --git a/config/routes.rb b/config/routes.rb index 7ea7edd8..3b48f300 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -25,7 +25,7 @@ Orbit::Application.routes.draw do end - match 'ad_banner/:title/preivew' => 'ad_banners#realtime_preview',:as => :realtime_preview_ad_banner,:via => :put + match 'ad_banner/:title/preview' => '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