archive module: sort for backend/frontend. move get_sorted_and_filtered from orbit_backend_controller.rb to application_controller.rb

This commit is contained in:
iCross committed 2013-06-06 19:20:21 +08:00
1 parent dd206437d8
commit c63ac751ea
15 files changed
+352 -286

No files matched your search

@@ -1,47 +1,52 @@
class Panel::Archive::Widget::ArchiveFilesController < OrbitWidgetController
include AdminHelper
def initialize
super
@app_title = 'archive_files'
end
def index
@part = PagePart.find(params[:part_id])
if @part.widget_data_count
@page_num = @part.widget_data_count
else
@page_num = 4
end
if @part.widget_field
@widget_fields = @part.widget_field
else
@widget_fields = []
end
@widget_style = @part.widget_style
@category_id = @part.category
date_now = Time.now
if !params[:category_id].blank?
@archive_files = ArchiveFile.all.can_display.any_in(:archive_file_category_id => params[:category_id]).merge(ArchiveFileCategory.excludes('disable' => true)).desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num)
@archive_files = ArchiveFile.default_sort(params[:sort]).all.can_display.any_in(:archive_file_category_id => params[:category_id]).merge(ArchiveFileCategory.excludes('disable' => true)).desc( :is_top ).page( params[:page_main] ).per(@page_num)
@archive_file_categorys = ArchiveFileCategory.any_in(:_id => params[:category_id]).excludes('disable' => true)
elsif !params[:tag_id].blank?
@archive_files = ArchiveFile.all.can_display.any_in(:tagged_ids => params[:tag_id]).merge(ArchiveFileCategory.excludes('disable' => true)).desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num)
@archive_files = ArchiveFile.default_sort(params[:sort]).all.can_display.any_in(:tagged_ids => params[:tag_id]).merge(ArchiveFileCategory.excludes('disable' => true)).desc( :is_top ).page( params[:page_main] ).per(@page_num)
get_categorys
else
@archive_files = ArchiveFile.all.can_display.merge(ArchiveFileCategory.excludes('disable' => true)).desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num)
@archive_files = ArchiveFile.default_sort(params[:sort]).all.can_display.merge(ArchiveFileCategory.excludes('disable' => true)).desc( :is_top).page( params[:page_main] ).per(@page_num)
get_categorys
end
if params[:sort]
@archive_files = get_sorted_and_filtered('archive_file', nil, @archive_files)
end
end
def get_categorys
@archive_file_categorys = ArchiveFileCategory.excludes('disable' => true)
end
end
+19 -18
View File
@@ -4,7 +4,8 @@ class ArchiveFile
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::MultiParameterAttributes
include Mongoid::Sortable
BelongsToCategory = :archive_file_category
include OrbitCoreLib::BelongsToCategoryMayDisable
@@ -14,26 +15,26 @@ class ArchiveFile
taggable
field :title, localize: true
# has_and_belongs_to_many :tags, :class_name => "ArchiveTag"
field :create_user_id
field :update_user_id
field :is_top, :type => Boolean, :default => false
field :is_hot, :type => Boolean, :default => false
field :is_hidden, :type => Boolean, :default => false
field :is_top, :type => Boolean, :default => false
field :is_hot, :type => Boolean, :default => false
field :is_hidden, :type => Boolean, :default => false
scope :can_display,where(is_hidden: false)
# belongs_to :archive_file_category
has_many :archive_file_multiples, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :archive_file_multiples, :allow_destroy => true
validates :title, :at_least_one => true
after_save :save_archive_file_multiples
# searchable do
@@ -47,17 +48,17 @@ class ArchiveFile
# end
def self.search( category_id = nil )
if category_id.to_s.size > 0
find(:all, :conditions => {archive_file_category_id: category_id}).desc( :is_top, :title )
else
find(:all).desc( :is_top, :title)
end
end
@@ -75,7 +76,7 @@ class ArchiveFile
def get_file_icon( file_data )
file_icon = "<span class=\"o-archives-file-type\">#{file_data.split('.')[-1]}</span>".html_safe
end
def save_archive_file_multiples
self.archive_file_multiples.each do |t|
if t.should_destroy
@@ -83,5 +84,5 @@ class ArchiveFile
end
end
end
end
end
@@ -4,6 +4,9 @@
<%= check_box_tag 'to_delete[]', archive_file.id, false, :class => "checkbox_in_list" %>
<% end -%>
</td>
<td>
<%= archive_file.sort_number %>
</td>
<td>
<div class="label-group">
<div class="label-td">
@@ -3,9 +3,9 @@
<%= f.error_messages %>
<!--Widget start-->
<div id="sub-wiget">
<div id="widget-status" class="widget-box widget-size-300">
<div class="widget-action clear tip" title="Setting the announcement state">
<a class="action"><i class="icon-exclamation-sign icon-white"></i></a>
@@ -31,51 +31,54 @@
<%= tag.name %>
<% end %>
</div>
</div>
</div>
</div>
<!--Wiget End-->
<!--Post Start-->
<div id="post-body">
<div id="post-body-content" class="clear">
<%= f.label :category %>
<%= f.select :archive_file_category_id, @archive_file_categorys.collect {|t| [ t.title, t.id ]} %>
<%= f.label :sort_number %>
<%= f.text_field :sort_number %>
<ul class="nav nav-tabs">
<% @site_valid_locales.each_with_index do |locale, i| %>
<%# site_valid_locales_default_head.each_with_index do |locale, i| %>
<li <%= ( i == 0 ) ? "class=active" : '' %>><a data-toggle="tab" href=".<%= locale %>"><%= I18nVariable.from_locale(locale) %></a></li>
<% end %>
</ul>
<div class="tab-content">
<% @site_valid_locales.each_with_index do |locale, i| %>
<div class="<%= locale %> fade tab-pane <%= ( i == 0 ) ? "in active" : '' %>">
<div class="title">
<%= f.label :title %>
<%= f.fields_for :title_translations do |f| %>
<%= I18nVariable.from_locale(locale) %>
<%= f.text_field locale, :class=>'post-title', :value => (@archive_file.title_translations[locale] rescue nil) %>
<% end %>
<% end %>
</div>
</div>
<% end %>
</div>
<div>
<div class="archive_file_multiples_block">
<table class="table table-condensed">
<thead>
<tr>
@@ -94,38 +97,38 @@
</div>
</td>
</tr>
</tfoot>
<tbody>
<% @archive_file.archive_file_multiples.asc(:_id).each_with_index do |archive_file_multiple, i| %>
<%= f.fields_for :archive_file_multiples, archive_file_multiple do |f| %>
<%= render :partial => 'form_file', :object => archive_file_multiple, :locals => {:f => f, :i => i} %>
<% end %>
<% end %>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
<!--Post End-->
<div class="form-actions">
<%= hidden_field_tag 'page', params[:page] if !params[:page].blank? %>
<%= hidden_field_tag 'filter', params[:filter] %>
<%= f.submit t('submit'), :class=>'btn btn-primary' %>
<%= link_to t('cancel'), get_go_back, :class=>"btn" %>
<%= link_to t('cancel'), get_go_back, :class=>"btn" %>
</div>
</div>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "archive_form" %>
@@ -136,7 +139,7 @@
$(this).prev().attr('value', parseInt(new_id) + 1);
$(this).parents('table').append(("<%= escape_javascript(add_attribute 'form_file', f, :archive_file_multiples) %>").replace(old_id, new_id));
});
$('.archive_file_multiples_block a.delete').live('click', function(){
$(this).parents('.list_item').remove();
});
@@ -148,4 +151,4 @@
</script>
<% end %>
@@ -1,5 +1,6 @@
<%= render_sort_bar(true, delete_panel_archive_back_end_archive_files_path(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]),
['sort_number', 'sort_number', 'span1', :sort_number],
['status', ['is_top', 'is_hot', 'is_hidden'], 'span1', :status],
['category', 'archive_file_category', 'span2', :category],
['title', 'title','span3', :title],
['tags', 'tags', 'span2', :tags]).html_safe %>
['tags', 'tags', 'span2', :tags]).html_safe %>
@@ -3,6 +3,7 @@
<table class="table main-list">
<thead>
<tr>
<th class="span1"></th>
<th class="span1"></th>
<th class="span1"></th>
<th class="span2"></th>
@@ -20,4 +21,4 @@
<div id="archive_file_pagination" class="paginationFixed">
<%= paginate @archive_files, :params => {:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil} %>
</div>
</div>
</div>
@@ -8,13 +8,12 @@
<table>
<thead>
<tr>
<th class="column-ctrl col-title"><%= t("archive.Title")%></th>
<th class="column-ctrl col-title"><%= sortable(:title, t("archive.Title"))%></th>
<th class="column-ctrl col-file"><%= t("archive.Files")%></th>
<th class="column-ctrl col-category"><%= t("archive.Category")%></th>
<th class="column-ctrl col-category"><%= sortable(:archive_file_category, t("archive.Category"))%></th>
</tr>
</thead>
<tbody>
<% @archive_files.each_with_index do |post,i| %>
<tr <% if ( (i + 1) % 2 ) == 0 %> class="even" <% end %>>
<td><div class="o-archives-title"><%= post.title %></div></td>
@@ -22,7 +21,7 @@
<div class="o-archives-list-item">
<% if !post.archive_file_multiples.blank? %>
<ol>
<% post.archive_file_multiples.asc(:_id).each do | afile | %>
<% post.archive_file_multiples.asc(:_id).each do | afile | %>
<% if afile.file.file and afile.choose_lang_display(I18n.locale.to_s) %>
<li>
<%= link_to afile.file_title, afile.file.url, {:target => '_blank', :title => afile.file_title, :class => "o-archives-file"} %>
@@ -43,7 +42,7 @@
</tbody>
</table>
</div>
<div class="pull_right">
<div class="pull_right">
<% if !params[:category_id].blank? %>
<%= link_to t(:more_plus), panel_archive_front_end_archive_files_path(:category_id => @part.category) %>
<% else %>
@@ -72,7 +71,7 @@
<% if !post.archive_file_multiples.blank? %>
<ol>
<% post.archive_file_multiples.asc(:_id).each do | afile | %>
<% post.archive_file_multiples.asc(:_id).each do | afile | %>
<% if afile.file.file and afile.choose_lang_display(I18n.locale.to_s) %>
<li>
<%= link_to afile.file_title, afile.file.url, {:target => '_blank', :title => afile.file_title, :class => "o-archives-file"} %>
@@ -95,5 +94,5 @@
</div>
</div>
<% end %>
@@ -1 +1 @@
$('#bulletin_widget').html("<%= j render 'index' %>")
$('#archive_file_widget').html("<%= j render 'index' %>")
+5 -1
View File
@@ -8,4 +8,8 @@ zh_tw:
frontend:
archive: 檔案室前台
widget:
index: 檔案室Widget
index: 檔案室Widget
mongoid:
attributes:
archive_file:
sort_number: 排序數