mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-02 07:27:04 +00:00
update zip download dir
This commit is contained in:
@@ -414,7 +414,7 @@
|
||||
|
||||
<script type="text/template" id="grid-view-dir-op-tmpl">
|
||||
<ul class="grid-item-op sf-dropdown-menu">
|
||||
<li><a class="op download" href="<%= download_url %>">{% trans "Download" %}</a></li>
|
||||
<li><a class="op download" href="#">{% trans "Download" %}</a></li>
|
||||
<% if (!repo_encrypted && (can_generate_share_link || can_generate_upload_link || is_repo_owner)) { %>
|
||||
<li><a class="op share" href="#">{% trans "Share" %}</a></li>
|
||||
<% } %>
|
||||
|
@@ -788,67 +788,19 @@ define([
|
||||
},
|
||||
|
||||
download: function () {
|
||||
var dirents = this.dir;
|
||||
var parent_dir = dirents.path;
|
||||
var selected_dirents = dirents.where({'selected':true});
|
||||
|
||||
var selected_dirents = this.dir.where({'selected':true});
|
||||
// select 1 item, and it is a file
|
||||
if (selected_dirents.length == 1 &&
|
||||
selected_dirents[0].get('is_file')) {
|
||||
location.href = selected_dirents[0].getDownloadUrl();
|
||||
return;
|
||||
}
|
||||
|
||||
var selected_names = [];
|
||||
var interval;
|
||||
var zip_token;
|
||||
var packagingTip = gettext("Packaging...");
|
||||
var $tip = $('<p></p>');
|
||||
var queryZipProgress = function() {
|
||||
$.ajax({
|
||||
url: Common.getUrl({name: 'query_zip_progress'}) + '?token=' + zip_token,
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
success: function(data) {
|
||||
var progress = data.total == 0 ? '100%' : (data.zipped/data.total*100).toFixed(0) + '%';
|
||||
$tip.html(packagingTip + ' ' + progress);
|
||||
if (data['total'] == data['zipped']) {
|
||||
setTimeout(function() { $.modal.close(); }, 500);
|
||||
clearInterval(interval);
|
||||
location.href = Common.getUrl({
|
||||
name: 'download_dir_zip_url',
|
||||
zip_token: zip_token
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function(xhr) {
|
||||
Common.ajaxErrorHandler(xhr);
|
||||
clearInterval(interval);
|
||||
}
|
||||
});
|
||||
};
|
||||
$(selected_dirents).each(function() {
|
||||
selected_names.push(this.get('obj_name'));
|
||||
});
|
||||
$.ajax({
|
||||
url: Common.getUrl({name: 'zip_task', repo_id: dirents.repo_id}),
|
||||
data: {
|
||||
'parent_dir': parent_dir,
|
||||
'dirents': selected_names
|
||||
},
|
||||
traditional: true,
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
zip_token = data['zip_token'];
|
||||
$tip.html(packagingTip).modal();
|
||||
$('#simplemodal-container').css({'width':'auto'});
|
||||
queryZipProgress();
|
||||
interval = setInterval(queryZipProgress, 1000);
|
||||
},
|
||||
error: function(xhr) {
|
||||
Common.ajaxErrorHandler(xhr);
|
||||
}
|
||||
});
|
||||
|
||||
Common.zipDownloadDirents(this.dir.repo_id, this.dir.path, selected_names);
|
||||
},
|
||||
|
||||
del: function () {
|
||||
|
@@ -107,7 +107,6 @@ define([
|
||||
var op = template({
|
||||
dirent: this.model.attributes,
|
||||
dirent_path: this.model.getPath(),
|
||||
download_url: this.model.getDownloadUrl(),
|
||||
category: dir.category,
|
||||
repo_id: dir.repo_id,
|
||||
is_repo_owner: dir.is_repo_owner,
|
||||
@@ -127,6 +126,7 @@ define([
|
||||
|
||||
// Using _.bind(function, object) to make that whenever the function is
|
||||
// called, the value of this will be the object.
|
||||
this.$('.download').on('click', _.bind(this.download, this));
|
||||
this.$('.delete').on('click', _.bind(this.del, this));
|
||||
this.$('.share').on('click', _.bind(this.share, this));
|
||||
this.$('.mv').on('click', _.bind(this.mvcp, this));
|
||||
@@ -151,6 +151,13 @@ define([
|
||||
this.$('.grid-item-op').remove();
|
||||
},
|
||||
|
||||
download: function() {
|
||||
this.closeMenu();
|
||||
var obj_name = this.model.get('obj_name');
|
||||
Common.zipDownloadDirents(this.dir.repo_id, this.dir.path, obj_name);
|
||||
return false;
|
||||
},
|
||||
|
||||
del: function(event) {
|
||||
this.closeMenu();
|
||||
var dirent_name = this.model.get('obj_name');
|
||||
|
@@ -127,58 +127,7 @@ define([
|
||||
},
|
||||
|
||||
downloadDir: function() {
|
||||
var dir = this.dirView.dir;
|
||||
var obj_name = this.model.get('obj_name');
|
||||
var interval;
|
||||
var zip_token;
|
||||
var packagingTip = gettext("Packaging...");
|
||||
var $tip = $('<p></p>');
|
||||
var queryZipProgress = function() {
|
||||
$.ajax({
|
||||
url: Common.getUrl({name: 'query_zip_progress'}) + '?token=' + zip_token,
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
success: function(data) {
|
||||
var progress = data.total == 0 ? '100%' : (data.zipped/data.total*100).toFixed(0) + '%';
|
||||
$tip.html(packagingTip + ' ' + progress);
|
||||
if (data['total'] == data['zipped']) {
|
||||
setTimeout(function() { $.modal.close(); }, 500);
|
||||
clearInterval(interval);
|
||||
location.href = Common.getUrl({
|
||||
name: 'download_dir_zip_url',
|
||||
zip_token: zip_token
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function(xhr) {
|
||||
Common.ajaxErrorHandler(xhr);
|
||||
clearInterval(interval);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: Common.getUrl({
|
||||
name: 'zip_task',
|
||||
repo_id: dir.repo_id
|
||||
}),
|
||||
data: {
|
||||
'parent_dir': dir.path,
|
||||
'dirents': obj_name
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
zip_token = data['zip_token'];
|
||||
$tip.html(packagingTip).modal();
|
||||
$('#simplemodal-container').css({'width':'auto'});
|
||||
queryZipProgress();
|
||||
interval = setInterval(queryZipProgress, 1000);
|
||||
},
|
||||
error: function(xhr) {
|
||||
Common.ajaxErrorHandler(xhr);
|
||||
}
|
||||
});
|
||||
|
||||
Common.zipDownloadDirents(this.dirView.dir.repo_id, this.dirView.dir.path, this.model.get('obj_name'));
|
||||
return false;
|
||||
},
|
||||
|
||||
|
@@ -952,7 +952,60 @@ define([
|
||||
} else {
|
||||
return input.setSelectionRange(pos, pos);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
zipDownloadDirents:function(repo_id, parent_dir, dirents) {
|
||||
var _this = this;
|
||||
var interval;
|
||||
var zip_token;
|
||||
var packagingTip = gettext("Packaging...");
|
||||
var $tip = $('<p></p>');
|
||||
var queryZipProgress = function() {
|
||||
$.ajax({
|
||||
url: _this.getUrl({name: 'query_zip_progress'}) + '?token=' + zip_token,
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
success: function(data) {
|
||||
var progress = data.total == 0 ? '100%' : (data.zipped/data.total*100).toFixed(0) + '%';
|
||||
$tip.html(packagingTip + ' ' + progress);
|
||||
if (data['total'] == data['zipped']) {
|
||||
setTimeout(function() { $.modal.close(); }, 500);
|
||||
clearInterval(interval);
|
||||
location.href = _this.getUrl({
|
||||
name: 'download_dir_zip_url',
|
||||
zip_token: zip_token
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function(xhr) {
|
||||
_this.ajaxErrorHandler(xhr);
|
||||
clearInterval(interval);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: _this.getUrl({
|
||||
name: 'zip_task',
|
||||
repo_id: repo_id
|
||||
}),
|
||||
data: {
|
||||
'parent_dir': parent_dir,
|
||||
'dirents': dirents
|
||||
},
|
||||
traditional: true,
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
zip_token = data['zip_token'];
|
||||
$tip.html(packagingTip).modal();
|
||||
$('#simplemodal-container').css({'width':'auto'});
|
||||
queryZipProgress();
|
||||
interval = setInterval(queryZipProgress, 1000);
|
||||
},
|
||||
error: function(xhr) {
|
||||
_this.ajaxErrorHandler(xhr);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user