var settings_bots = (function () { var exports = {}; function add_bot_row(info) { info.id_suffix = _.uniqueId('_bot_'); var row = $(templates.render('bot_avatar_row', info)); if (info.is_active) { $('#active_bots_list').append(row); } else { $('#inactive_bots_list').append(row); } } function is_local_part(value, element) { // Adapted from Django's EmailValidator return this.optional(element) || /^[\-!#$%&'*+\/=?\^_`{}|~0-9A-Z]+(\.[\-!#$%&'*+\/=?\^_`{}|~0-9A-Z]+)*$/i.test(value); } exports.type_id_to_string = function (type_id) { var name = _.find(page_params.bot_types, function (bot_type) { return bot_type.type_id === type_id; }).name; return i18n.t(name); }; function render_bots() { $('#active_bots_list').empty(); $('#inactive_bots_list').empty(); _.each(bot_data.get_all_bots_for_current_user(), function (elem) { add_bot_row({ name: elem.full_name, email: elem.email, user_id: elem.user_id, type: exports.type_id_to_string(elem.bot_type), avatar_url: elem.avatar_url, api_key: elem.api_key, is_active: elem.is_active, zuliprc: 'zuliprc', // Most browsers do not allow filename starting with `.` }); }); if ($("#bots_lists_navbar .add-a-new-bot-tab").hasClass("active")) { $("#add-a-new-bot-form").show(); $("#active_bots_list").hide(); $("#inactive_bots_list").hide(); } else if ($("#bots_lists_navbar .active-bots-tab").hasClass("active")) { $("#add-a-new-bot-form").hide(); $("#active_bots_list").show(); $("#inactive_bots_list").hide(); } else { $("#add-a-new-bot-form").hide(); $("#active_bots_list").hide(); $("#inactive_bots_list").show(); } } exports.generate_zuliprc_uri = function (email, api_key) { var data = exports.generate_zuliprc_content(email, api_key); return "data:application/octet-stream;charset=utf-8," + encodeURIComponent(data); }; exports.generate_zuliprc_content = function (email, api_key) { return "[api]" + "\nemail=" + email + "\nkey=" + api_key + "\nsite=" + page_params.realm_uri + // Some tools would not work in files without a trailing new line. "\n"; }; function bot_name_from_email(email) { return email.substring(0, email.indexOf("-bot@")); } exports.generate_flaskbotrc_content = function (email, api_key) { return "[" + bot_name_from_email(email) + "]" + "\nemail=" + email + "\nkey=" + api_key + "\nsite=" + page_params.realm_uri + "\n"; }; exports.set_up = function () { $('#payload_url_inputbox').hide(); $('#create_payload_url').val(''); $('#service_name_list').hide(); $('#config_inputbox').hide(); page_params.realm_embedded_bots.forEach(function (bot) { $('#select_service_name').append($('