From b952a10f6423e8c4dc8b5f66a1505097bca5122a Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Tue, 30 Oct 2012 14:14:27 +0100 Subject: [PATCH] fix message handling for mobile --- .../{application.js => application.js.erb} | 26 +++++-- app/views/layouts/phone.html.slim | 23 +++---- config/locales/devise.nl.yml | 69 +++++++++++++++++++ config/locales/en.yml | 4 +- config/locales/nl.yml | 4 +- 5 files changed, 106 insertions(+), 20 deletions(-) rename app/assets/javascripts/user/{application.js => application.js.erb} (85%) create mode 100644 config/locales/devise.nl.yml diff --git a/app/assets/javascripts/user/application.js b/app/assets/javascripts/user/application.js.erb similarity index 85% rename from app/assets/javascripts/user/application.js rename to app/assets/javascripts/user/application.js.erb index a2e790d8..be129448 100644 --- a/app/assets/javascripts/user/application.js +++ b/app/assets/javascripts/user/application.js.erb @@ -14,7 +14,7 @@ //= require jquery_ujs // require twitter/bootstrap //= require twitter/bootstrap/bootstrap-transition -// require twitter/bootstrap/bootstrap-alert +//= require twitter/bootstrap/bootstrap-alert //= require twitter/bootstrap/bootstrap-modal //= require twitter/bootstrap/bootstrap-dropdown //= require twitter/bootstrap/bootstrap-scrollspy @@ -38,8 +38,9 @@ var path_mapping = { history_list: '/user/history_list', obtain_user_token: '/user/obtain_token' } -var translations = { +var $translations = { en: { + messages: <%= I18n.t('messages', locale: :en).to_json %>, confirmations: { }, list_needs_help: { @@ -70,6 +71,7 @@ var translations = { } }, nl: { + messages: <%= I18n.t('messages', locale: :en).to_json %>, confirmations: { }, list_needs_help: { @@ -117,7 +119,7 @@ String.prototype.capitalize = function() { function t(path, vars){ vars || (vars = {}); var parts = path.split('.'); - var accessor = 'translations["' + parts.join('"]["')+ '"]'; + var accessor = '$translations.'+$locale+'["' + parts.join('"]["')+ '"]'; var result; try{ result = eval(accessor); @@ -133,4 +135,20 @@ $.ajaxSetup({ window.location = data_host + '/user/obtain_token.html'; } } -}) +}); +function getUrlVars() { + if($url_vars) return $url_vars; + $url_vars = {}; + var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { + $url_vars[key] = value; + }); + return $url_vars; +} +$(function(){ + + if(getUrlVars().message){ + var container = $('.alert-success div'); + container.text($translations[$locale]['messages'][getUrlVars().message] || ('Message ' + getUrlVars().message + ' not found')); + container.show(); + } +}); diff --git a/app/views/layouts/phone.html.slim b/app/views/layouts/phone.html.slim index 672ab03d..2f6ecc3f 100644 --- a/app/views/layouts/phone.html.slim +++ b/app/views/layouts/phone.html.slim @@ -17,18 +17,19 @@ html lang="en" link href="/images/apple-touch-icon.png" rel="apple-touch-icon-precomposed" link href="/favicon.ico" rel="shortcut icon" javascript: - var data_host = 'http://data.qwaiter.com'; + //var data_host = 'http://data.qwaiter.com'; //var data_host = 'http://localhost:3000'; - //var data_host = 'http://192.168.1.240:3000'; + var data_host = 'http://192.168.1.74:3000'; var $locale = '#{I18n.locale}'; + var $url_vars = null; // Dummy holder when Qmobile object is not supplied by the mobile phone var QMobile, Qwaiter, Quser; QMobile || (QMobile = { scanQr: function(){window.location = '/select_qrcode'}, activateRotation: function(){}, mobile: function(){return false}, - authentication_string: function(){return this.authentication_string_storage}, - authentication_object: function(){return this.authentication_object_storage}, + authentication_string: function(){return this.authentication_string_storage || ''}, + authentication_object: function(){return this.authentication_object_storage || '{}'}, setAuthToken: function(token){ this.authentication_string_storage = 'auth_token='+token; this.authentication_object_storage = '{"auth_token": "'+token+'"}' @@ -55,14 +56,12 @@ html lang="en" .container .content - - if flash[:alert].present? - .alert.alert-error - a.close data-dismiss="alert" × - div= flash[:alert] - - if flash[:notice].present? - .alert.alert-success - a.close data-dismiss="alert" × - div= flash[:notice] + .alert.alert-error.hide + button.close type="button" data-dismiss="alert" × + div= flash[:alert] + .alert.alert-success.hide + button.close type="button" data-dismiss="alert" × + div .row .span12 = yield diff --git a/config/locales/devise.nl.yml b/config/locales/devise.nl.yml new file mode 100644 index 00000000..dde4263b --- /dev/null +++ b/config/locales/devise.nl.yml @@ -0,0 +1,69 @@ +nl: + errors: + messages: + not_found: "bestaat niet" + already_confirmed: "was reeds bevestigd" + not_locked: "was niet vergrendeld" + not_saved: "niet uitgevoerd" + + devise: + failure: + already_authenticated: 'U bent reeds ingelogd.' + unauthenticated: 'U moet inloggen voordat u verder kunt' + unconfirmed: 'U dient deze account te bevestigen voordat u verder kunt.' + locked: 'Uw account is geblokkeerd.' + invalid: 'Deze login gegevens zijn niet geldig' + invalid_token: 'Invalid authentication token.' + timeout: 'Uw sessie is verlopen. U moet opnieuw inloggen om verder te gaan.' + inactive: 'Your account was not activated yet.' + sessions: + title: Inloggen + button: Inloggen + signed_in: Succesvol ingelogd + signed_out: Succesvol uitgelogd + signed_in_as: Ingelogd als + forgot_your_password: Wachtwoord vergeten? + sign_out: Uitloggen + sign_in: Inloggen + remember_me: Ingelogd blijven? + passwords: + send_instructions: 'U ontvangt binnen enkele minuten een e-mail met instructies voor het resetten van uw wachtwoord' + updated: 'Uw wachtwoord is succesvol gewijzigd. U bent nu ingelogd.' + forgot_password: Wachtwoord vergeten? + send_instructions_button: Stuur mij reset instructies + confirmations: + send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.' + confirmed: 'Your account was successfully confirmed. You are now signed in.' + did_not_receive_instructions_link: "Heeft u geen bevestigingsinstructies ontvangen?" + did_not_receive: Heeft u geen bevestigingsinstructies ontvangen? + registrations: + title: Aanmelden + button: Aanmelden + signed_up: 'Welcome! You have signed up successfully.' + signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.' + signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.' + signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.' + updated: 'You updated your account successfully.' + update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address." + + signed_up: 'You have signed up successfully. If enabled, a confirmation was sent your e-mail.' + updated: 'You updated your account successfully.' + destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.' + sign_up: Acount aanvragen + unlocks: + did_not_receive_instructions_link: "Didn't receive unlock instructions?" + send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.' + unlocked: 'Your account was successfully unlocked. You are now signed in.' + did_not_receive: Heeft u geen deblokkeerinstructies ontvangen? + send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.' + omniauth_callbacks: + sign_in_with: "Sign in with %{provider}" + success: 'Successfully authorized from %{kind} account.' + failure: 'Could not authorize you from %{kind} because "%{reason}".' + mailer: + confirmation_instructions: + subject: 'Bevestigingsinstructies' + reset_password_instructions: + subject: 'Wachtwoord reset instructies' + unlock_instructions: + subject: 'Ontsluitings instructies' diff --git a/config/locales/en.yml b/config/locales/en.yml index 4cd555ba..c4ef7670 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -13,14 +13,14 @@ en: messages: cannot_order_on_non_active_list: You cannot place an order on a closed list order_is_placed: Your order has been received in good order - the_list_has_been_closed: The %{list} has been closed + the_list_has_been_closed: The list has been closed illegal_history_list_attempt: The list you want to access is not yours table_is_occupied: The table you want to sit on is already occupied table_is_reserved: The table you want to sit on is reserved by someone else table_is_closed: The table you want to sit on is not available for service supplier_is_closed: The owner of this table is currently not handling orders join_request_rejected: Your request to join the table has been rejected - table_is_from_other_supplier: You cannot move to another table when you have a %{list} open + table_is_from_other_supplier: You cannot move to another table when you have an open list moved_to_another_table: You successfully moved to another table cannot_identify_table: The application cannot determine the table number action: diff --git a/config/locales/nl.yml b/config/locales/nl.yml index 8225d285..fe7b10e6 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -12,14 +12,14 @@ nl: messages: cannot_order_on_non_active_list: Je kan niet bestellen op een gesloten lijst order_is_placed: Je bestelling is in goede orde aangekomen - the_list_has_been_closed: De %{list} is afgesloten + the_list_has_been_closed: De lijst is afgesloten illegal_history_list_attempt: Je probeert een lijst op te vragen die niet van jou is table_is_occupied: De tafel waar je aan wil gaan zitten is reeds bezet table_is_reserved: De tafel waar je aan wil gaan zitten is gereserveerd table_is_closed: De tafel waar je aan wil gaan zitten is niet beschikbaar voor bediening supplier_is_closed: De eigenaar van deze tafel is momenteel gesloten join_request_rejected: Je verzoek om te mogen bestellen op een bestaande lijst is afgewezen - table_is_from_other_supplier: Je kan geen lijst openen bij een andere zaak zolang je huidige %{list} nog niet is afgesloten + table_is_from_other_supplier: Je kan geen lijst openen bij een andere zaak zolang je huidige lijst nog niet is afgesloten moved_to_another_table: De tafel is gewijzigd cannot_identify_table: De applicatie kan niet bepalen om welke tafel het gaat action: