1 define(function(require) {
7 var $ = require('libs/jquery'),
8 _ = require('libs/underscore'),
9 choiceBase = require('./choiceBase'),
10 ListView = require('./list');
13 var choiceMulti = Object.create(choiceBase);
14 _.extend(choiceMulti, {
16 createListView: function(listNode) {
17 return new ListView(this, listNode, {
18 onItemViewAdded: function(itemView) {
19 var checkbox = new CheckboxView(itemView.node.getAttr('answer') === 'true', function(checked) {
20 itemView.node.document.transaction(function() {
21 itemView.node.getParent('exercise.choice').object.setAnswer(itemView.node, checked);
24 description: gettext('Change answer')
28 itemView.addPrefixView(checkbox);
32 onNodeAttrChange: function(event) {
33 if(this.listView.listNode.sameNode(event.meta.node.parent())) {
34 this.listView.getItemView(event.meta.node).prefixView.dom.attr('checked', event.meta.newVal === 'true');
39 var CheckboxView = function(checked, onValueChange) {
40 this.dom = $('<input type="checkbox">')
41 .attr('checked', checked);
42 this.dom.on('click', function() {
43 onValueChange(this.checked);