1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-17 15:53:28 +00:00

[repo] improvement for 'file upload'

This commit is contained in:
llj
2014-07-25 16:23:22 +08:00
parent 79a21e0e6c
commit 2815bf9be6

View File

@@ -893,13 +893,44 @@ $('#upload-file').click(function () {
{% else %}
$('#upload-file').click(function () {
var upload_success = false;
var uploaded_files = [];
$('#upload-file-dialog').modal({
focus:false,
containerCss: {width:600, height:$(window).height()/1.5},
onClose: function() {
$.modal.close();
if (upload_success) {
reqDirData('{% url 'repo_dir_data' repo.id %}?p=' + e(cur_path));
if ($('.file-item').length == 0) { // there is no file before this upload
reqDirData('{% url 'repo_dir_data' repo.id %}?p=' + e(cur_path));
} else {
var file_tpl = $($('.file-item')[0]);
var path = cur_path;
for (var i = 0, len = uploaded_files.length; i < len; i++) { // [{'id':'', 'name':'', 'size':''}]
var new_file_data = uploaded_files[i];
var new_name = new_file_data.name;
var new_file_item = file_tpl.clone(true);
new_file_item.attr('data-name', new_file_data.name).data('time', new Date().getTime()/1000);
$('.file-star', new_file_item).attr('title', "{% trans "unstarred" %}").attr('class', 'icon-star-empty file-star').attr('data-status', 'unstarred');
$('.dirent-icon img', new_file_item).attr('src', '{{MEDIA_URL}}img/file/file.png');
var name_link = $('.dirent-name a', new_file_item);
name_link.html(new_name).attr('href', name_link.attr('href').substr(0, name_link.attr('href').indexOf('?')) + '?p=' + e(path+new_name));
var size_ct = $('.dirent-size', new_file_item);
if (new_file_data.size != undefined) {
size_ct.html(filesizeformat(new_file_data.size, 1));
} else { // no 'size' field, for IE
size_ct.html('');
}
$('.dirent-update', new_file_item).html("{% trans "Just now" %}");
$('.file-download', new_file_item).attr('href', '{{SITE_ROOT}}repo/{{repo.id}}/' + new_file_data.id + '/?file_name=' + e(new_name) + '&op=download');
$('.file-share', new_file_item).data('link', '').data('token', '');
var file_history = $('.file-history', new_file_item), fh_href = file_history.attr('href');
file_history.attr('href', fh_href.substr(0, fh_href.indexOf('?')) + '?p=' + e(path+new_name));
file_tpl.before(new_file_item);
}
updateCmt();
}
}
}
});
@@ -925,6 +956,7 @@ $('#upload-file').click(function () {
.bind('fileuploaddone', function(e, data) {
if (data.textStatus == 'success') {
upload_success = true;
uploaded_files.push(data.result[0]);
}
});