mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-01 15:09:14 +00:00
admin add group
This commit is contained in:
@@ -24,7 +24,7 @@ define([
|
||||
render: function() {
|
||||
this.$el.append(this.template());
|
||||
|
||||
this.$exportExcel = this.$('.js-export-excel');
|
||||
this.$newGroup = this.$('.js-add-group');
|
||||
this.$table = this.$('table');
|
||||
this.$tableBody = $('tbody', this.$table);
|
||||
this.$loadingTip = this.$('.loading-tip');
|
||||
@@ -35,13 +35,13 @@ define([
|
||||
},
|
||||
|
||||
events: {
|
||||
'click .js-add-group': 'addGroup',
|
||||
'click #paginator .js-next': 'getNextPage',
|
||||
'click #paginator .js-previous': 'getPreviousPage'
|
||||
},
|
||||
|
||||
initPage: function() {
|
||||
this.$loadingTip.show();
|
||||
this.$exportExcel.hide();
|
||||
this.$table.hide();
|
||||
this.$tableBody.empty();
|
||||
this.$jsNext.hide();
|
||||
@@ -50,6 +50,61 @@ define([
|
||||
this.$error.hide();
|
||||
},
|
||||
|
||||
addGroup: function () {
|
||||
var $form = $('#group-add-form'),
|
||||
groups = this.groupCollection,
|
||||
_this = this;
|
||||
|
||||
$form.modal();
|
||||
$('#simplemodal-container').css({'height':'auto'});
|
||||
|
||||
$('[name="group_owner"]', $form).select2($.extend(
|
||||
Common.contactInputOptionsForSelect2(), {
|
||||
width: '270px',
|
||||
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 group_name = $.trim($('[name="group_name"]', $form).val());
|
||||
var group_owner = $.trim($('[name="group_owner"]', $form).val());
|
||||
var $error = $('.error', $form);
|
||||
var $submitBtn = $('[type="submit"]', $form);
|
||||
|
||||
if (!group_name) {
|
||||
$error.html(gettext("It is required.")).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
$error.hide();
|
||||
Common.disableButton($submitBtn);
|
||||
|
||||
groups.create({'group_name': group_name, 'group_owner': group_owner}, {
|
||||
prepend: true,
|
||||
wait: true,
|
||||
success: function() {
|
||||
if (groups.length == 1) {
|
||||
groups.reset(groups.models);
|
||||
}
|
||||
Common.closeModal();
|
||||
},
|
||||
error: function(collection, response, options) {
|
||||
var err_msg;
|
||||
if (response.responseText) {
|
||||
err_msg = response.responseJSON.error_msg;
|
||||
} else {
|
||||
err_msg = gettext('Please check the network.');
|
||||
}
|
||||
$error.html(err_msg).show();
|
||||
Common.enableButton($submitBtn);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
},
|
||||
|
||||
getNextPage: function() {
|
||||
this.initPage();
|
||||
var current_page = this.groupCollection.state.current_page;
|
||||
@@ -114,13 +169,14 @@ define([
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
this.initPage();
|
||||
|
||||
// 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.$exportExcel.show();
|
||||
this.groupCollection.each(this.addOne, this);
|
||||
this.$table.show();
|
||||
this.renderPaginator();
|
||||
@@ -144,9 +200,14 @@ define([
|
||||
}
|
||||
},
|
||||
|
||||
addOne: function(group) {
|
||||
addOne: function(group, collection, options) {
|
||||
var view = new GroupView({model: group});
|
||||
this.$tableBody.append(view.render().el);
|
||||
if (options.prepend) {
|
||||
this.$tableBody.prepend(view.render().el);
|
||||
} else {
|
||||
this.$tableBody.append(view.render().el);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user