1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-31 14:42:10 +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

@@ -0,0 +1,27 @@
define([
'underscore',
'backbone',
'common',
'app/models/group-repo'
], function(_, Backbone, Common, GroupRepo) {
'use strict';
var GroupRepoCollection = Backbone.Collection.extend({
model: GroupRepo,
comparator: -'mtime',
url: function() {
return Common.getUrl({name: 'group_owned_repos', group_id: this.group_id});
},
parse: function(data) {
//return data.repos;
},
setGroupID: function(group_id) {
this.group_id = group_id;
}
});
return GroupRepoCollection;
});

View File

@@ -43,15 +43,22 @@ define([
// Generate the attributes for a new GroupRepo item.
newAttributes: function() {
return {
var data = {
name: $.trim($('input[name=repo_name]', this.$el).val()),
encrypted: $('#encrypt-switch').prop('checked'),
passwd1: $('input[name=passwd]', this.$el).val(),
passwd2: $('input[name=passwd_again]', this.$el).val(),
passwd: $('input[name=passwd]', this.$el).val(),
library_template: $('[name="library_template"]', this.$el).val(),
storage_id: $('[name="storage"]', this.$el).val()
};
if (data.encrypted) {
$.extend(data, {
passwd1: $('input[name=passwd]', this.$el).val(),
passwd2: $('input[name=passwd_again]', this.$el).val(),
passwd: $('input[name=passwd]', this.$el).val()
});
}
return data;
},
// TODO: move to common

View File

@@ -34,6 +34,7 @@ define([
return Common.compareTwoWord(a.name, b.name);
});
var group_id = this.model.get('id'),
parent_group_id = this.model.get('parent_group_id'),
is_staff = $.inArray(app.pageOptions.username, this.model.get('admins')) != -1 ? true : false,
$listContainer = this.$('tbody');
var groupRepos = new GroupRepos();
@@ -42,6 +43,7 @@ define([
var view = new GroupRepoView({
model: new GroupRepo(item, {collection: groupRepos}),
group_id: group_id,
parent_group_id: parent_group_id,
is_staff: is_staff,
show_repo_owner: false // don't show 'Owner'
});

View File

@@ -15,6 +15,7 @@ define([
mobileTemplate: _.template($('#group-repo-mobile-tmpl').html()),
events: {
'click .delete-repo': 'delRepo', // for group owned repo
'click .cancel-share': 'unshare',
'click .repo-share-btn': 'share'
},
@@ -23,12 +24,38 @@ define([
HLItemView.prototype.initialize.call(this);
this.group_id = options.group_id;
this.parent_group_id = options.parent_group_id;
this.is_staff = options.is_staff;
this.show_repo_owner = options.show_repo_owner;
this.listenTo(this.model, 'destroy', this.remove);
},
delRepo: function() {
var _this = this;
$.ajax({
url: Common.getUrl({
'name': 'group_owned_repo',
'group_id': this.group_id,
'repo_id': this.model.get('id')
}),
type: 'DELETE',
cache: false,
dataType: 'json',
beforeSend: Common.prepareCSRFToken,
success: function() {
var msg = gettext("Successfully deleted library {placeholder}")
.replace('{placeholder}', _this.model.get('name'));
_this.remove();
Common.feedback(msg, 'success');
},
error: function(xhr, textStatus, errorThrown) {
Common.ajaxErrorHandler(xhr, textStatus, errorThrown);
}
});
return false;
},
render: function() {
var obj = this.model.toJSON();
var icon_size = Common.isHiDPI() ? 48 : 24;
@@ -36,6 +63,7 @@ define([
var tmpl = $(window).width() >= 768 ? this.template : this.mobileTemplate;
$.extend(obj, {
group_id: this.group_id,
parent_group_id: this.parent_group_id,
is_staff: this.is_staff,
// for '#groups' (no 'share_from_me')
is_repo_owner: app.pageOptions.username == this.model.get('owner'),

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() {

View File

@@ -148,6 +148,8 @@ define([
case 'group_member_bulk': return siteRoot + 'api/v2.1/groups/' + options.group_id + '/members/bulk/';
case 'group_import_members': return siteRoot + 'ajax/group/' + options.group_id + '/members/import/';
case 'group_repos': return siteRoot + 'api2/groups/' + options.group_id + '/repos/';
case 'group_owned_repos': return siteRoot + 'api/v2.1/groups/' + options.group_id + '/group-owned-libraries/';
case 'group_owned_repo': return siteRoot + 'api/v2.1/groups/' + options.group_id + '/group-owned-libraries/' + options.repo_id + '/';
case 'group_discussions': return siteRoot + 'api2/groups/' + options.group_id + '/discussions/';
case 'group_discussion': return siteRoot + 'api2/groups/' + options.group_id + '/discussions/' + options.discussion_id + '/';