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