[schema] Save enter_sends on the server in the database.

(imported from commit 4d82f6aaf5918f155a930253c9cc334dbcc0d97a)
This commit is contained in:
Jeff Arnold
2013-02-27 17:18:38 -05:00
committed by Tim Abbott
parent ebb9be1ead
commit fcd033e33e
7 changed files with 30 additions and 5 deletions

View File

@@ -71,6 +71,7 @@ urlpatterns = patterns('',
url(r'^json/update_active_status$', 'zephyr.views.json_update_active_status'),
url(r'^json/get_active_statuses$', 'zephyr.views.json_get_active_statuses'),
url(r'^json/tutorial_send_message$', 'zephyr.views.json_tutorial_send_message'),
url(r'^json/change_enter_sends$', 'zephyr.views.json_change_enter_sends'),
# These are json format views used by the API. They require an API key.
url(r'^api/v1/get_messages$', 'zephyr.tornadoviews.api_get_messages'),

View File

@@ -64,6 +64,7 @@ var email = "{{ user_profile.user.email|escapejs }}";
var domain = "{{ user_profile.realm.domain|escapejs }}";
var have_initial_messages = {{ have_initial_messages|escapejs }};
var desktop_notifications_enabled = {{ desktop_notifications_enabled|escapejs }};
var enter_sends = {{ enter_sends|escapejs }};
{# We use JSONEncoderForHTML to generate "streams". #}
var stream_list = {{ streams }};

View File

@@ -7,7 +7,7 @@ var globals =
// index.html
+ ' initial_pointer email stream_list people_list have_initial_messages'
+ ' fullname desktop_notifications_enabled domain poll_timeout'
+ ' fullname desktop_notifications_enabled enter_sends domain poll_timeout'
// common.js
+ ' status_classes'

View File

@@ -292,6 +292,10 @@ def do_change_enable_desktop_notifications(user_profile, enable_desktop_notifica
'user': user_profile.user.email,
'enable_desktop_notifications': enable_desktop_notifications})
def do_change_enter_sends(user_profile, enter_sends):
user_profile.enter_sends = enter_sends
user_profile.save()
def set_default_streams(realm, stream_names):
DefaultStream.objects.filter(realm=realm).delete()
for stream_name in stream_names:

View File

@@ -55,6 +55,7 @@ class UserProfile(models.Model):
realm = models.ForeignKey(Realm)
api_key = models.CharField(max_length=32)
enable_desktop_notifications = models.BooleanField(default=True)
enter_sends = models.NullBooleanField(default=False)
def __repr__(self):
return "<UserProfile: %s %s>" % (self.user.email, self.realm)

View File

@@ -99,8 +99,7 @@ function handle_keydown(e) {
// If no typeaheads are shown and the user has configured enter to send,
// then make enter send instead of inserting a line break.
if (e.target.id === "new_message_content" && code === 13 &&
$("#enter_sends").is(':checked')) {
if (e.target.id === "new_message_content" && code === 13 && enter_sends) {
e.preventDefault();
compose.finish();
}
@@ -147,6 +146,17 @@ exports.initialize = function () {
handle_keyup(e);
});
$("#enter_sends").click(function () {
enter_sends = $("#enter_sends").is(":checked");
return $.ajax({
dataType: 'json',
url: '/json/change_enter_sends',
type: 'POST',
data: {'enter_sends': enter_sends}
});
});
$("#enter_sends").prop('checked', enter_sends);
// limit number of items so the list doesn't fall off the screen
$( "#stream" ).typeahead({
source: function (query, process) {

View File

@@ -16,8 +16,8 @@ from zephyr.models import Message, UserProfile, Stream, Subscription, \
StreamColor, PreregistrationUser, get_client, MitUser, User, UserActivity, \
MAX_SUBJECT_LENGTH, MAX_MESSAGE_LENGTH, get_stream, UserPresence
from zephyr.lib.actions import do_add_subscription, do_remove_subscription, \
do_change_password, create_mit_user_if_needed, \
do_change_full_name, do_change_enable_desktop_notifications, \
do_change_password, create_mit_user_if_needed, do_change_full_name, \
do_change_enable_desktop_notifications, do_change_enter_sends, \
do_activate_user, add_default_subs, do_create_user, do_send_message, \
log_subscription_property_change, internal_send_message, \
create_stream_if_needed, gather_subscriptions, subscribed_to_stream, \
@@ -419,6 +419,8 @@ def home(request):
js_bool(num_messages > 0),
'desktop_notifications_enabled':
js_bool(user_profile.enable_desktop_notifications),
'enter_sends':
js_bool(user_profile.enter_sends),
'show_debug':
settings.DEBUG and ('show_debug' in request.GET),
'show_activity': can_view_activity(request),
@@ -649,6 +651,12 @@ def json_tutorial_send_message(request, user_profile, message=POST('message')):
message)
return json_success()
@authenticated_json_post_view
@has_request_variables
def json_change_enter_sends(request, user_profile, enter_sends=POST('enter_sends', json_to_bool)):
do_change_enter_sends(user_profile, enter_sends)
return json_success()
# Currently tabbott/extra@mit.edu is our only superuser. TODO: Make
# this a real superuser security check.
def is_super_user_api(request):