1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-06-22 13:18:42 +00:00
seahub/static/scripts/sysadmin-app/views/repos.js

154 lines
4.7 KiB
JavaScript
Raw Normal View History

2016-05-25 02:45:22 +00:00
define([
'jquery',
'underscore',
'backbone',
'common',
2016-05-27 08:42:40 +00:00
'sysadmin-app/views/repo',
'sysadmin-app/collection/repos'
], function($, _, Backbone, Common, RepoView, RepoCollection) {
2016-05-25 02:45:22 +00:00
'use strict';
2016-05-27 08:42:40 +00:00
var ReposView = Backbone.View.extend({
2016-05-25 02:45:22 +00:00
2016-05-27 08:42:40 +00:00
id: 'libraries',
2016-05-25 02:45:22 +00:00
tabNavTemplate: _.template($("#libraries-tabnav-tmpl").html()),
2016-05-25 02:45:22 +00:00
template: _.template($("#libraries-tmpl").html()),
initialize: function() {
2016-05-27 08:42:40 +00:00
this.repoCollection = new RepoCollection();
this.listenTo(this.repoCollection, 'add', this.addOne);
this.listenTo(this.repoCollection, 'reset', this.reset);
2016-05-25 02:45:22 +00:00
this.render();
},
render: function() {
var $tabnav = $(this.tabNavTemplate({'cur_tab': 'all'}));
this.$el.append($tabnav);
this.$el.append(this.template());
2016-05-25 02:45:22 +00:00
this.$table = this.$('table');
this.$tableBody = $('tbody', this.$table);
this.$loadingTip = this.$('.loading-tip');
this.$emptyTip = this.$('.empty-tips');
this.$jsPrevious = this.$('.js-previous');
this.$jsNext = this.$('.js-next');
},
events: {
'click #paginator .js-next': 'getNextPage',
'click #paginator .js-previous': 'getPreviousPage'
},
initPage: function() {
this.$table.hide();
this.$tableBody.empty();
this.$loadingTip.show();
this.$emptyTip.hide();
this.$jsNext.hide();
this.$jsPrevious.hide();
},
getNextPage: function() {
this.initPage();
2016-05-27 08:42:40 +00:00
var current_page = this.repoCollection.state.current_page;
if (this.repoCollection.state.has_next_page) {
2016-05-27 08:42:40 +00:00
this.repoCollection.getPage(current_page + 1, {
2016-05-25 02:45:22 +00:00
reset: true
});
}
return false;
},
getPreviousPage: function() {
this.initPage();
2016-05-27 08:42:40 +00:00
var current_page = this.repoCollection.state.current_page;
if (current_page > 1) {
2016-05-27 08:42:40 +00:00
this.repoCollection.getPage(current_page - 1, {
2016-05-25 02:45:22 +00:00
reset: true
});
}
return false;
},
hide: function() {
this.$el.detach();
this.attached = false;
},
show: function(option) {
this.option = option;
if (!this.attached) {
this.attached = true;
$("#right-panel").html(this.$el);
}
this.getContent();
2016-05-25 02:45:22 +00:00
},
getContent: function() {
2016-05-25 02:45:22 +00:00
this.initPage();
var _this = this;
2016-05-27 08:42:40 +00:00
this.repoCollection.fetch({
data: {'page': this.option.page},
cache: false,
2016-05-25 02:45:22 +00:00
reset: true,
error: function(collection, response, opts) {
2016-05-25 02:45:22 +00:00
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');
},
complete:function() {
_this.$loadingTip.hide();
2016-05-25 02:45:22 +00:00
}
});
},
reset: function() {
// update the url
var current_page = this.repoCollection.state.current_page;
app.router.navigate('all-libs/?page=' + current_page);
2016-05-25 02:45:22 +00:00
this.$loadingTip.hide();
if (this.repoCollection.length > 0) {
2016-05-27 08:42:40 +00:00
this.repoCollection.each(this.addOne, this);
2016-05-25 02:45:22 +00:00
this.$table.show();
this.renderPaginator();
} else {
this.$emptyTip.show();
}
},
renderPaginator: function() {
if (this.repoCollection.state.has_next_page) {
2016-05-25 02:45:22 +00:00
this.$jsNext.show();
} else {
this.$jsNext.hide();
}
2016-05-27 08:42:40 +00:00
var current_page = this.repoCollection.state.current_page;
2016-05-25 02:45:22 +00:00
if (current_page > 1) {
this.$jsPrevious.show();
} else {
this.$jsPrevious.hide();
}
},
addOne: function(library) {
2016-05-27 08:42:40 +00:00
var view = new RepoView({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 ReposView;
2016-05-25 02:45:22 +00:00
});