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 name: 'True or False',
18 createListView: function(listNode) {
19 return new ListView(this, listNode, {
20 onItemViewAdded: function(itemView) {
21 var switchView = new Switch(itemView.node.getAttr('answer') === 'true', function(choice) {
22 itemView.node.document.transaction(function() {
23 itemView.node.getParent('exercise.choice').object.setAnswer(itemView.node, choice);
26 description: gettext('Change answer')
30 itemView.addPrefixView(switchView);
36 var Switch = function(checked, onValueChange) {
37 this.dom = $(_.template(switchTemplate)());
38 var trueBtn = this.dom.find('.true'),
39 falseBtn = this.dom.find('.false');
41 trueBtn.on('click', function() {
42 trueBtn.addClass('selected');
43 falseBtn.removeClass('selected');
46 this.dom.find('.false').on('click', function() {
47 falseBtn.addClass('selected');
48 trueBtn.removeClass('selected');
51 trueBtn.toggleClass('selected', checked);
52 falseBtn.toggleClass('selected', !checked);