file order mechanism changed

This commit is contained in:
Harry Bomrah 2016-02-16 18:10:52 +08:00
parent c676e4cabe
commit fb8ea6ebc7
4 changed files with 37 additions and 25 deletions

View File

@ -39,7 +39,7 @@ class Admin::ArchiveFilesController < OrbitAdminController
respond_to do |format|
if @archive_file.save
format.html { redirect_to(admin_archive_files_path) }
format.html { redirect_to(edit_admin_archive_file_path(@archive_file.id)) }
format.xml { render :xml => @archive_file, :status => :created, :location => @archive_file }
else
@tags = @module_app.tags
@ -58,7 +58,7 @@ class Admin::ArchiveFilesController < OrbitAdminController
respond_to do |format|
if @archive_file.update_attributes(archive_vars)
format.html { redirect_to(admin_archive_files_path(:page => params[:page])) }
format.html { redirect_to(edit_admin_archive_file_path(@archive_file.id)) }
format.xml { head :ok }
else
format.html { render :action => "edit" }

View File

@ -20,7 +20,7 @@ class ArchivesController < ApplicationController
}
end
files = []
archive.archive_file_multiples.order_by(:sort_number=>'asc').each do |file|
archive.archive_file_multiples.order_by(:sort_number=>'desc').each do |file|
if file.choose_lang.include?(I18n.locale.to_s)
title = (file.file_title.blank? ? File.basename(file.file.path) : file.file_title) rescue ""
extension = file.file.file.extension.downcase rescue ""

View File

@ -3,11 +3,18 @@
<%= stylesheet_link_tag "lib/main-forms" %>
<%= stylesheet_link_tag "lib/fileupload" %>
<%= stylesheet_link_tag "lib/main-list" %>
<style type="text/css">
.sort-order-icon{
font-size: 25px;
cursor: move;
}
</style>
<% end %>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "lib/bootstrap-fileupload" %>
<%= javascript_include_tag "lib/file-type" %>
<%= javascript_include_tag "lib/module-area" %>
<%= javascript_include_tag "lib/jquery-ui-sortable.min" %>
<% end %>
<%#= f.error_messages %>
@ -123,11 +130,20 @@
<div class="control-group">
<label class="control-label muted"><%= t(:file_) %></label>
<div class="controls">
<p class="add-btn">
<%= hidden_field_tag 'archive_file_multiple_field_count', @archive_file.archive_file_multiples.count %>
<a id="add_file" class="trigger btn btn-small btn-primary"><i class="icons-plus"></i> <%= t(:add) %></a>
</p>
</div>
</div>
<div class="control-group">
<div class="controls">
<!-- Add -->
<div class="add-target" id="add-target"></div>
<!-- Exist -->
<% if @archive_file && !@archive_file.archive_file_multiples.blank? %>
<div class="exist">
<% @archive_file.archive_file_multiples.each_with_index do |archive_file_multiple, i| %>
<div class="exist plugin-sortable">
<% @archive_file.archive_file_multiples.desc(:sort_number).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 %>
@ -135,40 +151,38 @@
<hr>
</div>
<% end %>
<!-- Add -->
<div class="add-target">
</div>
<p class="add-btn">
<%= hidden_field_tag 'archive_file_multiple_field_count', @archive_file.archive_file_multiples.count %>
<a id="add_file" class="trigger btn btn-small btn-primary"><i class="icons-plus"></i> <%= t(:add) %></a>
</p>
</div>
</div>
</div>
</div>
<!-- Form Actions -->
<div class="form-actions">
<%= hidden_field_tag 'page', params[:page] if !params[:page].blank? %>
<%= f.submit t('submit'), class: 'btn btn-primary' %>
<a href="/<%= I18n.locale.to_s %>/admin/archive_files/" class="btn" >Cancel</a>
<a href="<%= admin_archive_files_path %>" class="btn">Back to Archives</a>
</div>
<% content_for :page_specific_javascript do %>
<script>
$(document).ready(function() {
$(".plugin-sortable").sortable({
update : function(event, ui){
var existingfiles = $(".exist.plugin-sortable div.fileupload")
existingfiles.each(function(i, file){
$(file).find("input.file-sort-number-field").val(existingfiles.length - i);
})
}
});
$('.main-forms .add-on').tooltip();
$(document).on('click', '#add_file', function(){
var new_id = $(this).prev().attr('value');
var old_id = new RegExp("new_archive_file_multiples", "g");
var on = $('.language-nav li.active').index();
var le = $(this).parent('.add-btn').prev('.add-target').children('.start-line').length;
var le = $('#add-target').children('.start-line').length;
$(this).prev().attr('value', parseInt(new_id) + 1);
$(this).parent().siblings('.add-target').append(("<%= escape_javascript(add_attribute 'form_file', f, :archive_file_multiples) %>").replace(old_id, new_id));
$(this).parent('.add-btn').prev('.add-target').children('.start-line').eq(le).children('.input-append').find('.tab-content').each(function() {
$('#add-target').prepend(("<%= escape_javascript(add_attribute 'form_file', f, :archive_file_multiples) %>").replace(old_id, new_id).replace("new_archive_file_sort_order_XXX", parseInt(new_id) + 1));
$('#add-target').children('.start-line').eq(le).children('.input-append').find('.tab-content').each(function() {
$(this).children('.tab-pane').eq(on).addClass('in active').siblings().removeClass('in active');
});
formTip();

View File

@ -2,6 +2,7 @@
<div class="fileupload fileupload-new start-line" data-provides="fileupload">
<% else %>
<div class="fileupload fileupload-exist start-line" data-provides="fileupload">
<i class="icons-list-2 sort-order-icon"></i>
<% if form_file.file.blank? %>
<%= t(:no_file) %>
<% else %>
@ -30,11 +31,6 @@
<% end %>
</span>
<span class="add-on icon-list-ol" title="<%= t(:sort_number) %>"></span>
<span class="tab-content">
<%= f.text_field :sort_number , :class => "input-mini" %>
</span>
<span class="add-on btn-group btn" title="<%= t('archive.show_lang') %>">
<i class="icons-earth"></i> <span class="caret"></span>
<ul class="dropdown-menu">
@ -53,10 +49,12 @@
<% if form_file.new_record? %>
<span class="delete_file add-on btn" title="<%= t(:delete_) %>">
<a class="icon-trash"></a>
<%= f.hidden_field :sort_number, :value => "new_archive_file_sort_order_XXX", :class => "input-mini" %>
</span>
<% else %>
<span class="remove_existing_record add-on btn" title="<%= t(:remove) %>">
<%= f.hidden_field :id %>
<%= f.hidden_field :sort_number , :class => "file-sort-number-field" %>
<a class=" icon-remove"></a>
<%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %>
</span>