Added support of permanent and on demand widgets.

This commit is contained in:
Martin Edenhofer 2015-06-10 00:22:56 +02:00
parent 228b37f372
commit 62ad616f75
7 changed files with 53 additions and 31 deletions

View file

@ -669,3 +669,26 @@ class App.UpdateTastbar extends App.Controller
# update taskbar with new meta data # update taskbar with new meta data
App.Event.trigger 'task:render' App.Event.trigger 'task:render'
class App.ControllerWidgetPermanent extends App.Controller
constructor: (params) ->
if params.el
params.el.append('<div id="' + params.key + '"></div>')
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("<div id=\"#{@key}\" class=\"#{@className}\"></div>")
$("##{@key}").html raw

View file

@ -1,4 +1,4 @@
class App.Navigation extends App.Controller class App.Navigation extends App.ControllerWidgetPermanent
className: 'navigation vertical' className: 'navigation vertical'
constructor: -> constructor: ->

View file

@ -1,4 +1,4 @@
class Widget extends App.Controller class Widget extends App.ControllerWidgetPermanent
events: events:
'submit #chat_form': 'submitMessage' 'submit #chat_form': 'submitMessage'
'focusin [name=chat_message]': 'focusIn' 'focusin [name=chat_message]': 'focusIn'

View file

@ -1,32 +1,30 @@
class App.Notify extends Spine.Controller class App.Notify extends App.ControllerWidgetPermanent
events: events:
'click .alert': 'destroy' 'click .alert': 'destroy'
constructor: -> constructor: ->
super super
App.Event.bind 'notify', (data) => @bind 'notify', (data) =>
@render(data) @render(data)
App.Event.bind 'notify:removeall', => @bind 'notify:removeall', =>
@log 'notify:removeall', @ @log 'notify:removeall', @
@destroyAll() @destroyAll()
App.Event.bind 'notifyDesktop', (data) => @bind 'notifyDesktop', (data) =>
if !data['icon'] if !data['icon']
data['icon'] = 'unknown' data['icon'] = 'unknown'
notify.createNotification( data.msg, data ) notify.createNotification( data.msg, data )
# request desktop notification after login # request desktop notification after login
App.Event.bind 'auth', (data) -> @bind 'auth', (data) ->
if !_.isEmpty(data) if !_.isEmpty(data)
notify.requestPermission() notify.requestPermission()
notify.config( pageVisibility: false ) notify.config( pageVisibility: false )
render: (data) -> render: (data) ->
# notify = App.view('notify')(data: data)
# @append( notify )
# map noty naming # map noty naming
if data['type'] is 'info' if data['type'] is 'info'
@ -62,10 +60,8 @@ class App.Notify extends Spine.Controller
destroy: (e) -> destroy: (e) ->
e.preventDefault() e.preventDefault()
# $(e.target).parents('.alert').remove();
destroyAll: -> destroyAll: ->
$.noty.closeAll() $.noty.closeAll()
# $(@el).find('.alert').remove();
App.Config.set( 'notify', App.Notify, 'Widgets' ) App.Config.set( 'notify', App.Notify, 'Widgets' )

View file

@ -1,8 +1,5 @@
class Widget extends App.Controller class Widget extends App.ControllerWidgetOnDemand
className: 'switchBackToUser' className: 'switchBackToUser'
events:
'click .js-close': 'switchBack'
constructor: -> constructor: ->
super super
@ -10,6 +7,10 @@ class Widget extends App.Controller
@bind 'app:ready', => @bind 'app:ready', =>
@render() @render()
# e. g. if language has chnaged
@bind 'ui:rerender', =>
@render()
# remove widget # remove widget
@bind 'auth:logout', => @bind 'auth:logout', =>
App.Config.set('switch_back_to_possible', false) 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 no switch to user is active
if !App.Config.get('switch_back_to_possible') || !App.Session.get() if !App.Config.get('switch_back_to_possible') || !App.Session.get()
@el.html('') @element().remove()
$('#app').removeClass('switchBackToUserSpace')
return return
# show switch back widget # show switch back widget
@html App.view('widget/switch_back_to_user')() @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) => switchBack: (e) =>
e.preventDefault() e.preventDefault()
@ -34,5 +37,4 @@ class Widget extends App.Controller
App.Auth._logout() App.Auth._logout()
window.location = App.Config.get('api_path') + '/sessions/switch_back' window.location = App.Config.get('api_path') + '/sessions/switch_back'
App.Config.set( 'switch_back_to_user', Widget, 'Widgets' ) App.Config.set( 'switch_back_to_user', Widget, 'Widgets' )

View file

@ -1,6 +1,5 @@
class Widget extends App.Controller class Widget
constructor: -> constructor: ->
super
# bind on key down # bind on key down
# if ctrl+shift+t is pressed, enable translation_inline and fire ui:rerender # if ctrl+shift+t is pressed, enable translation_inline and fire ui:rerender

View file

@ -35,21 +35,23 @@ class App.Run extends App.Controller
setupWidget: (config, event, el) -> setupWidget: (config, event, el) ->
# start widgets # start widgets
App.Event.trigger( event + ':init') App.Event.trigger(event + ':init')
widgets = App.Config.get( config ) widgets = App.Config.get(config)
if widgets if widgets
for key, widget of widgets for key, widget of widgets
el.append('<div id="' + key + '"></div>') new widget(
new widget( el: el.find("##{key}") ) el: el
App.Event.trigger( event + ':ready') key: key
)
App.Event.trigger(event + ':ready')
class App.Content extends App.Controller class App.Content extends App.ControllerWidgetPermanent
className: 'content flex horizontal' className: 'content flex horizontal'
constructor: -> constructor: ->
super super
Routes = @Config.get( 'Routes' ) Routes = @Config.get('Routes')
for route, callback of Routes for route, callback of Routes
do (route, callback) => do (route, callback) =>
@route(route, (params) -> @route(route, (params) ->
@ -88,11 +90,11 @@ class App.Content extends App.Controller
# execute controller # execute controller
controller = (params) => controller = (params) =>
params.el = @el params.el = @el
new callback( params ) new callback(params)
controller( params ) controller(params)
# scroll to top / remember last screen position # scroll to top / remember last screen position
# @scrollTo( 0, 0, 100 ) # @scrollTo(0, 0, 100)
) )
Spine.Route.setup() Spine.Route.setup()