source: Dev/trunk/client/qed/widgets/MultipleChoiceWidget.js @ 433

Last change on this file since 433 was 427, checked in by hendrikvanantwerpen, 12 years ago

Display content elements on their own line.
Use className iso 'class' in node creation.
Added required version field to package.json.

File size: 3.2 KB
RevLine 
[288]1define(['dojo/_base/declare','dojo/_base/array','dojo/_base/lang',
2    'dojo/dom-construct','dijit/registry','dijit/_WidgetBase',
3    'dijit/_TemplatedMixin','dijit/_WidgetsInTemplateMixin','dijit/_Container',
4    'dojo/text!./templates/MultipleChoiceWidget.html',
[426]5    'dijit/form/RadioButton','dijit/form/CheckBox','dijit/form/TextBox','dijit/form/Button'
6], function(declare,array,lang,domConstruct,registry,_WidgetBase,_TemplatedMixin,
7    _WidgetsInTemplateMixin,_Container, templateString,RadioButton,CheckBox,TextBox,Button){
8    return declare([_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container],{
9        templateString: templateString,
10        multiple: true,
11        baseClass: 'rftMultipleChoiceWidget',
12       
13        allowMultiple: false,
14        name: '',
15        value: null,
16       
17        _widgetCache: null,
18        constuctor: function() {
19            this.inherited(arguments);
20            this.value = [];
21            this._widgetCache = {};
22        },
23        _setValueAttr: function(value) {
24            this.reset();
25            this.value = value;
26            array.forEach(this.value,lang.hitch(this,function(val){
27                this._addRow(val);
28            }));
29        },
30        _getValueAttr: function() {
31            var value = [];
32            registry.findWidgets(this.domNode).forEach(function(w){
33                if ( w.isInstanceOf(TextBox) ) { value.push(w.get('value')); }
34            });
35            this.value = value;
36            return value;
37        },
38        reset: function() {
39            this._removeWidgetsBelowNode(this.rows);
40            domConstruct.empty(this.rows);
41        },
42        _onAddRow: function() {
43            this._addRow();
44        },
45        _addRow: function(value,tagRow,pos) {
[427]46            var row = domConstruct.create('div',{className:'row'});
[426]47            if ( this.allowMultiple ) {
48                new CheckBox({
[288]49                    name:this.name,
[427]50                    className:'rowBox',
[426]51                    disabled: this.mode === 'edit'
[288]52                }).placeAt(row);
[426]53            } else {
54                new RadioButton({
55                    name:this.name,
[427]56                    className:'rowBox',
[426]57                    disabled: this.mode === 'edit'
[288]58                }).placeAt(row);
59            }
[426]60            new TextBox({
61                name:this.name,
62                value:value || '',
[427]63                className:'rowText'
[426]64            }).placeAt(row);
65            new Button({
66                label:'-',
[427]67                className:'rowBtn',
[426]68                onClick:lang.hitch(this,'_removeNodeWithWidgets',row)
69            }).placeAt(row);
70            new Button({
71                label:'+',
[427]72                className:'rowBtn',
[426]73                onClick:lang.hitch(this,'_addRow','',row,'before')
74            }).placeAt(row);
75            domConstruct.place(row,tagRow || this.rows,pos||'last');
76        },
77        _removeNodeWithWidgets: function(node) {
78            this._removeWidgetsBelowNode(node);
79            domConstruct.destroy(node);
80        },
81        _removeWidgetsBelowNode: function(node) {
82            registry.findWidgets(node).forEach(function(w){
83                w.destroyRecursive();
84            });
85        },
86        _onRowChange: function(/*row*/) {}
87    });
88});
Note: See TracBrowser for help on using the repository browser.