Add event expiry ranking and file drag-sort functionality
This commit is contained in:
parent
75acbf7d6d
commit
90f7fbedf1
|
|
@ -109,6 +109,8 @@ class EventNews
|
|||
accepts_nested_attributes_for :event_carousel_images, :allow_destroy => true
|
||||
before_destroy :destroy_email
|
||||
|
||||
before_save :calculate_is_event_expired
|
||||
|
||||
scope :open_in_future, ->{where(:is_hidden.ne=>true,:is_preview.ne => true,:postdate.gt=>Time.now).order(postdate: :asc)}
|
||||
scope :can_display_and_sorted, ->{
|
||||
is_approved_and_show
|
||||
|
|
@ -355,6 +357,17 @@ class EventNews
|
|||
(self.deadline < Time.now) rescue false
|
||||
end
|
||||
|
||||
def calculate_is_event_expired
|
||||
setting = EventNewsSetting.first
|
||||
if setting && setting.expired_event_to_bottom && event_end_date.present? && event_end_date >= Time.now
|
||||
self.is_top = true
|
||||
self.top_end_date = event_end_date
|
||||
elsif setting && setting.expired_event_to_bottom && event_end_date.present? && event_end_date < Time.now
|
||||
self.is_top = false
|
||||
self.top_end_date = nil
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_email
|
||||
mail = Email.find(self.email_id) rescue nil
|
||||
mail.destroy if !mail.nil?
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ class EventNewsFile
|
|||
field :title, localize: true
|
||||
field :choose_lang, :type => Array, :default => ["en","zh_tw"]
|
||||
field :privacy_type, type: String, default: 'public'
|
||||
field :position, type: Integer, default: 0
|
||||
default_scope ->{ order_by(position: :asc) }
|
||||
belongs_to :event_news
|
||||
def self.to_fronted(locale=I18n.locale)
|
||||
self.all.map{|file| file.to_fronted(locale)}.compact rescue []
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ class EventNewsSetting
|
|||
field :hour_clock_24, type: Boolean, default: true
|
||||
field :enable_manually_sort, type: Boolean, default: false
|
||||
field :is_postdate_sort_first, type: Boolean, default: false
|
||||
field :expired_event_to_bottom, type: Boolean, default: false
|
||||
|
||||
field :migrate_flag, type: Array, default: []
|
||||
|
||||
|
|
@ -128,4 +129,4 @@ class EventNewsSetting
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,6 +3,24 @@
|
|||
<%= stylesheet_link_tag "lib/fileupload" %>
|
||||
<%= stylesheet_link_tag "lib/main-list" %>
|
||||
<% end %>
|
||||
<style type="text/css">
|
||||
.sort-order-icon {
|
||||
font-size: 25px;
|
||||
}
|
||||
.ui-state-highlight {
|
||||
height: 40px;
|
||||
background-color: #fcf8e3;
|
||||
border: 1px dashed #fbeed5;
|
||||
margin-bottom: 10px;
|
||||
list-style: none;
|
||||
}
|
||||
.exist .file-link {
|
||||
cursor: grab;
|
||||
}
|
||||
.icons-list-2 {
|
||||
cursor: all-scroll;
|
||||
}
|
||||
</style>
|
||||
<style type="text/css">
|
||||
[aria-describedby] ul.dropdown-menu {
|
||||
display: block;
|
||||
|
|
@ -542,9 +560,12 @@
|
|||
<% if @event_news && !@event_news.event_news_files.blank? %>
|
||||
<div class="exist">
|
||||
<% @event_news.event_news_files.each_with_index do |event_news_file, i| %>
|
||||
<%= f.fields_for :event_news_files, event_news_file do |f| %>
|
||||
<%= render :partial => 'form_file', :object => event_news_file, :locals => {:f => f, :i => i} %>
|
||||
<% end %>
|
||||
<div class="file-sort-item">
|
||||
<%= f.fields_for :event_news_files, event_news_file do |f| %>
|
||||
<%= f.hidden_field :position, class: "file-position" %>
|
||||
<%= render :partial => 'form_file', :object => event_news_file, :locals => {:f => f, :i => i} %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
<hr>
|
||||
</div>
|
||||
|
|
@ -731,5 +752,28 @@
|
|||
}
|
||||
})
|
||||
|
||||
function init_file_sortable() {
|
||||
var $container = $(".exist");
|
||||
|
||||
if ($container.data("ui-sortable")) {
|
||||
$container.sortable("destroy");
|
||||
}
|
||||
|
||||
$container.sortable({
|
||||
items: ".file-sort-item",
|
||||
handle: ".sort-order-icon, .file-link",
|
||||
axis: "y",
|
||||
placeholder: "ui-state-highlight",
|
||||
forcePlaceholderSize: true,
|
||||
update: function(event, ui) {
|
||||
$(".file-sort-item").each(function(index) {
|
||||
$(this).find("input.file-position").val(index);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
init_file_sortable();
|
||||
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
<div class="fileupload fileupload-new start-line" data-provides="fileupload">
|
||||
<% else %>
|
||||
<div class="fileupload fileupload-exists start-line" data-provides="fileupload">
|
||||
<i class="icons-list-2 sort-order-icon ui-sortable-handle"></i>
|
||||
<% if form_file.file.blank? %>
|
||||
<%= t(:no_file) %>
|
||||
<% else %>
|
||||
|
|
|
|||
|
|
@ -182,6 +182,12 @@
|
|||
<%= f.check_box :is_postdate_sort_first %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<%= f.label :expired_event_to_bottom, t("event_news.expired_event_to_bottom"), :class => "control-label muted" %>
|
||||
<div class="controls">
|
||||
<%= f.check_box :expired_event_to_bottom %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<%= f.label :top_limit, t("event_news.top_limit"), :class => "control-label muted" %>
|
||||
<div class="controls">
|
||||
|
|
@ -428,4 +434,4 @@
|
|||
});
|
||||
});
|
||||
})
|
||||
</script>
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -176,6 +176,7 @@ en:
|
|||
display_img: Display Cover Image in Content Page
|
||||
is_display_edit_only: Only display editable event news
|
||||
is_postdate_sort_first: Sort by Post Date first (Sort by Event Date first as Default)
|
||||
expired_event_to_bottom: Expired events appear at the bottom
|
||||
only_manager_can_edit_status: Only manager can edit status of event news
|
||||
layout_type: Layout type
|
||||
event_news_setting_for_iframe: Event News settings for iframe
|
||||
|
|
|
|||
|
|
@ -179,6 +179,7 @@ zh_tw:
|
|||
display_img: 內容頁顯示封面圖片
|
||||
is_display_edit_only: 只顯示可更新的活動公告
|
||||
is_postdate_sort_first: 優先使用公告日期排序(預設優先使用事件日期)
|
||||
expired_event_to_bottom: 已達事件結束日期排最後
|
||||
only_manager_can_edit_status: 只有管理者可更新活動公告狀態
|
||||
layout_type: 頁面樣式
|
||||
event_news_setting_for_iframe: 活動公告iframe設定
|
||||
|
|
|
|||
Loading…
Reference in New Issue