1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 23:20:51 +00:00

[user panel] added 'group owned library' function

This commit is contained in:
llj
2018-05-04 14:40:54 +08:00
parent b87f0312d7
commit 1b6a8479da
9 changed files with 156 additions and 22 deletions

View File

@@ -4,12 +4,13 @@ define([
'backbone',
'common',
'app/collections/group-repos',
'app/collections/group-owned-repos', // for address book group
'app/views/group-repo',
'app/views/add-group-repo',
'app/views/group-members',
'app/views/group-discussions',
'app/views/group-settings'
], function($, _, Backbone, Common, GroupRepos, GroupRepoView,
], function($, _, Backbone, Common, GroupRepos, GroupOwnedRepos, GroupRepoView,
AddGroupRepoView, GroupMembersView, GroupDiscussionsView, GroupSettingsView) {
'use strict';
@@ -21,6 +22,7 @@ define([
toolbar2Template: _.template($('#group-toolbar2-tmpl').html()),
pathTemplate: _.template($('#group-path-tmpl').html()),
theadTemplate: _.template($('#shared-repos-hd-tmpl').html()),
ownedReposTheadTemplate: _.template($('#group-owned-repos-hd-tmpl').html()),
theadMobileTemplate: _.template($('#shared-repos-hd-mobile-tmpl').html()),
events: {
@@ -39,18 +41,33 @@ define([
this.listenTo(this.repos, 'add', this.addOne);
this.listenTo(this.repos, 'reset', this.reset);
this.ownedRepos = new GroupOwnedRepos();
this.listenTo(this.ownedRepos, 'add', this.addOne);
this.settingsView = new GroupSettingsView({groupView: this});
this.membersView = new GroupMembersView({groupView: this});
this.discussionsView = new GroupDiscussionsView({groupView: this});
},
addOne: function(repo, collection, options) {
// 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")
});
}
var view = new GroupRepoView({
model: repo,
group_id: this.group_id,
show_repo_owner: true,
parent_group_id: this.group.parent_group_id,
show_repo_owner: this.group.show_repo_owner,
is_staff: this.repos.is_staff
});
if (options.prepend) {
this.$tableBody.prepend(view.render().el);
} else {
@@ -59,7 +76,16 @@ define([
},
renderThead: function() {
var tmpl = $(window).width() >= 768 ? this.theadTemplate : this.theadMobileTemplate;
var tmpl;
if ($(window).width() < 768) {
tmpl = this.theadMobileTemplate;
} else {
if (this.group.parent_group_id == 0) {
tmpl = this.theadTemplate;
} else {
tmpl = this.ownedReposTheadTemplate;
}
}
this.$tableHead.html(tmpl());
},
@@ -99,7 +125,29 @@ define([
dataType: 'json',
success: function(data) {
_this.group = data;
_this.$toolbar.removeClass('hide');
var user_can_add_repo = false;
var user_is_admin = false;
if ($.inArray(app.pageOptions.username, data.admins) != -1) {
user_is_admin = true;
}
if (data.parent_group_id == 0) { // common group
user_can_add_repo = true;
_this.group.show_repo_owner = true; // for repo list
_this.group.repos_for_new = _this.repos; // for creating a new library
} else { // address book group
_this.group.show_repo_owner = false;
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');
}
_this.renderPath({
'name': data.name
});
@@ -159,12 +207,14 @@ define([
},
renderToolbar: function() {
this.$toolbar = $('<div class="cur-view-toolbar hide" id="group-toolbar"></div>').html(this.toolbarTemplate());
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.$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);
@@ -206,7 +256,9 @@ define([
},
createRepo: function() {
new AddGroupRepoView(this.repos);
var repos = this.group.repos_for_new;
repos.setGroupID(this.group_id);
new AddGroupRepoView(repos);
},
sortByName: function() {