Skip to content

Instantly share code, notes, and snippets.

@uris77
Created August 23, 2013 19:05
Show Gist options
  • Save uris77/6322867 to your computer and use it in GitHub Desktop.
Save uris77/6322867 to your computer and use it in GitHub Desktop.
Views configured as modules
@RedParrot.module "AttendeeAdmin.CenterRegion", (CenterRegion, App, Backbone, Marionette, $, _) ->
class CenterRegion.Controller extends App.Controllers.Base
initialize: (options) ->
@region = options.region
@attendee = options.attendee
@layout = @getLayout()
@_listenToLayoutEvents()
@show @layout
@modulesOptions = {region: @layout.tabContentRegion, attendee: @attendee}
@_startModule @_getModule('Accountinfo')
getLayout: ->
new App.AttendeeAdmin.CenterRegion.Views.Layout
model: @attendee
## All the modules that represent a tab in the view.
_modules: ->
{
'Accountinfo': App.module('AttendeeAdmin.CenterRegion.Accountinfo'),
'Preferences': App.module('AttendeeAdmin.CenterRegion.Preferences'),
'Schedule': App.module('AttendeeAdmin.CenterRegion.Schedule'),
'Survey': App.module('Question.Main')
}
## Get a module by name. Possible values:
## Accountinfo
## Preferences
## Schedule
_getModule: (moduleName) ->
filter = (value, key) -> key == moduleName
_.find(@_modules(), filter)
## Get all modules that don't match the module name.
_getComplementaryModules: (moduleName) ->
filter = (value, key) -> key != moduleName
_.filter(@_modules(), filter)
## Stop all modules in the list.
_stopModules: (modules) ->
modules.forEach (module)->
module.stop()
## Start the module with the provided options.
_startModule: (module, options=@modulesOptions) ->
module.start(options)
## Listen to events triggered by the layout view.
## We normally handle click events on the tabs here.
_listenToLayoutEvents: ->
@_preferenceTabListener()
@_accountInfoTabListener()
@_scheduleTabListener()
@_surveyTabListener()
_preferenceTabListener: ->
@listenTo @layout, 'attendeeAdmin:showPreferences', =>
@_stopModules @_getComplementaryModules("Preferences")
@_startModule @_getModule("Preferences")
_accountInfoTabListener: ->
@listenTo @layout, 'attendeeAdmin:showAccountInfo', =>
@_stopModules @_getComplementaryModules("Accountinfo")
@_startModule @_getModule("Accountinfo")
_scheduleTabListener: ->
@listenTo @layout, 'attendeeAdmin:showSchedule', =>
@_stopModules @_getComplementaryModules("Schedule")
@_startModule @_getModule("Schedule")
_surveyTabListener: ->
@listenTo @layout, 'attendeeAdmin:showSurvey', =>
@_stopModules @_getComplementaryModules("Survey")
console.info "Start Module Survey: "
@_startModule @_getModule("Survey")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment