2015-01-21 14:22:34 +00:00
|
|
|
define([
|
|
|
|
'jquery',
|
|
|
|
'underscore',
|
|
|
|
'backbone',
|
2015-01-27 09:32:31 +00:00
|
|
|
'common',
|
2015-01-21 14:22:34 +00:00
|
|
|
'app/collections/group-repos',
|
|
|
|
'app/collections/dirents',
|
|
|
|
'app/views/group-repos',
|
2015-01-29 06:45:26 +00:00
|
|
|
'app/views/add-group-repo',
|
|
|
|
'app/views/group-recent-change'
|
2015-01-27 09:32:31 +00:00
|
|
|
// 'app/views/dirents'
|
2015-01-29 06:45:26 +00:00
|
|
|
], function($, _, Backbone, Common, Repos, DirentCollection, GroupRepoView, AddGroupRepoView/*, DirentView*/, GroupRecentChangeView) {
|
2015-01-21 14:22:34 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var GroupView = Backbone.View.extend({
|
|
|
|
el: '#main',
|
|
|
|
|
2015-01-22 09:15:17 +00:00
|
|
|
events: {
|
|
|
|
'click #repo-create': 'createRepo',
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function() {
|
2015-01-27 09:32:31 +00:00
|
|
|
Common.prepareApiCsrf();
|
2015-01-21 14:22:34 +00:00
|
|
|
|
|
|
|
this.$cont = this.$('#right-panel');
|
2015-01-27 09:32:31 +00:00
|
|
|
|
2015-01-21 14:22:34 +00:00
|
|
|
this.$tab = this.$('#tabs div:first-child');
|
2015-01-27 09:32:31 +00:00
|
|
|
|
|
|
|
this.$table = this.$('#grp-repos table');
|
|
|
|
this.$tableHead = $('thead', this.$table);
|
|
|
|
this.$tableBody = $('tbody', this.$table);
|
|
|
|
|
2015-01-22 09:15:17 +00:00
|
|
|
this.$createForm = this.$('#repo-create-form');
|
2015-01-21 14:22:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
initializeRepos: function() {
|
|
|
|
this.listenTo(Repos, 'add', this.addOne);
|
|
|
|
this.listenTo(Repos, 'reset', this.addAll);
|
2015-01-27 09:32:31 +00:00
|
|
|
// this.listenTo(Repos, 'sync', this.render);
|
|
|
|
this.listenTo(Repos, 'all', this.render); // XXX: really render table when recieve any event ?
|
2015-01-29 06:45:26 +00:00
|
|
|
this.listenTo(Repos, 'all', this.all);
|
2015-01-21 14:22:34 +00:00
|
|
|
},
|
|
|
|
|
2015-01-27 09:32:31 +00:00
|
|
|
all: function(event) {
|
|
|
|
console.log('event: ' + event);
|
2015-01-21 14:22:34 +00:00
|
|
|
},
|
2015-01-27 09:32:31 +00:00
|
|
|
|
|
|
|
addOne: function(repo, collection, options) {
|
|
|
|
console.log('add repo: ' + repo.get('name'));
|
2015-01-21 14:22:34 +00:00
|
|
|
var view = new GroupRepoView({model: repo});
|
2015-01-27 09:32:31 +00:00
|
|
|
if (options.prepend) {
|
2015-01-31 05:17:47 +00:00
|
|
|
this.$tableBody.prepend(view.render().el);
|
2015-01-27 09:32:31 +00:00
|
|
|
} else {
|
|
|
|
this.$tableBody.append(view.render().el);
|
|
|
|
}
|
2015-01-21 14:22:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
addAll: function() {
|
|
|
|
console.log('add all');
|
|
|
|
this.resetTable();
|
|
|
|
Repos.each(this.addOne, this);
|
|
|
|
},
|
|
|
|
|
2015-01-27 09:32:31 +00:00
|
|
|
// Reset table by empty table body.
|
2015-01-21 14:22:34 +00:00
|
|
|
resetTable: function() {
|
|
|
|
console.log('rest table');
|
2015-01-27 09:32:31 +00:00
|
|
|
this.$tableBody.empty();
|
2015-01-21 14:22:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
hideTable: function() {
|
2015-01-27 09:32:31 +00:00
|
|
|
this.$table.hide();
|
2015-01-21 14:22:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
showTable: function() {
|
2015-01-27 09:32:31 +00:00
|
|
|
this.$table.show();
|
2015-01-21 14:22:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
hideLoading: function() {
|
|
|
|
this.$cont.find('.loading').hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
showLoading: function() {
|
|
|
|
this.$cont.find('.loading').show();
|
|
|
|
},
|
|
|
|
|
|
|
|
hideEmptyTips: function() {
|
|
|
|
this.$cont.find('.empty-tips').hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
showEmptyTips: function() {
|
|
|
|
this.$cont.find('.empty-tips').show();
|
|
|
|
},
|
|
|
|
|
2015-01-27 09:32:31 +00:00
|
|
|
render: function(event) {
|
|
|
|
console.log('got event: ' + event + ', render repo list...' );
|
|
|
|
|
2015-01-29 06:45:26 +00:00
|
|
|
this.$table.parent().show();
|
2015-01-21 14:22:34 +00:00
|
|
|
this.hideLoading();
|
2015-01-29 06:45:26 +00:00
|
|
|
|
2015-01-21 14:22:34 +00:00
|
|
|
if (Repos.length) {
|
|
|
|
this.hideEmptyTips();
|
|
|
|
this.showTable();
|
|
|
|
} else {
|
|
|
|
this.showEmptyTips();
|
2015-01-27 09:32:31 +00:00
|
|
|
this.hideTable();
|
2015-01-21 14:22:34 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
showRepoList: function() {
|
|
|
|
this.initializeRepos();
|
|
|
|
Repos.fetch({reset: true});
|
|
|
|
},
|
|
|
|
|
2015-01-22 09:15:17 +00:00
|
|
|
createRepo: function() {
|
2015-01-27 09:32:31 +00:00
|
|
|
new AddGroupRepoView();
|
2015-01-29 06:45:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
showChanges: function() {
|
|
|
|
this.$table.parent().hide(); // XXX: hide or empty ?
|
|
|
|
|
|
|
|
if (!this.recentChangeView) {
|
|
|
|
this.recentChangeView = new GroupRecentChangeView();
|
|
|
|
}
|
|
|
|
this.recentChangeView.show();
|
2015-01-21 14:22:34 +00:00
|
|
|
}
|
2015-01-22 09:15:17 +00:00
|
|
|
|
2015-01-21 14:22:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return GroupView;
|
|
|
|
});
|