From d81ca40f90079c011c876acf70172c8570d0662a Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Fri, 13 Apr 2012 17:24:30 +0800 Subject: [PATCH 1/9] AdBanner i18n vars patch --- app/controllers/admin/ad_banners_controller.rb | 6 ++++-- app/views/admin/ad_banners/_ad_banner_tab.html.erb | 6 +++--- config/locales/en.yml | 10 ++++++++++ config/locales/zh_tw.yml | 2 ++ config/routes.rb | 1 + 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/ad_banners_controller.rb b/app/controllers/admin/ad_banners_controller.rb index 95ce7e7c3..a6f4fd5fe 100644 --- a/app/controllers/admin/ad_banners_controller.rb +++ b/app/controllers/admin/ad_banners_controller.rb @@ -39,8 +39,10 @@ class Admin::AdBannersController < ApplicationController redirect_to admin_ad_banners_url end - def destroy_ad_image - + def realtime_preview + @ad_banner = AdBanner.find(params[:id]) + @ad_banner.update_attributes(params[:ad_banner]) + render end def index 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 d9b1b9025..10a98b522 100644 --- a/app/views/admin/ad_banners/_ad_banner_tab.html.erb +++ b/app/views/admin/ad_banners/_ad_banner_tab.html.erb @@ -1,14 +1,14 @@
" id=<%= ad_banner_tab.title %>> -

尺寸:

+

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

