Changeset 511 for Dev/trunk/src/client/qed-client/model/widgets/questions/MultipleChoiceInputWidget.js
- Timestamp:
- 03/13/14 00:44:08 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/src/client/qed-client/model/widgets/questions/MultipleChoiceInputWidget.js
r510 r511 1 1 define([ 2 "dijit/_Container", 3 "dijit/_TemplatedMixin", 4 "dijit/_WidgetBase", 5 "dijit/_WidgetsInTemplateMixin", 2 "../../../widgets/_ComplexValueWidget", 6 3 "dijit/form/CheckBox", 4 "dijit/form/RadioButton", 5 "dijit/form/TextBox", 7 6 "dojo/_base/array", 8 7 "dojo/_base/declare", 8 "dojo/_base/lang", 9 9 "dojo/dom-construct", 10 10 "dojo/text!./templates/MultipleChoiceInputWidget.html" 11 ], function(_Co ntainer, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, CheckBox, array, declare, domConstruct, template) {12 return declare([_ WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{11 ], function(_ComplexValueWidget, CheckBox, RadioButton, TextBox, array, declare, lang, domConstruct, template) { 12 return declare([_ComplexValueWidget],{ 13 13 templateString: template, 14 baseClass: 'qedMultipleChoiceWidget', 15 allowMultiple: false, 14 16 startup: function() { 15 17 if ( this._started ) { return; } 16 18 this.inherited(arguments); 17 19 20 var Ctor = this.allowMultiple ? CheckBox : RadioButton; 21 22 var input; 18 23 domConstruct.empty(this.domNode); 19 24 array.forEach(this.items, function(item){ 20 25 var div = domConstruct.create("div", { 21 26 }, this.domNode, "last"); 22 var input = new CheckBox({23 name: this.code + item.subcode,24 value: 127 input = new Ctor({ 28 name: this.code + (this.allowMultiple?item.subcode:this.subcode), 29 value: this.allowMultiple ? 1 : item.value 25 30 }).placeAt(div); 26 31 var label = domConstruct.create("label",{ … … 29 34 }, div); 30 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 } 31 69 } 32 70 });
Note: See TracChangeset
for help on using the changeset viewer.