1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-03 16:10:26 +00:00

[system admin] trash repos: list by page

This commit is contained in:
llj
2016-06-20 15:47:26 +08:00
parent 9e2617e77b
commit 18a800cb5d
9 changed files with 315 additions and 40 deletions

View File

@@ -34,33 +34,32 @@ define([
this.$loadingTip = this.$('.loading-tip');
this.$emptyTip = this.$('.empty-tips');
this.$cleanBtn = this.$('.js-clean');
this.$jsPrevious = this.$('.js-previous');
this.$jsNext = this.$('.js-next');
},
events: {
'click .js-clean': 'cleanTrashLibraries'
'click .js-clean': 'cleanTrashLibraries',
'click #paginator .js-next': 'getNextPage',
'click #paginator .js-previous': 'getPreviousPage'
},
cleanTrashLibraries: function() {
var _this = this;
var popupTitle, popupContent;
var owner = this.trashRepoCollection.search_owner;
if (owner) {
popupTitle = gettext("Delete Library By Owner");
popupContent = gettext("Are you sure you want to delete all %s's libraries?").replace('%s', '<span class="op-target ellipsis ellipsis-op-target">' + Common.HTMLescape(owner) + '</span>');
} else {
popupTitle = gettext("Clear Trash");
popupContent = gettext("Are you sure you want to clear trash?");
}
var popupTitle = gettext("Clear Trash");
var popupContent = gettext("Are you sure you want to clear trash?");
var yesCallback = function() {
$.ajax({
url: Common.getUrl({'name':'admin-trash-libraries'}),
type: 'DELETE',
data: {'owner': _this.option.owner},
beforeSend: Common.prepareCSRFToken,
dataType: 'json',
success: function() {
_this.$cleanBtn.hide();
_this.$tip.hide();
_this.$table.hide();
_this.$jsNext.hide();
_this.$jsPrevious.hide();
_this.$emptyTip.show();
Common.feedback(gettext("Success"), 'success');
},
@@ -75,6 +74,29 @@ define([
Common.showConfirm(popupTitle, popupContent, yesCallback);
},
getNextPage: function() {
this.initPage();
var current_page = this.trashRepoCollection.state.current_page;
if (this.trashRepoCollection.state.has_next_page) {
this.trashRepoCollection.getPage(current_page + 1, {
reset: true
});
}
return false;
},
getPreviousPage: function() {
this.initPage();
var current_page = this.trashRepoCollection.state.current_page;
if (current_page > 1) {
this.trashRepoCollection.getPage(current_page - 1, {
reset: true
});
}
return false;
},
initPage: function() {
this.$tip.hide();
this.$table.hide();
@@ -82,6 +104,8 @@ define([
this.$loadingTip.show();
this.$emptyTip.hide();
this.$cleanBtn.hide();
this.$jsNext.hide();
this.$jsPrevious.hide();
},
hide: function() {
@@ -103,7 +127,7 @@ define([
var _this = this;
this.trashRepoCollection.fetch({
data: {'owner': this.option.owner},
data: {'page': this.option.page},
cache: false,
reset: true,
error: function (collection, response, opts) {
@@ -123,21 +147,38 @@ define([
},
reset: function() {
var length = this.trashRepoCollection.length;
// update the url
var current_page = this.trashRepoCollection.state.current_page;
app.router.navigate('trash-libs/?page=' + current_page);
this.$loadingTip.hide();
if (length > 0) {
if (this.trashRepoCollection.length > 0) {
this.trashRepoCollection.each(this.addOne, this);
this.$cleanBtn.show();
this.$tip.show();
this.$table.show();
this.renderPaginator();
} else {
this.$emptyTip.show();
this.$cleanBtn.hide();
}
},
renderPaginator: function() {
if (this.trashRepoCollection.state.has_next_page) {
this.$jsNext.show();
} else {
this.$jsNext.hide();
}
var current_page = this.trashRepoCollection.state.current_page;
if (current_page > 1) {
this.$jsPrevious.show();
} else {
this.$jsPrevious.hide();
}
},
addOne: function(library) {
var view = new TrashRepoView({model: library});
this.$tableBody.append(view.render().el);