From 16ada34585cfd0221670d28d934d89392ff78107 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Thu, 17 May 2012 21:31:29 +0800 Subject: [PATCH] fix ad_banner. new ad_image with best size from ad_banner. content editable at tab --- .../javascripts/lib/contenteditable.js.erb | 35 ++++++++---- app/assets/stylesheets/style.css.erb | 13 +++++ .../admin/ad_banners_controller.rb | 2 +- app/controllers/admin/ad_images_controller.rb | 3 +- app/views/admin/ad_banners/index.html.erb | 5 +- .../bulletins/_modal_preview.html.erb | 55 +++++++++++++++++++ .../bulletins/realtime_preview.js.erb | 2 + .../page_contexts/_modal_preview.html.erb | 55 +++++++++++++++++++ .../page_contexts/realtime_preview.js.erb | 2 + 9 files changed, 159 insertions(+), 13 deletions(-) create mode 100644 vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_modal_preview.html.erb create mode 100644 vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/realtime_preview.js.erb create mode 100644 vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/_modal_preview.html.erb create mode 100644 vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/realtime_preview.js.erb diff --git a/app/assets/javascripts/lib/contenteditable.js.erb b/app/assets/javascripts/lib/contenteditable.js.erb index 28dc9137..515be3e6 100644 --- a/app/assets/javascripts/lib/contenteditable.js.erb +++ b/app/assets/javascripts/lib/contenteditable.js.erb @@ -1,25 +1,37 @@ <%#= encoding: utf-8 %> $(function() { var content_holder, content; - var selector = 'li[contenteditable="true"]'; + var selector = 'a[contenteditable="true"]'; // prevent clicks inside editable area to fire // a click event on the body // and therefor saving our content before we even edit it - $(selector).click(function(e) { - e.stopPropagation(); - }); + +$(".nav-tabs").find(".icons-pencil").click(function(){ + $(this).css({ + "display" : "none" + }) + $(this).next().attr("contenteditable",true).addClass("edit"); + // $(selector).click(function(e) { + // e.stopPropagation(); + // }); // initialize the "save" function $(selector).focus(function(e) { content_holder = $(this); - content = content_holder.html(); - + content = content_holder.html(); // one click outside the editable area saves the content - $('body').one('click', function(e) { + $(selector).keypress( function(e) { // but not if the content didn't change - if ($(e.target).is(selector) || content == content_holder.html()) { - return; - } + //alert('out!!'); + if(e.keyCode == 13){ + $(".nav-tabs>li>a").removeClass("edit"); + $(this).prev(".icons-pencil").css({ + "display" : "block" + }) + e.preventDefault(); + // if ($(e.target).is(selector) || content == content_holder.html()) { + // return; + // } $.ajax({ url: content_holder.data('edit-url'), @@ -27,6 +39,7 @@ $(function() { dataType: 'json', data: { body: content_holder.html() }, success: function(json) { + $(selector).attr("contenteditable",false) alert("<%= I18n.t("admin.contenteditable.update_done") %>"); //content_holder.effect('highlight', {'color': '#0f0'}, 3000); }, @@ -36,6 +49,8 @@ $(function() { content_holder.html(content); } }); + } }); }); +}); }); \ No newline at end of file diff --git a/app/assets/stylesheets/style.css.erb b/app/assets/stylesheets/style.css.erb index ba1c3066..fa79084f 100644 --- a/app/assets/stylesheets/style.css.erb +++ b/app/assets/stylesheets/style.css.erb @@ -606,6 +606,19 @@ .news_paragraph p { line-height: 20px; } +.nav-tabs>li>.edit, .nav-tabs>li>.edit:hover { + background-color: #333; + color: #FFF; + padding-right: 12px; +} +.nav-tabs li .icons-pencil { + float: right; + margin-top: 8px; +} +.nav-tabs li a { + padding-right: 32px; +} + /*icons*/ .the-icons i:after { diff --git a/app/controllers/admin/ad_banners_controller.rb b/app/controllers/admin/ad_banners_controller.rb index 347b9e88..cd436a12 100644 --- a/app/controllers/admin/ad_banners_controller.rb +++ b/app/controllers/admin/ad_banners_controller.rb @@ -6,7 +6,7 @@ class Admin::AdBannersController < OrbitBackendController def rename @ad_banner = AdBanner.find(params[:id]) - @ad_banner.title = Nokogiri::HTML.fragment(params["body"]).at("a").children().to_s + @ad_banner.title = params[:body] render :json => {:success =>@ad_banner.save!} end def destroy diff --git a/app/controllers/admin/ad_images_controller.rb b/app/controllers/admin/ad_images_controller.rb index d2039ab5..945629ed 100644 --- a/app/controllers/admin/ad_images_controller.rb +++ b/app/controllers/admin/ad_images_controller.rb @@ -18,7 +18,8 @@ class Admin::AdImagesController < ApplicationController end def new - @ad_image =AdImage.new + ad_banner = AdBanner.find params[:ad_banner_id] + @ad_image =ad_banner.ad_images.build @ad_image.post_date = Date.today @ad_image.unpost_date = Date.today + 30 #render :action => 'new',:url=> {:ad_banner_id => params.has_key?(:ad_banner_id)? params[:ad_banner_id],nil} diff --git a/app/views/admin/ad_banners/index.html.erb b/app/views/admin/ad_banners/index.html.erb index 3e3b4689..b4be090f 100644 --- a/app/views/admin/ad_banners/index.html.erb +++ b/app/views/admin/ad_banners/index.html.erb @@ -12,7 +12,10 @@