1 define(function(require) {
7 var $ = require('libs/jquery'),
8 _ = require('libs/underscore'),
9 choiceBase = require('./choiceBase'),
10 ListView = require('./list');
13 var choiceSingle = Object.create(choiceBase);
14 _.extend(choiceSingle, {
16 name: gettext('Single Choice'),
18 this._comboName = _.uniqueId('edumed_exercise_hash_');
19 choiceBase.init.call(this);
21 createListView: function(listNode) {
23 return new ListView(this, listNode, {
24 onItemViewAdded: function(itemView) {
25 var radiobox = new RadioView(itemView.node.getAttr('answer') === 'true', el._comboName, function() {
26 itemView.node.document.transaction(function() {
27 itemView.node.getParent('exercise.choice').object.markAsAnswer(itemView.node);
30 description: gettext('Change answer')
35 itemView.addPrefixView(radiobox);
39 onNodeAttrChange: function(event) {
40 if(this.listView.listNode.sameNode(event.meta.node.parent())) {
41 this.listView.getItemView(event.meta.node).prefixView.dom.attr('checked', event.meta.newVal === 'true');
46 var RadioView = function(checked, name, onValueChange) {
47 this.dom = $('<input type="radio" style="float: left; margin-right: 40px;">')
48 .attr('checked', checked)
50 this.dom.on('change', function() {
51 onValueChange(this.checked);