Skip to content

Instantly share code, notes, and snippets.

@spencerfdavis
Created May 13, 2014 17:26
Show Gist options
  • Save spencerfdavis/7ef924fe8e4b76c0b5f9 to your computer and use it in GitHub Desktop.
Save spencerfdavis/7ef924fe8e4b76c0b5f9 to your computer and use it in GitHub Desktop.
class Rise.Views.Teach.Courses.Content extends Backbone.Marionette.Layout
el: '.course--content'
ui:
$addLesson: '.add--lesson'
$addSection: '.add--section'
$reorderButton: '.reorder--items'
regions:
items: '#course--items'
contentModal: '#lesson--upload--content--modal'
events:
'click @ui.$addLesson': '_handleAddLessonClick'
'click @ui.$addSection': '_handleAddSectionClick'
'click @ui.$reorderButton': '_handleReorderClick'
collectionEvents:
'add': '_handleCollectionAdd'
'remove': '_handleCollectionRemove'
MODAL_TYPES:
'Content::Document': 'UploadDocumentModal'
'Content::Media': 'UploadMediaModal'
'Content::Link': 'LinkContentModal'
initialize: ->
@bindUIElements()
@items.attachView(new Rise.Views.Teach.Courses.CourseItems(collection: @collection))
@items.currentView.on('itemview:add:content:initialize', @_handleAddContentInitialize)
contentModalView: (model) ->
Rise.Views.Teach.Lessons[@MODAL_TYPES[model.get('content_type')]]
toggleReorderText: ->
if @ui.$reorderButton.hasClass('btn--success')
@ui.$reorderButton.text("Done")
else
@ui.$reorderButton.text("Reorder")
_handleAddLessonClick: (event) ->
@model.items.create(new Rise.Models.Lesson(position: @model.items.length))
_handleAddSectionClick: (event) ->
@model.items.create(new Rise.Models.Section(position: @model.items.length))
_handleReorderClick: (event) ->
event.preventDefault()
@ui.$reorderButton
.toggleClass('btn--base')
.toggleClass('btn--success')
@toggleReorderText()
@ui.$addSection.toggleDisabled()
@ui.$addLesson.toggleDisabled()
@items.currentView.toggleReorder()
_handleAddContentInitialize: (lesson) =>
MediaUploader.upload
el: '#upload-modal'
events:
'uploaded': (data) ->
console.log data.url
importerConfig:
endpoint: 'http://authoring-importer.herokuapp.com/uploads'
_handleCollectionAdd: ->
@ui.$reorderButton.removeClass('hidden') if @collection.length > 1
_handleCollectionRemove: ->
@ui.$reorderButton.addClass('hidden') if @collection.length < 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment