mirror of
https://github.com/haiwen/seahub.git
synced 2025-07-13 15:05:30 +00:00
98 lines
3.2 KiB
HTML
98 lines
3.2 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 submit_and_real_time_show (dialog_id) {
|
|
var form = $(dialog_id + ' form')[0],
|
|
uuid = gen_uuid(); // id for this upload so we can fetch progress info.
|
|
$(dialog_id + ' #upload-progress').removeClass('hide');
|
|
|
|
// Append X-Progress-ID uuid form action
|
|
form.action += (form.action.indexOf('?') == -1 ? '?' : '&') + 'X-Progress-ID=' + uuid;
|
|
form.submit();
|
|
$(dialog_id + ' form .submit').addClass('hide');
|
|
|
|
// Update progress bar: not work in chrome.
|
|
function update_progress_info() {
|
|
$.ajax({
|
|
url: '{{ httpserver_root }}/upload_progress/?X-Progress-ID=' + uuid + '&callback=?',
|
|
dataType: 'jsonp',
|
|
cache: false,
|
|
success: function(data) {
|
|
if (data) {
|
|
$(dialog_id + ' #upload-progress-text').html(filesizeformat(data.uploaded, 2) + ' / ' + filesizeformat(data.length, 2));
|
|
$(dialog_id + ' #task-progress-bar').removeClass('hide').progressbar({
|
|
value: data.uploaded / data.length * 100
|
|
});
|
|
}
|
|
}
|
|
});
|
|
setTimeout(update_progress_info, 1000);
|
|
};
|
|
update_progress_info();
|
|
|
|
// Update progress bar: for chrome
|
|
if ($.browser.safari) {
|
|
$(dialog_id + ' iframe').attr('src', '{{ SITE_ROOT }}file_upload_progress_page/?uuid=' + uuid + '&dlg_id=' + dialog_id.substr(1));
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
if (this.files) {
|
|
var total = 0;
|
|
$.each($('#upload-file-form input[type=file]'), function() {
|
|
if($(this).val()) {
|
|
total += this.files[0].size;
|
|
}
|
|
});
|
|
if (total > {{ 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
|
|
submit_and_real_time_show('#upload-file-dialog');
|
|
return false;
|
|
});
|
|
|
|
$('#upload-file-dialog #upload-cancel').click(function() {
|
|
location.reload(true);
|
|
});
|
|
|
|
$('#update-file-form .submit').click(function () {
|
|
if (!$.trim($('#update-file-form input[type=file]').val())) {
|
|
$('#update-file-form .error').html('{% trans "Please choose a file at first." %}').removeClass('hide');
|
|
return false;
|
|
}
|
|
|
|
$('#update-file-form .error').addClass('hide');
|
|
|
|
$.fn.MultiFile.disableEmpty(); // disable dummy element before submiting the form
|
|
submit_and_real_time_show('#update-file-dialog');
|
|
return false;
|
|
});
|
|
|
|
$('#update-file-dialog #upload-cancel').click(function() {
|
|
location.reload(true);
|
|
});
|
|
|
|
</script>
|
|
{% endif %}
|