Add UI to create bots with a default send to stream

(imported from commit 1333de89a75bd972ec85be7f11f6ea11d4fa34cd)
This commit is contained in:
Jason Michalski 2014-02-11 13:53:55 -05:00
parent 846dfd5105
commit 538d76e6ed
3 changed files with 34 additions and 0 deletions

View File

@ -44,6 +44,7 @@ exports.show_autoscroll_forever_option = page_params.show_autoscroll_forever_opt
exports.full_width = false; //page_params.staging;
exports.cleanup_before_reload = page_params.staging || is_customer4;
exports.new_bot_ui = page_params.staging;
// This list must match the list of domains in enqueue_digest_emails.
exports.dont_show_digest_email_setting = _.contains(["mit.edu", "customer29.invalid", "customer20.invalid"],

View File

@ -2,6 +2,8 @@ var settings = (function () {
var exports = {};
var streams = [];
function add_bot_row(name, email, avatar_url, api_key) {
var info = {
name: name,
@ -20,6 +22,16 @@ function is_local_part(value, element) {
return this.optional(element) || /^[\-!#$%&'*+\/=?\^_`{}|~0-9A-Z]+(\.[\-!#$%&'*+\/=?\^_`{}|~0-9A-Z]+)*$/i.test(value);
}
function build_stream_list($select) {
$select.empty();
_.each(_.pluck(streams, 'name'), function (name) {
$select.append($('<option>')
.attr('value', name)
.text(name)
);
});
}
// Choose avatar stamp fairly randomly, to help get old avatars out of cache.
exports.avatar_stamp = Math.floor(Math.random()*100);
@ -45,6 +57,14 @@ exports.setup_page = function () {
clear_password_change();
channel.get({
url: '/json/streams',
success: function (data) {
streams = data.streams;
build_stream_list($('#create_bot_default_sending_stream'));
}
});
$('#api_key_button').click(function (e) {
if (page_params.password_auth_enabled !== false) {
$("#get_api_key_box").show();
@ -68,6 +88,9 @@ exports.setup_page = function () {
if (feature_flags.dont_show_digest_email_setting) {
$("#digest_container").hide();
}
if (!feature_flags.new_bot_ui) {
$('.new-bot-ui').hide();
}
function settings_change_error(message) {
@ -363,10 +386,16 @@ exports.setup_page = function () {
submitHandler: function () {
var full_name = $('#create_bot_name').val();
var short_name = $('#create_bot_short_name').val();
var default_sending_stream = $('#create_bot_default_sending_stream').val();
var formData = new FormData();
formData.append('csrfmiddlewaretoken', csrf_token);
formData.append('full_name', full_name);
formData.append('short_name', short_name);
if (feature_flags.new_bot_ui) {
formData.append('default_sending_stream', default_sending_stream);
}
jQuery.each($('#bot_avatar_file_input')[0].files, function (i, file) {
formData.append('file-'+i, file);
});

View File

@ -237,6 +237,10 @@
placeholder="bot_user_name" value="" />-bot@{{ page_params.domain }}
<div><label for="create_bot_short_name" generated="true" class="text-error"></label></div>
</div>
<div class="control-group new-bot-ui">
<label for="create_bot_default_sending_stream" class="control-label">Send to stream</label>
<select name="bot_default_sending_stream" id="create_bot_default_sending_stream"></select>
</div>
<div class="control-group">
<div class="controls">
<div id="bot_avatar_file"></div>