2015-03-07 07:56:10 +00:00
|
|
|
define([
|
|
|
|
'jquery',
|
|
|
|
'underscore',
|
|
|
|
'backbone',
|
|
|
|
'common',
|
2015-04-03 09:01:13 +00:00
|
|
|
'app/collections/pub-repos',
|
2015-03-07 08:40:30 +00:00
|
|
|
'app/views/organization-repo',
|
2015-04-03 09:01:13 +00:00
|
|
|
'app/views/add-pub-repo'
|
|
|
|
], function($, _, Backbone, Common, PubRepoCollection, OrganizationRepoView,
|
2015-04-17 10:07:17 +00:00
|
|
|
AddPubRepoView) {
|
2015-03-07 07:56:10 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var OrganizationView = Backbone.View.extend({
|
|
|
|
el: '#main',
|
|
|
|
|
2015-04-17 10:07:17 +00:00
|
|
|
initialize: function(options) {
|
2015-04-03 09:01:13 +00:00
|
|
|
|
2015-04-11 10:03:43 +00:00
|
|
|
this.$sideNav = $('#org-side-nav');
|
2015-03-07 08:40:30 +00:00
|
|
|
this.$reposDiv = $('#organization-repos');
|
2015-03-07 07:56:10 +00:00
|
|
|
this.$table = $('#organization-repos table');
|
|
|
|
this.$tableBody = $('tbody', this.$table);
|
|
|
|
this.$loadingTip = $('#organization-repos .loading-tip');
|
|
|
|
this.$emptyTip = $('#organization-repos .empty-tips');
|
|
|
|
|
2015-04-03 09:01:13 +00:00
|
|
|
this.repos = new PubRepoCollection();
|
2015-03-07 07:56:10 +00:00
|
|
|
this.listenTo(this.repos, 'add', this.addOne);
|
|
|
|
this.listenTo(this.repos, 'reset', this.reset);
|
2015-03-07 08:40:30 +00:00
|
|
|
|
2015-04-17 10:07:17 +00:00
|
|
|
this.dirView = options.dirView;
|
2015-03-07 07:56:10 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
events: {
|
2015-04-20 08:38:59 +00:00
|
|
|
'click #organization-repos .repo-create': 'createRepo',
|
2015-03-24 08:59:46 +00:00
|
|
|
'click #organization-repos .by-name': 'sortByName',
|
|
|
|
'click #organization-repos .by-time': 'sortByTime'
|
2015-03-07 07:56:10 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
createRepo: function() {
|
2015-04-03 09:01:13 +00:00
|
|
|
new AddPubRepoView(this.repos).render();
|
2015-03-07 07:56:10 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
addOne: function(repo, collection, options) {
|
|
|
|
var view = new OrganizationRepoView({model: repo, collection: this.repos});
|
|
|
|
if (options.prepend) {
|
|
|
|
this.$tableBody.prepend(view.render().el);
|
|
|
|
} else {
|
|
|
|
this.$tableBody.append(view.render().el);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
reset: function() {
|
|
|
|
this.$tableBody.empty();
|
|
|
|
this.repos.each(this.addOne, this);
|
|
|
|
if (this.repos.length) {
|
|
|
|
this.$emptyTip.hide();
|
|
|
|
this.$table.show();
|
|
|
|
} else {
|
|
|
|
this.$emptyTip.show();
|
|
|
|
this.$table.hide();
|
|
|
|
}
|
|
|
|
this.$loadingTip.hide();
|
|
|
|
},
|
|
|
|
|
2015-04-11 07:14:56 +00:00
|
|
|
showRepoList: function() {
|
2015-04-11 10:03:43 +00:00
|
|
|
this.$sideNav.show();
|
2015-03-07 08:40:30 +00:00
|
|
|
this.dirView.hide();
|
|
|
|
this.$reposDiv.show();
|
2015-03-07 07:56:10 +00:00
|
|
|
this.repos.fetch({reset: true});
|
2015-03-07 08:40:30 +00:00
|
|
|
this.$loadingTip.show();
|
|
|
|
},
|
|
|
|
|
2015-04-11 07:14:56 +00:00
|
|
|
hideRepoList: function() {
|
2015-03-07 08:40:30 +00:00
|
|
|
this.$reposDiv.hide();
|
|
|
|
},
|
|
|
|
|
|
|
|
showDir: function(repo_id, path) {
|
2015-04-11 10:03:43 +00:00
|
|
|
this.$sideNav.show();
|
2015-03-07 08:40:30 +00:00
|
|
|
var path = path || '/';
|
2015-04-11 07:14:56 +00:00
|
|
|
this.hideRepoList();
|
2015-04-11 09:35:02 +00:00
|
|
|
this.dirView.showDir('org', repo_id, path);
|
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() {
|
2015-04-11 10:03:43 +00:00
|
|
|
this.$sideNav.hide();
|
2015-04-11 07:14:56 +00:00
|
|
|
this.hideRepoList();
|
2015-04-14 06:48:56 +00:00
|
|
|
this.$emptyTip.hide();
|
2015-04-11 07:14:56 +00:00
|
|
|
this.dirView.hide();
|
2015-03-07 07:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return OrganizationView;
|
|
|
|
});
|