Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
alter toJSON
class App.Models.Assignment.AssignmentTopic extends Backbone.Model
loading: -> @get('loading') || false
questionsRemainingCount: -> @get('questions_count') - @get('questions_answered_count')
questionsRemaining: -> @get('status') == 'try_it_again' || @get('status') == 'in_progress'
className: -> (@get('status') || '').replace(/_/g, '-')
scores: ->
if !@get('scores') || @get('scores').length == 0
i = @get('questions_count')
_([0..i]).map(-> { success: false, className: '' })
else
_(@get('scores')).map((score) -> {
success: score
className: if score then 'success' else 'failure'
})
iconClassName: ->
if @get('status') == 'not_started' || @get('status') == 'todo'
'sprite-progress-todo'
else if @get('status') == 'in_progress'
'sprite-progress-inprogress'
else if @get('status') == 'mastered'
'sprite-progress-mastered'
else if @get('status') == 'try_it_again'
'sprite-progress-tryitagain'
mastered: ->
@get('status') == 'mastered'
toJSON: ->
_(super()).extend
loading: @loading()
questions_remaining_count: @questionsRemainingCount()
questions_remaining: @questionsRemaining()
class_name: @className()
mastered: @mastered()
icon_class_name: @iconClassName()
scores: @scores()
# This view represents a single topic within an assignment.
#
class App.Views.Assignment.AssignmentTopic extends Backbone.View
template: Tpl["class/assignment_topic"]
className: 'assignment-topic stackable col-sm-6 col-md-4'
initialize: ->
@listenTo(@model, "change", @render)
remove: ->
@$el.remove()
render: =>
@$el.html @template(@model.toJSON())
if @model.loading()
@$('.stackable-body').addClass('loading-small')
else
@$('.stackable-body').removeClass('loading-small')
@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment