1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-06-29 08:27:55 +00:00
seahub/static/scripts/app/views/organization.js

137 lines
4.2 KiB
JavaScript
Raw Normal View History

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',
'app/views/organization-repo',
2015-04-03 09:01:13 +00:00
'app/views/add-pub-repo'
], function($, _, Backbone, Common, PubRepoCollection, OrganizationRepoView,
AddPubRepoView) {
2015-03-07 07:56:10 +00:00
'use strict';
var OrganizationView = Backbone.View.extend({
el: '#main',
2015-05-11 10:39:21 +00:00
reposHdTemplate: _.template($('#shared-repos-hd-tmpl').html()),
initialize: function(options) {
2015-04-03 09:01:13 +00:00
2015-04-11 10:03:43 +00:00
this.$sideNav = $('#org-side-nav');
this.$reposDiv = $('#organization-repos');
2015-03-07 07:56:10 +00:00
this.$table = $('#organization-repos table');
this.$tableHead = $('thead', this.$table);
2015-03-07 07:56:10 +00:00
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);
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',
'click #organization-repos .by-name': 'sortByName',
'click #organization-repos .by-time': 'sortByTime'
2015-03-07 07:56:10 +00:00
},
createRepo: function() {
new AddPubRepoView(this.repos);
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);
}
},
2015-05-11 10:39:21 +00:00
renderReposHd: function() {
this.$tableHead.html(this.reposHdTemplate());
},
2015-03-07 07:56:10 +00:00
reset: function() {
2015-05-11 10:39:21 +00:00
this.renderReposHd();
2015-03-07 07:56:10 +00:00
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();
this.dirView.hide();
this.$reposDiv.show();
2015-03-07 07:56:10 +00:00
this.repos.fetch({reset: true});
this.$loadingTip.show();
},
2015-04-11 07:14:56 +00:00
hideRepoList: function() {
this.$reposDiv.hide();
},
showDir: function(repo_id, path) {
2015-04-11 10:03:43 +00:00
this.$sideNav.show();
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);
},
sortByName: function() {
var repos = this.repos;
var el = $('.by-name', this.$table);
repos.comparator = function(a, b) { // a, b: model
var result = Common.compareTwoWord(a.get('name'), b.get('name'));
if (el.hasClass('icon-caret-up')) {
return -result;
} else {
return result;
}
};
repos.sort();
this.$tableBody.empty();
repos.each(this.addOne, this);
el.toggleClass('icon-caret-up icon-caret-down');
2015-05-11 07:31:03 +00:00
repos.comparator = null;
},
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-05-11 07:31:03 +00:00
repos.comparator = null;
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;
});