2017-10-21 03:15:12 +02:00
|
|
|
var settings_invites = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
var meta = {
|
|
|
|
loaded: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.reset = function () {
|
|
|
|
meta.loaded = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
function failed_listing_invites(xhr) {
|
|
|
|
loading.destroy_indicator($('#admin_page_invites_loading_indicator'));
|
|
|
|
ui_report.error(i18n.t("Error listing invites"), xhr, $("#organization-status"));
|
|
|
|
}
|
|
|
|
|
|
|
|
function populate_invites(invites_data) {
|
|
|
|
if (!meta.loaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var invites_table = $("#admin_invites_table").expectOne();
|
|
|
|
|
2018-02-23 00:26:12 +01:00
|
|
|
var admin_invites_list = list_render.get("admin_invites_list");
|
|
|
|
|
|
|
|
if (admin_invites_list) {
|
|
|
|
admin_invites_list.data(invites_data.invites);
|
|
|
|
admin_invites_list.set_container(invites_table);
|
|
|
|
admin_invites_list.render();
|
|
|
|
} else {
|
2018-06-20 18:32:39 +02:00
|
|
|
list_render.create(invites_table, invites_data.invites, {
|
2018-02-23 00:26:12 +01:00
|
|
|
name: "admin_invites_list",
|
|
|
|
modifier: function (item) {
|
|
|
|
item.invited = timerender.absolute_time(item.invited * 1000);
|
|
|
|
return templates.render("admin_invites_list", { invite: item });
|
|
|
|
},
|
|
|
|
filter: {
|
|
|
|
element: invites_table.closest(".settings-section").find(".search"),
|
|
|
|
callback: function (item, value) {
|
|
|
|
return item.email.toLowerCase().indexOf(value) >= 0;
|
|
|
|
},
|
2017-10-21 03:15:12 +02:00
|
|
|
},
|
2018-02-23 00:26:12 +01:00
|
|
|
}).init();
|
|
|
|
}
|
2017-10-21 03:15:12 +02:00
|
|
|
|
|
|
|
loading.destroy_indicator($('#admin_page_invites_loading_indicator'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
exports.set_up = function () {
|
|
|
|
meta.loaded = true;
|
|
|
|
|
|
|
|
// create loading indicators
|
|
|
|
loading.make_indicator($('#admin_page_invites_loading_indicator'));
|
|
|
|
|
|
|
|
// Populate invites table
|
|
|
|
channel.get({
|
|
|
|
url: '/json/invites',
|
|
|
|
idempotent: true,
|
2018-12-18 19:34:45 +01:00
|
|
|
timeout: 10 * 1000,
|
2017-10-21 03:15:12 +02:00
|
|
|
success: exports.on_load_success,
|
|
|
|
error: failed_listing_invites,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.on_load_success = function (invites_data) {
|
|
|
|
meta.loaded = true;
|
|
|
|
populate_invites(invites_data);
|
|
|
|
|
|
|
|
$(".admin_invites_table").on("click", ".revoke", function (e) {
|
2018-05-23 22:29:00 +02:00
|
|
|
// This click event must not get propagated to parent container otherwise the modal
|
|
|
|
// will not show up because of a call to `close_active_modal` in `settings.js`.
|
2017-10-21 03:15:12 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
var row = $(e.target).closest(".invite_row");
|
|
|
|
var email = row.find('.email').text();
|
|
|
|
meta.current_revoke_invite_user_modal_row = row;
|
|
|
|
meta.invite_id = $(e.currentTarget).attr("data-invite-id");
|
|
|
|
|
|
|
|
$("#revoke_invite_modal .email").text(email);
|
|
|
|
$("#revoke_invite_modal #do_revoke_invite_button").attr("data-invite-id", meta.invite_id);
|
|
|
|
$("#revoke_invite_modal").modal("show");
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".admin_invites_table").on("click", ".resend", function (e) {
|
2018-05-23 22:29:00 +02:00
|
|
|
// This click event must not get propagated to parent container otherwise the modal
|
|
|
|
// will not show up because of a call to `close_active_modal` in `settings.js`.
|
2017-10-21 03:15:12 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
var row = $(e.target).closest(".invite_row");
|
|
|
|
var email = row.find('.email').text();
|
|
|
|
meta.current_resend_invite_user_modal_row = row;
|
|
|
|
meta.invite_id = $(e.currentTarget).attr("data-invite-id");
|
|
|
|
|
|
|
|
$("#resend_invite_modal .email").text(email);
|
|
|
|
$("#resend_invite_modal #do_resend_invite_button").attr("data-invite-id", meta.invite_id);
|
|
|
|
$("#resend_invite_modal").modal("show");
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#do_revoke_invite_button").click(function () {
|
|
|
|
var modal_invite_id = $("#revoke_invite_modal #do_revoke_invite_button").attr("data-invite-id");
|
|
|
|
var revoke_button = meta.current_revoke_invite_user_modal_row.find("button.revoke");
|
|
|
|
|
|
|
|
if (modal_invite_id !== meta.invite_id) {
|
|
|
|
blueslip.error("Invite revoking canceled due to non-matching fields.");
|
2017-11-04 15:42:38 +01:00
|
|
|
ui_report.message(i18n.t("Resending encountered an error. Please reload and try again."),
|
2018-05-06 21:43:17 +02:00
|
|
|
$("#home-error"), 'alert-error');
|
2017-10-21 03:15:12 +02:00
|
|
|
}
|
|
|
|
$("#revoke_invite_modal").modal("hide");
|
|
|
|
revoke_button.prop("disabled", true).text(i18n.t("Working…"));
|
|
|
|
channel.del({
|
|
|
|
url: '/json/invites/' + meta.invite_id,
|
|
|
|
error: function (xhr) {
|
2018-03-25 11:12:06 +02:00
|
|
|
ui_report.generic_row_button_error(xhr, revoke_button);
|
2017-10-21 03:15:12 +02:00
|
|
|
},
|
|
|
|
success: function () {
|
|
|
|
meta.current_revoke_invite_user_modal_row.remove();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#do_resend_invite_button").click(function () {
|
|
|
|
var modal_invite_id = $("#resend_invite_modal #do_resend_invite_button").attr("data-invite-id");
|
|
|
|
var resend_button = meta.current_resend_invite_user_modal_row.find("button.resend");
|
|
|
|
|
|
|
|
if (modal_invite_id !== meta.invite_id) {
|
|
|
|
blueslip.error("Invite resending canceled due to non-matching fields.");
|
2017-11-04 15:42:38 +01:00
|
|
|
ui_report.message(i18n.t("Resending encountered an error. Please reload and try again."),
|
2018-05-06 21:43:17 +02:00
|
|
|
$("#home-error"), 'alert-error');
|
2017-10-21 03:15:12 +02:00
|
|
|
}
|
|
|
|
$("#resend_invite_modal").modal("hide");
|
|
|
|
resend_button.prop("disabled", true).text(i18n.t("Working…"));
|
|
|
|
channel.post({
|
|
|
|
url: '/json/invites/' + meta.invite_id + "/resend",
|
|
|
|
error: function (xhr) {
|
2018-03-25 11:12:06 +02:00
|
|
|
ui_report.generic_row_button_error(xhr, resend_button);
|
2017-10-21 03:15:12 +02:00
|
|
|
},
|
|
|
|
success: function (data) {
|
2017-12-05 06:31:29 +01:00
|
|
|
resend_button.text(i18n.t("Sent!"));
|
2017-10-21 03:15:12 +02:00
|
|
|
resend_button.removeClass('resend btn-warning').addClass('sea-green');
|
2017-12-19 08:23:03 +01:00
|
|
|
data.timestamp = timerender.absolute_time(data.timestamp * 1000);
|
2017-10-21 03:15:12 +02:00
|
|
|
meta.current_resend_invite_user_modal_row.find(".invited_at").text(data.timestamp);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
}());
|
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = settings_invites;
|
|
|
|
}
|
2018-05-28 08:04:36 +02:00
|
|
|
window.settings_invites = settings_invites;
|