1 | define([ |
---|
2 | "../../../widgets/_ComplexValueWidget", |
---|
3 | "dijit/form/CheckBox", |
---|
4 | "dijit/form/RadioButton", |
---|
5 | "dojo/_base/array", |
---|
6 | "dojo/_base/declare", |
---|
7 | "dojo/_base/lang", |
---|
8 | "dojo/dom-attr", |
---|
9 | "dojo/dom-construct", |
---|
10 | "dojo/text!./templates/ScaleInputWidget.html" |
---|
11 | ], function(_ComplexValueWidget, CheckBox, RadioButton, array, declare, lang, domAttr, domConstruct, template) { |
---|
12 | return declare([_ComplexValueWidget],{ |
---|
13 | templateString: template, |
---|
14 | baseClass: "qedScaleWidget", |
---|
15 | startup: function() { |
---|
16 | if ( this._started ) { return; } |
---|
17 | this.inherited(arguments); |
---|
18 | this._renderHead(); |
---|
19 | this._renderItems(); |
---|
20 | }, |
---|
21 | _renderHead: function() { |
---|
22 | this.minNode.innerHTML = this.minLabel || ""; |
---|
23 | this.maxNode.innerHTML = this.maxLabel || ""; |
---|
24 | if ( this.naLabel ) { |
---|
25 | this.naNode.innerHTML = this.naLabel; |
---|
26 | } |
---|
27 | for (var i = this.min; i <= this.max; i++) { |
---|
28 | domConstruct.create("th", { |
---|
29 | innerHTML: i.toString() |
---|
30 | }, this.maxNode, "before"); |
---|
31 | } |
---|
32 | }, |
---|
33 | _renderItems: function() { |
---|
34 | array.forEach(this.items, function(item) { |
---|
35 | var tr = domConstruct.create("tr", {}, this.itemsNode); |
---|
36 | var td; |
---|
37 | var radio; |
---|
38 | domConstruct.create("th", { |
---|
39 | innerHTML: item.text || "", |
---|
40 | 'class': "item" |
---|
41 | }, tr); |
---|
42 | domConstruct.create("th", { |
---|
43 | innerHTML: item.minLabel || "", |
---|
44 | 'class': 'min' |
---|
45 | }, tr); |
---|
46 | for (var i = this.min; i <= this.max; i++) { |
---|
47 | td = domConstruct.create("td", {}, tr); |
---|
48 | radio = new RadioButton({ |
---|
49 | name: this.code+item.subcode, |
---|
50 | value: i.toString() |
---|
51 | }); |
---|
52 | domConstruct.place(radio.domNode, td); |
---|
53 | } |
---|
54 | domConstruct.create("th", { |
---|
55 | innerHTML: item.maxLabel || "", |
---|
56 | className: 'max' |
---|
57 | }, tr); |
---|
58 | if ( this.naLabel ) { |
---|
59 | td = domConstruct.create("td", {}, tr); |
---|
60 | radio = new RadioButton({ |
---|
61 | name: this.code+item.subcode, |
---|
62 | value: "n/a" |
---|
63 | }); |
---|
64 | domConstruct.place(radio.domNode, td); |
---|
65 | } |
---|
66 | }, this); |
---|
67 | } |
---|
68 | }); |
---|
69 | }); |
---|