source: Dev/trunk/src/qed-client/model/widgets/questions/ScaleInputConfigWidget.js @ 443

Last change on this file since 443 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([
2    "../../../widgets/ListWidget",
3    "../../../widgets/_ComplexValueWidget",
4    "dijit/form/Button",
5    "dijit/form/RadioButton",
6    "dijit/form/TextBox",
7    "dijit/form/ValidationTextBox",
8    "dojo/_base/array",
9    "dojo/_base/declare",
10    "dojo/_base/event",
11    "dojo/_base/lang",
12    "dojo/dom-attr",
13    "dojo/dom-construct",
14    "dojo/dom-style",
15    "dojo/text!./templates/ScaleInputConfigRowWidget.html",
16    "dojo/text!./templates/ScaleInputConfigWidget.html",
17    "dijit/form/NumberTextBox",
18    "dijit/form/TextBox"
19], function(ListWidget, _ComplexValueWidget, Button, RadioButton, TextBox, ValidationTextBox, array, declare, event, lang, domAttr, domConstruct, domStyle, rowTemplate, template) {
20
21    var Row = declare([_ComplexValueWidget],{
22        templateString: rowTemplate,
23        hasNA: true,
24        startup: function() {
25            if ( this._started ) { return; }
26            this.inherited(arguments);
27        },
28        onDestroy: function(evt) {},
29        _setHasNAAttr: function(value) {
30            if ( value === true ) {
31                domStyle.set(this.naRadioButton.domNode, "display", "");
32            } else {
33                domStyle.set(this.naRadioButton.domNode, "display", "none");
34            }
35        }
36    });
37   
38    return declare([_ComplexValueWidget],{
39        templateString: template,
40        baseClass: "qedScaleWidget",
41        _hasNA: false,
42        constuctor: function() {
43            this.inherited(arguments);
44            this.value = {};
45        },
46        buildRendering: function() {
47            this.inherited(arguments);
48            this.itemsWidget = new ListWidget({
49                name: "items",
50                type: "ScaleItem",
51                delay: 5,
52                skipForm: true,
53                createListElement: lang.hitch(this, "_createRowWidget"),
54                createAvatar: lang.hitch(this, "_createAvatar")
55            }, this.itemsNode);
56        },
57        _createRowWidget: function(id, item) {
58            var widget = new Row({
59                value: item,
60                hasNA: this._hasNA,
61                id: id,
62                onDestroy: lang.hitch(this,function(evt){
63                    this.itemsWidget.removeItem(id);
64                    event.stop(evt);
65                    return false;
66                })
67            });
68            widget.startup();
69            return widget;
70        },
71        _createAvatar: function(id, item) {
72            return domConstruct.create("div", {
73                innerHTML: item.text || "(empty item)"
74            });
75        },
76        onAddNewItem: function(e) {
77            this.itemsWidget.appendItem({});
78            event.stop(e);
79            return false;
80        },
81        _getValueAttr: function(){
82            var value = this.inherited(arguments);
83            value.type = 'ScaleInput';
84            return value;
85        },
86        onNAChange: function(value) {
87            this._hasNA = value !== null && value !== "";
88            this._updateNA();
89        },
90        _updateNA: function(value) {
91            array.forEach(this.itemsWidget.getChildren(), function(child) {
92                child.set('hasNA', this._hasNA);
93            }, this);
94        }
95    });
96});
Note: See TracBrowser for help on using the repository browser.