redmine_dmsf/app/views/dmsf_upload/_multi_upload.html.erb
2018-01-16 09:38:24 +01:00

139 lines
5.9 KiB
Plaintext

<%
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
#
# Copyright © 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright © 2012 Daniel Munn <dan.munn@munnster.co.uk>
# Copyright © 2011-18 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
%>
<div class="dmsf_upload_select">
<select id="uploader_select">
<option value="1">
<%= l(:label_drag_drop) %>
</option>
<option value="2">
<%= l(:label_classic) %>
</option>
</select>
</div>
<h3><%= l(:label_upload) %></h3>
<%= form_tag({:controller => 'dmsf_upload', :action => 'upload_files', :id => @project, :folder_id => @folder},
:id => 'uploadform', :method => :post, :multipart => true) do %>
<div id="dmsf_uploader">
<span class="dmsf_uploader">
<%= render :partial => 'dmsf_upload/form',
:locals => { :multiple => true, :container => nil, :description => true, :awf => false } %>
</span>
<%= submit_tag l(:label_upload) %>
</div>
<% end %>
<%# TODO: late_javascript_tag is not working here %>
<%= javascript_tag do %>
var originalUploaderContent;
var uploader = $('#dmsf_uploader');
originalUploaderContent = uploader.html();
$('#uploader_select').change(function() {
if($(this).val() === '2') {
uploader.html(originalUploaderContent);
dmsfSetupFileDrop();
} else {
initPlUploader(uploader);
}
});
initPlUploader(uploader);
var dmsfFileFieldCount = 1;
<% end %>
<% content_for :header_tags do %>
<%= stylesheet_link_tag 'plupload/jquery.ui.plupload.css', :plugin => 'redmine_dmsf' %>
<%= javascript_include_tag 'plupload/js/plupload.full.min.js', :plugin => 'redmine_dmsf' %>
<%= javascript_include_tag 'plupload/js/jquery.ui.plupload/jquery.ui.plupload.js', :plugin => 'redmine_dmsf' %>
<%= javascript_include_tag(js_url, :plugin => 'redmine_dmsf') %>
<%= javascript_tag do %>
function initPlUploader(uploader) {
uploader.html('<div></div>');
uploader = $('div', uploader);
uploader.plupload({
runtimes : 'html5,flash,silverlight,html4',
url : '<%= url_for({:controller => 'dmsf_upload', :action => 'upload_file', :id => @project}) %>',
max_file_size : '<%= "#{@ajax_upload_size}mb" %>',
max_file_count: '<%= Setting.plugin_redmine_dmsf['dmsf_max_file_upload'].to_i if Setting.plugin_redmine_dmsf['dmsf_max_file_upload'].to_i > 0 %>',
multipart: true,
// Enable ability to drag'n'drop files onto the widget (currently only HTML5 supports that)
dragdrop: true,
multipart_params : { authenticity_token : $('input[name=authenticity_token]').val() },
// Rename files by clicking on their titles
rename: true,
// Views to activate
views: {
list: true,
thumbs: true, // Show thumbs
active: 'thumbs'
},
// Flash settings
flash_swf_url : '<%= plugin_asset_path(:redmine_dmsf, 'javascripts', 'plupload/js/Moxie.swf') %>',
// Silverlight settings
silverlight_xap_url : '<%= plugin_asset_path(:redmine_dmsf, 'javascripts', 'plupload/js/Moxie.xap') %>'
});
$('.plupload_scroll',uploader).resizable({
handles: 's'
});
var pluploader = uploader.plupload('getUploader');
pluploader.bind('FileUploaded', function(pluploader, file, response) {
var responseObject = $.parseJSON(response.response);
if (responseObject == null) { //Bug: on Firefox folders entries act unexpectedly.
file.status = plupload.FAILED;
pluploader.trigger('UploadProgress', file);
pluploader.trigger('QueueChanged');
} else {
if (responseObject.error == null) {
var disk_filename_input = $('<input/>').attr('type', 'hidden')
.attr('name', 'uploaded[' + dmsfFileFieldCount + '][disk_filename]')
.val(responseObject.disk_filename);
uploader.append(disk_filename_input);
var content_type_input = $('<input/>').attr('type', 'hidden')
.attr('name', 'uploaded[' + dmsfFileFieldCount + '][content_type]')
.val(responseObject.content_type);
uploader.append(content_type_input);
var original_filename_input = $('<input/>').attr('type', 'hidden')
.attr('name', 'uploaded[' + dmsfFileFieldCount + '][original_filename]')
.val(responseObject.original_filename);
uploader.append(original_filename_input);
var tempfile_path = $('<input/>').attr('type', 'hidden')
.attr('name', 'uploaded[' + dmsfFileFieldCount + '][tempfile_path]')
.val(responseObject.tempfile_path);
uploader.append(tempfile_path);
} else {
file.status = plupload.FAILED;
pluploader.trigger('UploadProgress', file);
pluploader.trigger('QueueChanged');
}
}
if(pluploader.total.uploaded == pluploader.files.length) $('#uploadform').submit();
else if((pluploader.total.uploaded + pluploader.total.failed) == pluploader.files.length) setTimeout(function() {$('#uploadform').submit();}, 2000);
else dmsfFileFieldCount++;
return true;
});
}
<% end %>
<% end %>