Added support of permanent and on demand widgets.
This commit is contained in:
parent
228b37f372
commit
62ad616f75
7 changed files with 53 additions and 31 deletions
|
@ -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('<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
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class App.Navigation extends App.Controller
|
||||
class App.Navigation extends App.ControllerWidgetPermanent
|
||||
className: 'navigation vertical'
|
||||
|
||||
constructor: ->
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class Widget extends App.Controller
|
||||
class Widget extends App.ControllerWidgetPermanent
|
||||
events:
|
||||
'submit #chat_form': 'submitMessage'
|
||||
'focusin [name=chat_message]': 'focusIn'
|
||||
|
|
|
@ -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' )
|
|
@ -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' )
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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('<div id="' + key + '"></div>')
|
||||
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()
|
||||
|
|
Loading…
Reference in a new issue