source: Dev/trunk/client/qed/model/widgets/ScaleConfigWidget.js @ 434

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

Implemented Scale and ScaleConfig? widget.

File size: 3.1 KB
Line 
1define([
2    "dijit/_Container",
3    "dijit/_TemplatedMixin",
4    "dijit/_WidgetBase",
5    "dijit/_WidgetsInTemplateMixin",
6    "dijit/form/Button",
7    "dijit/form/RadioButton",
8    "dijit/form/TextBox",
9    "dijit/form/ValidationTextBox",
10    "dijit/form/_FormMixin",
11    "dojo/_base/array",
12    "dojo/_base/declare",
13    "dojo/_base/event",
14    "dojo/_base/lang",
15    "dojo/dom-attr",
16    "dojo/dom-construct",
17    "dojo/dom-style",
18    "dojo/text!./templates/ScaleConfigRowWidget.html",
19    "dojo/text!./templates/ScaleConfigWidget.html",
20    "dijit/form/NumberTextBox",
21    "dijit/form/TextBox"
22], function(_Container, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, Button, RadioButton, TextBox, ValidationTextBox, _FormMixin, array, declare, event, lang, domAttr, domConstruct, domStyle, rowTemplate, template) {
23
24    var Row = declare([_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container,_FormMixin],{
25        templateString: rowTemplate,
26        hasNA: true,
27        startup: function() {
28            if ( this._started ) { return; }
29            this.inherited(arguments);
30        },
31        onDestroy: function(e) {
32            this.destroyRecursive();
33            event.stop(e);
34            return false;
35        },
36        _setHasNAAttr: function(value) {
37            if ( value === true ) {
38                domStyle.set(this.naRadioButton.domNode, "display", "");
39            } else {
40                domStyle.set(this.naRadioButton.domNode, "display", "none");
41            }
42        }
43    });
44   
45    return declare([_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,_Container,_FormMixin],{
46        templateString: template,
47        baseClass: "qedScaleWidget",
48        value: null,
49        _hasNA: false,
50        constuctor: function() {
51            this.inherited(arguments);
52            this.items = [];
53            this.value = {};
54        },
55        onAddItem: function(e) {
56            this._addItem();
57            event.stop(e);
58            return false;
59        },
60        _clearItems: function() {
61            domConstruct.empty(this.itemsNode);
62        },
63        _addItem: function(value) {
64            var item = new Row({
65                name: 'items',
66                value: value,
67                hasNA: this._hasNA
68            });
69            item.placeAt(this.itemsNode);
70            return item;
71        },
72        _setValueAttr: function(value) {
73            this.inherited(arguments);
74            this._clearItems();
75            array.forEach(value.items, function(value){
76                this._addItem(value);
77            }, this);
78        },
79        _getValueAttr: function(){
80            var value = this.inherited(arguments);
81            if ( value.items && !lang.isArray(value.items) ) {
82                value.items = [value.items];
83            }
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.getChildren(), function(child) {
92                child.set('hasNA', this._hasNA);
93            }, this);
94        }
95    });
96});
Note: See TracBrowser for help on using the repository browser.