complete preview for both new and announcement
This commit is contained in:
1 parent
8bd5481b3f
commit
6044857fea
24 files changed
+301
-67
No files matched your search
@@ -3,25 +3,53 @@
|
||||
// <%= 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("<span id='show_preview'></span>");
|
||||
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
|
||||
});
|
||||
// $(".post_preview").click(function(e){
|
||||
// $("#main-wrap").after("<span id='show_preview'></span>");
|
||||
// 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");
|
||||
// // }
|
||||
// // });
|
||||
// url = "/panel/news/back_end/news_bulletins/preview?preview=true"
|
||||
// // alert(url)
|
||||
// form.attr("action",url);
|
||||
// form.submit();
|
||||
// //return false;
|
||||
// });
|
||||
var clicked_what = null;
|
||||
$("button.post_preview").click(function(){
|
||||
clicked_what = $(this);
|
||||
$("form.nccu_ajax_form").ajaxSubmit({
|
||||
beforeSubmit: function(a,f,o){
|
||||
$("#main-wrap").after("<span id='show_preview'></span>");
|
||||
o.dataType = 'script';
|
||||
o.url = clicked_what.attr("url");
|
||||
}
|
||||
});
|
||||
})
|
||||
// $("form.nccu_ajax_form").ajaxForm({
|
||||
// beforeSubmit: function(a,f,o) {
|
||||
// // if(clicked_what.hasClass("post_preview")){
|
||||
// // $("#main-wrap").after("<span id='show_preview'></span>");
|
||||
// // o.dataType = 'script';
|
||||
// // o.url = clicked_what.attr("url");
|
||||
// // }
|
||||
// },
|
||||
// success: function(data) {
|
||||
// // if(!clicked_what.hasClass("post_preview")){
|
||||
// // window.location = data.redirect_url;
|
||||
// // }
|
||||
// }
|
||||
// })
|
||||
|
||||
$("a.preview_trigger").click(function(){
|
||||
$("#main-wrap").after("<span id='show_preview'></span>");
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
module Admin::WebComponentHelper
|
||||
include ActionView::Helpers::TagHelper
|
||||
|
||||
def alert_block_tag(title="",context="",*args)
|
||||
content_tag(:div,:class=>"alert alert-block alert-error fade in") do
|
||||
a = ActiveSupport::SafeBuffer.new
|
||||
a << button_tag( 'x',:class=>"close",:data=>{:dismiss=>"alert"}) if (args.first[:close] rescue false)
|
||||
a << content_tag(:h4,:class=>"alert-heading") do
|
||||
title
|
||||
end
|
||||
a << content_tag(:p) do
|
||||
context
|
||||
end
|
||||
# TODO : 可以提供更多功能
|
||||
# a << content_tag(:p) do
|
||||
# b = link_to("Take this action","",:class=>"btn btn-danger")
|
||||
# b << link_to("Or do this","",:class=>"btn")
|
||||
# b
|
||||
# end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
+79
-2
@@ -2,12 +2,81 @@ class Preview
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
field :object, :type => Hash
|
||||
# field :object_f, :type => Hash
|
||||
field :object, :type=> Hash
|
||||
field :preview_at_link
|
||||
field :expired_at , :type => DateTime
|
||||
field :link_args, :type => Array
|
||||
field :object_class_type
|
||||
|
||||
has_many :preview_files, :autosave => true, :dependent => :destroy
|
||||
|
||||
# def object=(params)
|
||||
# save_upload_temp_link(params,"news_bulletin_files_attributes") #unless params[]
|
||||
# self.object_f = params
|
||||
# end
|
||||
|
||||
# def object
|
||||
# return object_f
|
||||
# end
|
||||
|
||||
# def save_upload_temp_link(params,field_name = "bulletin_files_attributes")
|
||||
# image = preview_files.build(:file=>params[:image])
|
||||
# params[:image] = image.id
|
||||
|
||||
# params[field_name].each_with_index do |item,index|
|
||||
# bfa = preview_files.build(:file=>params[field_name][index.to_s][:file])
|
||||
# params[field_name][index.to_s] = bfa.id
|
||||
# end unless params[field_name].nil?
|
||||
# end
|
||||
|
||||
# def dig_in_hash(hash,paths_ary)
|
||||
# hash.each_pair do |key,in_hash|
|
||||
# if in_hash.kind_of? Array
|
||||
# dig_in_array(hash,paths_ary)
|
||||
# elsif in_hash.kind_of? Hash
|
||||
# dig_in_hash(hash,paths_ary)
|
||||
# else
|
||||
# puts("\n End Node: \t #{paths_ary.join } #{in_hash.class} : #{key}##{in_hash}")
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
# def dig_in_array(array,paths_ary)
|
||||
# array.each do |item|
|
||||
# if item.kind_of? Array
|
||||
# dig_in_array(hash,paths_ary)
|
||||
# elsif item.kind_of? Hash
|
||||
# dig_in_hash(hash,paths_ary)
|
||||
# else
|
||||
# puts("\n End Node: \t #{paths_ary.join } #{item.class} : {item}")
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
|
||||
# def dig_in_hash_old(hash,paths_ary)
|
||||
# hash.each_pair do |k,in_hash|
|
||||
# if (!in_hash.kind_of? Array and !in_hash.kind_of? Hash)
|
||||
# #p "UploadedFile : #{in_hash.is_a? ActionDispatch::Http::UploadedFile}"
|
||||
# #in_hash = "no file" if in_hash.is_a? ActionDispatch::Http::UploadedFile
|
||||
# #in_hash.select{|key,hash| hash.is_a? ActionDispatch::Http::UploadedFile}
|
||||
# puts("\n End Node:# \n")
|
||||
# p "#{paths_ary.join } #{in_hash.class} : #{in_hash}"
|
||||
# #p "UploadedFile(#{in_hash}) : #{in_hash.is_a? ActionDispatch::Http::UploadedFile}"
|
||||
# else
|
||||
# if (!in_hash.first.kind_of? Array and !in_hash.first.kind_of? Hash)
|
||||
# paths_ary << "[#{in_hash.first}]"
|
||||
# end
|
||||
# puts("\n Go Down [#{in_hash.first}]\n")
|
||||
# dig_in_hash(in_hash,paths_ary)
|
||||
# puts("\n Go Out \n")
|
||||
# end
|
||||
# puts "This is last"
|
||||
# paths_ary.pop
|
||||
# end
|
||||
# end
|
||||
|
||||
def get_arg_hash
|
||||
object.slice(*link_args).inject({}){|la,(k,v)| la[k.to_sym] = v; la}
|
||||
end
|
||||
@@ -19,7 +88,15 @@ class Preview
|
||||
end
|
||||
|
||||
def get_virtual_object
|
||||
eval(self.object_class_type).new object
|
||||
virtual_object = eval(self.object_class_type).new object
|
||||
preview_files.each do |file|
|
||||
if file.file_in_array
|
||||
eval("virtual_object.#{file.field_name_for_rebuild}.build :file=>file.file")
|
||||
else
|
||||
eval("virtual_object.#{file.field_name_for_rebuild} = file.file")
|
||||
end
|
||||
end
|
||||
virtual_object
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,19 @@
|
||||
class PreviewFile
|
||||
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
mount_uploader :file, AssetUploader
|
||||
|
||||
field :title, localize: true
|
||||
field :description, localize: true
|
||||
field :field_name_for_rebuild
|
||||
field :file_in_array , :type => Boolean,default: false
|
||||
|
||||
# field :to_save, :type => Boolean
|
||||
field :should_destroy, :type => Boolean
|
||||
|
||||
belongs_to :preview
|
||||
# embedded_in :news_bulletin
|
||||
|
||||
end
|
||||
@@ -0,0 +1,47 @@
|
||||
<div class="modal hide fade in banner-preview" id="<%= @preview_obj.id %>">
|
||||
<div class="modal-header">
|
||||
<a class="close" data-dismiss="modal">×</a>
|
||||
<h3><%= t("modal.preview") %></h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p class="">
|
||||
<iframe src=<%= @preview_obj.get_preview_link %> style="width:1024px;height:300px" >
|
||||
|
||||
</iframe>
|
||||
|
||||
<%# preview_block_ad_images_helper(news_bulletin).each do |ad_image| -%>
|
||||
<%#= image_tag ad_image.file,:alt => (ad_image.title[locale] || " "),:time_to_next => news_bulletin.transition_msec,:link_open=> ad_image.link_open, :link_url =>((ad_image.out_link || news_bulletin.context || " ")) %>
|
||||
<%# end -%>
|
||||
</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
|
||||
<a href="#" class="btn" data-dismiss="modal"><%= t("modal.close") %></a>
|
||||
</div>
|
||||
<div>
|
||||
<script type="text/javascript" src="/static/kernel.js"></script>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
|
||||
// $("#news_bulletin-<%#=news_bulletin.title.dehumanize%>").on("show", function () {
|
||||
// $("#news_bulletin-<%#=news_bulletin.title.dehumanize%>").find(".news_bulletin_slideshow").cycle({delay: -1000, fx: "<%#= news_bulletin.ad_fx.nil?? "fade": news_bulletin.ad_fx %>", timeoutFn: getTimeout });
|
||||
// });
|
||||
$(".modal").on("hidden", function () {
|
||||
$("#show_preview").remove();
|
||||
});
|
||||
|
||||
$("iframe").load(function(){
|
||||
// Get the body element
|
||||
var frameBody = $("iframe").contents().find("body");
|
||||
|
||||
// Get all links inside the BODY tag
|
||||
$('a', frameBody).click(function(e){
|
||||
//Disable all default actions
|
||||
e.preventDefault();
|
||||
});
|
||||
$('input', frameBody).attr("disabled", true);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1 @@
|
||||
window.location = "<%= @info[:redirect_url]%>";
|
||||
@@ -0,0 +1,12 @@
|
||||
<% if !request.xhr? %>
|
||||
<textarea>
|
||||
<% end %>
|
||||
$('#show_preview').html('<%=escape_javascript(render :partial=>"/shared/preview/modal_preview") %>');
|
||||
var start_modal_with_id = "<%= @preview_obj.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");
|
||||
$("#"+start_modal_with_id).modal();
|
||||
<% if !request.xhr? %>
|
||||
</textarea>
|
||||
<% end %>
|
||||
@@ -0,0 +1,6 @@
|
||||
$('#show_preview').html('<%=escape_javascript(render :partial=>"/shared/preview/modal_preview") %>');
|
||||
var start_modal_with_id = "<%= @preview_obj.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");
|
||||
$("#"+start_modal_with_id).modal();
|
||||
Reference in new issue
Block a user