source: Dev/trunk/src/client/qed-client/widgets/MultipleChoiceWidget.js @ 500

Last change on this file since 500 was 443, checked in by hendrikvanantwerpen, 12 years ago

Reorganized for Node --- the SVN gods hate us all!

Lost all historical info on moved files, because SVN is a f *.

Also we have Node now, serving both the static content and forwarding
database requests.

File size: 3.2 KB
Line 
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',
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) {
46            var row = domConstruct.create('div',{className:'row'});
47            if ( this.allowMultiple ) {
48                new CheckBox({
49                    name:this.name,
50                    className:'rowBox',
51                    disabled: this.mode === 'edit'
52                }).placeAt(row);
53            } else {
54                new RadioButton({
55                    name:this.name,
56                    className:'rowBox',
57                    disabled: this.mode === 'edit'
58                }).placeAt(row);
59            }
60            new TextBox({
61                name:this.name,
62                value:value || '',
63                className:'rowText'
64            }).placeAt(row);
65            new Button({
66                label:'-',
67                className:'rowBtn',
68                onClick:lang.hitch(this,'_removeNodeWithWidgets',row)
69            }).placeAt(row);
70            new Button({
71                label:'+',
72                className:'rowBtn',
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.