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, {
17 this._comboName = _.uniqueId('edumed_exercise_hash_');
18 choiceBase.init.call(this);
20 createListView: function(listNode) {
22 return new ListView(this, listNode, {
23 onItemViewAdded: function(itemView) {
24 var radiobox = new RadioView(itemView.node.getAttr('answer') === 'true', el._comboName, function() {
25 itemView.node.document.transaction(function() {
26 itemView.node.getParent('exercise.choice').object.markAsAnswer(itemView.node);
29 description: gettext('Change answer')
34 itemView.addPrefixView(radiobox);
38 onNodeAttrChange: function(event) {
39 if(this.listView.listNode.sameNode(event.meta.node.parent())) {
40 this.listView.getItemView(event.meta.node).prefixView.dom.attr('checked', event.meta.newVal === 'true');
45 var RadioView = function(checked, name, onValueChange) {
46 this.dom = $('<input type="radio" style="float: left; margin-right: 40px;">')
47 .attr('checked', checked)
49 this.dom.on('change', function() {
50 onValueChange(this.checked);