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-12-11 12:41:16 +00:00
|
|
|
'app/views/add-group-repo',
|
2016-01-06 08:28:26 +00:00
|
|
|
'app/views/group-members',
|
2016-03-08 05:36:58 +00:00
|
|
|
'app/views/group-discussions',
|
2016-01-06 08:28:26 +00:00
|
|
|
'app/views/group-settings'
|
2015-04-17 02:59:48 +00:00
|
|
|
], function($, _, Backbone, Common, GroupRepos, GroupRepoView,
|
2016-03-08 05:36:58 +00:00
|
|
|
AddGroupRepoView, GroupMembersView, GroupDiscussionsView, GroupSettingsView) {
|
2015-01-21 14:22:34 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var GroupView = Backbone.View.extend({
|
2015-12-11 12:41:16 +00:00
|
|
|
el: '#group',
|
2015-01-21 14:22:34 +00:00
|
|
|
|
2015-11-24 08:55:38 +00:00
|
|
|
groupTopTemplate: _.template($('#group-top-tmpl').html()),
|
2015-05-11 10:39:21 +00:00
|
|
|
reposHdTemplate: _.template($('#shared-repos-hd-tmpl').html()),
|
|
|
|
|
2015-01-22 09:15:17 +00:00
|
|
|
events: {
|
2016-01-06 08:28:26 +00:00
|
|
|
'click #group-settings-icon': 'toggleSettingsPanel',
|
2015-12-11 12:41:16 +00:00
|
|
|
'click #group-members-icon': 'toggleMembersPanel',
|
2016-01-30 08:23:52 +00:00
|
|
|
'click #group-wiki-icon': 'showGroupWiki',
|
2016-03-08 05:36:58 +00:00
|
|
|
'click #group-discussions-icon': 'toggleDiscussionsPanel',
|
2015-05-12 08:35:39 +00:00
|
|
|
'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
|
|
|
},
|
|
|
|
|
2015-04-17 10:07:17 +00:00
|
|
|
initialize: function(options) {
|
2015-05-12 08:35:39 +00:00
|
|
|
this.$tabs = this.$el;
|
|
|
|
this.$table = this.$('table');
|
|
|
|
this.$tableHead = this.$('thead');
|
|
|
|
this.$tableBody = this.$('tbody');
|
2015-12-11 12:41:16 +00:00
|
|
|
this.$loadingTip = this.$('#group-repos .loading-tip');
|
|
|
|
this.$emptyTip = this.$('#group-repos .empty-tips');
|
2015-04-11 07:14:56 +00:00
|
|
|
|
2016-01-30 08:23:52 +00:00
|
|
|
this.group = {}; // will be fetched when rendering the top bar
|
|
|
|
|
2015-03-01 12:28:25 +00:00
|
|
|
this.repos = new GroupRepos();
|
|
|
|
this.listenTo(this.repos, 'add', this.addOne);
|
|
|
|
this.listenTo(this.repos, 'reset', this.reset);
|
|
|
|
|
2015-04-17 10:07:17 +00:00
|
|
|
this.dirView = options.dirView;
|
2015-11-24 08:55:38 +00:00
|
|
|
|
2015-12-11 12:41:16 +00:00
|
|
|
this.membersView = new GroupMembersView();
|
2016-01-09 06:35:16 +00:00
|
|
|
this.settingsView = new GroupSettingsView({
|
|
|
|
groupView: this
|
|
|
|
});
|
2016-03-25 04:02:30 +00:00
|
|
|
this.discussionsView = new GroupDiscussionsView({
|
|
|
|
groupView: this
|
|
|
|
});
|
2015-01-21 14:22:34 +00:00
|
|
|
},
|
|
|
|
|
2015-01-27 09:32:31 +00:00
|
|
|
addOne: function(repo, collection, options) {
|
2015-04-20 06:31:22 +00:00
|
|
|
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());
|
|
|
|
},
|
|
|
|
|
2015-03-01 12:28:25 +00:00
|
|
|
reset: function() {
|
2015-05-12 08:35:39 +00:00
|
|
|
this.$('.error').hide();
|
2015-03-01 12:28:25 +00:00
|
|
|
this.$loadingTip.hide();
|
|
|
|
if (this.repos.length) {
|
|
|
|
this.$emptyTip.hide();
|
2015-05-12 08:35:39 +00:00
|
|
|
this.renderReposHd();
|
|
|
|
this.$tableBody.empty();
|
|
|
|
this.repos.each(this.addOne, this);
|
2015-03-01 12:28:25 +00:00
|
|
|
this.$table.show();
|
|
|
|
} else {
|
|
|
|
this.$emptyTip.show();
|
|
|
|
this.$table.hide();
|
|
|
|
}
|
2015-01-21 14:22:34 +00:00
|
|
|
},
|
|
|
|
|
2016-01-09 06:35:16 +00:00
|
|
|
renderGroupTop: function() {
|
2015-11-24 08:55:38 +00:00
|
|
|
var _this = this;
|
|
|
|
var $groupTop = $('#group-top');
|
|
|
|
$.ajax({
|
|
|
|
url: Common.getUrl({
|
2016-01-09 06:35:16 +00:00
|
|
|
'name': 'group',
|
|
|
|
'group_id': this.group_id
|
2015-11-24 08:55:38 +00:00
|
|
|
}),
|
|
|
|
cache: false,
|
|
|
|
dataType: 'json',
|
|
|
|
success: function (data) {
|
2016-01-30 08:23:52 +00:00
|
|
|
_this.group = data;
|
2015-11-24 08:55:38 +00:00
|
|
|
$groupTop.html(_this.groupTopTemplate(data));
|
|
|
|
},
|
|
|
|
error: function(xhr) {
|
|
|
|
var err_msg;
|
|
|
|
if (xhr.responseText) {
|
2016-01-09 06:35:16 +00:00
|
|
|
err_msg = $.parseJSON(xhr.responseText).error_msg;
|
2015-11-24 08:55:38 +00:00
|
|
|
} else {
|
|
|
|
err_msg = gettext("Please check the network.");
|
|
|
|
}
|
|
|
|
$groupTop.html('<p class="error">' + err_msg + '</p>');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-04-11 07:14:56 +00:00
|
|
|
showRepoList: function(group_id) {
|
|
|
|
this.group_id = group_id;
|
2015-03-01 12:28:25 +00:00
|
|
|
this.dirView.hide();
|
2015-04-14 06:48:56 +00:00
|
|
|
this.$emptyTip.hide();
|
2016-01-09 06:35:16 +00:00
|
|
|
this.renderGroupTop();
|
2015-03-01 12:28:25 +00:00
|
|
|
this.$tabs.show();
|
2015-04-14 06:48:56 +00:00
|
|
|
this.$table.hide();
|
2015-05-12 08:35:39 +00:00
|
|
|
var $loadingTip = this.$loadingTip;
|
|
|
|
$loadingTip.show();
|
|
|
|
var _this = this;
|
2015-04-11 07:14:56 +00:00
|
|
|
this.repos.setGroupID(group_id);
|
2015-05-12 08:35:39 +00:00
|
|
|
this.repos.fetch({
|
2015-10-08 09:54:59 +00:00
|
|
|
cache: false,
|
2015-05-12 08:35:39 +00:00
|
|
|
reset: true,
|
|
|
|
data: {from: 'web'},
|
|
|
|
success: function (collection, response, opts) {
|
2016-01-30 08:23:52 +00:00
|
|
|
},
|
2015-05-12 08:35:39 +00:00
|
|
|
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
|
|
|
},
|
|
|
|
|
2015-03-01 12:28:25 +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-03-01 12:28:25 +00:00
|
|
|
this.hideRepoList();
|
2016-01-13 06:54:46 +00:00
|
|
|
|
2016-01-13 08:04:04 +00:00
|
|
|
var group_name = Common.groupId2Name(group_id);
|
2016-01-13 06:54:46 +00:00
|
|
|
if (group_name) {
|
|
|
|
this.dirView.showDir('group/' + this.group_id, repo_id, path, {'group_name': group_name});
|
|
|
|
} else {
|
|
|
|
// the group does not exist
|
2016-01-13 08:04:04 +00:00
|
|
|
Common.feedback('Group {group_id} not found'.replace('{group_id}', group_id), 'error');
|
2016-01-13 06:54:46 +00:00
|
|
|
app.router.navigate('my-libs/', {trigger: true});
|
|
|
|
}
|
2015-01-21 14:22:34 +00:00
|
|
|
},
|
|
|
|
|
2015-01-22 09:15:17 +00:00
|
|
|
createRepo: function() {
|
2015-04-22 10:45:28 +00:00
|
|
|
new AddGroupRepoView(this.repos);
|
2015-01-29 06:45:26 +00:00
|
|
|
},
|
|
|
|
|
2015-03-24 08:59:46 +00:00
|
|
|
sortByName: function() {
|
2015-07-11 06:51:26 +00:00
|
|
|
this.$('.by-time .sort-icon').hide();
|
2015-03-24 08:59:46 +00:00
|
|
|
var repos = this.repos;
|
2015-07-11 06:51:26 +00:00
|
|
|
var el = this.$('.by-name .sort-icon');
|
2015-03-24 08:59:46 +00:00
|
|
|
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);
|
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-03-24 08:59:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
sortByTime: function() {
|
2015-07-11 06:51:26 +00:00
|
|
|
this.$('.by-name .sort-icon').hide();
|
2015-03-24 08:59:46 +00:00
|
|
|
var repos = this.repos;
|
2015-07-11 06:51:26 +00:00
|
|
|
var el = this.$('.by-time .sort-icon');
|
2015-03-24 08:59:46 +00:00
|
|
|
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() {
|
|
|
|
this.hideRepoList();
|
|
|
|
this.dirView.hide();
|
2015-04-14 06:48:56 +00:00
|
|
|
this.$emptyTip.hide();
|
2015-12-11 12:41:16 +00:00
|
|
|
},
|
|
|
|
|
2016-01-06 08:28:26 +00:00
|
|
|
showSettings: function() {
|
|
|
|
this.settingsView.show({
|
2016-01-30 08:23:52 +00:00
|
|
|
'group': this.group
|
2016-01-06 08:28:26 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleSettingsPanel: function() {
|
|
|
|
var panel_id = this.settingsView.el.id;
|
|
|
|
if ($('#' + panel_id + ':visible').length) { // the panel is shown
|
|
|
|
this.settingsView.hide();
|
|
|
|
} else {
|
|
|
|
this.showSettings();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-01-30 08:23:52 +00:00
|
|
|
showGroupWiki: function() {
|
|
|
|
location.href = '/group/' + this.group.id + '/wiki/';
|
|
|
|
},
|
|
|
|
|
2015-12-15 03:33:07 +00:00
|
|
|
showMembers: function() {
|
2015-12-11 12:41:16 +00:00
|
|
|
this.membersView.show({'group_id': this.group_id});
|
|
|
|
},
|
|
|
|
|
2015-12-15 03:33:07 +00:00
|
|
|
toggleMembersPanel: function() {
|
2015-12-11 12:41:16 +00:00
|
|
|
var panel_id = this.membersView.el.id;
|
|
|
|
if ($('#' + panel_id + ':visible').length) { // the panel is shown
|
|
|
|
this.membersView.hide();
|
|
|
|
} else {
|
|
|
|
this.showMembers();
|
|
|
|
}
|
2016-03-08 05:36:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
showDiscussions: function() {
|
|
|
|
this.discussionsView.show({'group_id': this.group_id});
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleDiscussionsPanel: function() {
|
|
|
|
var panel_id = this.discussionsView.el.id;
|
|
|
|
if ($('#' + panel_id + ':visible').length) { // the panel is shown
|
|
|
|
this.discussionsView.hide();
|
|
|
|
} else {
|
|
|
|
this.showDiscussions();
|
|
|
|
}
|
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;
|
|
|
|
});
|