Implement viewStack to support nested view
This commit is contained in:
@@ -2,9 +2,28 @@
|
||||
Models: {}
|
||||
Views: {}
|
||||
|
||||
viewStack: []
|
||||
|
||||
start: ->
|
||||
new CMS.Views.Course el: $('section.main-container')
|
||||
|
||||
replaceView: (view) ->
|
||||
@viewStack = [view]
|
||||
CMS.trigger('content.show', view)
|
||||
|
||||
pushView: (view) ->
|
||||
@viewStack.push(view)
|
||||
CMS.trigger('content.show', view)
|
||||
|
||||
popView: ->
|
||||
@viewStack.pop()
|
||||
if _.isEmpty(@viewStack)
|
||||
CMS.trigger('content.hide')
|
||||
else
|
||||
view = _.last(@viewStack)
|
||||
CMS.trigger('content.show', view)
|
||||
view.delegateEvents()
|
||||
|
||||
_.extend CMS, Backbone.Events
|
||||
|
||||
$ ->
|
||||
|
||||
@@ -3,8 +3,8 @@ class CMS.Views.Course extends Backbone.View
|
||||
@$('#weeks > li').each (index, week) =>
|
||||
new CMS.Views.Week el: week, height: @maxWeekHeight()
|
||||
|
||||
CMS.on('showContent', @showContent)
|
||||
CMS.on('hideContent', @hideContent)
|
||||
CMS.on('content.show', @showContent)
|
||||
CMS.on('content.hide', @hideContent)
|
||||
|
||||
showContent: (subview) =>
|
||||
$('body').addClass('content')
|
||||
|
||||
@@ -6,4 +6,4 @@ class CMS.Views.Module extends Backbone.View
|
||||
@model = new CMS.Models.Module(id: @$el.data('id'), type: @$el.data('type'))
|
||||
|
||||
edit: =>
|
||||
CMS.trigger('showContent', new CMS.Views.ModuleEdit(model: @model))
|
||||
CMS.replaceView(new CMS.Views.ModuleEdit(model: @model))
|
||||
|
||||
@@ -4,10 +4,10 @@ class CMS.Views.ModuleEdit extends Backbone.View
|
||||
|
||||
events:
|
||||
'click .cancel': 'cancel'
|
||||
# 'click .module-edit', 'edit'
|
||||
|
||||
initialize: ->
|
||||
CMS.trigger 'module.edit'
|
||||
@$el.append($("""<div id="#{@model.get('id')}">""").load(@model.editUrl()))
|
||||
|
||||
cancel: ->
|
||||
CMS.trigger 'hideContent'
|
||||
CMS.popView()
|
||||
|
||||
@@ -11,11 +11,11 @@ class CMS.Views.Week extends Backbone.View
|
||||
@$('.modules .module').each ->
|
||||
new CMS.Views.Module el: this
|
||||
|
||||
CMS.on('showContent', @resetHeight)
|
||||
CMS.on('hideContent', @setHeight)
|
||||
CMS.on('content.show', @resetHeight)
|
||||
CMS.on('content.hide', @setHeight)
|
||||
|
||||
edit: =>
|
||||
CMS.trigger('showContent', new CMS.Views.WeekEdit(model: @model))
|
||||
CMS.replaceView(new CMS.Views.WeekEdit(model: @model))
|
||||
|
||||
setHeight: =>
|
||||
@$el.height(@options.height)
|
||||
|
||||
Reference in New Issue
Block a user