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',
|
2015-04-11 07:14:56 +00:00
|
|
|
'app/views/group-repo',
|
2015-01-29 06:45:26 +00:00
|
|
|
'app/views/add-group-repo',
|
2015-03-01 12:28:25 +00:00
|
|
|
'app/views/group-recent-change',
|
|
|
|
'app/views/dir',
|
|
|
|
], function($, _, Backbone, Common, GroupRepos, DirentCollection,
|
2015-04-11 07:14:56 +00:00
|
|
|
GroupRepoView, AddGroupRepoView, GroupRecentChangeView,
|
|
|
|
DirView) {
|
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',
|
2015-03-24 08:59:46 +00:00
|
|
|
'click #grp-repos .by-name': 'sortByName',
|
|
|
|
'click #grp-repos .by-time': 'sortByTime'
|
2015-01-22 09:15:17 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function() {
|
2015-04-11 07:14:56 +00:00
|
|
|
this.$tabs = this.$('#group-repo-tabs');
|
|
|
|
this.$table = this.$('#grp-repos table', this.$tabs);
|
2015-01-27 09:32:31 +00:00
|
|
|
this.$tableHead = $('thead', this.$table);
|
|
|
|
this.$tableBody = $('tbody', this.$table);
|
2015-04-11 07:14:56 +00:00
|
|
|
this.$loadingTip = $('.loading-tip', this.$tabs);
|
|
|
|
this.$emptyTip = $('.empty-tips', this.$tabs);
|
2015-01-22 09:15:17 +00:00
|
|
|
this.$createForm = this.$('#repo-create-form');
|
2015-04-11 07:14:56 +00:00
|
|
|
|
2015-03-01 12:28:25 +00:00
|
|
|
this.repos = new GroupRepos();
|
|
|
|
this.listenTo(this.repos, 'add', this.addOne);
|
|
|
|
this.listenTo(this.repos, 'reset', this.reset);
|
|
|
|
|
|
|
|
this.dirView = new DirView();
|
2015-01-21 14:22:34 +00:00
|
|
|
},
|
|
|
|
|
2015-03-01 12:28:25 +00:00
|
|
|
/*
|
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-03-01 12:28:25 +00:00
|
|
|
*/
|
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) {
|
2015-04-11 07:14:56 +00:00
|
|
|
var view = new GroupRepoView({model: repo, group_id: this.group_id});
|
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
|
|
|
},
|
|
|
|
|
2015-03-01 12:28:25 +00:00
|
|
|
reset: function() {
|
2015-01-27 09:32:31 +00:00
|
|
|
this.$tableBody.empty();
|
2015-03-01 12:28:25 +00:00
|
|
|
this.repos.each(this.addOne, this);
|
|
|
|
this.$loadingTip.hide();
|
|
|
|
if (this.repos.length) {
|
|
|
|
this.$emptyTip.hide();
|
|
|
|
this.$table.show();
|
|
|
|
} else {
|
|
|
|
this.$emptyTip.show();
|
|
|
|
this.$table.hide();
|
|
|
|
}
|
2015-01-21 14:22:34 +00:00
|
|
|
},
|
|
|
|
|
2015-04-11 07:14:56 +00:00
|
|
|
showRepoList: function(group_id) {
|
|
|
|
this.group_id = group_id;
|
2015-03-01 12:28:25 +00:00
|
|
|
this.dirView.hide();
|
|
|
|
this.$tabs.show();
|
2015-04-11 07:14:56 +00:00
|
|
|
this.repos.setGroupID(group_id);
|
2015-03-01 12:28:25 +00:00
|
|
|
this.repos.fetch({reset: true});
|
|
|
|
this.$loadingTip.show();
|
2015-01-21 14:22:34 +00:00
|
|
|
},
|
|
|
|
|
2015-03-01 12:28:25 +00:00
|
|
|
hideRepoList: function() {
|
|
|
|
this.$tabs.hide();
|
2015-01-21 14:22:34 +00:00
|
|
|
},
|
|
|
|
|
2015-04-11 07:14:56 +00:00
|
|
|
showDir: function(group_id, repo_id, path) {
|
|
|
|
this.group_id = group_id;
|
2015-03-01 12:28:25 +00:00
|
|
|
this.hideRepoList();
|
|
|
|
this.dirView.showDir('', repo_id, path);
|
2015-01-21 14:22:34 +00:00
|
|
|
},
|
|
|
|
|
2015-01-22 09:15:17 +00:00
|
|
|
createRepo: function() {
|
2015-03-01 12:28:25 +00:00
|
|
|
var addGroupRepoView = new AddGroupRepoView(this.repos);
|
|
|
|
addGroupRepoView.render();
|
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-03-24 08:59:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
sortByName: function() {
|
|
|
|
var repos = this.repos;
|
|
|
|
var el = $('.by-name', this.$table);
|
|
|
|
repos.comparator = function(a, b) { // a, b: model
|
|
|
|
if (el.hasClass('icon-caret-up')) {
|
|
|
|
return a.get('name').toLowerCase() < b.get('name').toLowerCase() ? 1 : -1;
|
|
|
|
} else {
|
|
|
|
return a.get('name').toLowerCase() < b.get('name').toLowerCase() ? -1 : 1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
repos.sort();
|
|
|
|
this.$tableBody.empty();
|
|
|
|
repos.each(this.addOne, this);
|
|
|
|
el.toggleClass('icon-caret-up icon-caret-down');
|
|
|
|
},
|
|
|
|
|
|
|
|
sortByTime: function() {
|
|
|
|
var repos = this.repos;
|
|
|
|
var el = $('.by-time', this.$table);
|
|
|
|
repos.comparator = function(a, b) { // a, b: model
|
|
|
|
if (el.hasClass('icon-caret-down')) {
|
|
|
|
return a.get('mtime') < b.get('mtime') ? 1 : -1;
|
|
|
|
} else {
|
|
|
|
return a.get('mtime') < b.get('mtime') ? -1 : 1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
repos.sort();
|
|
|
|
this.$tableBody.empty();
|
|
|
|
repos.each(this.addOne, this);
|
|
|
|
el.toggleClass('icon-caret-up icon-caret-down');
|
2015-04-11 07:14:56 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
hide: function() {
|
|
|
|
this.hideRepoList();
|
|
|
|
this.dirView.hide();
|
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;
|
|
|
|
});
|