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

Merge pull request #1952 from haiwen/invite-multi

[invite people] enable to invite multiple guests at one time
This commit is contained in:
xiez
2017-12-25 13:32:42 +08:00
committed by GitHub
7 changed files with 272 additions and 19 deletions

View File

@@ -34,7 +34,7 @@ define([
beforeSend: Common.prepareCSRFToken,
success: function() {
_this.remove();
Common.feedback(gettext("Successfully deleted 1 item"), 'success');
Common.feedback(gettext("Successfully deleted 1 item."), 'success');
},
error: function(xhr) {
Common.ajaxErrorHandler(xhr);

View File

@@ -46,38 +46,80 @@ define([
$('#simplemodal-container').css({'height':'auto'});
$form.submit(function() {
var accepter = $.trim($('input[name="accepter"]', $form).val());
var accepters = $.trim($('input[name="accepter"]', $form).val());
var accepter_list = [];
var email;
var $error = $('.error', $form);
var $submitBtn = $('[type="submit"]', $form);
var $loading = $('.loading-icon', $form);
if (!accepter) {
if (!accepters) {
$error.html(gettext("It is required.")).show();
return false;
};
accepters = accepters.split(',');
for (var i = 0, len = accepters.length; i < len; i++) {
email = $.trim(accepters[i]);
if (email) {
accepter_list.push(email);
}
}
if (!accepter_list.length) {
return false;
}
$error.hide();
Common.disableButton($submitBtn);
$loading.show();
_this.collection.create({
'type': 'guest',
'accepter': accepter
}, {
wait: true,
prepend: true,
success: function() {
if (_this.collection.length == 1) {
_this.reset();
$.ajax({
url: Common.getUrl({'name': 'invitations_batch'}),
type: 'POST',
cache: false,
data: {
'type': 'guest',
'accepter': accepter_list
},
traditional: true,
beforeSend: Common.prepareCSRFToken,
success: function(data) {
var msgs = [];
if (data.success.length) {
var msg;
_this.collection.add(data.success, {prepend: true});
if (_this.collection.length == data.success.length) {
_this.reset();
}
if (data.success.length == 1) {
msg = gettext('Successfully invited %(email).')
.replace('%(email)', data.success[0].accepter);
} else {
msg = gettext('Successfully invited %(email) and %(num) other people.')
.replace('%(email)', data.success[0].accepter)
.replace('%(num)', data.success.length - 1);
}
msgs.push({'msg': msg, 'type': 'success'});
}
if (data.failed.length) {
$(data.failed).each(function(index, item) {
var err_msg = item.email + ': ' + item.error_msg;
msgs.push({'msg': err_msg, 'type': 'error'});
});
}
if (msgs.length) {
Common.feedback(msgs);
}
$.modal.close();
},
error: function(collection, response, options) {
error: function(xhr) {
var err_msg;
if (response.responseText) {
err_msg = response.responseJSON.error_msg||response.responseJSON.detail;
if (xhr.responseText) {
err_msg = xhr.responseJSON.error_msg||xhr.responseJSON.detail;
} else {
err_msg = gettext('Please check the network.');
}
$error.html(err_msg).show();
Common.enableButton($submitBtn);
},
complete: function() {

View File

@@ -170,6 +170,7 @@ define([
case 'events': return siteRoot + 'api2/events/';
case 'devices': return siteRoot + 'api2/devices/';
case 'invitations': return siteRoot + 'api/v2.1/invitations/';
case 'invitations_batch': return siteRoot + 'api/v2.1/invitations/batch/';
case 'invitation': return siteRoot + 'api/v2.1/invitations/' + options.token + '/';
case 'search_user': return siteRoot + 'api2/search-user/';
case 'user_profile': return siteRoot + 'profile/' + options.username + '/';
@@ -374,14 +375,25 @@ define([
},
feedback: function(con, type, time) {
var _this = this;
var time = time || 5000;
var $el;
var hide_pos_top,
show_pos_top = '15px';
var $con, str = '';
if (typeof con == 'string') { // most of the time
$con = $('<li class="' + type + '">' + this.HTMLescape(con) + '</li>');
} else { // [{'msg':'', 'type':''}]
$(con).each(function(index, item) {
str += '<li class="' + item.type + '">' + _this.HTMLescape(item.msg) + '</li>';
});
$con = $(str);
}
if ($('.messages').length > 0) {
$el = $('.messages').html('<li class="' + type + '">' + this.HTMLescape(con) + '</li>');
$el = $('.messages').html($con);
} else {
$el = $('<ul class="messages"><li class="' + type + '">' + this.HTMLescape(con) + '</li></ul>');
$el = $('<ul class="messages"></ul>').html($con);
$('#main').append($el);
}