From 2c632551e5040ab6497c53d3ab6a287a7c9ff7f7 Mon Sep 17 00:00:00 2001 From: Fu Matthew Date: Wed, 2 Jan 2013 17:51:53 +0800 Subject: [PATCH] fix preview filed after ad_banner created. --- app/assets/javascripts/inc/modal-preview.js | 2 +- app/controllers/pages_controller.rb | 3 ++- app/views/admin/ad_banners/new_created_node.js.erb | 6 +++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/inc/modal-preview.js b/app/assets/javascripts/inc/modal-preview.js index 87973b55..f2483170 100644 --- a/app/assets/javascripts/inc/modal-preview.js +++ b/app/assets/javascripts/inc/modal-preview.js @@ -55,7 +55,7 @@ $(document).ready(function() { // } // }) - $("a.preview_trigger").click(function(){ + $("a.preview_trigger").live('click',function(){ $("#main-wrap").after(""); $.ajax({ type: 'PUT', diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index f39a9078..dada6152 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -17,7 +17,6 @@ class PagesController < ApplicationController def show #begin @item = Item.first(:conditions => {:path => params[:page_name]}) - #binding.pry if @item && @item.is_published && (@item.enabled_for.nil? ? true : @item.enabled_for.include?(I18n.locale.to_s)) impressionist(@item) case @item.class.to_s @@ -66,6 +65,7 @@ class PagesController < ApplicationController def get_item module_app = ModuleApp.first(:conditions => {:key => params[:app_name]}) + if !params[:category_id].blank? && !params[:tag_id].blank? @item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => params[:tag_id]}) @item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => ''}) unless @item @@ -75,6 +75,7 @@ class PagesController < ApplicationController @item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action],tag: params[:tag_id]).any_in(category: [nil,'']).first end @item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action]).all_of("tag" => {"$in" => [nil,'']},"category" => { "$in" => [nil,'']}).first unless @item + @item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action]).first unless @item #TODO 需要做 error handler 處理沒有新增該模組頁面導致錯誤的可能性 end 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 a53135da..df27da4f 100644 --- a/app/views/admin/ad_banners/new_created_node.js.erb +++ b/app/views/admin/ad_banners/new_created_node.js.erb @@ -11,4 +11,8 @@ $("#ad_banner-tab-content").children(".tab-pane").removeClass("active"); $('#post-body-content').find(".nav.nav-tabs").children('li[id!="new_ad_banner_tab_but"]').last().addClass("active"); $("#ad_banner-tab-content").children(".tab-pane").last().addClass("active"); - +<% if params[:action] && params[:action] =='create'%> + var trigger = $("#ad_banner-tab-content").children(".tab-pane").last().find(".preview_trigger"); + new_url = trigger.attr("href").replace(/\/admin\/ad_banners\/.*\/preview/gi,"/admin/ad_banners/<%= @ad_banner.id %>/preview"); + trigger.attr("href",new_url); +<% end %> \ No newline at end of file