Update preview with file upload
This commit is contained in:
parent
cdc2a79222
commit
39b8b1f17a
|
@ -62,34 +62,84 @@ class Admin::AnnouncementsController < OrbitAdminController
|
||||||
|
|
||||||
def delete
|
def delete
|
||||||
if params[:ids]
|
if params[:ids]
|
||||||
bulletins = Bulletin.any_in(:uid => params[:ids]).destroy_all
|
Bulletin.any_in(:uid => params[:ids]).destroy_all
|
||||||
end
|
end
|
||||||
redirect_to "/admin/announcements"
|
redirect_to "/admin/announcements"
|
||||||
end
|
end
|
||||||
|
|
||||||
def preview
|
def preview
|
||||||
bulletin_data = bulletin_params
|
if params['preview_type'].eql?('edit')
|
||||||
|
bulletin_data = bulletin_params
|
||||||
unless bulletin_data['bulletin_files_attributes'].nil?
|
org_bulletin = Bulletin.find(params['bulletin_id'])
|
||||||
bulletin_data['bulletin_files_attributes'].each do |key, value|
|
bulletin = org_bulletin.clone
|
||||||
bulletin_data['bulletin_files_attributes'][key].delete('id')
|
bulletin.generate_uid
|
||||||
end
|
bulletin.bulletin_files = []
|
||||||
end
|
bulletin.bulletin_links = []
|
||||||
|
if bulletin_data['image'].blank?
|
||||||
unless bulletin_data['bulletin_links_attributes'].nil?
|
bulletin.image = org_bulletin.image
|
||||||
bulletin_data['bulletin_links_attributes'].each do |key, value|
|
|
||||||
bulletin_data['bulletin_links_attributes'][key].delete('id')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if !bulletin_data['bulletin_files_attributes'].blank?
|
||||||
|
bulletin_data['bulletin_files_attributes'].each do |key, bulletin_file|
|
||||||
|
next if !bulletin_file['_destroy'].blank?
|
||||||
|
file = nil
|
||||||
|
if bulletin_file['id'].blank?
|
||||||
|
file = BulletinFile.new(bulletin_file)
|
||||||
|
file.bulletin_id = bulletin.id
|
||||||
|
file.save
|
||||||
|
else
|
||||||
|
file = BulletinFile.find(bulletin_file['id']).clone
|
||||||
|
file.bulletin_id = bulletin.id
|
||||||
|
bulletin_file.delete('id')
|
||||||
|
bulletin_file.delete('_destroy')
|
||||||
|
file.update_attributes(bulletin_file)
|
||||||
|
end
|
||||||
|
|
||||||
|
file.save
|
||||||
|
bulletin.bulletin_files << file
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if !bulletin_data['bulletin_links_attributes'].blank?
|
||||||
|
bulletin_data['bulletin_links_attributes'].each do |key, bulletin_link|
|
||||||
|
next if !bulletin_link['_destroy'].blank?
|
||||||
|
|
||||||
|
if bulletin_link['id'].blank?
|
||||||
|
link = BulletinLink.new(bulletin_link)
|
||||||
|
link.bulletin_id = bulletin.id
|
||||||
|
else
|
||||||
|
link = BulletinLink.find(bulletin_link['id']).clone
|
||||||
|
link.bulletin_id = bulletin.id
|
||||||
|
bulletin_link.delete('id')
|
||||||
|
bulletin_link.delete('_destroy')
|
||||||
|
link.update_attributes(bulletin_link)
|
||||||
|
end
|
||||||
|
|
||||||
|
link.save
|
||||||
|
bulletin.bulletin_links << link
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
bulletin_data.delete('bulletin_files_attributes')
|
||||||
|
bulletin_data.delete('bulletin_links_attributes')
|
||||||
|
bulletin.update_attributes(bulletin_data)
|
||||||
|
else
|
||||||
|
bulletin = Bulletin.new(bulletin_params)
|
||||||
end
|
end
|
||||||
|
|
||||||
bulletin = Bulletin.new(bulletin_data)
|
|
||||||
bulletin.is_preview = true
|
bulletin.is_preview = true
|
||||||
bulletin.create_user_id = current_user.id
|
|
||||||
bulletin.update_user_id = current_user.id
|
|
||||||
bulletin.save
|
bulletin.save
|
||||||
render :text=>page_for_bulletin(bulletin)
|
render :text=>page_for_bulletin(bulletin)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy_preview
|
||||||
|
bulletin = Bulletin.find_by(:uid=>params['uid'])
|
||||||
|
if bulletin.is_preview
|
||||||
|
bulletin.destroy
|
||||||
|
end
|
||||||
|
render :json=>{'destroy'=>bulletin.id.to_s}
|
||||||
|
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?
|
||||||
|
|
|
@ -4,6 +4,7 @@ class Bulletin
|
||||||
|
|
||||||
include OrbitModel::Status
|
include OrbitModel::Status
|
||||||
include OrbitModel::Impression
|
include OrbitModel::Impression
|
||||||
|
# encoding: utf-8
|
||||||
include OrbitTag::Taggable
|
include OrbitTag::Taggable
|
||||||
include OrbitCategory::Categorizable
|
include OrbitCategory::Categorizable
|
||||||
include Slug
|
include Slug
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# encoding: utf-8
|
||||||
class BulletinFile
|
class BulletinFile
|
||||||
|
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# encoding: utf-8
|
||||||
require 'uri'
|
require 'uri'
|
||||||
|
|
||||||
class BulletinLink
|
class BulletinLink
|
||||||
|
|
|
@ -298,7 +298,7 @@
|
||||||
<h3><%= t(:preview) %></h3>
|
<h3><%= t(:preview) %></h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<iframe src=""></iframe>
|
<iframe id="preview-iframe" src=""></iframe>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<a href="#" class="btn" data-dismiss="modal"><%= t(:close) %></a>
|
<a href="#" class="btn" data-dismiss="modal"><%= t(:close) %></a>
|
||||||
|
@ -354,22 +354,33 @@
|
||||||
$('#button_for_preview').click(function(){
|
$('#button_for_preview').click(function(){
|
||||||
var method = $('.main-forms input[name="_method"]').val();
|
var method = $('.main-forms input[name="_method"]').val();
|
||||||
$('.main-forms input[name="_method"]').val("post");
|
$('.main-forms input[name="_method"]').val("post");
|
||||||
|
|
||||||
for ( instance in CKEDITOR.instances )
|
for ( instance in CKEDITOR.instances )
|
||||||
CKEDITOR.instances[instance].updateElement();
|
CKEDITOR.instances[instance].updateElement();
|
||||||
|
|
||||||
|
var formData = new FormData( $('.main-forms')[0] );
|
||||||
|
formData.append("preview_type", ( (method==undefined) ? "new" : "edit" ));
|
||||||
|
formData.append("bulletin_id", '<%= @bulletin.id.to_s %>');
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "post",
|
type: "post",
|
||||||
url: '<%= admin_announcement_preview_path %>',
|
url: '<%= admin_announcement_preview_path %>',
|
||||||
data : $('.main-forms').serialize()
|
data : formData,
|
||||||
|
processData: false,
|
||||||
|
contentType: false
|
||||||
}).done(function(data){
|
}).done(function(data){
|
||||||
$('.modal-body iframe').attr('src',data);
|
$('.modal-body iframe').attr('src',data);
|
||||||
$('#show_preview .modal').modal();
|
$('#show_preview .modal').modal();
|
||||||
$('#show_preview .modal').height(function() {
|
$('#show_preview .modal').height(function() {
|
||||||
return $(window).height() * 0.7;
|
return $(window).height() * 0.7;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var slug = data.split('/')[(data.split('/').length-1)];
|
||||||
|
$('#preview-iframe').on('load', function(){
|
||||||
|
$.get('/admin/announcement/destroy_preview/'+slug,function(data){
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.main-forms input[name="_method"]').val(method);
|
$('.main-forms input[name="_method"]').val(method);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,6 +5,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'
|
post 'announcement/preview', to: 'announcements#preview'
|
||||||
|
get 'announcement/destroy_preview/:slug_title-:uid', to: 'announcements#destroy_preview'
|
||||||
resources :announcements
|
resources :announcements
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue