1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-31 14:42:10 +00:00

[org admin] added 'address-book'

This commit is contained in:
llj
2018-08-07 17:05:41 +08:00
parent 0105e8e8ef
commit ff90c7cfb4
16 changed files with 588 additions and 266 deletions

View File

@@ -200,7 +200,7 @@ define([
case 'admin-group-owned-libraries': return siteRoot + 'api/v2.1/admin/groups/' + options.group_id + '/group-owned-libraries/';
case 'admin-group-owned-library': return siteRoot + 'api/v2.1/admin/groups/' + options.group_id + '/group-owned-libraries/' + options.repo_id + '/';
case 'admin-group-members': return siteRoot + 'api/v2.1/admin/groups/' + options.group_id + '/members/';
case 'admin-group-member': return siteRoot + 'api/v2.1/admin/groups/' + options.group_id + '/members/' + options.email+ '/';
case 'admin-group-member': return siteRoot + 'api/v2.1/admin/groups/' + options.group_id + '/members/' + encodeURIComponent(options.email) + '/';
case 'admin-system-library': return siteRoot + 'api/v2.1/admin/system-library/';
case 'admin-system-library-upload-link': return siteRoot + 'api/v2.1/admin/system-library/upload-link/';
case 'admin-trash-libraries': return siteRoot + 'api/v2.1/admin/trash-libraries/';
@@ -213,6 +213,16 @@ define([
case 'admin-address-book-groups': return siteRoot + 'api/v2.1/admin/address-book/groups/';
case 'admin-address-book-group': return siteRoot + 'api/v2.1/admin/address-book/groups/' + options.group_id + '/';
// org admin
case 'org-admin-address-book-groups': return siteRoot + 'api/v2.1/org/' + options.org_id + '/admin/address-book/groups/';
case 'org-admin-address-book-group': return siteRoot + 'api/v2.1/org/' + options.org_id + '/admin/address-book/groups/' + options.group_id + '/';
case 'org-admin-group': return siteRoot + 'api/v2.1/org/' + options.org_id + '/admin/groups/' + options.group_id + '/';
case 'org-admin-group-members': return siteRoot + 'api/v2.1/org/' + options.org_id + '/admin/groups/' + options.group_id + '/members/';
case 'org-admin-group-member': return siteRoot + 'api/v2.1/org/' + options.org_id + '/admin/groups/' + options.group_id + '/members/' + encodeURIComponent(options.email) + '/';
case 'org-admin-group-libraries': return siteRoot + 'api/v2.1/org/' + options.org_id + '/admin/groups/' + options.group_id + '/libraries/';
case 'org-admin-group-owned-libraries': return siteRoot + 'api/v2.1/org/' + options.org_id + '/admin/groups/' + options.group_id + '/group-owned-libraries/';
case 'org-admin-group-owned-library': return siteRoot + 'api/v2.1/org/' + options.org_id + '/admin/groups/' + options.group_id + '/group-owned-libraries/' + options.repo_id + '/';
case 'license': return siteRoot + 'api/v2.1/admin/license/';
}
},
@@ -359,14 +369,13 @@ define([
$yesBtn.on('click', yesCallback);
},
confirm_with_extra_option_template: _.template($('#confirm-dialog-with-extra-option-tmpl').html()),
showConfirmWithExtraOption: function(title, content, extraOption, yesCallback) {
var $popup = $("#confirm-popup");
var $cont = $('#confirm-con');
var $yesBtn = $('#confirm-yes');
var html = this.confirm_with_extra_option_template({
var confirm_with_extra_option_template = _.template($('#confirm-dialog-with-extra-option-tmpl').html());
var html = confirm_with_extra_option_template({
'is_pro': app.pageOptions.is_pro,
'title': title,
'content': content,

View File

@@ -0,0 +1,6 @@
define([
'orgadmin-app/router'
], function(Router){
app.router = new Router();
Backbone.history.start();
});

View File

@@ -0,0 +1,76 @@
/*global define*/
define([
'jquery',
'backbone',
'common',
'orgadmin-app/views/side-nav',
'sysadmin-app/views/address-book',
'sysadmin-app/views/address-book-group',
'app/views/account'
], function($, Backbone, Common, SideNavView,
AddressBookView, AddressBookGroupView,
AccountView) {
"use strict";
var Router = Backbone.Router.extend({
routes: {
'': 'showAddressBook',
'address-book/': 'showAddressBook',
'address-book/groups/:group_id/': 'showAddressBookGroup',
// Default
'*actions': 'showAddressBook',
},
initialize: function() {
$('#initial-loading').hide()
.next('.row').removeClass('hide');
Common.prepareApiCsrf();
Common.initLocale();
this.accountView = new AccountView();
this.sideNavView = new SideNavView();
app.ui = {
sideNavView: this.sideNavView,
accountView: this.accountView
};
$('#info-bar .close').on('click', Common.closeTopNoticeBar);
this.addressBookView = new AddressBookView();
this.addressBookGroupView = new AddressBookGroupView();
},
switchCurrentView: function(newView) {
if (!this.currentView) {
this.currentView = newView;
} else {
if (this.currentView != newView) {
this.currentView.hide();
this.currentView = newView;
}
}
},
showAddressBook: function() {
this.switchCurrentView(this.addressBookView);
this.sideNavView.setCurTab('address-book');
this.addressBookView.show();
},
showAddressBookGroup: function(group_id) {
this.switchCurrentView(this.addressBookGroupView);
this.sideNavView.setCurTab('address-book');
this.addressBookGroupView.show({'group_id': group_id});
}
});
return Router;
});

View File

@@ -0,0 +1,74 @@
define([
'jquery',
'underscore',
'backbone',
'common'
], function($, _, Backbone, Common) {
'use strict';
var sideNavView = Backbone.View.extend({
el: '#side-nav',
template: _.template($("#side-nav-tmpl").html()),
initialize: function() {
this.default_cur_tab = 'address-book';
this.data = {
'cur_tab': this.default_cur_tab
};
this.render();
var _this = this;
$('#js-toggle-side-nav').on('click', function() {
_this.show();
return false;
});
$(window).on('resize', function() {
if ($(window).width() >= 768) {
_this.show();
}
});
},
render: function() {
this.$el.html(this.template(this.data));
return this;
},
setCurTab: function(cur_tab, options) {
this.data.cur_tab = cur_tab || this.default_cur_tab;
if (options) {
$.extend(this.data, options);
}
this.render();
},
show: function() {
this.$el.css({ 'left':'0px' });
},
hide: function() {
this.$el.css({ 'left':'-300px' });
},
events: {
'click .js-close-side-nav': 'closeNav',
'click li a': 'visitLink'
},
closeNav: function() {
this.hide();
return false;
},
visitLink: function(e) {
if ($(window).width() < 768) {
this.hide();
}
return true;
}
});
return sideNavView;
});

View File

@@ -0,0 +1,4 @@
//Load common code that includes config, then load the app logic for this page.
require(['./common'], function (common) {
require(['orgadmin-app/main']);
});

View File

@@ -11,10 +11,21 @@ define([
},
url: function() {
return Common.getUrl({
name: 'admin-address-book-group',
group_id: this.options.group_id
});
var url_options;
if (app.pageOptions.org_id) { // org admin
url_options = {
name: 'org-admin-address-book-group',
org_id: app.pageOptions.org_id,
group_id: this.options.group_id
};
} else {
url_options = {
name: 'admin-address-book-group',
group_id: this.options.group_id
};
}
return Common.getUrl(url_options);
},
parse: function(data) {

View File

@@ -7,7 +7,18 @@ define([
var collection = Backbone.Collection.extend({
url: function() {
return Common.getUrl({name: 'admin-address-book-groups'});
var url_options;
if (app.pageOptions.org_id) { // org admin
url_options = {
name: 'org-admin-address-book-groups',
org_id: app.pageOptions.org_id
};
} else {
url_options = {
name: 'admin-address-book-groups'
};
}
return Common.getUrl(url_options);
},
parse: function(data) {

View File

@@ -21,7 +21,20 @@ define([
},
url: function () {
return Common.getUrl({name: 'admin-group-libraries', group_id: this.group_id});
var url_options = {
group_id: this.group_id
};
if (app.pageOptions.org_id) { // org admin
$.extend(url_options, {
name: 'org-admin-group-libraries',
org_id: app.pageOptions.org_id
});
} else {
$.extend(url_options, {
name: 'admin-group-libraries'
});
}
return Common.getUrl(url_options);
}
});

View File

@@ -29,14 +29,25 @@ define([
deleteGroup: function() {
var _this = this;
var group_name = this.model.get('name');
var url_options = {
'group_id': _this.model.get('id')
};
if (app.pageOptions.org_id) { // org admin
$.extend(url_options, {
'name':'org-admin-address-book-group',
'org_id': app.pageOptions.org_id
});
} else {
$.extend(url_options, {
'name':'admin-address-book-group'
});
}
var popupTitle = gettext("Delete Department");
var popupContent = gettext("Are you sure you want to delete %s ?").replace('%s', '<span class="op-target ellipsis ellipsis-op-target" title="' + Common.HTMLescape(group_name) + '">' + Common.HTMLescape(group_name) + '</span>');
var yesCallback = function() {
$.ajax({
url: Common.getUrl({
'name':'admin-address-book-group',
'group_id': _this.model.get('id')
}),
url: Common.getUrl(url_options),
type: 'DELETE',
cache: false,
beforeSend: Common.prepareCSRFToken,
@@ -81,12 +92,23 @@ define([
return false;
}
Common.disableButton($submitBtn);
$.ajax({
url: Common.getUrl({
var url_options;
if (app.pageOptions.org_id) { // org admin
url_options = {
'name':'org-admin-group',
'org_id': app.pageOptions.org_id,
'group_id': model.get('id')
};
} else {
url_options = {
'name':'admin-group',
'group_id': model.get('id')
}),
};
}
Common.disableButton($submitBtn);
$.ajax({
url: Common.getUrl(url_options),
type: 'PUT',
cache: false,
beforeSend: Common.prepareCSRFToken,

View File

@@ -30,12 +30,23 @@ define([
var popupTitle = gettext("Delete Library");
var popupContent = gettext("Are you sure you want to delete %s ?").replace('%s', '<span class="op-target ellipsis ellipsis-op-target" title="' + Common.HTMLescape(repo_name) + '">' + Common.HTMLescape(repo_name) + '</span>');
var yesCallback = function() {
var url_options = {
group_id: _this.group_id,
repo_id: _this.model.get('repo_id')
};
if (app.pageOptions.org_id) { // org admin
$.extend(url_options, {
name: 'org-admin-group-owned-library',
org_id: app.pageOptions.org_id
});
} else {
$.extend(url_options, {
name: 'admin-group-owned-library'
});
}
$.ajax({
url: Common.getUrl({
'name': 'admin-group-owned-library',
'group_id': _this.group_id,
'repo_id': _this.model.get('repo_id')
}),
url: Common.getUrl(url_options),
type: 'DELETE',
beforeSend: Common.prepareCSRFToken,
dataType: 'json',

View File

@@ -3,13 +3,15 @@ define([
'underscore',
'backbone',
'common',
'select2',
'sysadmin-app/views/address-book-group-item',
'sysadmin-app/views/group-member',
'sysadmin-app/views/address-book-group-library',
'sysadmin-app/collection/address-book-group',
'sysadmin-app/collection/group-repos'
], function($, _, Backbone, Common, GroupItemView, MemberItemView,
LibItemView, GroupCollection, GroupRepoCollection) {
], function($, _, Backbone, Common, Select2,
GroupItemView, MemberItemView, LibItemView,
GroupCollection, GroupRepoCollection) {
'use strict';
var view = Backbone.View.extend({
@@ -107,18 +109,28 @@ define([
var $error = $('.error', $form);
var $submitBtn = $('[type="submit"]', $form);
if (!group_name) {
$error.html(gettext("Name is required.")).show();
return false;
}
var url_options;
if (app.pageOptions.org_id) { // org admin
url_options = {
name: 'org-admin-address-book-groups',
org_id: app.pageOptions.org_id
};
} else {
url_options = {
name: 'admin-address-book-groups'
};
}
$error.hide();
Common.disableButton($submitBtn);
$.ajax({
url: Common.getUrl({
'name': 'admin-address-book-groups'
}),
url: Common.getUrl(url_options),
type: 'POST',
cache: false,
data: {
@@ -170,14 +182,25 @@ define([
return false;
}
var url_options;
if (app.pageOptions.org_id) { // org admin
url_options = {
name: 'org-admin-group-members',
org_id: app.pageOptions.org_id,
group_id: _this.options.group_id
};
} else {
url_options = {
name: 'admin-group-members',
group_id: _this.options.group_id
};
}
$error.hide();
Common.disableButton($submitBtn);
$.ajax({
url: Common.getUrl({
'name': 'admin-group-members',
'group_id': _this.options.group_id
}),
url: Common.getUrl(url_options),
type: 'POST',
dataType: 'json',
data: {'email': emails.split(',')},
@@ -233,11 +256,22 @@ define([
$error.hide();
Common.disableButton($submitBtn);
var url_options = {
group_id: _this.options.group_id
};
if (app.pageOptions.org_id) { // org admin
$.extend(url_options, {
name: 'org-admin-group-owned-libraries',
org_id: app.pageOptions.org_id
});
} else {
$.extend(url_options, {
name: 'admin-group-owned-libraries'
});
}
$.ajax({
url: Common.getUrl({
'name': 'admin-group-owned-libraries',
'group_id': _this.options.group_id
}),
url: Common.getUrl(url_options),
type: 'POST',
dataType: 'json',
data: {'repo_name': name},
@@ -321,7 +355,10 @@ define([
},
addLibrary: function(item, collection, options) {
var view = new LibItemView({model: item, group_id: this.options.group_id});
var view = new LibItemView({
model: item,
group_id: this.options.group_id
});
if (options.prepend) {
this.$libsTableBody.prepend(view.render().el);
} else {

View File

@@ -24,6 +24,23 @@ define([
HLItemView.prototype.initialize.call(this);
this.listenTo(this.model, 'change', this.render);
var url_options = {
'group_id': this.model.get('group_id'),
'email': this.model.get('email')
};
if (app.pageOptions.org_id) { // org admin
$.extend(url_options, {
'name': 'org-admin-group-member',
'org_id': app.pageOptions.org_id
});
} else {
$.extend(url_options, {
'name': 'admin-group-member'
});
}
this.url_options = url_options;
var _this = this;
$(document).on('click', function(e) {
var target = e.target || event.srcElement;
@@ -45,12 +62,9 @@ define([
// '0': member, '1': admin
var val = this.$('[name="role"]').val();
var is_admin = val == 1 ? true : false;
$.ajax({
url: Common.getUrl({
'name': 'admin-group-member',
'group_id': _this.model.get('group_id'),
'email': _this.model.get('email')
}),
url: Common.getUrl(this.url_options),
type: 'put',
dataType: 'json',
beforeSend: Common.prepareCSRFToken,
@@ -77,11 +91,7 @@ define([
var popupContent = gettext("Are you sure you want to delete %s ?").replace('%s', '<span class="op-target ellipsis ellipsis-op-target" title="' + Common.HTMLescape(email) + '">' + Common.HTMLescape(email) + '</span>');
var yesCallback = function() {
$.ajax({
url: Common.getUrl({
'name': 'admin-group-member',
'group_id': _this.model.get('group_id'),
'email': email
}),
url: Common.getUrl(_this.url_options),
type: 'DELETE',
beforeSend: Common.prepareCSRFToken,
dataType: 'json',