1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-06-23 21:58:53 +00:00
seahub/static/scripts/sysadmin-app/views/trash-repos.js

120 lines
3.6 KiB
JavaScript
Raw Normal View History

2016-05-25 02:45:22 +00:00
define([
'jquery',
'underscore',
'backbone',
'common',
'moment',
2016-05-27 08:42:40 +00:00
'sysadmin-app/views/trash-repo',
'sysadmin-app/collection/trash-repos'
], function($, _, Backbone, Common, Moment, TrashRepoView,
TrashRepoCollection) {
2016-05-25 02:45:22 +00:00
'use strict';
2016-05-27 08:42:40 +00:00
var TrashReposView = Backbone.View.extend({
2016-05-25 02:45:22 +00:00
2016-05-27 08:42:40 +00:00
id: 'trash-libraries',
2016-05-25 02:45:22 +00:00
template: _.template($("#trash-libraries-tmpl").html()),
initialize: function() {
2016-05-27 08:42:40 +00:00
this.trashRepoCollection = new TrashRepoCollection();
this.listenTo(this.trashRepoCollection, 'add', this.addOne);
this.listenTo(this.trashRepoCollection, 'reset', this.reset);
2016-05-25 02:45:22 +00:00
},
render: function() {
var data = {'cur_tab': 'trash',};
this.$el.html(this.template(data));
this.$table = this.$('table');
this.$tableBody = $('tbody', this.$table);
this.$loadingTip = this.$('.loading-tip');
this.$emptyTip = this.$('.empty-tips');
},
events: {
'click #clean-trash-libraries': 'cleanTrashLibraries',
},
cleanTrashLibraries: function() {
var _this = this;
$.ajax({
url: Common.getUrl({'name':'admin-trash-libraries'}),
type: 'DELETE',
beforeSend: Common.prepareCSRFToken,
dataType: 'json',
success: function() {
_this.$table.hide();
_this.$emptyTip.show();
Common.feedback(gettext("Success"), 'success');
},
error: function(xhr, textStatus, errorThrown) {
Common.ajaxErrorHandler(xhr, textStatus, errorThrown);
}
})
},
initPage: function() {
this.$table.hide();
this.$tableBody.empty();
this.$loadingTip.show();
this.$emptyTip.hide();
},
hide: function() {
this.$el.detach();
},
show: function(option) {
this.option = option;
this.render();
$("#right-panel").html(this.$el);
this.showTrashLibraries();
},
showTrashLibraries: function() {
this.initPage();
var _this = this;
2016-05-27 08:42:40 +00:00
this.trashRepoCollection.fetch({
2016-05-25 02:45:22 +00:00
data: {},
cache: false, // for IE
reset: true,
error: function (collection, response, opts) {
var err_msg;
if (response.responseText) {
if (response['status'] == 401 || response['status'] == 403) {
err_msg = gettext("Permission error");
} else {
err_msg = $.parseJSON(response.responseText).error_msg;
}
} else {
err_msg = gettext("Failed. Please check the network.");
}
Common.feedback(err_msg, 'error');
}
});
},
reset: function() {
2016-05-27 08:42:40 +00:00
var length = this.trashRepoCollection.length;
2016-05-25 02:45:22 +00:00
this.$loadingTip.hide();
if (length > 0) {
2016-05-27 08:42:40 +00:00
this.trashRepoCollection.each(this.addOne, this);
2016-05-25 02:45:22 +00:00
this.$table.show();
} else {
this.$emptyTip.show();
}
},
addOne: function(library) {
2016-05-27 08:42:40 +00:00
var view = new TrashRepoView({model: library});
2016-05-25 02:45:22 +00:00
this.$tableBody.append(view.render().el);
}
});
2016-05-27 08:42:40 +00:00
return TrashReposView;
2016-05-25 02:45:22 +00:00
});