1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-06-29 16:37:56 +00:00
seahub/static/scripts/app/views/group.js

182 lines
5.8 KiB
JavaScript
Raw Normal View History

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',
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-04-13 12:05:30 +00:00
'app/views/group-side-nav'
], function($, _, Backbone, Common, GroupRepos, GroupRepoView,
AddGroupRepoView, GroupSideNavView) {
2015-01-21 14:22:34 +00:00
'use strict';
var GroupView = Backbone.View.extend({
el: '#group-repo-tabs',
2015-01-21 14:22:34 +00:00
2015-05-11 10:39:21 +00:00
reposHdTemplate: _.template($('#shared-repos-hd-tmpl').html()),
2015-01-22 09:15:17 +00:00
events: {
'click .repo-create': 'createRepo',
2015-07-09 09:16:10 +00:00
'click .by-name': 'sortByName',
'click .by-time': 'sortByTime'
2015-01-22 09:15:17 +00:00
},
initialize: function(options) {
this.$tabs = this.$el;
this.$table = this.$('table');
this.$tableHead = this.$('thead');
this.$tableBody = this.$('tbody');
this.$loadingTip = this.$('.loading-tip');
this.$emptyTip = this.$('.empty-tips');
2015-04-11 07:14:56 +00:00
2015-04-13 12:05:30 +00:00
this.sideNavView = new GroupSideNavView();
this.repos = new GroupRepos();
this.listenTo(this.repos, 'add', this.addOne);
this.listenTo(this.repos, 'reset', this.reset);
this.dirView = options.dirView;
2015-01-21 14:22:34 +00:00
},
2015-01-27 09:32:31 +00:00
addOne: function(repo, collection, options) {
var view = new GroupRepoView({
model: repo,
group_id: this.group_id,
is_staff: this.repos.is_staff
});
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-05-11 10:39:21 +00:00
renderReposHd: function() {
this.$tableHead.html(this.reposHdTemplate());
},
reset: function() {
this.$('.error').hide();
this.$loadingTip.hide();
if (this.repos.length) {
this.$emptyTip.hide();
this.renderReposHd();
this.$tableBody.empty();
this.repos.each(this.addOne, this);
this.$table.show();
} else {
this.$emptyTip.show();
this.$table.hide();
}
2015-01-21 14:22:34 +00:00
},
2015-04-13 12:05:30 +00:00
showSideNav: function () {
2015-04-14 07:56:11 +00:00
var sideNavView = this.sideNavView;
if (sideNavView.group_id && sideNavView.group_id == this.group_id) {
sideNavView.show();
return;
}
sideNavView.render(this.group_id);
sideNavView.show();
2015-04-13 12:05:30 +00:00
},
2015-04-11 07:14:56 +00:00
showRepoList: function(group_id) {
this.group_id = group_id;
2015-04-13 12:05:30 +00:00
this.showSideNav();
this.dirView.hide();
2015-04-14 06:48:56 +00:00
this.$emptyTip.hide();
this.$tabs.show();
2015-04-14 06:48:56 +00:00
this.$table.hide();
var $loadingTip = this.$loadingTip;
$loadingTip.show();
var _this = this;
2015-04-11 07:14:56 +00:00
this.repos.setGroupID(group_id);
this.repos.fetch({
reset: true,
data: {from: 'web'},
success: function (collection, response, opts) {
},
error: function (collection, response, opts) {
$loadingTip.hide();
var $error = _this.$('.error');
var err_msg;
if (response.responseText) {
if (response['status'] == 401 || response['status'] == 403) {
err_msg = gettext("Permission error");
} else {
err_msg = gettext("Error");
}
} else {
err_msg = gettext('Please check the network.');
}
$error.html(err_msg).show();
}
});
2015-01-21 14:22:34 +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-04-13 12:05:30 +00:00
this.showSideNav();
this.hideRepoList();
2015-04-11 09:35:02 +00:00
this.dirView.showDir('group/' + this.group_id, repo_id, path);
2015-01-21 14:22:34 +00:00
},
2015-01-22 09:15:17 +00:00
createRepo: function() {
new AddGroupRepoView(this.repos);
2015-01-29 06:45:26 +00:00
},
sortByName: function() {
2015-07-09 09:16:10 +00:00
$('.by-time .sort-icon').hide();
var repos = this.repos;
2015-07-09 09:16:10 +00:00
var el = $('.by-name .sort-icon', 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);
2015-07-09 09:16:10 +00:00
el.toggleClass('icon-caret-up icon-caret-down').show();
2015-05-11 07:31:03 +00:00
repos.comparator = null;
},
sortByTime: function() {
2015-07-09 09:16:10 +00:00
$('.by-name .sort-icon').hide();
var repos = this.repos;
2015-07-09 09:16:10 +00:00
var el = $('.by-time .sort-icon', 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);
2015-07-09 09:16:10 +00:00
el.toggleClass('icon-caret-up icon-caret-down').show();
2015-05-11 07:31:03 +00:00
repos.comparator = null;
2015-04-11 07:14:56 +00:00
},
hide: function() {
2015-04-13 12:05:30 +00:00
this.sideNavView.hide();
2015-04-11 07:14:56 +00:00
this.hideRepoList();
this.dirView.hide();
2015-04-14 06:48:56 +00:00
this.$emptyTip.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;
});