diff --git a/app/assets/javascripts/app/controllers/_application_controller.js.coffee b/app/assets/javascripts/app/controllers/_application_controller.js.coffee index 92a7fc435..c31b1dc1b 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.js.coffee @@ -669,3 +669,26 @@ class App.UpdateTastbar extends App.Controller # update taskbar with new meta data App.Event.trigger 'task:render' + +class App.ControllerWidgetPermanent extends App.Controller + constructor: (params) -> + if params.el + params.el.append('
') + params.el = ("##{params.key}") + + super(params) + +class App.ControllerWidgetOnDemand extends App.Controller + constructor: (params) -> + params.el = $("##{params.key}") + super + + element: => + $("##{@key}") + + html: (raw) => + + # check if parent exists + if !$("##{@key}").get(0) + $('#app').before("
") + $("##{@key}").html raw diff --git a/app/assets/javascripts/app/controllers/navigation.js.coffee b/app/assets/javascripts/app/controllers/navigation.js.coffee index 7b8817bae..660a522b8 100644 --- a/app/assets/javascripts/app/controllers/navigation.js.coffee +++ b/app/assets/javascripts/app/controllers/navigation.js.coffee @@ -1,4 +1,4 @@ -class App.Navigation extends App.Controller +class App.Navigation extends App.ControllerWidgetPermanent className: 'navigation vertical' constructor: -> diff --git a/app/assets/javascripts/app/controllers/widget/chat.js.coffee b/app/assets/javascripts/app/controllers/widget/chat.js.coffee index 1e0e55013..0c9bab12d 100644 --- a/app/assets/javascripts/app/controllers/widget/chat.js.coffee +++ b/app/assets/javascripts/app/controllers/widget/chat.js.coffee @@ -1,4 +1,4 @@ -class Widget extends App.Controller +class Widget extends App.ControllerWidgetPermanent events: 'submit #chat_form': 'submitMessage' 'focusin [name=chat_message]': 'focusIn' diff --git a/app/assets/javascripts/app/controllers/notify.js.coffee b/app/assets/javascripts/app/controllers/widget/notify.js.coffee similarity index 79% rename from app/assets/javascripts/app/controllers/notify.js.coffee rename to app/assets/javascripts/app/controllers/widget/notify.js.coffee index 4f164a157..0b4562f07 100644 --- a/app/assets/javascripts/app/controllers/notify.js.coffee +++ b/app/assets/javascripts/app/controllers/widget/notify.js.coffee @@ -1,32 +1,30 @@ -class App.Notify extends Spine.Controller +class App.Notify extends App.ControllerWidgetPermanent events: 'click .alert': 'destroy' constructor: -> super - App.Event.bind 'notify', (data) => + @bind 'notify', (data) => @render(data) - App.Event.bind 'notify:removeall', => + @bind 'notify:removeall', => @log 'notify:removeall', @ @destroyAll() - App.Event.bind 'notifyDesktop', (data) => + @bind 'notifyDesktop', (data) => if !data['icon'] data['icon'] = 'unknown' notify.createNotification( data.msg, data ) # request desktop notification after login - App.Event.bind 'auth', (data) -> + @bind 'auth', (data) -> if !_.isEmpty(data) notify.requestPermission() notify.config( pageVisibility: false ) render: (data) -> -# notify = App.view('notify')(data: data) -# @append( notify ) # map noty naming if data['type'] is 'info' @@ -62,10 +60,8 @@ class App.Notify extends Spine.Controller destroy: (e) -> e.preventDefault() -# $(e.target).parents('.alert').remove(); destroyAll: -> $.noty.closeAll() -# $(@el).find('.alert').remove(); App.Config.set( 'notify', App.Notify, 'Widgets' ) diff --git a/app/assets/javascripts/app/controllers/widget/switch_back_to_user.js.coffee b/app/assets/javascripts/app/controllers/widget/switch_back_to_user.js.coffee index 5871caba5..220d09ad0 100644 --- a/app/assets/javascripts/app/controllers/widget/switch_back_to_user.js.coffee +++ b/app/assets/javascripts/app/controllers/widget/switch_back_to_user.js.coffee @@ -1,8 +1,5 @@ -class Widget extends App.Controller +class Widget extends App.ControllerWidgetOnDemand className: 'switchBackToUser' - events: - 'click .js-close': 'switchBack' - constructor: -> super @@ -10,6 +7,10 @@ class Widget extends App.Controller @bind 'app:ready', => @render() + # e. g. if language has chnaged + @bind 'ui:rerender', => + @render() + # remove widget @bind 'auth:logout', => App.Config.set('switch_back_to_possible', false) @@ -19,13 +20,15 @@ class Widget extends App.Controller # if no switch to user is active if !App.Config.get('switch_back_to_possible') || !App.Session.get() - @el.html('') - $('#app').removeClass('switchBackToUserSpace') + @element().remove() return # show switch back widget @html App.view('widget/switch_back_to_user')() - $('#app').addClass('switchBackToUserSpace') + console.log('@el', @element()) + @element().on('click', '.js-close', (e) => + @switchBack(e) + ) switchBack: (e) => e.preventDefault() @@ -34,5 +37,4 @@ class Widget extends App.Controller App.Auth._logout() window.location = App.Config.get('api_path') + '/sessions/switch_back' - App.Config.set( 'switch_back_to_user', Widget, 'Widgets' ) diff --git a/app/assets/javascripts/app/controllers/widget/translation_inline.js.coffee b/app/assets/javascripts/app/controllers/widget/translation_inline.js.coffee index 89c145ef3..7525f66d1 100644 --- a/app/assets/javascripts/app/controllers/widget/translation_inline.js.coffee +++ b/app/assets/javascripts/app/controllers/widget/translation_inline.js.coffee @@ -1,6 +1,5 @@ -class Widget extends App.Controller +class Widget constructor: -> - super # bind on key down # if ctrl+shift+t is pressed, enable translation_inline and fire ui:rerender diff --git a/app/assets/javascripts/app/lib/app_post/interface_handle.js.coffee b/app/assets/javascripts/app/lib/app_post/interface_handle.js.coffee index 8ba574f06..89cacaa2f 100644 --- a/app/assets/javascripts/app/lib/app_post/interface_handle.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/interface_handle.js.coffee @@ -35,21 +35,23 @@ class App.Run extends App.Controller setupWidget: (config, event, el) -> # start widgets - App.Event.trigger( event + ':init') - widgets = App.Config.get( config ) + App.Event.trigger(event + ':init') + widgets = App.Config.get(config) if widgets for key, widget of widgets - el.append('
') - new widget( el: el.find("##{key}") ) - App.Event.trigger( event + ':ready') + new widget( + el: el + key: key + ) + App.Event.trigger(event + ':ready') -class App.Content extends App.Controller +class App.Content extends App.ControllerWidgetPermanent className: 'content flex horizontal' constructor: -> super - Routes = @Config.get( 'Routes' ) + Routes = @Config.get('Routes') for route, callback of Routes do (route, callback) => @route(route, (params) -> @@ -88,11 +90,11 @@ class App.Content extends App.Controller # execute controller controller = (params) => params.el = @el - new callback( params ) - controller( params ) + new callback(params) + controller(params) # scroll to top / remember last screen position -# @scrollTo( 0, 0, 100 ) +# @scrollTo(0, 0, 100) ) Spine.Route.setup()