1 | define([ |
---|
2 | "../../../widgets/_ComplexValueWidget", |
---|
3 | "dijit/form/CheckBox", |
---|
4 | "dijit/form/RadioButton", |
---|
5 | "dijit/form/TextBox", |
---|
6 | "dojo/_base/array", |
---|
7 | "dojo/_base/declare", |
---|
8 | "dojo/_base/lang", |
---|
9 | "dojo/dom-construct", |
---|
10 | "dojo/text!./templates/MultipleChoiceInputWidget.html" |
---|
11 | ], function(_ComplexValueWidget, CheckBox, RadioButton, TextBox, array, declare, lang, domConstruct, template) { |
---|
12 | return declare([_ComplexValueWidget],{ |
---|
13 | templateString: template, |
---|
14 | baseClass: 'qedMultipleChoiceWidget', |
---|
15 | allowMultiple: false, |
---|
16 | startup: function() { |
---|
17 | if ( this._started ) { return; } |
---|
18 | this.inherited(arguments); |
---|
19 | |
---|
20 | var Ctor = this.allowMultiple ? CheckBox : RadioButton; |
---|
21 | |
---|
22 | var input; |
---|
23 | domConstruct.empty(this.domNode); |
---|
24 | array.forEach(this.items, function(item){ |
---|
25 | var div = domConstruct.create("div", { |
---|
26 | }, this.domNode, "last"); |
---|
27 | input = new Ctor({ |
---|
28 | name: this.code + (this.allowMultiple?item.subcode:this.subcode), |
---|
29 | value: this.allowMultiple ? 1 : item.value |
---|
30 | }).placeAt(div); |
---|
31 | var label = domConstruct.create("label",{ |
---|
32 | 'for': input.id, |
---|
33 | innerHTML: item.text |
---|
34 | }, div); |
---|
35 | }, this); |
---|
36 | |
---|
37 | if ( this.lastItemIsOpen && input ) { |
---|
38 | this.lastItem = input; |
---|
39 | var openItemDiv = domConstruct.create("div", { |
---|
40 | }, this.domNode, "last"); |
---|
41 | this.openItemTextBox = new TextBox({ |
---|
42 | name: this.code + this.lastItemIsOpen.subcode, |
---|
43 | disabled: true, |
---|
44 | readOnly: true, |
---|
45 | 'class': 'openItem' |
---|
46 | }); |
---|
47 | this.openItemTextBox.placeAt(openItemDiv); |
---|
48 | this.own(this.lastItem.on( |
---|
49 | 'change',lang.hitch(this,'_handleOpenItemChange'))); |
---|
50 | } |
---|
51 | }, |
---|
52 | _setDisabledAttr: function() { |
---|
53 | this.inherited(arguments); |
---|
54 | this._handleOpenItemChange(); |
---|
55 | }, |
---|
56 | _setReadOnlyAttr: function() { |
---|
57 | this.inherited(arguments); |
---|
58 | this._handleOpenItemChange(); |
---|
59 | }, |
---|
60 | _handleOpenItemChange: function() { |
---|
61 | if ( this.lastItem ) { |
---|
62 | var value = this.allowMultiple ? |
---|
63 | this.lastItem.get('value') : |
---|
64 | this.lastItem.get('value')[0]; |
---|
65 | var enabled = !(this.readOnly || this.disabled) && value; |
---|
66 | this.openItemTextBox.set('disabled',!enabled); |
---|
67 | this.openItemTextBox.set('readOnly',!enabled); |
---|
68 | } |
---|
69 | } |
---|
70 | }); |
---|
71 | }); |
---|