Basic preview function

This commit is contained in:
manson 2014-06-17 18:46:52 +08:00
parent b976c9efd8
commit cb7769ea4f
5 changed files with 72 additions and 7 deletions

View File

@ -15,7 +15,7 @@ class Admin::AnnouncementsController < OrbitAdminController
@filter_fields = filter_fields(@categories, @tags)
@table_fields = [:status, :category, :title, :start_date, :end_date, :last_modified]
@bulletins = Bulletin.order_by(sort).with_categories(filters("category")).with_tags(filters("tag")).with_status(filters("status")).page(params[:page]).per(10)
@bulletins = Bulletin.where(:is_preview=>false).order_by(sort).with_categories(filters("category")).with_tags(filters("tag")).with_status(filters("status")).page(params[:page]).per(10)
if request.xhr?
render :partial => "index"
@ -67,6 +67,29 @@ class Admin::AnnouncementsController < OrbitAdminController
redirect_to "/admin/announcements"
end
def preview
bulletin_data = bulletin_params
unless bulletin_data['bulletin_files_attributes'].nil?
bulletin_data['bulletin_files_attributes'].each do |key, value|
bulletin_data['bulletin_files_attributes'][key].delete('id')
end
end
unless bulletin_data['bulletin_links_attributes'].nil?
bulletin_data['bulletin_links_attributes'].each do |key, value|
bulletin_data['bulletin_links_attributes'][key].delete('id')
end
end
bulletin = Bulletin.new(bulletin_data)
bulletin.is_preview = true
bulletin.create_user_id = current_user.id
bulletin.update_user_id = current_user.id
bulletin.save
render :text=>page_for_bulletin(bulletin)
end
def build_email(bulletin)
if bulletin.email_sent and !bulletin.email_addresses.blank?
if bulletin.email.nil?

View File

@ -1,7 +1,7 @@
class AnnouncementsController < ApplicationController
def index
announcements = Bulletin.can_display.order_by(:created_at=>'desc').filter_by_categories
announcements = Bulletin.where(:is_preview=>false).can_display.order_by(:created_at=>'desc').filter_by_categories
anns = announcements.collect do |a|
statuses = a.statuses.collect do |status|
{
@ -28,7 +28,7 @@ class AnnouncementsController < ApplicationController
end
def widget
announcements = Bulletin.can_display.order_by(:created_at=>'desc').filter_by_widget_categories
announcements = Bulletin.where(:is_preview=>false).can_display.order_by(:created_at=>'desc').filter_by_widget_categories
anns = announcements.collect do |a|
statuses = a.statuses.collect do |status|
{
@ -61,6 +61,7 @@ class AnnouncementsController < ApplicationController
files = announcement.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title) } } rescue []
links = announcement.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue []
update_user = announcement.update_user.member_profile.name rescue ""
# announcement.destroy if announcement.is_preview
{
"tags" => tags,
"bulletin_files" => files,
@ -72,7 +73,7 @@ class AnnouncementsController < ApplicationController
"body" =>announcement.text,
"image" => announcement.image.url
},
"impressionist" => announcement
"impressionist" => (announcement.is_preview ? nil : announcement)
}
end

View File

@ -17,6 +17,7 @@ class Bulletin
field :postdate , :type => DateTime, :default => Time.now
field :deadline , :type => DateTime
field :rss2_sn
field :is_preview, :type => Boolean, :default => false
field :email_id
field :email_sent, :type => Boolean, :default => false

View File

@ -7,7 +7,6 @@
<%= javascript_include_tag "lib/bootstrap-fileupload" %>
<%= javascript_include_tag "lib/bootstrap-datetimepicker" %>
<%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %>
<%= javascript_include_tag "lib/modal-preview" %>
<%= javascript_include_tag "lib/file-type" %>
<%= javascript_include_tag "lib/module-area" %>
<% end %>
@ -288,13 +287,30 @@
<!-- Form Actions -->
<div class="form-actions">
<%= f.submit t('submit'), class: 'btn btn-primary' %>
<%= button_tag t("preview"), id: "button_for_preview", name: "commit", class: 'btn post_preview', type: :button, url: admin_announcements_path %>
<%= button_tag t("preview"), id: "button_for_preview", name: "commit", class: 'btn', type: :button %>
<%= link_to t('cancel'), admin_announcements_path, :class=>"btn" %>
</div>
<span id='show_preview'>
<div class="modal hide fade in banner-preview" id="">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3><%= t(:preview) %></h3>
</div>
<div class="modal-body">
<iframe src=""></iframe>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal"><%= t(:close) %></a>
</div>
</div>
</span>
<% content_for :page_specific_javascript do %>
<script>
$(function() {
$("#main-wrap").after("");
$(document).on('click', '#add_link', function(){
var new_id = $(this).prev().attr('value');
var old_id = new RegExp("new_bulletin_links", "g");
@ -335,6 +351,29 @@
$(this).prop('checked') ? $('.content-box').removeClass('hide'):$('.content-box').addClass('hide')
})
$('#button_for_preview').click(function(){
var method = $('.main-forms input[name="_method"]').val();
$('.main-forms input[name="_method"]').val("post");
for ( instance in CKEDITOR.instances )
CKEDITOR.instances[instance].updateElement();
$.ajax({
type: "post",
url: '<%= admin_announcement_preview_path %>',
data : $('.main-forms').serialize()
}).done(function(data){
$('.modal-body iframe').attr('src',data);
$('#show_preview .modal').modal();
$('#show_preview .modal').height(function() {
return $(window).height() * 0.7;
});
});
$('.main-forms input[name="_method"]').val(method);
return false;
});
});
</script>
<% end %>

View File

@ -4,6 +4,7 @@ Rails.application.routes.draw do
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
namespace :admin do
post 'announcement/preview', to: 'announcements#preview'
resources :announcements
end