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'
|
2016-09-08 08:26:23 +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({
|
2017-12-05 09:53:45 +00:00
|
|
|
el: '.main-panel',
|
2015-01-21 14:22:34 +00:00
|
|
|
|
2016-03-24 06:43:20 +00:00
|
|
|
template: _.template($('#group-tmpl').html()),
|
2017-12-05 09:53:45 +00:00
|
|
|
toolbarTemplate: _.template($('#group-toolbar-tmpl').html()),
|
|
|
|
toolbar2Template: _.template($('#group-toolbar2-tmpl').html()),
|
|
|
|
pathTemplate: _.template($('#group-path-tmpl').html()),
|
|
|
|
theadTemplate: _.template($('#shared-repos-hd-tmpl').html()),
|
|
|
|
theadMobileTemplate: _.template($('#shared-repos-hd-mobile-tmpl').html()),
|
2015-05-11 10:39:21 +00:00
|
|
|
|
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-03-08 05:36:58 +00:00
|
|
|
'click #group-discussions-icon': 'toggleDiscussionsPanel',
|
2017-12-05 09:53:45 +00:00
|
|
|
'click #group-toolbar .repo-create': 'createRepo',
|
|
|
|
'click #group-repos .by-name': 'sortByName',
|
|
|
|
'click #group-repos .by-time': 'sortByTime'
|
2015-01-22 09:15:17 +00:00
|
|
|
},
|
|
|
|
|
2015-04-17 10:07:17 +00:00
|
|
|
initialize: function(options) {
|
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);
|
|
|
|
|
2017-12-05 09:53:45 +00:00
|
|
|
this.settingsView = new GroupSettingsView({groupView: this});
|
|
|
|
this.membersView = new GroupMembersView({groupView: this});
|
|
|
|
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,
|
2017-09-06 07:37:00 +00:00
|
|
|
show_repo_owner: true,
|
2017-09-05 08:07:09 +00:00
|
|
|
is_staff: this.repos.is_staff
|
2015-04-20 06:31:22 +00:00
|
|
|
});
|
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
|
|
|
},
|
|
|
|
|
2017-12-05 09:53:45 +00:00
|
|
|
renderThead: function() {
|
|
|
|
var tmpl = $(window).width() >= 768 ? this.theadTemplate : this.theadMobileTemplate;
|
2016-11-30 07:56:25 +00:00
|
|
|
this.$tableHead.html(tmpl());
|
2015-05-11 10:39:21 +00:00
|
|
|
},
|
|
|
|
|
2015-03-01 12:28:25 +00:00
|
|
|
reset: function() {
|
|
|
|
if (this.repos.length) {
|
|
|
|
this.$emptyTip.hide();
|
2017-12-05 09:53:45 +00:00
|
|
|
this.renderThead();
|
2015-05-12 08:35:39 +00:00
|
|
|
this.$tableBody.empty();
|
2016-09-08 08:26:23 +00:00
|
|
|
|
|
|
|
// sort
|
|
|
|
Common.updateSortIconByMode({'context': this.$el});
|
|
|
|
Common.sortLibs({'libs': this.repos});
|
|
|
|
|
2015-05-12 08:35:39 +00:00
|
|
|
this.repos.each(this.addOne, this);
|
2015-03-01 12:28:25 +00:00
|
|
|
this.$table.show();
|
|
|
|
} else {
|
|
|
|
this.$emptyTip.show();
|
|
|
|
this.$table.hide();
|
|
|
|
}
|
2016-09-07 02:03:21 +00:00
|
|
|
|
2015-01-21 14:22:34 +00:00
|
|
|
},
|
|
|
|
|
2017-12-05 09:53:45 +00:00
|
|
|
showGroup: function(options) {
|
2015-11-24 08:55:38 +00:00
|
|
|
var _this = this;
|
2017-12-05 09:53:45 +00:00
|
|
|
|
|
|
|
this.$table.hide();
|
|
|
|
this.$emptyTip.hide();
|
|
|
|
this.$error.hide();
|
|
|
|
this.$loadingTip.show();
|
|
|
|
|
2015-11-24 08:55:38 +00:00
|
|
|
$.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',
|
2017-12-05 09:53:45 +00:00
|
|
|
success: function(data) {
|
2016-01-30 08:23:52 +00:00
|
|
|
_this.group = data;
|
2017-12-05 09:53:45 +00:00
|
|
|
_this.$toolbar.removeClass('hide');
|
|
|
|
_this.renderPath({
|
|
|
|
'name': data.name
|
|
|
|
});
|
|
|
|
_this.renderToolbar2({
|
|
|
|
'id': data.id,
|
|
|
|
'wiki_enabled': data.wiki_enabled
|
|
|
|
});
|
|
|
|
_this.showRepoList();
|
2016-03-28 10:12:25 +00:00
|
|
|
if (options) {
|
|
|
|
if (options.showDiscussions) {
|
|
|
|
_this.showDiscussions();
|
|
|
|
}
|
|
|
|
}
|
2015-11-24 08:55:38 +00:00
|
|
|
},
|
|
|
|
error: function(xhr) {
|
|
|
|
var err_msg;
|
|
|
|
if (xhr.responseText) {
|
2018-02-05 08:47:56 +00:00
|
|
|
err_msg = JSON.parse(xhr.responseText).error_msg;
|
2015-11-24 08:55:38 +00:00
|
|
|
} else {
|
|
|
|
err_msg = gettext("Please check the network.");
|
|
|
|
}
|
2017-12-05 09:53:45 +00:00
|
|
|
_this.$toolbar.addClass('hide');
|
|
|
|
_this.$path.empty();
|
|
|
|
_this.$toolbar2.empty();
|
|
|
|
_this.$loadingTip.hide();
|
|
|
|
_this.$error.html(err_msg).show();
|
2015-11-24 08:55:38 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-12-05 09:53:45 +00:00
|
|
|
showRepoList: function() {
|
2015-05-12 08:35:39 +00:00
|
|
|
var _this = this;
|
2017-12-05 09:53:45 +00:00
|
|
|
this.repos.setGroupID(this.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'},
|
2017-12-05 09:53:45 +00:00
|
|
|
success: function(collection, response, opts) {
|
2016-01-30 08:23:52 +00:00
|
|
|
},
|
2017-12-05 09:53:45 +00:00
|
|
|
error: function(collection, response, opts) {
|
2015-05-12 08:35:39 +00:00
|
|
|
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.');
|
|
|
|
}
|
2017-12-05 09:53:45 +00:00
|
|
|
_this.$error.html(err_msg).show();
|
|
|
|
},
|
|
|
|
complete: function() {
|
|
|
|
_this.$loadingTip.hide();
|
2015-05-12 08:35:39 +00:00
|
|
|
}
|
|
|
|
});
|
2015-01-21 14:22:34 +00:00
|
|
|
},
|
|
|
|
|
2017-12-05 09:53:45 +00:00
|
|
|
renderToolbar: function() {
|
|
|
|
this.$toolbar = $('<div class="cur-view-toolbar hide" id="group-toolbar"></div>').html(this.toolbarTemplate());
|
|
|
|
this.$('.common-toolbar').before(this.$toolbar);
|
|
|
|
},
|
|
|
|
|
|
|
|
renderMainCon: function() {
|
|
|
|
this.$mainCon = $('<div class="main-panel-main main-panel-main-with-side" id="group"></div>').html(this.template());
|
|
|
|
this.$el.append(this.$mainCon);
|
|
|
|
|
|
|
|
this.$path = $('.group-path', this.$mainCon);
|
|
|
|
this.$toolbar2 = $('.group-toolbar-2', this.$mainCon);
|
|
|
|
this.$table = $('table', this.$mainCon);
|
|
|
|
this.$tableHead = $('thead', this.$table);
|
|
|
|
this.$tableBody = $('tbody', this.$table);
|
|
|
|
this.$loadingTip = $('.loading-tip', this.$mainCon);
|
2016-03-24 06:43:20 +00:00
|
|
|
this.$emptyTip = this.$('#group-repos .empty-tips');
|
2017-12-05 09:53:45 +00:00
|
|
|
this.$error = $('.error', this.$mainCon);
|
|
|
|
},
|
|
|
|
|
|
|
|
renderPath: function(data) {
|
|
|
|
this.$path.html(this.pathTemplate(data));
|
|
|
|
},
|
|
|
|
|
|
|
|
renderToolbar2: function(data) {
|
|
|
|
this.$toolbar2.html(this.toolbar2Template(data));
|
|
|
|
},
|
|
|
|
|
|
|
|
// update group name. e.g 'rename'
|
|
|
|
updateName: function(new_name) {
|
|
|
|
this.group.name = new_name;
|
|
|
|
$('.group-name', this.$mainCon).html(Common.HTMLescape(new_name));
|
2015-01-21 14:22:34 +00:00
|
|
|
},
|
|
|
|
|
2016-03-24 06:43:20 +00:00
|
|
|
show: function(group_id, options) {
|
2017-12-05 09:53:45 +00:00
|
|
|
if (!$('#group').length) {
|
|
|
|
this.renderToolbar();
|
|
|
|
this.renderMainCon();
|
2016-01-13 06:54:46 +00:00
|
|
|
}
|
2017-12-05 09:53:45 +00:00
|
|
|
this.group_id = group_id;
|
|
|
|
this.showGroup(options);
|
2016-03-24 06:43:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
hide: function() {
|
2017-12-05 09:53:45 +00:00
|
|
|
this.$toolbar.detach();
|
|
|
|
this.$mainCon.detach();
|
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() {
|
2016-09-08 08:26:23 +00:00
|
|
|
Common.toggleSortByNameMode();
|
|
|
|
Common.updateSortIconByMode({'context': this.$el});
|
|
|
|
Common.sortLibs({'libs': this.repos});
|
2016-09-07 02:03:21 +00:00
|
|
|
|
2015-03-24 08:59:46 +00:00
|
|
|
this.$tableBody.empty();
|
2016-09-07 02:03:21 +00:00
|
|
|
this.repos.each(this.addOne, this);
|
|
|
|
this.repos.comparator = null;
|
|
|
|
|
2016-04-19 06:41:17 +00:00
|
|
|
return false;
|
2015-03-24 08:59:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
sortByTime: function() {
|
2016-09-08 08:26:23 +00:00
|
|
|
Common.toggleSortByTimeMode();
|
|
|
|
Common.updateSortIconByMode({'context': this.$el});
|
|
|
|
Common.sortLibs({'libs': this.repos});
|
2016-09-07 02:03:21 +00:00
|
|
|
|
2015-03-24 08:59:46 +00:00
|
|
|
this.$tableBody.empty();
|
2016-09-07 02:03:21 +00:00
|
|
|
this.repos.each(this.addOne, this);
|
|
|
|
this.repos.comparator = null;
|
|
|
|
|
2016-04-19 06:41:17 +00:00
|
|
|
return false;
|
2015-04-11 07:14:56 +00:00
|
|
|
},
|
|
|
|
|
2016-01-06 08:28:26 +00:00
|
|
|
toggleSettingsPanel: function() {
|
2016-04-01 07:22:28 +00:00
|
|
|
return this.settingsView.toggle();
|
2016-01-06 08:28:26 +00:00
|
|
|
},
|
|
|
|
|
2015-12-15 03:33:07 +00:00
|
|
|
toggleMembersPanel: function() {
|
2016-04-01 07:22:28 +00:00
|
|
|
return this.membersView.toggle();
|
2016-03-08 05:36:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
showDiscussions: function() {
|
2016-04-01 07:22:28 +00:00
|
|
|
return this.discussionsView.show();
|
2016-03-08 05:36:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
toggleDiscussionsPanel: function() {
|
2016-04-01 07:22:28 +00:00
|
|
|
return this.discussionsView.toggle();
|
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;
|
|
|
|
});
|