1 | <!DOCTYPE html> |
---|
2 | <html> |
---|
3 | <head> |
---|
4 | <title>Test ScaleWidget</title> |
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
---|
6 | <link rel="stylesheet" type="text/css" href="../css/qed.css" /> |
---|
7 | </head> |
---|
8 | <body class="dijitReset claro" id="rft"> |
---|
9 | <script type="text/javascript" src="../../dojo/dojo.js" data-dojo-config="async: true, parseOnLoad: false, isDebug: true"></script> |
---|
10 | <script> |
---|
11 | require([ |
---|
12 | 'dijit/registry', |
---|
13 | 'dojo/dom', |
---|
14 | 'dojo/when', |
---|
15 | 'dojo/parser', |
---|
16 | 'qed/model/widgets/questions/ScaleInputConfigWidget', |
---|
17 | 'qed/model/widgets/questions/ScaleInputWidget', |
---|
18 | 'dojo/domReady!' |
---|
19 | ], function(registry,dom,when,parser,ScaleInputConfigWidget,ScaleInputWidget){ |
---|
20 | when(parser.parse()).then(function(){ |
---|
21 | |
---|
22 | var configWidget = registry.byId("configWidget"); |
---|
23 | var configNode = dom.byId("configNode"); |
---|
24 | var valueNode = dom.byId("valueNode"); |
---|
25 | var widgetNode = dom.byId("widgetNode"); |
---|
26 | var widget = null; |
---|
27 | |
---|
28 | registry.byId("configButton").on("click",function(){ |
---|
29 | if ( configWidget.validate() ) { |
---|
30 | var config = configWidget.get('value'); |
---|
31 | configNode.innerHTML = JSON.stringify(config); |
---|
32 | widgetNode.innerHTML = ''; |
---|
33 | widget = new ScaleInputWidget(config) |
---|
34 | widget.startup(); |
---|
35 | widget.placeAt(widgetNode); |
---|
36 | } |
---|
37 | }); |
---|
38 | |
---|
39 | registry.byId("valueButton").on("click",function(){ |
---|
40 | if ( widget ) { |
---|
41 | var value = widget.get('value'); |
---|
42 | valueNode.innerHTML = JSON.stringify(value); |
---|
43 | } |
---|
44 | }); |
---|
45 | |
---|
46 | registry.byId("defaultConfigButton").on("click",function(){ |
---|
47 | configWidget.set('value',{ |
---|
48 | min: -2, |
---|
49 | max: 2, |
---|
50 | minLabel: "Bad", |
---|
51 | maxLabel: "Good", |
---|
52 | naLabel: "N/A", |
---|
53 | items: [{ |
---|
54 | text: "How were the lectures?", |
---|
55 | minLabel: "Boring", |
---|
56 | maxLabel: "Engaging" |
---|
57 | },{ |
---|
58 | text: "How was the lab organised? How was the lab organised? How was the lab organised?", |
---|
59 | minLabel: "Sloppy", |
---|
60 | maxLabel: "Stiff as a board" |
---|
61 | }] |
---|
62 | }); |
---|
63 | }); |
---|
64 | |
---|
65 | }); |
---|
66 | }); |
---|
67 | </script> |
---|
68 | |
---|
69 | <h1>Test ScaleWidget</h1> |
---|
70 | |
---|
71 | <h2>Config Widget</h2> |
---|
72 | <div> |
---|
73 | <div> |
---|
74 | <div id="configWidget" |
---|
75 | data-dojo-type="qed/model/widgets/questions/ScaleInputConfigWidget"></div> |
---|
76 | <button id="defaultConfigButton" |
---|
77 | data-dojo-type="dijit/form/Button">Set Example</button> |
---|
78 | <button id="configButton" |
---|
79 | data-dojo-type="dijit/form/Button">Create widget</button> |
---|
80 | </div> |
---|
81 | <div id="configNode"></div> |
---|
82 | </div> |
---|
83 | |
---|
84 | <h2>Widget</h2> |
---|
85 | <div> |
---|
86 | <div> |
---|
87 | <div id="widgetNode"></div> |
---|
88 | <button id="valueButton" |
---|
89 | data-dojo-type="dijit/form/Button">Done</button> |
---|
90 | </div> |
---|
91 | <div id="valueNode"></div> |
---|
92 | </div> |
---|
93 | |
---|
94 | </body> |
---|
95 | </html> |
---|