Last active
August 29, 2015 13:56
-
-
Save mplatts/9090676 to your computer and use it in GitHub Desktop.
alter toJSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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