2015-02-04 13:57:26 +00:00
|
|
|
define([
|
|
|
|
'jquery',
|
|
|
|
'underscore',
|
|
|
|
'backbone',
|
|
|
|
'common',
|
|
|
|
'app/collections/repos',
|
|
|
|
'app/views/shared-repo',
|
|
|
|
], function($, _, Backbone, Common, RepoCollection, SharedRepoView) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var SharedReposView = Backbone.View.extend({
|
|
|
|
el: $('#repo-tabs'),
|
|
|
|
|
|
|
|
initialize: function(options) {
|
|
|
|
this.$tabs = $('#repo-tabs');
|
2015-03-06 09:53:41 +00:00
|
|
|
this.$table = $('#repos-shared-to-me table');
|
2015-02-04 13:57:26 +00:00
|
|
|
this.$tableHead = $('thead', this.$table);
|
|
|
|
this.$tableBody = $('tbody', this.$table);
|
|
|
|
this.$loadingTip = $('.loading-tip', this.$tabs);
|
2015-03-06 09:53:41 +00:00
|
|
|
this.$emptyTip = $('#repos-shared-to-me .empty-tips');
|
2015-02-04 13:57:26 +00:00
|
|
|
|
|
|
|
this.repos = new RepoCollection({type: 'shared'});
|
|
|
|
this.listenTo(this.repos, 'add', this.addOne);
|
|
|
|
this.listenTo(this.repos, 'reset', this.reset);
|
|
|
|
},
|
|
|
|
|
|
|
|
addOne: function(repo, collection, options) {
|
2015-03-06 09:53:41 +00:00
|
|
|
var view = new SharedRepoView({model: repo, collection: this.repos});
|
2015-02-04 13:57:26 +00:00
|
|
|
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();
|
|
|
|
},
|
|
|
|
|
|
|
|
renderPath: function() {
|
|
|
|
//
|
|
|
|
},
|
|
|
|
|
|
|
|
showSharedRepos: function() {
|
|
|
|
this.repos.fetch({reset: true});
|
|
|
|
this.$tabs.show();
|
|
|
|
//this.$table.parent().show();
|
|
|
|
this.$table.hide();
|
|
|
|
this.$loadingTip.show();
|
2015-02-11 14:36:35 +00:00
|
|
|
$('#shared-lib-tab', this.$tabs).parent().addClass('ui-state-active');
|
2015-02-04 13:57:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
show: function() {
|
|
|
|
this.showSharedRepos();
|
|
|
|
},
|
|
|
|
|
|
|
|
hide: function() {
|
|
|
|
this.$el.hide();
|
|
|
|
this.$table.hide();
|
2015-03-31 08:22:35 +00:00
|
|
|
this.$emptyTip.hide();
|
2015-02-11 14:36:35 +00:00
|
|
|
$('#shared-lib-tab', this.$tabs).parent().removeClass('ui-state-active');
|
2015-02-04 13:57:26 +00:00
|
|
|
},
|
|
|
|
|
2015-03-24 08:59:46 +00:00
|
|
|
events: {
|
|
|
|
'click #repos-shared-to-me .by-name': 'sortByName',
|
|
|
|
'click #repos-shared-to-me .by-time': 'sortByTime'
|
|
|
|
},
|
|
|
|
|
|
|
|
sortByName: function() {
|
|
|
|
var repos = this.repos;
|
|
|
|
var el = $('.by-name', this.$table);
|
|
|
|
repos.comparator = function(a, b) { // a, b: model
|
2015-04-30 03:59:09 +00:00
|
|
|
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
|
2015-03-24 08:59:46 +00:00
|
|
|
if (el.hasClass('icon-caret-up')) {
|
2015-04-30 03:59:09 +00:00
|
|
|
return -result;
|
2015-03-24 08:59:46 +00:00
|
|
|
} else {
|
2015-04-30 03:59:09 +00:00
|
|
|
return result;
|
2015-03-24 08:59:46 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
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-02-04 13:57:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return SharedReposView;
|
|
|
|
});
|