archive module: add sort feature to achive files
This commit is contained in:
parent
c63ac751ea
commit
5b7ac1a22b
|
@ -21,7 +21,7 @@ module Mongoid
|
|||
private
|
||||
|
||||
def set_sort_number
|
||||
if self.sort_number.nil?
|
||||
if self.new? && self.sort_number.nil?
|
||||
last_record = self.class.desc(:sort_number).first
|
||||
if last_record
|
||||
self.sort_number = (last_record.sort_number + 10) / 10 * 10
|
||||
|
|
|
@ -2,23 +2,26 @@ class ArchiveFileMultiple
|
|||
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
include Mongoid::Sortable
|
||||
|
||||
mount_uploader :file, AssetUploader
|
||||
|
||||
|
||||
field :file_title, localize: true
|
||||
# field :description
|
||||
field :choose_lang, :type => Array, :default => nil
|
||||
|
||||
|
||||
field :should_destroy, :type => Boolean
|
||||
|
||||
default_scope asc(:sort_number)
|
||||
|
||||
def choose_lang_display(lang)
|
||||
self.choose_lang.include?(lang)
|
||||
end
|
||||
|
||||
|
||||
belongs_to :archive_file
|
||||
|
||||
|
||||
# has_many :archive_file_multiple_langs, :autosave => true, :dependent => :destroy
|
||||
|
||||
|
||||
# accepts_nested_attributes_for :archive_file_multiple_langs, :allow_destroy => true
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -82,6 +82,7 @@
|
|||
<table class="table table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>排序數</th>
|
||||
<th>File</th>
|
||||
<th>File Name</th>
|
||||
<th class="span2"><%= t('呈現語系')%></th>
|
||||
|
@ -137,7 +138,9 @@
|
|||
var new_id = $(this).prev().attr('value');
|
||||
var old_id = new RegExp("new_archive_file_multiples", "g");
|
||||
$(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(){
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
<% # encoding: utf-8 %>
|
||||
|
||||
<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>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
|
@ -8,13 +15,13 @@
|
|||
<%= form_file.file.file ? ( link_to t(:view), form_file.file.url, {:class => 'btn', :target => '_blank', :title => t(:view)} ) : '' %>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
<div class="tab-content">
|
||||
|
||||
|
||||
<% @site_valid_locales.each_with_index do |locale, i| %>
|
||||
|
||||
|
||||
<div class="<%= locale %> fade tab-pane <%= ( i == 0 ) ? "in active" : '' %>">
|
||||
<%#= f.fields_for :i18n_variable, (form_file.new_record? ? form_file.build_i18n_variable : form_file.i18n_variable ) do |f| %>
|
||||
<%= f.fields_for :file_title_translations do |f| %>
|
||||
|
@ -24,14 +31,14 @@
|
|||
<%= f.text_field locale, :class=>'post-file_title', :value => (form_file.file_title_translations[locale] rescue nil) %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
|
||||
<% end %>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</td>
|
||||
<td>
|
||||
<% @site_valid_locales.each do |locale| %>
|
||||
|
@ -40,18 +47,18 @@
|
|||
<% end %>
|
||||
<%= hidden_field_tag 'archive_file[archive_file_multiples_attributes][0][choose_lang][]', '' %>
|
||||
</td>
|
||||
|
||||
|
||||
<td>
|
||||
<span class="action">
|
||||
<% if form_file.new_record? %>
|
||||
<a class="delete"><i class="icon-remove"></i></a>
|
||||
<% else %>
|
||||
<% else %>
|
||||
<%= f.hidden_field :id %>
|
||||
<a class="remove_existing_record"><i class="icon-remove"></i></a>
|
||||
<%= f.hidden_field :should_destroy, :value => nil, :class => 'should_destroy' %>
|
||||
<% end %>
|
||||
</span>
|
||||
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
|
|
Reference in New Issue