<%= form_for ad_banner_tab,:url=> admin_ad_banner_path(ad_banner_tab),:method => :put,:class=>"input-medium" do |f| -%> <%= 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.submit %> - <%= f.submit 'Cancel',:type=>'reset' %> + <%= f.submit t("admin.ad.update_banner") %> + <%= f.submit t("cancel"),:type=>'reset' %>
<%= 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" } %> diff --git a/config/locales/en.yml b/config/locales/en.yml index da72a4eb9..9b5861488 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -42,6 +42,16 @@ en: admin: action: Action ad_banner: AD Banner + ad: + ab_fx: FX + all_banners: AdBanner list + banner_best_size: Banner Best Size + new_banner: New banner + new_image: New image + title: Title + transition_sec: Transition time + trans_unit_sec: sec + update_banner: Update Banner add: Add add_item: Add item add_language: Add language diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 491d80e8d..ebc6e6b31 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -42,11 +42,13 @@ zh_tw: ad: ab_fx: 轉場特效 all_banners: 輪播清單 + banner_best_size: Banner 尺寸 new_banner: 新增輪播 new_image: 新增橫幅 title: 標題 transition_sec: 轉場單位時間 trans_unit_sec: 秒 + update_banner: 更新輪播 add: 新增 add_item: 新增項目 add_language: 新增語言 diff --git a/config/routes.rb b/config/routes.rb index 99860bb65..cdf3a7f05 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,6 +26,7 @@ Orbit::Application.routes.draw do resources :ad_banners do + match 'preview/:id' => 'ad_banners#realtime_preview',:as => :realtime_preview,:via => :put 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 From 7cf00d1d9322ca0b3e83f0752ca6f9e09ef5d1fe Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Fri, 13 Apr 2012 17:51:19 +0800 Subject: [PATCH 2/9] text area for ad_image --- app/views/admin/ad_images/_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/ad_images/_form.html.erb b/app/views/admin/ad_images/_form.html.erb index 1089db3b0..700aec58f 100644 --- a/app/views/admin/ad_images/_form.html.erb +++ b/app/views/admin/ad_images/_form.html.erb @@ -167,7 +167,7 @@
<%= f.fields_for :context, @ad_image.context do |f| %> - <%= f.text_area locale,:style => "width:100%", :class => "asd_tinymce_textarea" %> + <%= f.text_area locale,:style => "width:100%", :class => "tinymce_textarea" %> <% end %>
From 6cdebb440d23ed775b938cf7be3b3ab17956f886 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Fri, 13 Apr 2012 18:02:36 +0800 Subject: [PATCH 3/9] Ray's fix for ad_banner --- app/assets/stylesheets/widget.css | 68 ++++++++++++++++--------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/app/assets/stylesheets/widget.css b/app/assets/stylesheets/widget.css index 7a658f364..81862e25d 100644 --- a/app/assets/stylesheets/widget.css +++ b/app/assets/stylesheets/widget.css @@ -66,22 +66,20 @@ overflow: hidden; } .file-upload .file-name { - white-space: nowrap; - overflow: hidden; - border-style: solid; - border-width: 1px 1px 1px 0; - border-color: #CCC; - display: inline-block; - float: left; - padding: 4px 10px; - height: 18px; - line-height: 18px; - -webkit-border-radius: 0 3px 3px 0; - -moz-border-radius: 0 3px 3px 0; - border-radius: 0 3px 3px 0; - text-align: left; - margin: 0; - width: 182px; + border-color: #CCCCCC; + border-radius: 0 3px 3px 0; + border-style: solid; + border-width: 1px 1px 1px 0; + display: inline-block; + float: left; + height: 18px; + line-height: 18px; + margin: 0; + overflow: hidden; + padding: 4px 10px; + text-align: left; + white-space: nowrap; + width: 182px; } .file-upload .upload { margin:0; @@ -111,11 +109,11 @@ width: 100%; } .widget-box .widgetInfo { - display: inline-block; - text-align: center; - width: 255px; - margin : 0px 0 5px; - padding: 5px 10px; + display: inline-block; + margin: 0 0 5px; + padding: 5px 10px; + text-align: center; + width: 255px; } .file-upload .input-medium { border-radius: 3px 3px 3px 3px !important; @@ -128,21 +126,25 @@ } /*Date*/ .showDate { - border-style: solid; - border-width: 1px 0 1px 1px; - border-color: #CCC; - display: inline-block; - float: left; - padding: 4px 10px; - height: 18px; - line-height: 18px; - -webkit-border-radius: 3px 0 0 3px; - -moz-border-radius: 3px 0 0 3px; - border-radius: 3px 0 0 3px; - text-align: center; + border-color: #CCCCCC; + border-radius: 3px 0 0 3px; + border-style: solid; + border-width: 1px 0 1px 1px; + display: inline-block; + float: left; + height: 18px; + line-height: 18px; + padding: 4px 10px; + text-align: center; } .calendarInput { position: absolute; visibility: hidden; left: 11px; +} +.file-upload .input-medium { + border-radius: 3px 3px 3px 3px !important; + position: relative; + width: 267px; + z-index: 5; } \ No newline at end of file From 06a3128be5ac7d43f3644ebc67ce02543c853acb Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 17 Apr 2012 11:34:25 +0800 Subject: [PATCH 4/9] realtime preview is working. but save to object when preview --- app/assets/javascripts/inc/modal-preview.js | 15 ++++ app/assets/stylesheets/new_admin.css.erb | 2 +- app/assets/stylesheets/widget.css | 70 +++++++++---------- .../admin/ad_banners_controller.rb | 4 +- .../admin/ad_banners/_ad_banner_tab.html.erb | 4 +- .../admin/ad_banners/_modal_preview.html.erb | 35 ++++++++++ app/views/admin/ad_banners/index.html.erb | 8 ++- .../admin/ad_banners/realtime_preview.js.erb | 2 + config/locales/en.yml | 7 +- config/locales/zh_tw.yml | 3 + config/routes.rb | 4 +- 11 files changed, 111 insertions(+), 43 deletions(-) create mode 100644 app/assets/javascripts/inc/modal-preview.js create mode 100644 app/views/admin/ad_banners/_modal_preview.html.erb create mode 100644 app/views/admin/ad_banners/realtime_preview.js.erb diff --git a/app/assets/javascripts/inc/modal-preview.js b/app/assets/javascripts/inc/modal-preview.js new file mode 100644 index 000000000..3453c0968 --- /dev/null +++ b/app/assets/javascripts/inc/modal-preview.js @@ -0,0 +1,15 @@ +//Preview need a link in form as Ex and a corresponding PUT action in controller +//Ex preview trigger: +// <%= link_to "NewPreview", realtime_preview_admin_ad_banner_path(ad_banner_tab) , :class=>'preview_trigger'%> + +$(document).ready(function() { + $("a.preview_trigger").click(function(){ + $(this).after("

