1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-06-30 17:02:15 +00:00
seahub/media/scripts/app/views/myhome-repos.js

117 lines
3.7 KiB
JavaScript
Raw Normal View History

2015-02-01 06:15:00 +00:00
define([
'jquery',
'underscore',
'backbone',
'common',
'app/collections/repos',
'app/views/repo',
'app/views/add-repo',
], function($, _, Backbone, Common, RepoCollection, RepoView, AddRepoView) {
'use strict';
var ReposView = Backbone.View.extend({
el: $('#repo-tabs'),
events: {
'click #repo-create': 'createRepo',
'click #my-own-repos .by-name': 'sortByName',
'click #my-own-repos .by-time': 'sortByTime'
2015-02-01 06:15:00 +00:00
},
initialize: function(options) {
this.$tabs = $('#repo-tabs');
this.$table = this.$('#my-own-repos table');
this.$tableHead = $('thead', this.$table);
this.$tableBody = $('tbody', this.$table);
this.$loadingTip = $('.loading-tip', this.$tabs);
2015-03-30 15:21:50 +00:00
this.$emptyTip = $('#my-own-repos .empty-tips');
2015-02-01 06:15:00 +00:00
this.repos = new RepoCollection();
this.listenTo(this.repos, 'add', this.addOne);
this.listenTo(this.repos, 'reset', this.reset);
},
addOne: function(repo, collection, options) {
var view = new RepoView({model: repo});
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();
},
showMyRepos: function() {
this.repos.fetch({reset: true});
this.$tabs.show();
this.$table.hide();
this.$loadingTip.show();
$('#mylib-tab', this.$tabs).parent().addClass('ui-state-active');
2015-02-01 06:15:00 +00:00
},
show: function() {
2015-03-22 14:39:39 +00:00
$('#repo-create').show();
2015-02-01 06:15:00 +00:00
this.showMyRepos();
},
hide: function() {
2015-03-22 14:39:39 +00:00
$('#repo-create').hide();
2015-02-01 06:15:00 +00:00
this.$el.hide();
2015-02-04 13:57:26 +00:00
this.$table.hide();
$('#mylib-tab', this.$tabs).parent().removeClass('ui-state-active');
2015-02-01 06:15:00 +00:00
},
createRepo: function() {
2015-03-01 02:44:00 +00:00
var addRepoView = new AddRepoView(this.repos);
addRepoView.render();
2015-02-01 06:15:00 +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-02-01 06:15:00 +00:00
});
return ReposView;
});