1 define(function(require) {
7 var $ = require('libs/jquery'),
8 _ = require('libs/underscore'),
9 choiceBase = require('./choiceBase'),
10 switchTemplate = require('libs/text!./trueOrFalseSwitch.html'),
11 ListView = require('./list');
14 var trueOrFalse = Object.create(choiceBase);
15 _.extend(trueOrFalse, {
16 type: 'true-or-false',
17 createListView: function(listNode) {
18 return new ListView(this, listNode, {
19 onItemViewAdded: function(itemView) {
20 var switchView = new Switch(itemView.node.getAttr('answer') === 'true', function(choice) {
21 itemView.node.document.transaction(function() {
22 itemView.node.getParent('exercise.choice').object.setAnswer(itemView.node, choice);
25 description: gettext('Change answer')
29 itemView.addPrefixView(switchView);
35 var Switch = function(checked, onValueChange) {
36 this.dom = $(_.template(switchTemplate)());
37 var trueBtn = this.dom.find('.true'),
38 falseBtn = this.dom.find('.false');
40 trueBtn.on('click', function() {
41 trueBtn.addClass('selected');
42 falseBtn.removeClass('selected');
45 this.dom.find('.false').on('click', function() {
46 falseBtn.addClass('selected');
47 trueBtn.removeClass('selected');
50 trueBtn.toggleClass('selected', checked);
51 falseBtn.toggleClass('selected', !checked);