From 0c46b4da23f7b8c2c929a44222e274a406016728 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Wed, 18 Apr 2012 15:26:59 +0800 Subject: [PATCH] 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 fd62a95e..2f915f6c 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 c3d0cc58..19983b66 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 47986323..530e45cb 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 66f8de2b..36ebc4a3 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 00000000..60f1d261 --- /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 00000000..140be0b4 --- /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"); +