mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-12 04:12:16 +00:00
89 lines
3.1 KiB
HTML
89 lines
3.1 KiB
HTML
{% load i18n %}
|
|
{% if not cloud_mode or not no_quota %}
|
|
<script type="text/javascript">
|
|
function gen_uuid() {
|
|
var uuid = "";
|
|
for (var i=0; i < 32; i++) {
|
|
uuid += Math.floor(Math.random() * 16).toString(16);
|
|
}
|
|
return uuid;
|
|
}
|
|
|
|
function submitAndShowProgress(form, upload_progress_con) {
|
|
var uuid = gen_uuid(); // id for this upload so we can fetch progress info.
|
|
upload_progress_con.removeClass('hide');
|
|
|
|
// Append X-Progress-ID uuid form action
|
|
var form_action = form.attr('action');
|
|
form.attr('action', form_action += (form_action.indexOf('?') == -1 ? '?' : '&') + 'X-Progress-ID=' + uuid);
|
|
form.submit();
|
|
form.find('.submit').addClass('hide');
|
|
|
|
// Update progress: not work in chrome.
|
|
function updateProgress() {
|
|
$.ajax({
|
|
url: '{{ httpserver_root }}/upload_progress/?X-Progress-ID=' + uuid + '&callback=?',
|
|
dataType: 'jsonp',
|
|
cache: false,
|
|
success: function(data) {
|
|
if (data) {
|
|
upload_progress_con.find('.upload-progress-text').html(filesizeformat(data.uploaded, 2) + ' / ' + filesizeformat(data.length, 2));
|
|
upload_progress_con.children('.upload-progress-bar').progressbar({
|
|
value: data.uploaded / data.length * 100
|
|
});
|
|
}
|
|
}
|
|
});
|
|
setTimeout(updateProgress, 1000);
|
|
};
|
|
updateProgress();
|
|
|
|
// Update progress bar: for chrome
|
|
if ($.browser.safari) {
|
|
upload_progress_con.children('iframe').attr('src', '{{ SITE_ROOT }}file_upload_progress_page/?uuid=' + uuid + '&upload_progress_con_id=' + upload_progress_con.attr('id'));
|
|
}
|
|
|
|
return false;
|
|
};
|
|
|
|
$('#upload-file-form .submit').click(function () {
|
|
if (!$.trim($('#upload-file-form input[type=file]').val())) {
|
|
$('#upload-file-form .error').html('{% trans "Please choose a file at first." %}').removeClass('hide');
|
|
return false;
|
|
}
|
|
|
|
var total_size = 0;
|
|
$.each($('#upload-file-form input[type=file]'), function() {
|
|
if(this.files && this.files.length > 0) {
|
|
total_size += this.files[0].size;
|
|
}
|
|
});
|
|
if (total_size > {{ max_upload_file_size }}) {
|
|
$('#upload-file-form .error').html('{% trans "File size surpasses the limit." %}').removeClass('hide');
|
|
return false;
|
|
}
|
|
|
|
$('#upload-file-form .error').addClass('hide');
|
|
|
|
$.fn.MultiFile.disableEmpty(); // disable dummy element before submiting the form
|
|
submitAndShowProgress($('#upload-file-form'), $('#upload-progress-con'))
|
|
return false;
|
|
});
|
|
|
|
|
|
$('#update-file-form .submit').click(function () {
|
|
if (!$.trim($('#file-update-input').val())) {
|
|
$('#update-file-form .error').html('{% trans "Please choose a file at first." %}').removeClass('hide');
|
|
return false;
|
|
}
|
|
$('#update-file-form .error').addClass('hide');
|
|
submitAndShowProgress($('#update-file-form'), $('#update-progress-con'))
|
|
return false;
|
|
});
|
|
|
|
$('#upload-progress-con .upload-cancel, #update-progress-con .unload-cancel').click(function() {
|
|
location.reload();
|
|
});
|
|
</script>
|
|
{% endif %}
|