|
@@ -2,12 +2,7 @@ class App.Controller extends Spine.Controller
|
|
|
@include App.LogInclude
|
|
|
@include App.RenderScreen
|
|
|
|
|
|
- constructor: (params) ->
|
|
|
-
|
|
|
- # unbind old bindings
|
|
|
- if params && params.el && params.el.unbind
|
|
|
- params.el.unbind()
|
|
|
-
|
|
|
+ constructor: ->
|
|
|
super
|
|
|
|
|
|
# generate controllerId
|
|
@@ -30,11 +25,14 @@ class App.Controller extends Spine.Controller
|
|
|
ajaxId = App.Ajax.request(data)
|
|
|
@ajaxCalls.push ajaxId
|
|
|
|
|
|
- navigate: (location, hideCurrentLocationFromHistory = false) ->
|
|
|
- @log 'debug', "navigate to '#{location}', hide from history '#{hideCurrentLocationFromHistory}'"
|
|
|
+ navigate: (location, params = {}) ->
|
|
|
+ @log 'debug', "navigate to '#{location}'"
|
|
|
+ @log 'debug', "navigate hide from history '#{params.hideCurrentLocationFromHistory}'" if params.hideCurrentLocationFromHistory
|
|
|
+ @el.empty() if params.emptyEl
|
|
|
+ @el.remove() if params.removeEl
|
|
|
|
|
|
# hide current location from browser history, allow to use back button in browser
|
|
|
- if hideCurrentLocationFromHistory
|
|
|
+ if params.hideCurrentLocationFromHistory
|
|
|
if window.history
|
|
|
history = App.Config.get('History')
|
|
|
oldLocation = history[history.length-2]
|
|
@@ -45,22 +43,14 @@ class App.Controller extends Spine.Controller
|
|
|
preventDefault: (e) ->
|
|
|
e.preventDefault()
|
|
|
|
|
|
- bind: (event, callback) =>
|
|
|
+ controllerBind: (event, callback) =>
|
|
|
App.Event.bind(
|
|
|
event
|
|
|
callback
|
|
|
@controllerId
|
|
|
)
|
|
|
|
|
|
- one: (event, callback) =>
|
|
|
- App.Event.bind(
|
|
|
- event
|
|
|
- callback
|
|
|
- @controllerId
|
|
|
- true
|
|
|
- )
|
|
|
-
|
|
|
- unbind: (event, callback) =>
|
|
|
+ controllerUnbind: (event, callback) =>
|
|
|
App.Event.unbind(
|
|
|
event
|
|
|
callback
|
|
@@ -85,6 +75,16 @@ class App.Controller extends Spine.Controller
|
|
|
App.Interval.clearLevel(@controllerId)
|
|
|
@abortAjaxCalls()
|
|
|
|
|
|
+ # release bindings
|
|
|
+ if @el
|
|
|
+ @el.undelegate()
|
|
|
+ @el.unbind()
|
|
|
+ @el.empty()
|
|
|
+
|
|
|
+ # release spine bindings (see release() of spine.coffee)
|
|
|
+ @unbind()
|
|
|
+ @stopListening()
|
|
|
+
|
|
|
abortAjaxCalls: =>
|
|
|
if !@ajaxCalls
|
|
|
return
|
|
@@ -125,11 +125,11 @@ class App.Controller extends Spine.Controller
|
|
|
|
|
|
# add @notify method to create notification
|
|
|
notify: (data) ->
|
|
|
- App.Event.trigger 'notify', data
|
|
|
+ App.Event.trigger('notify', data)
|
|
|
|
|
|
# add @notifyDesktop method to create desktop notification
|
|
|
notifyDesktop: (data) ->
|
|
|
- App.Event.trigger 'notifyDesktop', data
|
|
|
+ App.Event.trigger('notifyDesktop', data)
|
|
|
|
|
|
# add @navupdate method to update navigation
|
|
|
navupdate: (url, force = false) ->
|
|
@@ -137,17 +137,7 @@ class App.Controller extends Spine.Controller
|
|
|
# ignore navupdate until #clues are gone
|
|
|
return if !force && window.location.hash is '#clues'
|
|
|
|
|
|
- App.Event.trigger 'navupdate', url
|
|
|
-
|
|
|
- # show navigation
|
|
|
- navShow: ->
|
|
|
- return if $('#navigation').is(':visible')
|
|
|
- $('#navigation').removeClass('hide')
|
|
|
-
|
|
|
- # hide navigation
|
|
|
- navHide: ->
|
|
|
- return if !$('#navigation').is(':visible')
|
|
|
- $('#navigation').addClass('hide')
|
|
|
+ App.Event.trigger('navupdate', url)
|
|
|
|
|
|
updateNavMenu: =>
|
|
|
delay = ->
|
|
@@ -402,340 +392,3 @@ class App.Controller extends Spine.Controller
|
|
|
return true
|
|
|
|
|
|
throw 'Cant reload page!'
|
|
|
-
|
|
|
-class App.ControllerPermanent extends App.Controller
|
|
|
- constructor: ->
|
|
|
- if @requiredPermission
|
|
|
- @permissionCheckRedirect(@requiredPermission, true)
|
|
|
-
|
|
|
- super
|
|
|
-
|
|
|
- @navShow()
|
|
|
-
|
|
|
-class App.ControllerSubContent extends App.Controller
|
|
|
- constructor: ->
|
|
|
- if @requiredPermission
|
|
|
- @permissionCheckRedirect(@requiredPermission)
|
|
|
-
|
|
|
- super
|
|
|
-
|
|
|
- show: =>
|
|
|
- if @genericController && @genericController.show
|
|
|
- @genericController.show()
|
|
|
- return if !@header
|
|
|
- @title @header, true
|
|
|
-
|
|
|
- hide: =>
|
|
|
- if @genericController && @genericController.hide
|
|
|
- @genericController.hide()
|
|
|
-
|
|
|
-class App.ControllerContent extends App.Controller
|
|
|
- constructor: ->
|
|
|
- if @requiredPermission
|
|
|
- @permissionCheckRedirect(@requiredPermission)
|
|
|
-
|
|
|
- super
|
|
|
-
|
|
|
- # hide tasks
|
|
|
- App.TaskManager.hideAll()
|
|
|
- $('#content').removeClass('hide').removeClass('active')
|
|
|
- @navShow()
|
|
|
-
|
|
|
-class App.ControllerModal extends App.Controller
|
|
|
- authenticateRequired: false
|
|
|
- backdrop: true
|
|
|
- keyboard: true
|
|
|
- large: false
|
|
|
- small: false
|
|
|
- veryLarge: false
|
|
|
- head: '?'
|
|
|
- autoFocusOnFirstInput: true
|
|
|
- container: null
|
|
|
- buttonClass: 'btn--success'
|
|
|
- centerButtons: []
|
|
|
- leftButtons: []
|
|
|
- buttonClose: true
|
|
|
- buttonCancel: false
|
|
|
- buttonCancelClass: 'btn--text btn--subtle'
|
|
|
- buttonSubmit: true
|
|
|
- includeForm: true
|
|
|
- headPrefix: ''
|
|
|
- shown: true
|
|
|
- closeOnAnyClick: false
|
|
|
- initalFormParams: {}
|
|
|
- initalFormParamsIgnore: false
|
|
|
- showTrySupport: false
|
|
|
- showTryMax: 10
|
|
|
- showTrydelay: 1000
|
|
|
-
|
|
|
- events:
|
|
|
- 'submit form': 'submit'
|
|
|
- 'click .js-submit:not(.is-disabled)': 'submit'
|
|
|
- 'click .js-cancel': 'cancel'
|
|
|
- 'click .js-close': 'cancel'
|
|
|
-
|
|
|
- className: 'modal fade'
|
|
|
-
|
|
|
- constructor: ->
|
|
|
- super
|
|
|
- @showTryCount = 0
|
|
|
-
|
|
|
- if @authenticateRequired
|
|
|
- return if !@authenticateCheckRedirect()
|
|
|
-
|
|
|
- # rerender view, e. g. on langauge change
|
|
|
- @bind('ui:rerender', =>
|
|
|
- @update()
|
|
|
- 'modal'
|
|
|
- )
|
|
|
- if @shown
|
|
|
- @render()
|
|
|
-
|
|
|
- showDelayed: =>
|
|
|
- delay = =>
|
|
|
- @showTryCount += 1
|
|
|
- @render()
|
|
|
- @delay(delay, @showTrydelay)
|
|
|
-
|
|
|
- modalAlreadyExists: ->
|
|
|
- return true if $('.modal').length > 0
|
|
|
- false
|
|
|
-
|
|
|
- content: ->
|
|
|
- 'You need to implement a one @content()!'
|
|
|
-
|
|
|
- update: =>
|
|
|
- if @message
|
|
|
- content = App.i18n.translateContent(@message)
|
|
|
- else if @contentInline
|
|
|
- content = @contentInline
|
|
|
- else
|
|
|
- content = @content()
|
|
|
- modal = $(App.view('modal')(
|
|
|
- head: @head
|
|
|
- headPrefix: @headPrefix
|
|
|
- message: @message
|
|
|
- detail: @detail
|
|
|
- buttonClose: @buttonClose
|
|
|
- buttonCancel: @buttonCancel
|
|
|
- buttonCancelClass: @buttonCancelClass
|
|
|
- buttonSubmit: @buttonSubmit
|
|
|
- buttonClass: @buttonClass
|
|
|
- centerButtons: @centerButtons
|
|
|
- leftButtons: @leftButtons
|
|
|
- includeForm: @includeForm
|
|
|
- ))
|
|
|
- modal.find('.modal-body').html(content)
|
|
|
- if !@initRenderingDone
|
|
|
- @initRenderingDone = true
|
|
|
- @html(modal)
|
|
|
- else
|
|
|
- @$('.modal-dialog').replaceWith(modal)
|
|
|
- @post()
|
|
|
-
|
|
|
- post: ->
|
|
|
- # nothing
|
|
|
-
|
|
|
- element: =>
|
|
|
- @el
|
|
|
-
|
|
|
- render: =>
|
|
|
- if @showTrySupport is true && @modalAlreadyExists() && @showTryCount <= @showTryMax
|
|
|
- @showDelayed()
|
|
|
- return
|
|
|
-
|
|
|
- @initalFormParamsIgnore = false
|
|
|
-
|
|
|
- if @buttonSubmit is true
|
|
|
- @buttonSubmit = 'Submit'
|
|
|
- if @buttonCancel is true
|
|
|
- @buttonCancel = 'Cancel & Go Back'
|
|
|
-
|
|
|
- @update()
|
|
|
-
|
|
|
- if @container
|
|
|
- @el.addClass('modal--local')
|
|
|
- if @veryLarge
|
|
|
- @el.addClass('modal--veryLarge')
|
|
|
- if @large
|
|
|
- @el.addClass('modal--large')
|
|
|
- if @small
|
|
|
- @el.addClass('modal--small')
|
|
|
-
|
|
|
- @el
|
|
|
- .on(
|
|
|
- 'show.bs.modal': @localOnShow
|
|
|
- 'shown.bs.modal': @localOnShown
|
|
|
- 'hide.bs.modal': @localOnClose
|
|
|
- 'hidden.bs.modal': @localOnClosed
|
|
|
- 'dismiss.bs.modal': @localOnCancel
|
|
|
- ).modal(
|
|
|
- keyboard: @keyboard
|
|
|
- show: true
|
|
|
- backdrop: @backdrop
|
|
|
- container: @container
|
|
|
- )
|
|
|
-
|
|
|
- if @closeOnAnyClick
|
|
|
- @el.on('click', =>
|
|
|
- @close()
|
|
|
- )
|
|
|
-
|
|
|
- close: (e) =>
|
|
|
- if e
|
|
|
- e.preventDefault()
|
|
|
- @initalFormParamsIgnore = true
|
|
|
- @el.modal('hide')
|
|
|
-
|
|
|
- formParams: =>
|
|
|
- if @container
|
|
|
- return @formParam(@container.find('.modal form'))
|
|
|
- return @formParam(@$('.modal form'))
|
|
|
-
|
|
|
- showAlert: (message, suffix = 'danger') ->
|
|
|
- alert = $('<div>')
|
|
|
- .addClass("alert alert--#{suffix}")
|
|
|
- .text(message)
|
|
|
-
|
|
|
- @$('.modal-alerts-container').html(alert)
|
|
|
-
|
|
|
- clearAlerts: ->
|
|
|
- @$('.modal-alerts-container').empty()
|
|
|
-
|
|
|
- localOnShow: (e) =>
|
|
|
- @onShow(e)
|
|
|
-
|
|
|
- onShow: (e) ->
|
|
|
- # do nothing
|
|
|
-
|
|
|
- localOnShown: (e) =>
|
|
|
- @onShown(e)
|
|
|
-
|
|
|
- onShown: (e) =>
|
|
|
- if @autoFocusOnFirstInput
|
|
|
-
|
|
|
- # select generated form
|
|
|
- form = @$('.form-group').first()
|
|
|
-
|
|
|
- # if not exists, use whole @el
|
|
|
- if !form.get(0)
|
|
|
- form = @el
|
|
|
-
|
|
|
- # focus first input, select or textarea
|
|
|
- form.find('input:not([disabled]):not([type="hidden"]):not(".btn"), select:not([disabled]), textarea:not([disabled])').first().focus()
|
|
|
-
|
|
|
- @initalFormParams = @formParams()
|
|
|
-
|
|
|
- localOnClose: (e) =>
|
|
|
- diff = difference(@initalFormParams, @formParams())
|
|
|
- if @initalFormParamsIgnore is false && !_.isEmpty(diff)
|
|
|
- if !confirm(App.i18n.translateContent('The form content has been changed. Do you want to close it and lose your changes?'))
|
|
|
- e.preventDefault()
|
|
|
- return
|
|
|
- @onClose(e)
|
|
|
-
|
|
|
- onClose: ->
|
|
|
- # do nothing
|
|
|
-
|
|
|
- localOnClosed: (e) =>
|
|
|
- @onClosed(e)
|
|
|
- @el.modal('remove')
|
|
|
-
|
|
|
- onClosed: (e) ->
|
|
|
- # do nothing
|
|
|
-
|
|
|
- localOnCancel: (e) =>
|
|
|
- @onCancel(e)
|
|
|
-
|
|
|
- onCancel: (e) ->
|
|
|
- # do nothing
|
|
|
-
|
|
|
- cancel: (e) =>
|
|
|
- @close(e)
|
|
|
- @onCancel(e)
|
|
|
-
|
|
|
- onSubmit: (e) ->
|
|
|
- # do nothing
|
|
|
-
|
|
|
- submit: (e) =>
|
|
|
- e.stopPropagation()
|
|
|
- e.preventDefault()
|
|
|
- @clearAlerts()
|
|
|
- @onSubmit(e)
|
|
|
-
|
|
|
- startLoading: =>
|
|
|
- @$('.modal-body').addClass('hide')
|
|
|
- @$('.modal-loader').removeClass('hide')
|
|
|
-
|
|
|
- stopLoading: =>
|
|
|
- @$('.modal-body').removeClass('hide')
|
|
|
- @$('.modal-loader').addClass('hide')
|
|
|
-
|
|
|
-class App.SessionMessage extends App.ControllerModal
|
|
|
- showTrySupport: true
|
|
|
-
|
|
|
- onCancel: (e) =>
|
|
|
- if @forceReload
|
|
|
- @windowReload(e)
|
|
|
-
|
|
|
- onClose: (e) =>
|
|
|
- if @forceReload
|
|
|
- @windowReload(e)
|
|
|
-
|
|
|
- onSubmit: (e) =>
|
|
|
- if @forceReload
|
|
|
- @windowReload(e)
|
|
|
- else
|
|
|
- @close()
|
|
|
-
|
|
|
-class App.UpdateHeader extends App.Controller
|
|
|
- constructor: ->
|
|
|
- super
|
|
|
-
|
|
|
- # subscribe and reload data / fetch new data if triggered
|
|
|
- @subscribeId = @genericObject.subscribe(@render)
|
|
|
-
|
|
|
- release: =>
|
|
|
- App[ @genericObject.constructor.className ].unsubscribe(@subscribeId)
|
|
|
-
|
|
|
- render: (genericObject) =>
|
|
|
- @el.find('.page-header h1').html(genericObject.displayName())
|
|
|
-
|
|
|
-
|
|
|
-class App.UpdateTastbar extends App.Controller
|
|
|
- constructor: ->
|
|
|
- super
|
|
|
-
|
|
|
- # subscribe and reload data / fetch new data if triggered
|
|
|
- @subscribeId = @genericObject.subscribe(@update)
|
|
|
-
|
|
|
- release: =>
|
|
|
- App[ @genericObject.constructor.className ].unsubscribe(@subscribeId)
|
|
|
-
|
|
|
- update: (genericObject) =>
|
|
|
-
|
|
|
- # update taskbar with new meta data
|
|
|
- App.TaskManager.touch(@taskKey)
|
|
|
-
|
|
|
-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
|