From 4d652463ec576010f10f10af84f9081e4ccfd485 Mon Sep 17 00:00:00 2001 From: Zachary Chai Date: Tue, 14 Mar 2017 16:09:20 -0400 Subject: [PATCH] notify user when joining without name provided --- app/assets/javascripts/landing.js | 32 ++++++++++++++++++-------- app/assets/javascripts/meeting.coffee | 3 +++ app/assets/javascripts/shared.js.erb | 5 +++- app/views/landing/rooms.html.erb | 8 ------- app/views/layouts/application.html.erb | 10 ++++++++ app/views/shared/_join_form.html.erb | 4 +++- config/locales/en-us.yml | 1 + 7 files changed, 43 insertions(+), 20 deletions(-) diff --git a/app/assets/javascripts/landing.js b/app/assets/javascripts/landing.js index 39471219..7f293a9b 100644 --- a/app/assets/javascripts/landing.js +++ b/app/assets/javascripts/landing.js @@ -47,16 +47,20 @@ // a user name is set, join the user into the session if (name !== undefined && name !== null) { var jqxhr = Meeting.getInstance().getJoinMeetingResponse(); - jqxhr.done(function(data) { - if (data.messageKey === 'wait_for_moderator') { - waitForModerator(Meeting.getInstance().getURL()); - } else { - $(location).attr("href", data.response.join_url); - } - }); - jqxhr.fail(function(xhr, status, error) { - console.info("meeting join failed"); - }); + if (jqxhr) { + jqxhr.done(function(data) { + if (data.messageKey === 'wait_for_moderator') { + waitForModerator(Meeting.getInstance().getURL()); + } else { + $(location).attr("href", data.response.join_url); + } + }); + jqxhr.fail(function(xhr, status, error) { + console.info("meeting join failed"); + }); + } else { + $('.meeting-user-name').parent().addClass('has-error'); + } // if not user name was set it means we must ask for a name } else { @@ -68,6 +72,14 @@ Turbolinks.visit($('.meeting-url').val()); }); + $('.center-panel-wrapper').on ('input', '.meeting-user-name', function (event) { + if ($(this).val() === '') { + $(this).parent().addClass('has-error') + } else { + $(this).parent().removeClass('has-error') + } + }); + $('.center-panel-wrapper').on ('keypress', '.meeting-user-name', function (event) { if (event.keyCode === 13) { event.preventDefault(); diff --git a/app/assets/javascripts/meeting.coffee b/app/assets/javascripts/meeting.coffee index 8421ef52..d5e324b5 100644 --- a/app/assets/javascripts/meeting.coffee +++ b/app/assets/javascripts/meeting.coffee @@ -63,6 +63,9 @@ class @Meeting # Returns a response object # The response object contains the URL to join the meeting getJoinMeetingResponse: -> + if !@userName + showAlert(I18n.enter_name, 4000, 'danger') + return false return $.get @getURL() + "/join?name=" + @userName, (data) => # update name used to join meeting localStorage.setItem('lastJoinedName', @getUserName()) diff --git a/app/assets/javascripts/shared.js.erb b/app/assets/javascripts/shared.js.erb index 5b8e4c5f..0a5f3e1b 100644 --- a/app/assets/javascripts/shared.js.erb +++ b/app/assets/javascripts/shared.js.erb @@ -35,12 +35,15 @@ var loopJoin = function() { }; var alertTimeout = null; -var showAlert = function(html, timeout_delay) { +var showAlert = function(html, timeout_delay, type) { + type = type || 'success' + if (!html) { return; } $('.alert-template .alert-message').html(html); + $('.alert-template .alert').removeClass('alert-success alert-danger alert-info alert-warning').addClass('alert-'+type); $('#alerts').html($('.alert-template').html()); if (timeout_delay) { diff --git a/app/views/landing/rooms.html.erb b/app/views/landing/rooms.html.erb index 8c31e099..a7f2aeac 100644 --- a/app/views/landing/rooms.html.erb +++ b/app/views/landing/rooms.html.erb @@ -66,14 +66,6 @@ <%= t('client.unpublished') %> -
- -
+ diff --git a/app/views/shared/_join_form.html.erb b/app/views/shared/_join_form.html.erb index cb1bd679..f4e0f3ce 100644 --- a/app/views/shared/_join_form.html.erb +++ b/app/views/shared/_join_form.html.erb @@ -44,7 +44,9 @@ <% else %> - <%= text_field_tag 'user[name]', '', class: 'form-control meeting-user-name', placeholder: t('enter_name'), maxlength: user_name_limit %> +
+ <%= text_field_tag 'user[name]', '', class: 'form-control meeting-user-name', placeholder: t('enter_name'), maxlength: user_name_limit %> +