diff --git a/static/js/ui.js b/static/js/ui.js index baa9a924d9..eba41248cf 100644 --- a/static/js/ui.js +++ b/static/js/ui.js @@ -1029,6 +1029,7 @@ $(function () { var settings_status = $('#settings-status').expectOne(); var notify_settings_status = $('#notify-settings-status').expectOne(); + var ui_settings_status = $('#ui-settings-status').expectOne(); function settings_change_error(message) { // Scroll to the top so the error message is visible. @@ -1130,6 +1131,35 @@ $(function () { } }); + $("form.ui-settings").expectOne().ajaxForm({ + dataType: 'json', + + success: function (resp, statusText, xhr, form) { + var message = "Updated UI settings!"; + var result = $.parseJSON(xhr.responseText); + + if (result.autoscroll_forever !== undefined) { + page_params.autoscroll_forever = result.autoscroll_forever; + } + + ui_settings_status.removeClass(status_classes) + .addClass('alert-success') + .text(message).stop(true).fadeTo(0,1); + }, + 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; + } + + ui_settings_status.removeClass(status_classes) + .addClass('alert-error') + .text(response).stop(true).fadeTo(0,1); + } + }); + $("#get_api_key_box").hide(); $("#show_api_key_box").hide(); $("#get_api_key_box form").ajaxForm({ diff --git a/static/styles/zulip.css b/static/styles/zulip.css index 180c2f6449..1cd6002298 100644 --- a/static/styles/zulip.css +++ b/static/styles/zulip.css @@ -3033,7 +3033,7 @@ div.edit_bot { position: relative; } -#settings #notify-settings-status { +#settings #notify-settings-status,#ui-settings-status { width: 80%; text-align: center; margin: auto; @@ -3058,7 +3058,7 @@ div.edit_bot { left: 20px; } -#settings .settings-section .notification-settings-form { +#settings .settings-section .notification-settings-form,.ui-settings-form { width: 400px; margin: auto; } @@ -3076,7 +3076,8 @@ div.edit_bot { margin-left: 140px; } -#settings .settings-section .notification-settings-form .controls { +#settings .settings-section .notification-settings-form .controls, +#settings .settings-section .ui-settings-form .controls { display: inline-block; vertical-align: middle; margin: 0px; @@ -3087,7 +3088,8 @@ div.edit_bot { margin-right: 12px; } -#settings .settings-section .notification-settings-form .controls input[type='checkbox'] { +#settings .settings-section .notification-settings-form .controls input[type='checkbox'], +#settings .settings-section .ui-settings-form .controls input[type='checkbox'] { margin: 0px; padding: 0px; vertical-align: middle; @@ -3095,7 +3097,8 @@ div.edit_bot { top: -1px; } -#settings .settings-section .notification-settings-form .control-label { +#settings .settings-section .notification-settings-form .control-label, +#settings .settings-section .ui-settings-form .control-label { float: none; display: inline-block; vertical-align: middle; @@ -3105,11 +3108,13 @@ div.edit_bot { width: 240px; } -#settings .settings-section .notification-settings-form .notification-submission { +#settings .settings-section .notification-settings-form .notification-submission, +#settings .settings-section .ui-settings-form .ui-submission { margin-left: 140px; } -#settings .notification-settings-form .notification-settings-note { +#settings .notification-settings-form .notification-settings-note, +#settings .ui-settings-form .ui-settings-note { margin-left: 110px; width: 250px; font-size: 13px; @@ -3363,11 +3368,13 @@ div.edit_bot { cursor: pointer; } -#notification-settings .control-group { +#notification-settings .control-group, +#ui-settings .control-group { margin-bottom: 5px; } -#notification-settings .control-label { +#notification-settings .control-label, +#ui-settings .control-label { width: 280px; text-align: left; } diff --git a/templates/zerver/settings.html b/templates/zerver/settings.html index 5ea64ccfd0..5919dad340 100644 --- a/templates/zerver/settings.html +++ b/templates/zerver/settings.html @@ -174,6 +174,34 @@ +
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 170bc07eec..280c11678c 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -1240,6 +1240,15 @@ def do_change_enable_digest_emails(user_profile, enable_digest_emails, log=True) 'user': user_profile.email, 'enable_digest_emails': enable_digest_emails}) +def do_change_autoscroll_forever(user_profile, autoscroll_forever, log=True): + user_profile.autoscroll_forever = autoscroll_forever + user_profile.save(update_fields=["autoscroll_forever"]) + + if log: + log_event({'type': 'autoscroll_forever', + 'user': user_profile.email, + 'autoscroll_forever': autoscroll_forever}) + def do_change_enter_sends(user_profile, enter_sends): user_profile.enter_sends = enter_sends user_profile.save(update_fields=["enter_sends"]) diff --git a/zerver/tests.py b/zerver/tests.py index 5bf02edfbc..21a8879825 100644 --- a/zerver/tests.py +++ b/zerver/tests.py @@ -2301,6 +2301,19 @@ class ChangeSettingsTest(AuthedTestCase): self.assertEqual(get_user_profile_by_email("hamlet@zulip.com"). enable_desktop_notifications, False) + def test_ui_settings(self): + self.login("hamlet@zulip.com") + + json_result = self.client.post("/json/ui_settings/change", {"autoscroll_forever": "true"}) + self.assert_json_success(json_result) + self.assertEqual(get_user_profile_by_email("hamlet@zulip.com"). + enable_desktop_notifications, True) + + json_result = self.client.post("/json/ui_settings/change", {}) + self.assert_json_success(json_result) + self.assertEqual(get_user_profile_by_email("hamlet@zulip.com"). + autoscroll_forever, False) + def test_missing_params(self): """ full_name is a required POST parameter for json_change_settings. diff --git a/zerver/views/__init__.py b/zerver/views/__init__.py index f01b8cc0f6..da88934448 100644 --- a/zerver/views/__init__.py +++ b/zerver/views/__init__.py @@ -40,7 +40,7 @@ from zerver.lib.actions import bulk_remove_subscriptions, \ do_add_alert_words, do_remove_alert_words, do_set_alert_words, get_subscriber_emails, \ do_set_muted_topics, do_rename_stream, clear_followup_emails_queue, \ notify_for_streams_by_default, do_change_enable_offline_push_notifications, \ - do_deactivate_stream + do_deactivate_stream, do_change_autoscroll_forever from zerver.lib.create_user import random_api_key from zerver.lib.push_notifications import num_push_devices_for_user from zerver.forms import RegistrationForm, HomepageForm, ToSForm, \ @@ -812,7 +812,8 @@ def home(request): is_admin = user_profile.is_admin(), notify_for_streams_by_default = notify_for_streams_by_default(user_profile), name_changes_disabled = settings.NAME_CHANGES_DISABLED, - has_mobile_devices = num_push_devices_for_user(user_profile) > 0 + has_mobile_devices = num_push_devices_for_user(user_profile) > 0, + autoscroll_forever = user_profile.autoscroll_forever )) statsd.incr('views.home') @@ -1888,6 +1889,20 @@ def create_user_backend(request, user_profile, email=REQ, password=REQ, process_new_human_user(new_user_profile) return json_success() +@authenticated_json_post_view +@has_request_variables +def json_change_ui_settings(request, user_profile, + autoscroll_forever=REQ(converter=lambda x: x == "on", + default=False)): + + result = {} + + if user_profile.autoscroll_forever != autoscroll_forever: + do_change_autoscroll_forever(user_profile, autoscroll_forever) + result['autoscroll_forever'] = autoscroll_forever + + return json_success(result) + @authenticated_json_post_view @has_request_variables def json_stream_exists(request, user_profile, stream=REQ): diff --git a/zproject/urls.py b/zproject/urls.py index 1c5e1fad22..a477fb262c 100644 --- a/zproject/urls.py +++ b/zproject/urls.py @@ -112,6 +112,7 @@ urlpatterns += patterns('zerver.views', url(r'^json/bulk_invite_users$', 'json_bulk_invite_users'), url(r'^json/settings/change$', 'json_change_settings'), url(r'^json/notify_settings/change$', 'json_change_notify_settings'), + url(r'^json/ui_settings/change$', 'json_change_ui_settings'), url(r'^json/subscriptions/remove$', 'json_remove_subscriptions'), url(r'^json/subscriptions/add$', 'json_add_subscriptions'), url(r'^json/subscriptions/exists$', 'json_stream_exists'),