Created
July 19, 2011 07:44
-
-
Save stefanoverna/1091618 to your computer and use it in GitHub Desktop.
This file contains 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
App.Choice = SC.Record.extend({ | |
label: SC.Record.attr(String, { | |
isRequired: YES | |
}), | |
question: SC.Record.toOne("App.Question", { | |
isMaster: NO | |
}), | |
isSelected: NO | |
}); | |
App.Question = SC.Record.extend({ | |
question: SC.Record.attr(String, { | |
isRequired: YES | |
}), | |
quiz: SC.Record.toOne("App.Quiz", { | |
isMaster: NO | |
}), | |
choices: SC.Record.toMany("App.Choice", { | |
inverse: 'question', | |
isMaster: YES | |
}), | |
correctAnswers: SC.Record.toMany("App.Choice", { | |
inverse: 'question', | |
isMaster: YES | |
}) | |
}); | |
App.Quiz = SC.Record.extend({ | |
title: SC.Record.attr(String, { | |
isRequired: YES | |
}), | |
questions: SC.Record.toMany("App.Question", { | |
inverse: 'quiz', | |
isMaster: YES | |
}) | |
}); | |
App.quizController = SC.ArrayController.create({ | |
currentIndex: null, | |
currentQuestion: (function() { | |
return this.get('content').objectAt(this.get('currentIndex')); | |
}).property('currentIndex', 'content'), | |
nextQuestion: function() { | |
return this.set('currentIndex', this.get('currentIndex') + 1); | |
}, | |
previousQuestion: function() { | |
return this.set('currentIndex', this.get('currentIndex') - 1); | |
}, | |
nextDisabled: function() { | |
return this.get('currentIndex') + 1 === this.getPath('length') || !this.getPath("App.currentQuestion.isFilled"); | |
}, | |
previousDisabled: function() { | |
return this.get('currentIndex') === 0; | |
}, | |
progressString: (function() { | |
return "" + (this.get('currentIndex')) + "/" + (this.getPath('length')); | |
}).property('currentIndex') | |
}); | |
App.currentQuestionController = SC.ObjectController.create({ | |
contentBinding: 'App.quizController.currentQuestion' | |
}); | |
App.currentChoicesController = SC.ArrayController.create({ | |
contentBinding: 'App.currentQuestionController.choices', | |
allFilled: (function() { | |
console.log("111"); | |
return this.get('content').filterProperty("isSelected", true).get('length') === this.getPath('correctAnswers.length'); | |
}).property("@each.isSelected") | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment