2012-10-05 20:25:27 +02:00
|
|
|
// We want to remember how far we were scrolled on each 'tab'.
|
|
|
|
// To do so, we need to save away the old position of the
|
|
|
|
// scrollbar when we switch to a new tab (and restore it
|
|
|
|
// when we switch back.)
|
|
|
|
var scroll_positions = {};
|
|
|
|
|
2012-10-10 16:20:48 +02:00
|
|
|
function register_onclick(message_row, message_id) {
|
|
|
|
message_row.find(".messagebox").click(function (e) {
|
2012-10-03 21:44:07 +02:00
|
|
|
if (!(clicking && mouse_moved)) {
|
|
|
|
// Was a click (not a click-and-drag).
|
2012-10-10 16:20:48 +02:00
|
|
|
select_message_by_id(message_id);
|
2012-10-10 16:18:51 +02:00
|
|
|
respond_to_message();
|
2012-10-03 21:44:07 +02:00
|
|
|
}
|
|
|
|
mouse_moved = false;
|
|
|
|
clicking = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-10-09 17:41:34 +02:00
|
|
|
function focus_on(field_id) {
|
|
|
|
// Call after autocompleting on a field, to advance the focus to
|
|
|
|
// the next input field.
|
|
|
|
|
|
|
|
// Bootstrap's typeahead does not expose a callback for when an
|
|
|
|
// autocomplete selection has been made, so we have to do this
|
|
|
|
// manually.
|
|
|
|
$("#" + field_id).focus();
|
|
|
|
}
|
|
|
|
|
2012-10-03 21:44:07 +02:00
|
|
|
/* We use 'visibility' rather than 'display' and jQuery's show() / hide(),
|
|
|
|
because we want to reserve space for the email address. This avoids
|
|
|
|
things jumping around slightly when the email address is shown. */
|
|
|
|
|
|
|
|
function hide_email() {
|
2012-10-09 23:58:24 +02:00
|
|
|
$('.sender_email').addClass('invisible');
|
2012-10-03 21:44:07 +02:00
|
|
|
}
|
|
|
|
|
2012-10-10 16:20:48 +02:00
|
|
|
function show_email(message_id) {
|
2012-10-03 21:44:07 +02:00
|
|
|
hide_email();
|
2012-11-05 23:30:20 +01:00
|
|
|
var row_with_email = rows.get(message_id);
|
|
|
|
while (!row_with_email.hasClass('include-sender')) {
|
|
|
|
row_with_email = row_with_email.prev();
|
|
|
|
}
|
|
|
|
row_with_email.find('.sender_email').removeClass('invisible');
|
2012-10-03 21:44:07 +02:00
|
|
|
}
|
|
|
|
|
2012-10-31 23:38:34 +01:00
|
|
|
function report_message(response, status_box, cls) {
|
|
|
|
if (cls === undefined)
|
|
|
|
cls = 'alert';
|
|
|
|
|
|
|
|
status_box.removeClass(status_classes).addClass(cls)
|
|
|
|
.text(response).stop(true).fadeTo(0, 1);
|
|
|
|
status_box.show();
|
|
|
|
}
|
|
|
|
|
2012-10-03 21:44:07 +02:00
|
|
|
function report_error(response, xhr, status_box) {
|
|
|
|
if (xhr.status.toString().charAt(0) === "4") {
|
|
|
|
// Only display the error response for 4XX, where we've crafted
|
|
|
|
// a nice response.
|
|
|
|
response += ": " + $.parseJSON(xhr.responseText).msg;
|
|
|
|
}
|
|
|
|
|
2012-10-31 23:38:34 +01:00
|
|
|
report_message(response, status_box, 'alert-error');
|
2012-10-03 21:44:07 +02:00
|
|
|
}
|
|
|
|
|
2012-10-09 20:56:11 +02:00
|
|
|
function report_success(response, status_box) {
|
2012-10-31 23:38:34 +01:00
|
|
|
report_message(response, status_box, 'alert-success');
|
2012-10-17 20:43:20 +02:00
|
|
|
}
|
|
|
|
|
2012-10-03 21:44:07 +02:00
|
|
|
var clicking = false;
|
|
|
|
var mouse_moved = false;
|
|
|
|
|
2012-10-10 16:21:40 +02:00
|
|
|
function mousedown() {
|
2012-10-03 21:44:07 +02:00
|
|
|
mouse_moved = false;
|
|
|
|
clicking = true;
|
|
|
|
}
|
|
|
|
|
2012-10-10 16:21:40 +02:00
|
|
|
function mousemove() {
|
2012-10-03 21:44:07 +02:00
|
|
|
if (clicking) {
|
|
|
|
mouse_moved = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-11 22:34:57 +02:00
|
|
|
function resizehandler(e) {
|
|
|
|
var sidebar = $("#sidebar");
|
|
|
|
var sidebar_nav = $(".sidebar-nav");
|
|
|
|
var composebox = $("#compose");
|
2012-10-15 21:11:16 +02:00
|
|
|
var top_statusbar = $("#top_statusbar");
|
2012-10-11 22:34:57 +02:00
|
|
|
if (viewport.width() <= 767) {
|
|
|
|
sidebar.removeClass('nav-stacked');
|
|
|
|
|
|
|
|
var space_taken_up_by_navbar = sidebar_nav.outerHeight(true);
|
2012-10-27 02:29:23 +02:00
|
|
|
|
|
|
|
// .visible-phone only, so doesn't need undoing
|
|
|
|
$("#nav_whitespace").height(space_taken_up_by_navbar);
|
|
|
|
|
2012-10-15 21:11:16 +02:00
|
|
|
top_statusbar.css('top', space_taken_up_by_navbar);
|
2012-10-11 22:34:57 +02:00
|
|
|
|
|
|
|
var message_list_width = $("#main_div").outerWidth();
|
|
|
|
composebox.width(message_list_width);
|
2012-10-15 21:11:16 +02:00
|
|
|
top_statusbar.width(message_list_width);
|
2012-10-11 22:34:57 +02:00
|
|
|
sidebar_nav.width(message_list_width);
|
|
|
|
} else {
|
|
|
|
sidebar.addClass('nav-stacked');
|
2012-10-15 21:11:16 +02:00
|
|
|
top_statusbar.css('top', 0);
|
|
|
|
top_statusbar.width('');
|
2012-10-12 04:49:18 +02:00
|
|
|
composebox.width('');
|
|
|
|
sidebar_nav.width('');
|
2012-10-11 22:34:57 +02:00
|
|
|
}
|
2012-10-12 06:12:46 +02:00
|
|
|
|
|
|
|
// This function might run onReady (if we're in a narrow window),
|
|
|
|
// but before we've loaded in the messages; in that case, don't
|
|
|
|
// try to scroll to one.
|
|
|
|
if (selected_message_id !== -1) {
|
|
|
|
scroll_to_selected();
|
|
|
|
}
|
2012-10-11 22:34:57 +02:00
|
|
|
}
|
|
|
|
|
2012-10-16 01:29:03 +02:00
|
|
|
var old_label;
|
2012-10-16 03:33:43 +02:00
|
|
|
var is_floating_recipient_bar_showing = false;
|
|
|
|
function replace_floating_recipient_bar(desired_label) {
|
2012-10-16 01:29:03 +02:00
|
|
|
if (desired_label !== old_label) {
|
2012-10-17 22:03:00 +02:00
|
|
|
if (desired_label.children(".message_header_stream").length !== 0) {
|
2012-10-25 06:11:28 +02:00
|
|
|
$("#current_label_stream td:last").replaceWith(
|
|
|
|
desired_label.children(".message_header_stream.right_part").clone());
|
2012-10-16 01:29:03 +02:00
|
|
|
$("#current_label_huddle").css('display', 'none');
|
|
|
|
$("#current_label_stream").css('display', 'table-row');
|
|
|
|
} else {
|
2012-10-25 06:11:28 +02:00
|
|
|
$("#current_label_huddle td:last").replaceWith(
|
|
|
|
desired_label.children(".message_header_huddle.right_part").clone());
|
2012-10-16 01:29:03 +02:00
|
|
|
$("#current_label_stream").css('display', 'none');
|
|
|
|
$("#current_label_huddle").css('display', 'table-row');
|
|
|
|
}
|
|
|
|
old_label = desired_label;
|
|
|
|
}
|
2012-10-16 03:33:43 +02:00
|
|
|
if (!is_floating_recipient_bar_showing) {
|
2012-10-16 01:29:03 +02:00
|
|
|
$(".floating_recipient_bar").css('visibility', 'visible');
|
2012-10-16 03:33:43 +02:00
|
|
|
is_floating_recipient_bar_showing = true;
|
2012-10-14 04:13:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-16 03:33:43 +02:00
|
|
|
function hide_floating_recipient_bar() {
|
|
|
|
if (is_floating_recipient_bar_showing) {
|
2012-10-16 01:29:03 +02:00
|
|
|
$(".floating_recipient_bar").css('visibility', 'hidden');
|
2012-10-16 03:33:43 +02:00
|
|
|
is_floating_recipient_bar_showing = false;
|
2012-10-16 01:29:03 +02:00
|
|
|
}
|
2012-10-14 04:13:27 +02:00
|
|
|
}
|
|
|
|
|
2012-10-15 21:11:16 +02:00
|
|
|
function update_floating_recipient_bar() {
|
|
|
|
var top_statusbar = $("#top_statusbar");
|
|
|
|
var top_statusbar_top = top_statusbar.offset().top;
|
2012-10-16 04:45:10 +02:00
|
|
|
var top_statusbar_bottom = top_statusbar_top + top_statusbar.outerHeight();
|
2012-10-14 04:13:27 +02:00
|
|
|
|
2012-10-15 18:21:05 +02:00
|
|
|
// Find the last message where the top of the recipient
|
2012-10-16 00:14:04 +02:00
|
|
|
// row is at least partially occluded by our box.
|
|
|
|
// Start with the pointer's current location.
|
|
|
|
var candidate = selected_message;
|
2012-10-26 21:02:04 +02:00
|
|
|
if (candidate === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
2012-10-16 00:14:04 +02:00
|
|
|
while (true) {
|
|
|
|
candidate = candidate.prev();
|
|
|
|
if (candidate.length === 0) {
|
|
|
|
// We're at the top of the page and no labels are above us.
|
2012-10-16 03:33:43 +02:00
|
|
|
hide_floating_recipient_bar();
|
2012-10-16 00:14:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (candidate.is(".focused_table .recipient_row")) {
|
|
|
|
if (candidate.offset().top < top_statusbar_bottom) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-10-15 18:21:05 +02:00
|
|
|
}
|
2012-10-16 00:14:04 +02:00
|
|
|
var current_label = candidate;
|
2012-10-15 18:21:05 +02:00
|
|
|
|
|
|
|
// We now know what the floating stream/subject bar should say.
|
|
|
|
// Do we show it?
|
2012-10-14 04:13:27 +02:00
|
|
|
|
2012-10-15 18:21:05 +02:00
|
|
|
// Hide if the bottom of our floating stream/subject label is not
|
|
|
|
// lower than the bottom of current_label (since that means we're
|
|
|
|
// covering up a label that already exists).
|
2012-10-15 21:11:16 +02:00
|
|
|
if (top_statusbar_bottom <=
|
2012-10-16 04:45:10 +02:00
|
|
|
(current_label.offset().top + current_label.outerHeight())) {
|
2012-10-16 03:33:43 +02:00
|
|
|
hide_floating_recipient_bar();
|
2012-10-14 04:13:27 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-10-15 18:21:05 +02:00
|
|
|
|
|
|
|
// Hide if our bottom is in our bookend (or one bookend-height
|
|
|
|
// above it). This means we're not showing any useful part of the
|
2012-11-02 22:04:56 +01:00
|
|
|
// message above us, so why bother showing the label?
|
2012-10-27 03:38:31 +02:00
|
|
|
var current_bookend = current_label.nextUntil(".bookend_tr")
|
|
|
|
.andSelf()
|
|
|
|
.next(".bookend_tr:first");
|
2012-10-15 18:21:05 +02:00
|
|
|
// (The last message currently doesn't have a bookend, which is why this might be 0).
|
2012-10-27 03:38:31 +02:00
|
|
|
if (current_bookend.length > 0) {
|
2012-10-15 21:11:16 +02:00
|
|
|
if (top_statusbar_bottom >
|
2012-10-27 03:38:31 +02:00
|
|
|
(current_bookend.offset().top - current_bookend.outerHeight())) {
|
2012-10-16 03:33:43 +02:00
|
|
|
hide_floating_recipient_bar();
|
2012-10-15 18:21:05 +02:00
|
|
|
return;
|
2012-10-14 04:13:27 +02:00
|
|
|
}
|
|
|
|
}
|
2012-10-15 18:21:05 +02:00
|
|
|
|
2012-10-24 00:29:06 +02:00
|
|
|
// If we're narrowed to a huddle or a subject, the floating
|
|
|
|
// recipient bar would be identical to the narrowing header, so
|
|
|
|
// don't display it.
|
|
|
|
if (narrow.narrowing_type() === "huddle" || narrow.narrowing_type() === "subject") {
|
|
|
|
hide_floating_recipient_bar();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-16 03:33:43 +02:00
|
|
|
replace_floating_recipient_bar(current_label);
|
2012-10-14 04:13:27 +02:00
|
|
|
}
|
2012-10-15 21:57:30 +02:00
|
|
|
function hack_for_floating_recipient_bar() {
|
|
|
|
// So, as of this writing, Firefox respects visibility: collapse,
|
|
|
|
// but WebKit does not (at least, my Chrome doesn't.) Instead it
|
|
|
|
// renders it basically as visibility: hidden, which leaves a
|
|
|
|
// slight gap that our messages peek through as they scroll
|
|
|
|
// by. This hack fixes this by programmatically measuring how big
|
|
|
|
// the gap is, and then moving our table up to compensate.
|
|
|
|
var gap = $("#floating_recipient_layout_row").outerHeight(true);
|
|
|
|
var floating_recipient = $(".floating_recipient");
|
|
|
|
var offset = floating_recipient.offset();
|
|
|
|
offset.top = offset.top - gap;
|
|
|
|
floating_recipient.offset(offset);
|
|
|
|
}
|
2012-10-14 04:13:27 +02:00
|
|
|
|
2012-10-17 22:26:59 +02:00
|
|
|
function show_api_key_box() {
|
|
|
|
$("#get_api_key_box").show();
|
|
|
|
$("#api_key_button_box").hide();
|
|
|
|
}
|
|
|
|
|
2012-10-18 20:23:57 +02:00
|
|
|
var userinfo_currently_popped;
|
|
|
|
function userinfo_popover(event, element, id) {
|
|
|
|
event.stopPropagation();
|
|
|
|
select_message_by_id(id);
|
|
|
|
var elt = $(element);
|
|
|
|
if (elt.data('popover') === undefined) {
|
|
|
|
// One popover at a time.
|
|
|
|
if (userinfo_currently_popped) {
|
|
|
|
userinfo_currently_popped.popover("destroy");
|
2012-10-29 20:48:22 +01:00
|
|
|
userinfo_currently_popped = undefined;
|
2012-10-18 20:23:57 +02:00
|
|
|
}
|
|
|
|
var message = message_dict[id];
|
|
|
|
elt.popover({placement: "bottom",
|
|
|
|
title: templates.userinfo_popover_title(message),
|
|
|
|
content: templates.userinfo_popover_content(message),
|
|
|
|
trigger: "manual"
|
|
|
|
});
|
|
|
|
elt.popover("show");
|
|
|
|
userinfo_currently_popped = elt;
|
|
|
|
} else {
|
|
|
|
elt.popover("destroy");
|
|
|
|
userinfo_currently_popped = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-31 20:01:21 +01:00
|
|
|
function safari_composebox_hack(forwards) {
|
|
|
|
// OK, so the situation here is basically a lot of work so that
|
|
|
|
// Tab-Enter is a valid hotkey for sending a message in Safari.
|
|
|
|
// By default, Safari uses Tab only to cycle through textboxes,
|
|
|
|
// basically. Even if the tabindex is set on it, a button (like
|
|
|
|
// our submit button) will not get focus.
|
|
|
|
|
|
|
|
// HOWEVER, if you set the tabindex on a div, Safari/WebKit will
|
|
|
|
// respect that, and will focus it. So we make a div right before
|
|
|
|
// the Send button, which, when selected, focuses the send button.
|
|
|
|
// Then, we make another div right after it, that, when selected,
|
|
|
|
// focuses back the composebox (so as not to break Shift-Tab in
|
|
|
|
// these browsers).
|
|
|
|
|
|
|
|
// This behavior is configurable in Safari, but is not on by
|
|
|
|
// default. (It is on by default in Chrome.)
|
|
|
|
if (forwards) {
|
|
|
|
$('#compose-send-button').focus();
|
|
|
|
} else {
|
|
|
|
$('#new_message_content').focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-03 21:44:07 +02:00
|
|
|
$(function () {
|
|
|
|
// NB: This just binds to current elements, and won't bind to elements
|
|
|
|
// created after ready() is called.
|
2012-10-09 15:51:12 +02:00
|
|
|
|
2012-11-05 21:01:49 +01:00
|
|
|
$('#message-type-tabs a[href="#stream-message"]').on('shown', function (e) {
|
|
|
|
compose.set_message_type('stream');
|
|
|
|
});
|
|
|
|
$('#message-type-tabs a[href="#personal-message"]').on('shown', function (e) {
|
|
|
|
compose.set_message_type('huddle');
|
2012-10-03 21:44:07 +02:00
|
|
|
});
|
|
|
|
|
2012-10-10 23:37:14 +02:00
|
|
|
// Prepare the click handler for subbing to a new stream to which
|
2012-10-10 16:20:48 +02:00
|
|
|
// you have composed a message.
|
2012-10-03 21:44:07 +02:00
|
|
|
$('#create-it').click(function () {
|
2012-10-31 23:15:27 +01:00
|
|
|
subs.subscribe_for_send(compose.stream_name(), $('#stream-dne'));
|
2012-10-03 21:44:07 +02:00
|
|
|
});
|
|
|
|
|
2012-10-10 23:37:14 +02:00
|
|
|
// Prepare the click handler for subbing to an existing stream.
|
2012-10-03 21:44:07 +02:00
|
|
|
$('#sub-it').click(function () {
|
2012-10-31 23:15:27 +01:00
|
|
|
subs.subscribe_for_send(compose.stream_name(), $('#stream-nosub'));
|
2012-10-03 21:44:07 +02:00
|
|
|
});
|
|
|
|
|
2012-10-16 03:49:51 +02:00
|
|
|
var throttled_scrollhandler = $.throttle(50, function(e) {
|
2012-10-05 19:22:43 +02:00
|
|
|
if ($('#home').hasClass('active')) {
|
2012-10-10 20:20:31 +02:00
|
|
|
keep_pointer_in_view();
|
2012-10-16 03:49:51 +02:00
|
|
|
update_floating_recipient_bar();
|
2012-10-03 21:44:07 +02:00
|
|
|
}
|
2012-10-05 21:35:36 +02:00
|
|
|
});
|
|
|
|
$(window).scroll(throttled_scrollhandler);
|
2012-10-03 21:44:07 +02:00
|
|
|
|
2012-10-16 18:16:26 +02:00
|
|
|
var throttled_mousewheelhandler = $.throttle(50, function(e, delta) {
|
2012-10-16 03:49:51 +02:00
|
|
|
// Most of the mouse wheel's work will be handled by the
|
|
|
|
// scroll handler, but when we're at the top or bottom of the
|
|
|
|
// page, the pointer may still need to move.
|
2012-10-16 18:16:26 +02:00
|
|
|
move_pointer_at_page_top_and_bottom(delta);
|
2012-10-16 03:49:51 +02:00
|
|
|
});
|
|
|
|
$(window).mousewheel(throttled_mousewheelhandler);
|
|
|
|
|
2012-10-11 22:34:57 +02:00
|
|
|
var throttled_resizehandler = $.throttle(50, resizehandler);
|
|
|
|
$(window).resize(throttled_resizehandler);
|
|
|
|
|
2012-11-02 22:02:40 +01:00
|
|
|
function clear_password_change() {
|
|
|
|
// Clear the password boxes so that passwords don't linger in the DOM
|
|
|
|
// for an XSS attacker to find.
|
|
|
|
$('#old_password, #new_password, #confirm_password').val('');
|
|
|
|
}
|
|
|
|
|
2012-10-05 20:25:27 +02:00
|
|
|
$('#sidebar a[data-toggle="pill"]').on('show', function (e) {
|
|
|
|
// Save the position of our old tab away, before we switch
|
|
|
|
var old_tab = $(e.relatedTarget).attr('href');
|
|
|
|
scroll_positions[old_tab] = viewport.scrollTop();
|
|
|
|
});
|
|
|
|
$('#sidebar a[data-toggle="pill"]').on('shown', function (e) {
|
|
|
|
// Right after we show the new tab, restore its old scroll position
|
|
|
|
var target_tab = $(e.target).attr('href');
|
|
|
|
if (scroll_positions.hasOwnProperty(target_tab)) {
|
|
|
|
viewport.scrollTop(scroll_positions[target_tab]);
|
|
|
|
} else {
|
|
|
|
viewport.scrollTop(0);
|
|
|
|
}
|
2012-10-09 21:44:29 +02:00
|
|
|
|
|
|
|
// Hide all our error messages when switching tabs
|
|
|
|
$('.alert-error').hide();
|
|
|
|
$('.alert-success').hide();
|
|
|
|
$('.alert-info').hide();
|
|
|
|
$('.alert').hide();
|
2012-10-10 20:06:59 +02:00
|
|
|
|
2012-10-17 22:26:59 +02:00
|
|
|
$("#api_key_value").text("");
|
|
|
|
$("#get_api_key_box").hide();
|
|
|
|
$("#show_api_key_box").hide();
|
|
|
|
$("#api_key_button_box").show();
|
|
|
|
|
2012-11-02 22:02:40 +01:00
|
|
|
clear_password_change();
|
|
|
|
|
2012-10-10 20:06:59 +02:00
|
|
|
// Set the URL bar title to show the sub-page you're currently on.
|
2012-10-27 03:45:05 +02:00
|
|
|
var browser_url = target_tab;
|
2012-10-10 20:06:59 +02:00
|
|
|
if (browser_url === "#home") {
|
|
|
|
browser_url = "#";
|
|
|
|
}
|
|
|
|
window.history.pushState("object or string", "Title", browser_url);
|
2012-10-05 20:25:27 +02:00
|
|
|
});
|
|
|
|
|
2012-10-03 21:44:07 +02:00
|
|
|
$('.button-slide').click(function () {
|
2012-10-18 20:29:16 +02:00
|
|
|
compose.show('stream', $("#stream"));
|
2012-10-03 21:44:07 +02:00
|
|
|
});
|
2012-10-03 22:24:17 +02:00
|
|
|
|
2012-10-18 21:37:07 +02:00
|
|
|
$('#sidebar a[href="#subscriptions"]').click(subs.fetch);
|
2012-10-03 22:35:35 +02:00
|
|
|
|
|
|
|
var settings_status = $('#settings-status');
|
2012-10-17 22:26:59 +02:00
|
|
|
$("#settings-change-box form").ajaxForm({
|
2012-10-03 22:35:35 +02:00
|
|
|
dataType: 'json', // This seems to be ignored. We still get back an xhr.
|
|
|
|
success: function (resp, statusText, xhr, form) {
|
|
|
|
var message = "Updated settings!";
|
|
|
|
var result = $.parseJSON(xhr.responseText);
|
|
|
|
if ((result.full_name !== undefined) || (result.short_name !== undefined)) {
|
|
|
|
message = "Updated settings! You will need to reload the page for your changes to take effect.";
|
|
|
|
}
|
|
|
|
settings_status.removeClass(status_classes)
|
|
|
|
.addClass('alert-success')
|
|
|
|
.text(message).stop(true).fadeTo(0,1);
|
|
|
|
// TODO: In theory we should auto-reload or something if
|
|
|
|
// you changed the email address or other fields that show
|
|
|
|
// up on all screens
|
|
|
|
},
|
|
|
|
error: function (xhr, error_type, xhn) {
|
|
|
|
var response = "Error changing settings";
|
|
|
|
if (xhr.status.toString().charAt(0) === "4") {
|
|
|
|
// Only display the error response for 4XX, where we've crafted
|
|
|
|
// a nice response.
|
|
|
|
response += ": " + $.parseJSON(xhr.responseText).msg;
|
|
|
|
}
|
|
|
|
settings_status.removeClass(status_classes)
|
|
|
|
.addClass('alert-error')
|
|
|
|
.text(response).stop(true).fadeTo(0,1);
|
2012-10-30 21:08:58 +01:00
|
|
|
},
|
|
|
|
complete: function (xhr, statusText) {
|
2012-11-02 22:02:40 +01:00
|
|
|
// Whether successful or not, clear the password boxes.
|
2012-10-30 21:08:58 +01:00
|
|
|
// TODO: Clear these earlier, while the request is still pending.
|
2012-11-02 22:02:40 +01:00
|
|
|
clear_password_change();
|
2012-10-03 23:22:51 +02:00
|
|
|
}
|
2012-10-03 22:35:35 +02:00
|
|
|
});
|
2012-10-12 00:48:37 +02:00
|
|
|
|
2012-10-17 22:26:59 +02:00
|
|
|
$("#get_api_key_box").hide();
|
|
|
|
$("#show_api_key_box").hide();
|
|
|
|
$("#get_api_key_box form").ajaxForm({
|
|
|
|
dataType: 'json', // This seems to be ignored. We still get back an xhr.
|
|
|
|
success: function (resp, statusText, xhr, form) {
|
|
|
|
var message = "Updated settings!";
|
|
|
|
var result = $.parseJSON(xhr.responseText);
|
|
|
|
$("#get_api_key_password").val("");
|
|
|
|
$("#api_key_value").text(result.api_key);
|
|
|
|
$("#show_api_key_box").show();
|
|
|
|
$("#get_api_key_box").hide();
|
|
|
|
settings_status.hide();
|
|
|
|
},
|
|
|
|
error: function (xhr, error_type, xhn) {
|
|
|
|
var response = "Error getting API key";
|
|
|
|
if (xhr.status.toString().charAt(0) === "4") {
|
|
|
|
// Only display the error response for 4XX, where we've crafted
|
|
|
|
// a nice response.
|
|
|
|
response += ": " + $.parseJSON(xhr.responseText).msg;
|
|
|
|
}
|
|
|
|
settings_status.removeClass(status_classes)
|
|
|
|
.addClass('alert-error')
|
|
|
|
.text(response).stop(true).fadeTo(0,1);
|
|
|
|
$("#show_api_key_box").hide();
|
|
|
|
$("#get_api_key_box").show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-10-12 00:48:37 +02:00
|
|
|
// A little hackish, because it doesn't seem to totally get us
|
2012-10-16 03:33:43 +02:00
|
|
|
// the exact right width for the top_statusbar and compose box,
|
2012-10-12 00:48:37 +02:00
|
|
|
// but, close enough for now.
|
|
|
|
resizehandler();
|
2012-10-15 21:57:30 +02:00
|
|
|
hack_for_floating_recipient_bar();
|
2012-10-12 17:26:04 +02:00
|
|
|
|
2012-11-01 18:01:33 +01:00
|
|
|
composebox_typeahead.initialize();
|
2012-10-18 20:23:57 +02:00
|
|
|
|
|
|
|
$("body").bind('click', function() {
|
|
|
|
if (userinfo_currently_popped !== undefined) {
|
|
|
|
userinfo_currently_popped.popover('destroy');
|
|
|
|
userinfo_currently_popped = undefined;
|
|
|
|
}
|
|
|
|
});
|
2012-10-03 21:44:07 +02:00
|
|
|
});
|