From ae1595a0081d356cdb853c2a4a0d78f8c28bd0c4 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 4 Sep 2012 09:24:12 +0800 Subject: [PATCH] view for preview --- app/assets/javascripts/inc/modal-preview.js | 20 ++++++++ .../back_end/bulletins/_form.html.erb | 1 + .../announcement/config/routes.rb | 1 + .../back_end/news_bulletins/_form.html.erb | 5 +- .../news_bulletins/_modal_preview.html.erb | 47 +++++++++++++++++++ .../back_end/news_bulletins/preview.js.erb | 5 ++ vendor/built_in_modules/news/config/routes.rb | 2 + 7 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_modal_preview.html.erb create mode 100644 vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/preview.js.erb diff --git a/app/assets/javascripts/inc/modal-preview.js b/app/assets/javascripts/inc/modal-preview.js index 959f04b2..496b2080 100644 --- a/app/assets/javascripts/inc/modal-preview.js +++ b/app/assets/javascripts/inc/modal-preview.js @@ -3,6 +3,26 @@ // <%= link_to "NewPreview", realtime_preview_admin_ad_banner_path(ad_banner_tab) , :class=>'preview_trigger'%> $(document).ready(function() { + $("a.post_preview").click(function(e){ + $("#main-wrap").after(""); + e.preventDefault(); + var form = $(this).parents("form").first() + //var cont = form["content"].value; + $.ajax({ + type: 'POST', + url: $(this).attr("href")+'?preview=true', + data: form.serialize(), + dataType: "script", + success: function (msg) { + $("#"+start_modal_with_id).modal('show'); }, + error: function(){ + alert("ERROR"); + } + }); + + return false + }); + $("a.preview_trigger").click(function(){ $("#main-wrap").after(""); $.ajax({ diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb index 23e8b82e..8c32cc6b 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb @@ -238,6 +238,7 @@
+ <%= link_to t('preview'),panel_announcement_back_end_bulletin_preview_path, :class=>"btn" %> <%= f.submit t('submit'), :class=>'btn btn-primary' %> <%= link_to t('cancel'), get_go_back, :class=>"btn" %>
diff --git a/vendor/built_in_modules/announcement/config/routes.rb b/vendor/built_in_modules/announcement/config/routes.rb index b2d8d161..48308850 100644 --- a/vendor/built_in_modules/announcement/config/routes.rb +++ b/vendor/built_in_modules/announcement/config/routes.rb @@ -15,6 +15,7 @@ Rails.application.routes.draw do get 'load_quick_edit' end collection do + post "preview" get 'delete' end match "file_quick_add/:bulletin_id" => "bulletins#file_quick_add" ,:as => :file_quick_add diff --git a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_form.html.erb b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_form.html.erb index 3460f8d8..29d75d61 100644 --- a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_form.html.erb +++ b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_form.html.erb @@ -1,5 +1,7 @@ <% # encoding: utf-8 %> - +<% content_for :page_specific_javascript do -%> + <%= javascript_include_tag "inc/modal-preview" %> +<% end -%> <%= f.error_messages %> @@ -279,6 +281,7 @@
+ <%= link_to t('preview'),preview_panel_news_back_end_news_bulletins_path, :class=>"btn post_preview",:method=>:post , :remote => true%> <%= f.submit t('submit'), :class=>'btn btn-primary' %> <%= link_to t('cancel'), get_go_back, :class=>"btn" %>
diff --git a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_modal_preview.html.erb b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_modal_preview.html.erb new file mode 100644 index 00000000..c5ed3aba --- /dev/null +++ b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_modal_preview.html.erb @@ -0,0 +1,47 @@ + \ No newline at end of file diff --git a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/preview.js.erb b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/preview.js.erb new file mode 100644 index 00000000..ff3f4e3a --- /dev/null +++ b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/preview.js.erb @@ -0,0 +1,5 @@ +$('#show_preview').html('<%=escape_javascript(render :partial=>"modal_preview",:locals=>{:news_bulletin => @preview_news_bulletin}) %>'); +var start_modal_with_id = "<%= @preview_news_bulletin.id %>"; +$("#"+start_modal_with_id).css("width","1050px"); +$("#"+start_modal_with_id).css("height","768px"); +$("#"+start_modal_with_id).css("margin","-270px 0 0 -550px"); \ No newline at end of file diff --git a/vendor/built_in_modules/news/config/routes.rb b/vendor/built_in_modules/news/config/routes.rb index 5220248c..2bab5dc3 100644 --- a/vendor/built_in_modules/news/config/routes.rb +++ b/vendor/built_in_modules/news/config/routes.rb @@ -11,10 +11,12 @@ Rails.application.routes.draw do match "approve/:news_bulletin_id" => "news_approvals#approve",:as => :approve,:via => :post match "link_quick_add/:news_bulletin_id" => "news_bulletins#link_quick_add" ,:as => :link_quick_add match "link_quick_edit/:news_bulletin_id" => "news_bulletins#link_quick_edit" ,:as => :link_quick_edit + member do get 'load_quick_edit' end collection do + post "preview" get 'delete' end match "file_quick_add/:news_bulletin_id" => "news_bulletins#file_quick_add" ,:as => :file_quick_add