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',
|
2018-05-04 06:40:54 +00:00
|
|
|
'app/collections/group-owned-repos', // for address book group
|
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',
|
2018-05-17 09:42:27 +00:00
|
|
|
'app/views/add-department-repo',
|
|
|
|
'app/views/repo-details',
|
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'
|
2018-05-04 06:40:54 +00:00
|
|
|
], function($, _, Backbone, Common, GroupRepos, GroupOwnedRepos, GroupRepoView,
|
2018-05-17 09:42:27 +00:00
|
|
|
AddGroupRepoView, AddDepartmentRepoView, RepoDetailsView,
|
|
|
|
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);
|
|
|
|
|
2018-05-04 06:40:54 +00:00
|
|
|
this.ownedRepos = new GroupOwnedRepos();
|
|
|
|
this.listenTo(this.ownedRepos, 'add', this.addOne);
|
2018-08-13 09:30:55 +00:00
|
|
|
// for adding the first owned repo when there is no repos in the group.
|
|
|
|
this.listenTo(this.ownedRepos, 'reset', this.resetOwnedRepos);
|
2018-05-04 06:40:54 +00:00
|
|
|
|
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});
|
2018-05-17 09:42:27 +00:00
|
|
|
|
|
|
|
this.repoDetailsView = new RepoDetailsView({'parentView': this});
|
2015-01-21 14:22:34 +00:00
|
|
|
},
|
|
|
|
|
2015-01-27 09:32:31 +00:00
|
|
|
addOne: function(repo, collection, options) {
|
2018-05-04 06:40:54 +00:00
|
|
|
|
|
|
|
// for newly created group owned repo, returned by 'POST' request
|
|
|
|
if (!repo.get('size_formatted') && repo.get('size') == 0
|
|
|
|
&& !repo.get('mtime_relative')) {
|
|
|
|
repo.set({
|
|
|
|
'size_formatted': '0 bytes', // no trans here
|
|
|
|
'mtime_relative': gettext("Just now")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-04-20 06:31:22 +00:00
|
|
|
var view = new GroupRepoView({
|
|
|
|
model: repo,
|
|
|
|
group_id: this.group_id,
|
2018-06-12 10:34:49 +00:00
|
|
|
show_repo_owner: true,
|
2018-05-17 09:42:27 +00:00
|
|
|
repoDetailsView: this.repoDetailsView,
|
2017-09-05 08:07:09 +00:00
|
|
|
is_staff: this.repos.is_staff
|
2015-04-20 06:31:22 +00:00
|
|
|
});
|
2018-05-04 06:40:54 +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() {
|
2018-05-04 06:40:54 +00:00
|
|
|
var tmpl;
|
|
|
|
if ($(window).width() < 768) {
|
|
|
|
tmpl = this.theadMobileTemplate;
|
|
|
|
} else {
|
2018-06-12 10:34:49 +00:00
|
|
|
tmpl = this.theadTemplate;
|
2018-05-04 06:40:54 +00:00
|
|
|
}
|
2016-11-30 07:56:25 +00:00
|
|
|
this.$tableHead.html(tmpl());
|
2015-05-11 10:39:21 +00:00
|
|
|
},
|
|
|
|
|
2018-08-13 09:30:55 +00:00
|
|
|
reset: function(options) {
|
|
|
|
var repos = options.repos || this.repos;
|
|
|
|
if (repos.length) {
|
2015-03-01 12:28:25 +00:00
|
|
|
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});
|
2018-08-13 09:30:55 +00:00
|
|
|
Common.sortLibs({'libs': repos});
|
2016-09-08 08:26:23 +00:00
|
|
|
|
2018-08-13 09:30:55 +00:00
|
|
|
repos.each(this.addOne, this);
|
2015-03-01 12:28:25 +00:00
|
|
|
this.$table.show();
|
|
|
|
} else {
|
2018-05-17 09:42:27 +00:00
|
|
|
this.showEmptyTip();
|
2015-03-01 12:28:25 +00:00
|
|
|
this.$table.hide();
|
|
|
|
}
|
2018-08-13 09:30:55 +00:00
|
|
|
},
|
2016-09-07 02:03:21 +00:00
|
|
|
|
2018-08-13 09:30:55 +00:00
|
|
|
resetOwnedRepos: function() {
|
2018-08-16 02:56:10 +00:00
|
|
|
// no repos in the group
|
|
|
|
if (this.repos.length == 0) {
|
|
|
|
this.reset({repos: this.ownedRepos});
|
|
|
|
}
|
2015-01-21 14:22:34 +00:00
|
|
|
},
|
|
|
|
|
2018-05-17 09:42:27 +00:00
|
|
|
showEmptyTip: function() {
|
|
|
|
if (this.group.is_address_book_group) {
|
|
|
|
if (this.group.user_is_admin) {
|
|
|
|
this.$emptyTip.filter('.address-book-group-empty-tips-for-admin').show();
|
|
|
|
} else {
|
|
|
|
this.$emptyTip.filter('.address-book-group-empty-tips-for-member').show();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.$emptyTip.filter('.common-group-empty-tips').show();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
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;
|
2018-05-04 06:40:54 +00:00
|
|
|
|
|
|
|
var user_can_add_repo = false;
|
|
|
|
var user_is_admin = false;
|
|
|
|
if ($.inArray(app.pageOptions.username, data.admins) != -1) {
|
|
|
|
user_is_admin = true;
|
|
|
|
}
|
2018-05-17 09:42:27 +00:00
|
|
|
_this.group.is_address_book_group = false;
|
|
|
|
_this.group.user_is_admin = user_is_admin;
|
2018-05-04 06:40:54 +00:00
|
|
|
if (data.parent_group_id == 0) { // common group
|
|
|
|
user_can_add_repo = true;
|
|
|
|
_this.group.repos_for_new = _this.repos; // for creating a new library
|
|
|
|
} else { // address book group
|
2018-05-17 09:42:27 +00:00
|
|
|
_this.group.is_address_book_group = true;
|
2018-05-04 06:40:54 +00:00
|
|
|
if (app.pageOptions.is_pro && user_is_admin) {
|
|
|
|
user_can_add_repo = true;
|
|
|
|
_this.group.repos_for_new = _this.ownedRepos; // for creating a new library
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (user_can_add_repo) {
|
|
|
|
_this.$toolbar.removeClass('hide'); // show 'New Library' button
|
|
|
|
} else {
|
|
|
|
_this.$toolbar.addClass('hide');
|
|
|
|
}
|
|
|
|
|
2017-12-05 09:53:45 +00:00
|
|
|
_this.renderPath({
|
2018-05-07 11:55:41 +00:00
|
|
|
'name': data.name,
|
2018-05-17 09:42:27 +00:00
|
|
|
'is_address_book_group': _this.group.is_address_book_group
|
2017-12-05 09:53:45 +00:00
|
|
|
});
|
|
|
|
_this.renderToolbar2({
|
|
|
|
'id': data.id,
|
|
|
|
'wiki_enabled': data.wiki_enabled
|
|
|
|
});
|
2018-06-12 10:34:49 +00:00
|
|
|
// for common member in a group, there is only 'leave group' option in the 'settings' popup
|
|
|
|
// in an address book group, a common member can't 'leave group'
|
|
|
|
if (data.parent_group_id != 0 && !user_is_admin) {
|
|
|
|
$('#group-settings-icon').hide();
|
|
|
|
}
|
2017-12-05 09:53:45 +00:00
|
|
|
_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) {
|
2018-07-31 10:15:44 +00:00
|
|
|
var err_msg = Common.prepareAjaxErrorMsg(xhr);
|
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) {
|
2018-07-31 10:15:44 +00:00
|
|
|
var err_msg = Common.prepareCollectionFetchErrorMsg(collection, response, opts);
|
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() {
|
2018-05-04 06:40:54 +00:00
|
|
|
this.$toolbar = $('<div class="cur-view-toolbar hide" id="group-toolbar"></div>')
|
|
|
|
.html(this.toolbarTemplate());
|
2017-12-05 09:53:45 +00:00
|
|
|
this.$('.common-toolbar').before(this.$toolbar);
|
|
|
|
},
|
|
|
|
|
|
|
|
renderMainCon: function() {
|
2018-05-04 06:40:54 +00:00
|
|
|
this.$mainCon = $('<div class="main-panel-main main-panel-main-with-side" id="group"></div>')
|
|
|
|
.html(this.template());
|
2017-12-05 09:53:45 +00:00
|
|
|
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
|
|
|
}
|
2018-05-17 09:42:27 +00:00
|
|
|
// when switch from a group to another group
|
|
|
|
if (this.repoDetailsView.$el.is(':visible')) {
|
|
|
|
this.repoDetailsView.hide();
|
|
|
|
}
|
|
|
|
|
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() {
|
2018-05-04 06:40:54 +00:00
|
|
|
var repos = this.group.repos_for_new;
|
|
|
|
repos.setGroupID(this.group_id);
|
2018-05-17 09:42:27 +00:00
|
|
|
if (this.group.is_address_book_group) {
|
|
|
|
new AddDepartmentRepoView(repos);
|
|
|
|
} else {
|
|
|
|
new AddGroupRepoView(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;
|
|
|
|
});
|