mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-04 16:31:13 +00:00
new admin groups page
This commit is contained in:
24
static/scripts/sysadmin-app/collection/groups.js
Normal file
24
static/scripts/sysadmin-app/collection/groups.js
Normal file
@@ -0,0 +1,24 @@
|
||||
define([
|
||||
'underscore',
|
||||
'backbone.paginator',
|
||||
'common',
|
||||
'sysadmin-app/models/group'
|
||||
], function(_, BackbonePaginator, Common, GroupModel) {
|
||||
'use strict';
|
||||
|
||||
var GroupCollection = Backbone.PageableCollection.extend({
|
||||
model: GroupModel,
|
||||
state: {pageSize: 100},
|
||||
parseState: function(data) {
|
||||
return data.page_info; // {'has_next_page': has_next_page, 'current_page': current_page}
|
||||
},
|
||||
parseRecords: function(data) {
|
||||
return data.groups;
|
||||
},
|
||||
url: function () {
|
||||
return Common.getUrl({name: 'admin-groups'});
|
||||
}
|
||||
});
|
||||
|
||||
return GroupCollection;
|
||||
});
|
11
static/scripts/sysadmin-app/models/group.js
Normal file
11
static/scripts/sysadmin-app/models/group.js
Normal file
@@ -0,0 +1,11 @@
|
||||
define([
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
], function(_, Backbone, Common) {
|
||||
'use strict';
|
||||
|
||||
var GroupModel = Backbone.Model.extend({});
|
||||
|
||||
return GroupModel;
|
||||
});
|
@@ -14,11 +14,12 @@ define([
|
||||
'sysadmin-app/views/trash-repos',
|
||||
'sysadmin-app/views/search-trash-repos',
|
||||
'sysadmin-app/views/dir',
|
||||
'sysadmin-app/views/groups',
|
||||
'app/views/account'
|
||||
], function($, Backbone, Common, SideNavView, DashboardView,
|
||||
DesktopDevicesView, MobileDevicesView, DeviceErrorsView,
|
||||
ReposView, SearchReposView, SystemReposView, TrashReposView,
|
||||
SearchTrashReposView, DirView, AccountView) {
|
||||
ReposView, SearchReposView, SystemReposView, TrashReposView,
|
||||
SearchTrashReposView, DirView, GroupsView, AccountView) {
|
||||
|
||||
"use strict";
|
||||
|
||||
@@ -35,6 +36,7 @@ define([
|
||||
'trash-libs/': 'showTrashLibraries',
|
||||
'search-trash-libs/': 'showSearchTrashLibraries',
|
||||
'libs/:repo_id(/*path)': 'showLibraryDir',
|
||||
'groups/': 'showGroups',
|
||||
// Default
|
||||
'*actions': 'showDashboard'
|
||||
},
|
||||
@@ -62,6 +64,8 @@ define([
|
||||
this.searchTrashReposView = new SearchTrashReposView();
|
||||
this.dirView = new DirView();
|
||||
|
||||
this.groupsView = new GroupsView();
|
||||
|
||||
app.ui.accountView = this.accountView = new AccountView();
|
||||
|
||||
this.currentView = this.dashboardView;
|
||||
@@ -115,7 +119,7 @@ define([
|
||||
},
|
||||
|
||||
showLibraries: function() {
|
||||
// url_match: null or an array like ["http://127.0.0.1:8000/sysadmin/#libraries/?page=2", "2"]
|
||||
// url_match: null or an array like ["http://127.0.0.1:8000/sysadmin/#libraries/?page=2", "2"]
|
||||
var url_match = location.href.match(/.*?page=(\d+)/);
|
||||
var page = url_match ? url_match[1] : 1; // 1: default
|
||||
|
||||
@@ -175,6 +179,16 @@ define([
|
||||
this.switchCurrentView(this.searchTrashReposView);
|
||||
this.sideNavView.setCurTab('libraries', {'option': 'trash'});
|
||||
this.searchTrashReposView.show({'owner': decodeURIComponent(owner)});
|
||||
},
|
||||
|
||||
showGroups: function() {
|
||||
// url_match: null or an array like ["http://127.0.0.1:8000/sysadmin/#groups/?page=2", "2"]
|
||||
var url_match = location.href.match(/.*?page=(\d+)/);
|
||||
var page = url_match ? url_match[1] : 1; // 1: default
|
||||
|
||||
this.switchCurrentView(this.groupsView);
|
||||
this.sideNavView.setCurTab('groups');
|
||||
this.groupsView.show({'page': page});
|
||||
}
|
||||
|
||||
});
|
||||
|
136
static/scripts/sysadmin-app/views/group.js
Normal file
136
static/scripts/sysadmin-app/views/group.js
Normal file
@@ -0,0 +1,136 @@
|
||||
define([
|
||||
'jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'moment',
|
||||
'simplemodal',
|
||||
'select2',
|
||||
'app/views/widgets/hl-item-view'
|
||||
], function($, _, Backbone, Common, Moment, Simplemodal, Select2, HLItemView) {
|
||||
'use strict';
|
||||
|
||||
var GroupView = HLItemView.extend({
|
||||
tagName: 'tr',
|
||||
|
||||
template: _.template($('#group-item-tmpl').html()),
|
||||
transferTemplate: _.template($('#group-transfer-form-tmpl').html()),
|
||||
|
||||
events: {
|
||||
'click .group-delete-btn': 'deleteGroup',
|
||||
'click .group-transfer-btn': 'transferGroup'
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
HLItemView.prototype.initialize.call(this);
|
||||
this.listenTo(this.model, "change", this.render);
|
||||
},
|
||||
|
||||
deleteGroup: function() {
|
||||
var _this = this;
|
||||
var group_name = this.model.get('name');
|
||||
var popupTitle = gettext("Delete Group");
|
||||
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-group',
|
||||
'group_id': _this.model.get('id')
|
||||
}),
|
||||
type: 'DELETE',
|
||||
cache: false,
|
||||
beforeSend: Common.prepareCSRFToken,
|
||||
dataType: 'json',
|
||||
success: function() {
|
||||
_this.$el.remove();
|
||||
Common.feedback(gettext("Successfully deleted."), 'success');
|
||||
},
|
||||
error: function(xhr, textStatus, errorThrown) {
|
||||
Common.ajaxErrorHandler(xhr, textStatus, errorThrown);
|
||||
},
|
||||
complete: function() {
|
||||
$.modal.close();
|
||||
}
|
||||
});
|
||||
};
|
||||
Common.showConfirm(popupTitle, popupContent, yesCallback);
|
||||
return false;
|
||||
},
|
||||
|
||||
transferGroup: function() {
|
||||
var _this = this;
|
||||
var group_name = this.model.get('name');
|
||||
var $form = $(this.transferTemplate({
|
||||
title: gettext("Transfer Group {group_name} To").replace('{group_name}',
|
||||
'<span class="op-target ellipsis ellipsis-op-target" title="' + Common.HTMLescape(group_name) + '">' + Common.HTMLescape(group_name) + '</span>')
|
||||
}));
|
||||
|
||||
$form.modal({focus:false});
|
||||
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
|
||||
$('[name="email"]', $form).select2($.extend(
|
||||
Common.contactInputOptionsForSelect2(), {
|
||||
width: '300px',
|
||||
maximumSelectionSize: 1,
|
||||
placeholder: gettext("Search user or enter email and press Enter"), // to override 'placeholder' returned by `Common.conta...`
|
||||
formatSelectionTooBig: gettext("You cannot select any more choices")
|
||||
}));
|
||||
|
||||
$form.submit(function() {
|
||||
var email = $.trim($('[name="email"]', $(this)).val());
|
||||
if (!email) {
|
||||
return false;
|
||||
}
|
||||
if (email == _this.model.get('owner')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var url = Common.getUrl({'name': 'admin-group','group_id': _this.model.get('id')});
|
||||
var $submitBtn = $('[type="submit"]', $(this));
|
||||
Common.disableButton($submitBtn);
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'put',
|
||||
dataType: 'json',
|
||||
beforeSend: Common.prepareCSRFToken,
|
||||
data: {
|
||||
'new_owner': email,
|
||||
'old_owner': _this.model.get('owner')
|
||||
},
|
||||
success: function() {
|
||||
$.modal.close();
|
||||
_this.model.set({'owner': email}); // it will trigger 'change' event
|
||||
Common.feedback(gettext("Successfully transferred the group."), 'success');
|
||||
},
|
||||
error: function(xhr) {
|
||||
var error_msg;
|
||||
if (xhr.responseText) {
|
||||
error_msg = $.parseJSON(xhr.responseText).error_msg;
|
||||
} else {
|
||||
error_msg = gettext("Failed. Please check the network.");
|
||||
}
|
||||
$('.error', $form).html(error_msg).show();
|
||||
Common.enableButton($submitBtn);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
},
|
||||
|
||||
render: function() {
|
||||
var data = this.model.toJSON(),
|
||||
created_at = Moment(data['created_at']);
|
||||
|
||||
data['time'] = created_at.format('LLLL');
|
||||
data['time_from_now'] = Common.getRelativeTimeStr(created_at);
|
||||
|
||||
this.$el.html(this.template(data));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return GroupView;
|
||||
});
|
155
static/scripts/sysadmin-app/views/groups.js
Normal file
155
static/scripts/sysadmin-app/views/groups.js
Normal file
@@ -0,0 +1,155 @@
|
||||
define([
|
||||
'jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'sysadmin-app/views/group',
|
||||
'sysadmin-app/collection/groups'
|
||||
], function($, _, Backbone, Common, GroupView, GroupCollection) {
|
||||
'use strict';
|
||||
|
||||
var GroupsView = Backbone.View.extend({
|
||||
|
||||
id: 'admin-groups',
|
||||
|
||||
template: _.template($("#groups-tmpl").html()),
|
||||
|
||||
initialize: function() {
|
||||
this.groupCollection = new GroupCollection();
|
||||
this.listenTo(this.groupCollection, 'add', this.addOne);
|
||||
this.listenTo(this.groupCollection, 'reset', this.reset);
|
||||
this.render();
|
||||
},
|
||||
|
||||
render: function() {
|
||||
this.$el.append(this.template());
|
||||
|
||||
this.$table = this.$('table');
|
||||
this.$tableBody = $('tbody', this.$table);
|
||||
this.$loadingTip = this.$('.loading-tip');
|
||||
this.$emptyTip = this.$('.empty-tips');
|
||||
this.$jsPrevious = this.$('.js-previous');
|
||||
this.$jsNext = this.$('.js-next');
|
||||
},
|
||||
|
||||
events: {
|
||||
'click .js-export-excel': 'exportExcel',
|
||||
'click #paginator .js-next': 'getNextPage',
|
||||
'click #paginator .js-previous': 'getPreviousPage'
|
||||
},
|
||||
|
||||
exportExcel: function() {
|
||||
location.href = app.config.siteRoot + "sys/groupadmin/export-excel/";
|
||||
},
|
||||
|
||||
initPage: function() {
|
||||
this.$table.hide();
|
||||
this.$tableBody.empty();
|
||||
this.$loadingTip.show();
|
||||
this.$emptyTip.hide();
|
||||
this.$jsNext.hide();
|
||||
this.$jsPrevious.hide();
|
||||
},
|
||||
|
||||
getNextPage: function() {
|
||||
this.initPage();
|
||||
var current_page = this.groupCollection.state.current_page;
|
||||
if (this.groupCollection.state.has_next_page) {
|
||||
this.groupCollection.getPage(current_page + 1, {
|
||||
reset: true
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
getPreviousPage: function() {
|
||||
this.initPage();
|
||||
var current_page = this.groupCollection.state.current_page;
|
||||
if (current_page > 1) {
|
||||
this.groupCollection.getPage(current_page - 1, {
|
||||
reset: true
|
||||
});
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
hide: function() {
|
||||
this.$el.detach();
|
||||
this.attached = false;
|
||||
},
|
||||
|
||||
show: function(option) {
|
||||
this.option = option;
|
||||
if (!this.attached) {
|
||||
this.attached = true;
|
||||
$("#right-panel").html(this.$el);
|
||||
}
|
||||
this.getContent();
|
||||
},
|
||||
|
||||
getContent: function() {
|
||||
this.initPage();
|
||||
var _this = this;
|
||||
this.groupCollection.fetch({
|
||||
data: {'page': this.option.page},
|
||||
cache: false,
|
||||
reset: true,
|
||||
error: function(collection, response, opts) {
|
||||
var err_msg;
|
||||
if (response.responseText) {
|
||||
if (response['status'] == 401 || response['status'] == 403) {
|
||||
err_msg = gettext("Permission error");
|
||||
} else {
|
||||
err_msg = $.parseJSON(response.responseText).error_msg;
|
||||
}
|
||||
} else {
|
||||
err_msg = gettext("Failed. Please check the network.");
|
||||
}
|
||||
Common.feedback(err_msg, 'error');
|
||||
},
|
||||
complete:function() {
|
||||
_this.$loadingTip.hide();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
// update the url
|
||||
var current_page = this.groupCollection.state.current_page;
|
||||
app.router.navigate('groups/?page=' + current_page);
|
||||
|
||||
this.$loadingTip.hide();
|
||||
if (this.groupCollection.length > 0) {
|
||||
this.groupCollection.each(this.addOne, this);
|
||||
this.$table.show();
|
||||
this.renderPaginator();
|
||||
} else {
|
||||
this.$emptyTip.show();
|
||||
}
|
||||
},
|
||||
|
||||
renderPaginator: function() {
|
||||
if (this.groupCollection.state.has_next_page) {
|
||||
this.$jsNext.show();
|
||||
} else {
|
||||
this.$jsNext.hide();
|
||||
}
|
||||
|
||||
var current_page = this.groupCollection.state.current_page;
|
||||
if (current_page > 1) {
|
||||
this.$jsPrevious.show();
|
||||
} else {
|
||||
this.$jsPrevious.hide();
|
||||
}
|
||||
},
|
||||
|
||||
addOne: function(group) {
|
||||
var view = new GroupView({model: group});
|
||||
this.$tableBody.append(view.render().el);
|
||||
}
|
||||
});
|
||||
|
||||
return GroupsView;
|
||||
|
||||
});
|
Reference in New Issue
Block a user