1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-14 15:35:35 +00:00
seahub/templates/snippets/file_upload_progress_js.html
2012-11-17 17:31:37 +08:00

85 lines
2.8 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) + ' / ' + filesizeformat(data.length));
$(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) {
$('#request-progress').attr('src', '{{ SITE_ROOT }}file_upload_progress_page/?uuid=' + uuid);
}
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;
}
$('#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 %}