"); + $.ajax({ + type:"PUT", + url:$(this).attr("href"), + data:$(this).parents("form").serialize() + }).done(function(){ $("#"+start_modal_with_id).modal('show');}); + return false;} + ); +}); \ No newline at end of file diff --git a/app/assets/stylesheets/new_admin.css.erb b/app/assets/stylesheets/new_admin.css.erb index d81761bcf..12e32b993 100644 --- a/app/assets/stylesheets/new_admin.css.erb +++ b/app/assets/stylesheets/new_admin.css.erb @@ -12,4 +12,4 @@ *= require style *= require scroll_style *= require isotope -*/ \ No newline at end of file +*/ \ No newline at end of file diff --git a/app/assets/stylesheets/widget.css b/app/assets/stylesheets/widget.css index 81862e25d..3638bd4a8 100644 --- a/app/assets/stylesheets/widget.css +++ b/app/assets/stylesheets/widget.css @@ -59,27 +59,29 @@ } .select-role { display:none; - padding: 10px 0; + overflow:hidden; } .file-upload { position:relative; overflow: hidden; } .file-upload .file-name { - border-color: #CCCCCC; - border-radius: 0 3px 3px 0; - border-style: solid; - border-width: 1px 1px 1px 0; - display: inline-block; - float: left; - height: 18px; - line-height: 18px; - margin: 0; - overflow: hidden; - padding: 4px 10px; - text-align: left; - white-space: nowrap; - width: 182px; + white-space: nowrap; + overflow: hidden; + border-style: solid; + border-width: 1px 1px 1px 0; + border-color: #CCC; + display: inline-block; + float: left; + padding: 4px 10px; + height: 18px; + line-height: 18px; + -webkit-border-radius: 0 3px 3px 0; + -moz-border-radius: 0 3px 3px 0; + border-radius: 0 3px 3px 0; + text-align: left; + margin: 0; + width: 182px; } .file-upload .upload { margin:0; @@ -109,11 +111,11 @@ width: 100%; } .widget-box .widgetInfo { - display: inline-block; - margin: 0 0 5px; - padding: 5px 10px; - text-align: center; - width: 255px; + display: inline-block; + text-align: center; + width: 255px; + margin : 0px 0 5px; + padding: 5px 10px; } .file-upload .input-medium { border-radius: 3px 3px 3px 3px !important; @@ -126,25 +128,21 @@ } /*Date*/ .showDate { - border-color: #CCCCCC; - border-radius: 3px 0 0 3px; - border-style: solid; - border-width: 1px 0 1px 1px; - display: inline-block; - float: left; - height: 18px; - line-height: 18px; - padding: 4px 10px; - text-align: center; + border-style: solid; + border-width: 1px 0 1px 1px; + border-color: #CCC; + display: inline-block; + float: left; + padding: 4px 10px; + height: 18px; + line-height: 18px; + -webkit-border-radius: 3px 0 0 3px; + -moz-border-radius: 3px 0 0 3px; + border-radius: 3px 0 0 3px; + text-align: center; } .calendarInput { position: absolute; visibility: hidden; left: 11px; -} -.file-upload .input-medium { - border-radius: 3px 3px 3px 3px !important; - position: relative; - width: 267px; - z-index: 5; } \ No newline at end of file diff --git a/app/controllers/admin/ad_banners_controller.rb b/app/controllers/admin/ad_banners_controller.rb index a6f4fd5fe..5ce44a0dd 100644 --- a/app/controllers/admin/ad_banners_controller.rb +++ b/app/controllers/admin/ad_banners_controller.rb @@ -40,9 +40,9 @@ class Admin::AdBannersController < ApplicationController end def realtime_preview - @ad_banner = AdBanner.find(params[:id]) + @ad_banner = AdBanner.find(params[:id]).clone + debugger @ad_banner.update_attributes(params[:ad_banner]) - render end def index 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 10a98b522..7bba88c6a 100644 --- a/app/views/admin/ad_banners/_ad_banner_tab.html.erb +++ b/app/views/admin/ad_banners/_ad_banner_tab.html.erb @@ -13,7 +13,9 @@ <%= 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 'Add AdImage',new_admin_ad_banner_ad_image_path(ad_banner_tab) %> + <%= link_to "NewPreview", realtime_preview_admin_ad_banner_path(ad_banner_tab) , :class=>'preview_trigger'%> +
<% end -%> - <%= render :partial => 'preview_block',:locals=> {:ad_banner =>ad_banner_tab} %> + <%#= render :partial => 'preview_block',:locals=> {:ad_banner =>ad_banner_tab} %>
diff --git a/app/views/admin/ad_banners/_modal_preview.html.erb b/app/views/admin/ad_banners/_modal_preview.html.erb new file mode 100644 index 000000000..27222e57d --- /dev/null +++ b/app/views/admin/ad_banners/_modal_preview.html.erb @@ -0,0 +1,35 @@ +<% if ad_banner -%> + + + +<% end -%> + + + diff --git a/app/views/admin/ad_banners/index.html.erb b/app/views/admin/ad_banners/index.html.erb index e6ebfd5d9..365d020d4 100644 --- a/app/views/admin/ad_banners/index.html.erb +++ b/app/views/admin/ad_banners/index.html.erb @@ -1,4 +1,10 @@ -<%= stylesheet_link_tag "admin/ad_banner_preview" %> +<% content_for :page_specific_css do -%> + <%#= stylesheet_link_tag "admin/ad_banner_preview" %> +<% end -%> +<% content_for :page_specific_css do -%> + <%= javascript_include_tag "inc/modal-preview" %> +<% end -%> +
- - - + <%= link_to t("modal.preview"), realtime_preview_admin_ad_banner_path(@ad_image.ad_banner) ,:class=>"preview_trigger btn btn-success" rescue nil%> + +
\ No newline at end of file diff --git a/app/views/layouts/_side_bar.html.erb b/app/views/layouts/_side_bar.html.erb index f74f24f66..eb3bac863 100644 --- a/app/views/layouts/_side_bar.html.erb +++ b/app/views/layouts/_side_bar.html.erb @@ -32,9 +32,9 @@ <%= content_tag :li, :class => active_for_controllers('ad_banners', 'ad_images') do -%> <%= link_to content_tag(:i, nil, :class => 'icons-link') + t('admin.ad_banner'), admin_ad_banners_path %> <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('ad_banners', 'ad_images')) do -%> - <%= content_tag :li, link_to(t('admin.all_ad_banners'), admin_ad_banners_path), :class => active_for_action('ad_banners', 'index') %> - <%= content_tag :li, link_to(t('admin.new_ad_banner'), new_admin_ad_banner_path), :class => active_for_action('ad_banners', 'new') %> - <%= content_tag :li, link_to(t('admin.new_ad_image'), new_ad_image_admin_ad_banners_path), :class => active_for_action('ad_images', 'new') %> + <%= content_tag :li, link_to(t('admin.ad.all_banners'), admin_ad_banners_path), :class => active_for_action('ad_banners', 'index') %> + <%= content_tag :li, link_to(t('admin.ad.new_banner'), new_admin_ad_banner_path), :class => active_for_action('ad_banners', 'new') %> + <%= content_tag :li, link_to(t('admin.ad.new_image'), new_ad_image_admin_ad_banners_path), :class => active_for_action('ad_images', 'new') %> <% end %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 2716588ad..0d440e830 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,13 +26,13 @@ Orbit::Application.routes.draw do resources :ad_banners do - member do - match 'preivew' => 'ad_banners#realtime_preview',:as => :realtime_preview,:via => :put - end 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 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 6/9] 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 3453c0968..fd62a95e4 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 4d2ed213b..c3d0cc583 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 a2ac20964..0147c3d28 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 001726f4b..479863234 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 8e8de1d9a..66f8de2bc 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 365d020d4..4b7dfef26 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 ce17d4909..c19b2cf41 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 0d440e830..9200492d2 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 From 8d776fd30d13da44223d9b32a00b71b7fe34bab4 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Wed, 18 Apr 2012 15:26:59 +0800 Subject: [PATCH 7/9] AdImage and AnBanner JS fixed --- app/assets/javascripts/inc/modal-preview.js | 2 +- app/controllers/admin/ad_banners_controller.rb | 15 ++++++++++----- .../admin/ad_banners/_ad_banner_tab.html.erb | 2 +- .../ad_banners/_modal_ad_banner_form.html.erb | 4 ++-- .../admin/ad_banners/create_error_msg.js.erb | 1 + .../admin/ad_banners/new_created_node.js.erb | 7 +++++++ 6 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 app/views/admin/ad_banners/create_error_msg.js.erb create mode 100644 app/views/admin/ad_banners/new_created_node.js.erb diff --git a/app/assets/javascripts/inc/modal-preview.js b/app/assets/javascripts/inc/modal-preview.js index fd62a95e4..2f915f6cf 100644 --- a/app/assets/javascripts/inc/modal-preview.js +++ b/app/assets/javascripts/inc/modal-preview.js @@ -6,7 +6,7 @@ $(document).ready(function() { $("a.preview_trigger").click(function(){ $(this).after(""); $.ajax({ - type:"PUT", + type:"put", url:$(this).attr("href"), data:$(this).parents("form").serialize() }).done(function(){ $("#"+start_modal_with_id).modal('show');}); diff --git a/app/controllers/admin/ad_banners_controller.rb b/app/controllers/admin/ad_banners_controller.rb index c3d0cc583..19983b667 100644 --- a/app/controllers/admin/ad_banners_controller.rb +++ b/app/controllers/admin/ad_banners_controller.rb @@ -22,9 +22,14 @@ class Admin::AdBannersController < ApplicationController def create @ad_banner = AdBanner.new(params[:ad_banner]) - @ad_banner.save - redirect_to admin_ad_banners_url - + if @ad_banner.save + @active = @ad_banner + respond_to do |format| + format.js {render 'new_created_node'} + end + else + render 'create_error_msg' + end end def edit @@ -40,8 +45,8 @@ class Admin::AdBannersController < ApplicationController end def realtime_preview - @ad_banner = AdBanner.find(conditions: { title: params[:title] }).preview_clone - #@ad_banner.update_attributes(params[:ad_banner]).update_attributes(params[:ad_images]) + @ad_banner = AdBanner.first(conditions: { title: params[:title] }).preview_clone + @ad_banner.update_attributes(params[:ad_banner]).update_attributes(params[:ad_images]) end def index 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 479863234..530e45cbe 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,4 @@ -
" id=<%= ad_banner_tab.title %>> +
" id=<%= ad_banner_tab.title %>>

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

<%= form_for ad_banner_tab,:url=> admin_ad_banner_path(ad_banner_tab),:method => :put,:class=>"input-medium" do |f| -%> 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 66f8de2bc..36ebc4a37 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 @@ -4,7 +4,7 @@ <% end %> diff --git a/app/views/admin/ad_banners/create_error_msg.js.erb b/app/views/admin/ad_banners/create_error_msg.js.erb new file mode 100644 index 000000000..60f1d261e --- /dev/null +++ b/app/views/admin/ad_banners/create_error_msg.js.erb @@ -0,0 +1 @@ +alert("Error occures:<%= @ad_banner.errors.full_messages%>"); \ No newline at end of file diff --git a/app/views/admin/ad_banners/new_created_node.js.erb b/app/views/admin/ad_banners/new_created_node.js.erb new file mode 100644 index 000000000..140be0b44 --- /dev/null +++ b/app/views/admin/ad_banners/new_created_node.js.erb @@ -0,0 +1,7 @@ +$('<%= escape_javascript(content_tag(:li,link_to(@ad_banner.title,"##{@ad_banner.title}",:data=>{:toggle=>"tab"}))) %>').insertBefore("#new_ad_banner_tab_but"); +$('<%= escape_javascript(render(:partial => "ad_banner_tab",:locals => {:ad_banner_tab => @ad_banner})) %>').insertBefore($("#new-a-banner")); + +$('.modal').modal('hide'); +$('#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"); + From 0ddb66a3c91e0521fd747d2ddd064885726a72a1 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Wed, 18 Apr 2012 15:33:11 +0800 Subject: [PATCH 8/9] add i18n vars --- app/views/admin/ad_banners/_ad_image_update.html.erb | 2 +- config/locales/en.yml | 2 ++ config/locales/zh_tw.yml | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/views/admin/ad_banners/_ad_image_update.html.erb b/app/views/admin/ad_banners/_ad_image_update.html.erb index 583c3316e..c51b58853 100644 --- a/app/views/admin/ad_banners/_ad_image_update.html.erb +++ b/app/views/admin/ad_banners/_ad_image_update.html.erb @@ -1,7 +1,7 @@
  • <%= image_tag ad_image.file rescue nil%>

    - <%= ad_image.display? ? '[Showing]' : '[NotShawing]' %> + <%= ad_image.display? ? "[#{t('admin.ad.showing')}]" : "[#{t('admin.ad.not_showing')}]" %> <%= "#{ad_image.post_date ||'NeedReset' }~#{ad_image.unpost_date || 'NeedReset'}" %>

    diff --git a/config/locales/en.yml b/config/locales/en.yml index d019de7eb..f34557ca7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -48,6 +48,8 @@ en: banner_best_size: Banner Best Size new_banner: New banner new_image: New image + showing: Showing + not_showing: NotShowing title: Title transition_sec: Transition time trans_unit_sec: sec diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 708def101..2615c99c0 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -45,6 +45,8 @@ zh_tw: banner_best_size: Banner 尺寸 new_banner: 新增輪播 new_image: 新增橫幅 + showing: 顯示中 + not_showing: 沒有顯示 title: 標題 transition_sec: 轉場單位時間 trans_unit_sec: 秒 From 170c12bcdd08601bb2fa4a6c86e69856b1e5313a Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Wed, 18 Apr 2012 16:24:17 +0800 Subject: [PATCH 9/9] fix js --- .../ad_banners/_modal_ad_banner_form.html.erb | 14 ++++++-------- app/views/admin/ad_banners/index.html.erb | 2 +- app/views/admin/ad_banners/new_created_node.js.erb | 1 + 3 files changed, 8 insertions(+), 9 deletions(-) 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 36ebc4a37..235e7e157 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 @@ -36,17 +36,15 @@ <% end %>

  • diff --git a/app/views/admin/ad_banners/index.html.erb b/app/views/admin/ad_banners/index.html.erb index 4b7dfef26..8307885ab 100644 --- a/app/views/admin/ad_banners/index.html.erb +++ b/app/views/admin/ad_banners/index.html.erb @@ -12,7 +12,7 @@ <% @ad_banners.each do |ab| %> <%= content_tag :li,link_to(ab.title,"##{ab.title}",:data=>{:toggle=>"tab"}),:class => (ab == @active ? 'active' : nil ) %> <% end -%> - <%= content_tag :li,link_to('New',"#new-a-banner",:data=>{:toggle=>"tab"}),:id=>'new_ad_banner_tab_but',:class => (@active.nil? ? 'active' : nil ) %> + <%= content_tag :li,link_to(t("admin.ad.new_banner"),"#new-a-banner",:data=>{:toggle=>"tab"}),:id=>'new_ad_banner_tab_but',:class => (@active.nil? ? 'active' : nil ) %> diff --git a/app/views/admin/ad_banners/new_created_node.js.erb b/app/views/admin/ad_banners/new_created_node.js.erb index 140be0b44..86970e6a3 100644 --- a/app/views/admin/ad_banners/new_created_node.js.erb +++ b/app/views/admin/ad_banners/new_created_node.js.erb @@ -2,6 +2,7 @@ $('<%= escape_javascript(content_tag(:li,link_to(@ad_banner.title,"##{@ad_banner $('<%= escape_javascript(render(:partial => "ad_banner_tab",:locals => {:ad_banner_tab => @ad_banner})) %>').insertBefore($("#new-a-banner")); $('.modal').modal('hide'); +$('#new-a-banner').unbind(); $('#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");