archive module: add sort feature to achive files

This commit is contained in:
iCross 2013-06-06 22:19:44 +08:00
parent c63ac751ea
commit 5b7ac1a22b
4 changed files with 34 additions and 21 deletions

View File

@ -21,7 +21,7 @@ module Mongoid
private private
def set_sort_number def set_sort_number
if self.sort_number.nil? if self.new? && self.sort_number.nil?
last_record = self.class.desc(:sort_number).first last_record = self.class.desc(:sort_number).first
if last_record if last_record
self.sort_number = (last_record.sort_number + 10) / 10 * 10 self.sort_number = (last_record.sort_number + 10) / 10 * 10

View File

@ -2,6 +2,7 @@ class ArchiveFileMultiple
include Mongoid::Document include Mongoid::Document
include Mongoid::Timestamps include Mongoid::Timestamps
include Mongoid::Sortable
mount_uploader :file, AssetUploader mount_uploader :file, AssetUploader
@ -11,6 +12,8 @@ class ArchiveFileMultiple
field :should_destroy, :type => Boolean field :should_destroy, :type => Boolean
default_scope asc(:sort_number)
def choose_lang_display(lang) def choose_lang_display(lang)
self.choose_lang.include?(lang) self.choose_lang.include?(lang)
end end

View File

@ -82,6 +82,7 @@
<table class="table table-condensed"> <table class="table table-condensed">
<thead> <thead>
<tr> <tr>
<th>排序數</th>
<th>File</th> <th>File</th>
<th>File Name</th> <th>File Name</th>
<th class="span2"><%= t('呈現語系')%></th> <th class="span2"><%= t('呈現語系')%></th>
@ -137,7 +138,9 @@
var new_id = $(this).prev().attr('value'); var new_id = $(this).prev().attr('value');
var old_id = new RegExp("new_archive_file_multiples", "g"); var old_id = new RegExp("new_archive_file_multiples", "g");
$(this).prev().attr('value', parseInt(new_id) + 1); $(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)); var new_form_file = $("<%= escape_javascript(add_attribute 'form_file', f, :archive_file_multiples) %>".replace(old_id, new_id));
new_form_file.find('input#archive_file_archive_file_multiples_attributes_'+new_id+'_sort_number').val(new_id * 10)
$(this).parents('table').append(new_form_file);
}); });
$('.archive_file_multiples_block a.delete').live('click', function(){ $('.archive_file_multiples_block a.delete').live('click', function(){

View File

@ -1,6 +1,13 @@
<% # encoding: utf-8 %> <% # encoding: utf-8 %>
<tr id="<%= "archive_file_multiple_#{form_file.id}" if !form_file.new_record? %>" class='list_item'> <tr id="<%= "archive_file_multiple_#{form_file.id}" if !form_file.new_record? %>" class='list_item'>
<td>
<div class="control-group">
<div class="controls">
<%= f.text_field :sort_number %>
</div>
</div>
</td>
<td> <td>
<div class="control-group"> <div class="control-group">
<div class="controls"> <div class="controls">