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] 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 -%> +