From 09531e7a4dee8f039f612ddd253637d53e08ef72 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 9 May 2013 18:05:07 +0200 Subject: [PATCH] Notify code cleanup. --- .../app/controllers/login.js.coffee | 30 +++++++++---------- .../app/controllers/notify.js.coffee | 24 ++++++++------- .../app/controllers/reset_password.js.coffee | 12 ++++---- .../app/controllers/signup.js.coffee | 29 +++++++----------- 4 files changed, 44 insertions(+), 51 deletions(-) diff --git a/app/assets/javascripts/app/controllers/login.js.coffee b/app/assets/javascripts/app/controllers/login.js.coffee index ec82a39a7..284c44621 100644 --- a/app/assets/javascripts/app/controllers/login.js.coffee +++ b/app/assets/javascripts/app/controllers/login.js.coffee @@ -1,6 +1,6 @@ class Index extends App.ControllerContent events: - 'submit #login': 'login', + 'submit #login': 'login' constructor: -> super @@ -47,7 +47,7 @@ class Index extends App.ControllerContent auth_providers: auth_providers ) - # set focus + # set focus to username or password if !$(@el).find('[name="username"]').val() $(@el).find('[name="username"]').focus() else @@ -68,9 +68,9 @@ class Index extends App.ControllerContent # session create with login/password App.Auth.login( - data: params, + data: params success: @success - error: @error, + error: @error ) success: (data, status, xhr) => @@ -80,15 +80,14 @@ class Index extends App.ControllerContent App.WebSocket.send( event: 'navupdate_ticket_overview' ) # add notify - App.Event.trigger 'notify:removeall' - App.Event.trigger 'notify', { - type: 'success', - msg: App.i18n.translateContent('Login successfully! Have a nice day!'), - } + @notify + type: 'success' + msg: App.i18n.translateContent('Login successfully! Have a nice day!') + removeAll: true # redirect to # requested_url = @Config.get( 'requested_url' ) - if requested_url isnt '' + if requested_url && requested_url isnt '#login' console.log("REDIRECT to '#{requested_url}'") @navigate requested_url @@ -101,11 +100,10 @@ class Index extends App.ControllerContent error: (xhr, statusText, error) => # add notify - App.Event.trigger 'notify:removeall' - App.Event.trigger 'notify', { - type: 'error', - msg: App.i18n.translateContent('Wrong Username and Password combination.'), - } + @notify + type: 'error' + msg: App.i18n.translateContent('Wrong Username and Password combination.') + removeAll: true # rerender login page @render( @@ -115,7 +113,7 @@ class Index extends App.ControllerContent # login shake @delay( => @shake( @el.find('#login') ), - 700 + 600 ) App.Config.set( 'login', Index, 'Routes' ) diff --git a/app/assets/javascripts/app/controllers/notify.js.coffee b/app/assets/javascripts/app/controllers/notify.js.coffee index ef6f88770..2cbc3b786 100644 --- a/app/assets/javascripts/app/controllers/notify.js.coffee +++ b/app/assets/javascripts/app/controllers/notify.js.coffee @@ -24,27 +24,29 @@ class App.Notify extends Spine.Controller if data['type'] is 'warning' data['type'] = 'alert' - $.noty.closeAll() + if data['removeAll'] + $.noty.closeAll() if data.link data.msg = '' + data.msg + '' $('#notify').noty( { - text: data.msg, - layout: 'top', - type: data.type, - theme: 'noty_theme_twitter', + dismissQueue: true + text: data.msg + layout: 'top' + type: data.type + theme: 'noty_theme_twitter' animateOpen: { height: 'toggle' opacity: 0.85, }, animateClose: { - opacity: 0.25, + opacity: 0.25 }, - speed: 450, - timeout: data.timeout || 3800, - closeButton: false, - closeOnSelfClick: true, - closeOnSelfOver: false, + speed: 450 + timeout: data.timeout || 3800 + closeButton: false + closeOnSelfClick: true + closeOnSelfOver: false } ) diff --git a/app/assets/javascripts/app/controllers/reset_password.js.coffee b/app/assets/javascripts/app/controllers/reset_password.js.coffee index e5dc751f9..ca00958d5 100644 --- a/app/assets/javascripts/app/controllers/reset_password.js.coffee +++ b/app/assets/javascripts/app/controllers/reset_password.js.coffee @@ -140,10 +140,10 @@ class Verify extends App.ControllerContent App.Auth.loginCheck() # add notify - App.Event.trigger 'notify:removeall' @notify - type: 'success', - msg: 'Woo hoo! Your password has been changed!' + type: 'success' + msg: 'Woo hoo! Your password has been changed!' + removeAll: true # redirect to # @navigate '#' @@ -151,10 +151,10 @@ class Verify extends App.ControllerContent error: => # add notify - App.Event.trigger 'notify:removeall' @notify - type: 'error', - msg: 'Something went wrong. Please contact your administrator.' + type: 'error' + msg: 'Something went wrong. Please contact your administrator.' + removeAll: true ) render_changed_failed: => diff --git a/app/assets/javascripts/app/controllers/signup.js.coffee b/app/assets/javascripts/app/controllers/signup.js.coffee index 4098e5286..19af924af 100644 --- a/app/assets/javascripts/app/controllers/signup.js.coffee +++ b/app/assets/javascripts/app/controllers/signup.js.coffee @@ -2,9 +2,9 @@ class Index extends App.ControllerContent className: 'container signup' events: - 'submit form': 'submit', - 'click .submit': 'submit', - 'click .cancel': 'cancel', + 'submit form': 'submit' + 'click .submit': 'submit' + 'click .cancel': 'cancel' constructor: -> super @@ -37,7 +37,7 @@ class Index extends App.ControllerContent ) cancel: -> - @navigate 'login' + @navigate '#login' submit: (e) -> e.preventDefault() @@ -80,10 +80,10 @@ class Index extends App.ControllerContent App.Auth.loginCheck() # add notify - App.Event.trigger 'notify:removeall' @notify - type: 'success', - msg: 'Thanks for joining. Email sent to "' + @params.email + '". Please verify your email address.' + type: 'success' + msg: 'Thanks for joining. Email sent to "' + @params.email + '". Please verify your email address.' + removeAll: true # redirect to # @navigate '#' @@ -91,16 +91,9 @@ class Index extends App.ControllerContent error: (xhr, statusText, error) => # add notify - App.Event.trigger 'notify:removeall' - App.Event.trigger 'notify', { - type: 'warning' - msg: 'Wrong Username and Password combination.' - } - - # rerender login page - @render( - msg: 'Wrong Username and Password combination.' - username: @username - ) + @notify + type: 'warning' + msg: 'Wrong Username and Password combination.' + removeAll: true App.Config.set( 'signup', Index, 'Routes' ) \ No newline at end of file