Basic preview function
This commit is contained in:
parent
b976c9efd8
commit
cb7769ea4f
|
@ -15,7 +15,7 @@ class Admin::AnnouncementsController < OrbitAdminController
|
||||||
@filter_fields = filter_fields(@categories, @tags)
|
@filter_fields = filter_fields(@categories, @tags)
|
||||||
@table_fields = [:status, :category, :title, :start_date, :end_date, :last_modified]
|
@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?
|
if request.xhr?
|
||||||
render :partial => "index"
|
render :partial => "index"
|
||||||
|
@ -67,6 +67,29 @@ class Admin::AnnouncementsController < OrbitAdminController
|
||||||
redirect_to "/admin/announcements"
|
redirect_to "/admin/announcements"
|
||||||
end
|
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)
|
def build_email(bulletin)
|
||||||
if bulletin.email_sent and !bulletin.email_addresses.blank?
|
if bulletin.email_sent and !bulletin.email_addresses.blank?
|
||||||
if bulletin.email.nil?
|
if bulletin.email.nil?
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
class AnnouncementsController < ApplicationController
|
class AnnouncementsController < ApplicationController
|
||||||
|
|
||||||
def index
|
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|
|
anns = announcements.collect do |a|
|
||||||
statuses = a.statuses.collect do |status|
|
statuses = a.statuses.collect do |status|
|
||||||
{
|
{
|
||||||
|
@ -28,7 +28,7 @@ class AnnouncementsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def widget
|
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|
|
anns = announcements.collect do |a|
|
||||||
statuses = a.statuses.collect do |status|
|
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 []
|
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 []
|
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 ""
|
update_user = announcement.update_user.member_profile.name rescue ""
|
||||||
|
# announcement.destroy if announcement.is_preview
|
||||||
{
|
{
|
||||||
"tags" => tags,
|
"tags" => tags,
|
||||||
"bulletin_files" => files,
|
"bulletin_files" => files,
|
||||||
|
@ -72,8 +73,8 @@ class AnnouncementsController < ApplicationController
|
||||||
"body" =>announcement.text,
|
"body" =>announcement.text,
|
||||||
"image" => announcement.image.url
|
"image" => announcement.image.url
|
||||||
},
|
},
|
||||||
"impressionist" => announcement
|
"impressionist" => (announcement.is_preview ? nil : announcement)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,6 +17,7 @@ class Bulletin
|
||||||
field :postdate , :type => DateTime, :default => Time.now
|
field :postdate , :type => DateTime, :default => Time.now
|
||||||
field :deadline , :type => DateTime
|
field :deadline , :type => DateTime
|
||||||
field :rss2_sn
|
field :rss2_sn
|
||||||
|
field :is_preview, :type => Boolean, :default => false
|
||||||
|
|
||||||
field :email_id
|
field :email_id
|
||||||
field :email_sent, :type => Boolean, :default => false
|
field :email_sent, :type => Boolean, :default => false
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
<%= javascript_include_tag "lib/bootstrap-fileupload" %>
|
<%= javascript_include_tag "lib/bootstrap-fileupload" %>
|
||||||
<%= javascript_include_tag "lib/bootstrap-datetimepicker" %>
|
<%= javascript_include_tag "lib/bootstrap-datetimepicker" %>
|
||||||
<%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %>
|
<%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %>
|
||||||
<%= javascript_include_tag "lib/modal-preview" %>
|
|
||||||
<%= javascript_include_tag "lib/file-type" %>
|
<%= javascript_include_tag "lib/file-type" %>
|
||||||
<%= javascript_include_tag "lib/module-area" %>
|
<%= javascript_include_tag "lib/module-area" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -288,13 +287,30 @@
|
||||||
<!-- Form Actions -->
|
<!-- Form Actions -->
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<%= f.submit t('submit'), class: 'btn btn-primary' %>
|
<%= 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" %>
|
<%= link_to t('cancel'), admin_announcements_path, :class=>"btn" %>
|
||||||
</div>
|
</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 %>
|
<% content_for :page_specific_javascript do %>
|
||||||
<script>
|
<script>
|
||||||
$(function() {
|
$(function() {
|
||||||
|
$("#main-wrap").after("");
|
||||||
|
|
||||||
$(document).on('click', '#add_link', function(){
|
$(document).on('click', '#add_link', function(){
|
||||||
var new_id = $(this).prev().attr('value');
|
var new_id = $(this).prev().attr('value');
|
||||||
var old_id = new RegExp("new_bulletin_links", "g");
|
var old_id = new RegExp("new_bulletin_links", "g");
|
||||||
|
@ -335,6 +351,29 @@
|
||||||
$(this).prop('checked') ? $('.content-box').removeClass('hide'):$('.content-box').addClass('hide')
|
$(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>
|
</script>
|
||||||
<% end %>
|
<% end %>
|
|
@ -4,6 +4,7 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
||||||
namespace :admin do
|
namespace :admin do
|
||||||
|
post 'announcement/preview', to: 'announcements#preview'
|
||||||
resources :announcements
|
resources :announcements
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue