Fix preview bug.
This commit is contained in:
parent
0d1645f101
commit
8bab071a28
|
@ -288,6 +288,10 @@ class Admin::AnnouncementsController < OrbitAdminController
|
||||||
def update
|
def update
|
||||||
uid = params[:id].split('-').last
|
uid = params[:id].split('-').last
|
||||||
bulletin = Bulletin.find_by(:uid=>uid)
|
bulletin = Bulletin.find_by(:uid=>uid)
|
||||||
|
Bulletin.where(:copy_id=>bulletin.id.to_s).destroy
|
||||||
|
bulletin.is_edit = true
|
||||||
|
bulletin.save
|
||||||
|
bulletin = bulletin.get_org_model
|
||||||
bps = bulletin_params
|
bps = bulletin_params
|
||||||
bps[:tags] = bps[:tags].blank? ? [] : bps[:tags]
|
bps[:tags] = bps[:tags].blank? ? [] : bps[:tags]
|
||||||
bps[:email_member_ids] = bps[:email_member_ids].blank? ? [] : bps[:email_member_ids]
|
bps[:email_member_ids] = bps[:email_member_ids].blank? ? [] : bps[:email_member_ids]
|
||||||
|
@ -312,6 +316,8 @@ class Admin::AnnouncementsController < OrbitAdminController
|
||||||
end
|
end
|
||||||
bulletin.update_attributes(bps)
|
bulletin.update_attributes(bps)
|
||||||
bulletin.update_user_id = current_user.id
|
bulletin.update_user_id = current_user.id
|
||||||
|
bulletin.expirable_created_at = nil
|
||||||
|
bulletin.is_preview = false
|
||||||
if bulletin.rejected
|
if bulletin.rejected
|
||||||
bulletin.reapproval = true
|
bulletin.reapproval = true
|
||||||
bulletin.save
|
bulletin.save
|
||||||
|
@ -397,6 +403,7 @@ class Admin::AnnouncementsController < OrbitAdminController
|
||||||
bulletin_data.delete('bulletin_files_attributes')
|
bulletin_data.delete('bulletin_files_attributes')
|
||||||
bulletin_data.delete('bulletin_links_attributes')
|
bulletin_data.delete('bulletin_links_attributes')
|
||||||
bulletin.update_attributes(bulletin_data)
|
bulletin.update_attributes(bulletin_data)
|
||||||
|
bulletin.copy_id = params['bulletin_id']
|
||||||
else
|
else
|
||||||
bulletin = Bulletin.new(bulletin_params)
|
bulletin = Bulletin.new(bulletin_params)
|
||||||
end
|
end
|
||||||
|
@ -406,7 +413,18 @@ class Admin::AnnouncementsController < OrbitAdminController
|
||||||
#BulletinFeed.create_feed_cache(bulletin)
|
#BulletinFeed.create_feed_cache(bulletin)
|
||||||
render :text=>page_for_bulletin(bulletin) + "?preview=true"
|
render :text=>page_for_bulletin(bulletin) + "?preview=true"
|
||||||
end
|
end
|
||||||
|
def get_preview_action
|
||||||
|
bulletin = Bulletin.find_by(:uid=>params['uid'])
|
||||||
|
is_not_edit = (!bulletin.is_edit)
|
||||||
|
org_bulletin = bulletin.get_org_model
|
||||||
|
Bulletin.where(:copy_id=>org_bulletin.id.to_s).destroy
|
||||||
|
if is_not_edit
|
||||||
|
bulletin.destroy
|
||||||
|
render :json=> {:success=>true,:action=>"close"}
|
||||||
|
else
|
||||||
|
render :json=> {:success=>true,:action=>"redirect",:path=>edit_admin_announcement_path(:id=>org_bulletin.id)}
|
||||||
|
end
|
||||||
|
end
|
||||||
def destroy_preview
|
def destroy_preview
|
||||||
bulletin = Bulletin.find_by(:uid=>params['uid'])
|
bulletin = Bulletin.find_by(:uid=>params['uid'])
|
||||||
if bulletin.is_preview
|
if bulletin.is_preview
|
||||||
|
|
|
@ -26,6 +26,8 @@ class Bulletin
|
||||||
before_destroy do
|
before_destroy do
|
||||||
AnnsCache.all.destroy
|
AnnsCache.all.destroy
|
||||||
end
|
end
|
||||||
|
field :is_edit, type: Boolean, default: false #use to check whether the preview record changed
|
||||||
|
field :copy_id
|
||||||
field :custom_carousel_image_width, type: String, default: ""
|
field :custom_carousel_image_width, type: String, default: ""
|
||||||
field :image_display_class, type: String, default: "full-size-img" #3 choices: full-size-img , pull-left , pull-right
|
field :image_display_class, type: String, default: "full-size-img" #3 choices: full-size-img , pull-left , pull-right
|
||||||
field :add_to_calendar,type: Boolean,default: false
|
field :add_to_calendar,type: Boolean,default: false
|
||||||
|
@ -35,7 +37,7 @@ class Bulletin
|
||||||
field :calendar_type_id
|
field :calendar_type_id
|
||||||
field :event_id
|
field :event_id
|
||||||
field :page_id
|
field :page_id
|
||||||
field :title, type: String, localize: true
|
field :title, as: :slug_title, type: String, localize: true
|
||||||
field :subtitle, localize: true
|
field :subtitle, localize: true
|
||||||
field :text, localize: true
|
field :text, localize: true
|
||||||
field :create_user_id
|
field :create_user_id
|
||||||
|
@ -88,6 +90,19 @@ class Bulletin
|
||||||
before_save :check_limit
|
before_save :check_limit
|
||||||
index({postdate: 1}, { unique: false, background: true })
|
index({postdate: 1}, { unique: false, background: true })
|
||||||
index({is_top: -1,postdate: -1, _id: -1}, { unique: false, background: true })
|
index({is_top: -1,postdate: -1, _id: -1}, { unique: false, background: true })
|
||||||
|
def get_org_model
|
||||||
|
if self.is_preview
|
||||||
|
org_model = nil
|
||||||
|
if self.copy_id
|
||||||
|
org_model = self.class.find(self.copy_id) rescue nil
|
||||||
|
else
|
||||||
|
org_model = self.class.where(:title=>self.title,:is_preview.ne=>true).desc(:updated_at).first
|
||||||
|
end
|
||||||
|
org_model.nil? ? self : org_model
|
||||||
|
else
|
||||||
|
self
|
||||||
|
end
|
||||||
|
end
|
||||||
def to_calendar_param
|
def to_calendar_param
|
||||||
self.to_param
|
self.to_param
|
||||||
end
|
end
|
||||||
|
@ -113,7 +128,7 @@ class Bulletin
|
||||||
if status_settings.count != 0
|
if status_settings.count != 0
|
||||||
reach_limit = status_settings.collect do |status_setting|
|
reach_limit = status_settings.collect do |status_setting|
|
||||||
status = status_setting.status
|
status = status_setting.status
|
||||||
if status_setting.top_limit.to_i <= Bulletin.where(:update_user_id.in => Role.find(status_setting.role_id).member_profiles.collect(&:user).flatten.uniq.map{|v| v.id},status => true).count
|
if status_setting.top_limit.to_i <= Bulletin.where(:is_preview.ne=>true,:update_user_id.in => Role.find(status_setting.role_id).member_profiles.collect(&:user).flatten.uniq.map{|v| v.id},status => true).count
|
||||||
if !check_only
|
if !check_only
|
||||||
if self[status] && !Bulletin.where(id:self.id).first[status]
|
if self[status] && !Bulletin.where(id:self.id).first[status]
|
||||||
self[status] = false
|
self[status] = false
|
||||||
|
@ -136,10 +151,6 @@ class Bulletin
|
||||||
end
|
end
|
||||||
reach_limit
|
reach_limit
|
||||||
end
|
end
|
||||||
def slug_title
|
|
||||||
doc = Nokogiri::HTML(self.title)
|
|
||||||
title = doc.text.gsub('/','-')
|
|
||||||
end
|
|
||||||
def set_expire
|
def set_expire
|
||||||
self.expirable_created_at = Time.now if self.is_preview
|
self.expirable_created_at = Time.now if self.is_preview
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -644,7 +644,11 @@
|
||||||
$('#remind-check').on('change', function() {
|
$('#remind-check').on('change', function() {
|
||||||
$(this).prop('checked') ? $('.content-box').removeClass('hide'):$('.content-box').addClass('hide')
|
$(this).prop('checked') ? $('.content-box').removeClass('hide'):$('.content-box').addClass('hide')
|
||||||
})
|
})
|
||||||
|
try{
|
||||||
|
if( self != top ){
|
||||||
|
$('#button_for_preview,#show_preview').remove();
|
||||||
|
}
|
||||||
|
}catch(e){}
|
||||||
$('#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");
|
||||||
|
@ -666,11 +670,23 @@
|
||||||
if(window.location.protocol === "https:"){
|
if(window.location.protocol === "https:"){
|
||||||
data = data.replace("http:","https:");
|
data = data.replace("http:","https:");
|
||||||
}
|
}
|
||||||
|
window.preview_annc_uid = data.split("-").slice(-1)[0].split("?")[0];
|
||||||
$('.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;
|
||||||
});
|
});
|
||||||
|
$('#show_preview .modal').on('hidden.bs.modal', function () {
|
||||||
|
$.ajax({
|
||||||
|
type: "post",
|
||||||
|
url: '<%= admin_announcement_get_preview_action_path %>',
|
||||||
|
data: {uid: window.preview_annc_uid}
|
||||||
|
}).done(function(data){
|
||||||
|
if(data["action"] == "redirect"){
|
||||||
|
window.location.href = data["path"];
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
var slug = data.split('/')[(data.split('/').length-1)];
|
var slug = data.split('/')[(data.split('/').length-1)];
|
||||||
// $('#preview-iframe').on('load', function(){
|
// $('#preview-iframe').on('load', function(){
|
||||||
|
|
|
@ -8,6 +8,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/get_preview_action', to: 'announcements#get_preview_action'
|
||||||
post 'announcement/preview', to: 'announcements#preview'
|
post 'announcement/preview', to: 'announcements#preview'
|
||||||
post 'announcement/createfeed', to: 'announcements#createfeed'
|
post 'announcement/createfeed', to: 'announcements#createfeed'
|
||||||
post 'announcement/importanns', to: 'announcements#importanns'
|
post 'announcement/importanns', to: 'announcements#importanns'
|
||||||
|
|
Loading…
Reference in New Issue