1 | define([
|
---|
2 | 'dojo/_base/declare',
|
---|
3 | 'dojo/_base/fx',
|
---|
4 | 'dijit/_WidgetBase',
|
---|
5 | 'dojo/dom-class',
|
---|
6 | 'dojo/_base/lang',
|
---|
7 | 'dojo/on',
|
---|
8 | 'dijit/_TemplatedMixin',
|
---|
9 | 'dijit/_WidgetsInTemplateMixin',
|
---|
10 | 'dijit/form/TextBox',
|
---|
11 | 'dojo/text!./templates/QuestionEditorPreviewItem.html',
|
---|
12 | ], function(declare, fx, _WidgetBase, domClass, lang, on, _TemplatedMixin, _WidgetsInTemplateMixin, TextBox, templateFull) {
|
---|
13 | return declare("rft.ui.QuestionEditorPreviewItem", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
|
---|
14 |
|
---|
15 | version: "full",
|
---|
16 | templateString: templateFull,
|
---|
17 | baseClass: "surveyEditorPreviewItem",
|
---|
18 | previousContentHeight: 200,
|
---|
19 | innerWidget: null,
|
---|
20 | foldDuration: [250, 250],
|
---|
21 | animation: null,
|
---|
22 |
|
---|
23 | postCreate: function() {
|
---|
24 | this.foldButtonNode.onClick = lang.hitch(this, this.toggleFold);
|
---|
25 | if (this.item) {
|
---|
26 | this._createInnerWidget();
|
---|
27 | } else {
|
---|
28 | throw "No data supplied to create an innerWidget off of!";
|
---|
29 | }
|
---|
30 |
|
---|
31 | on(this.innerWidget, "onSetTitle", function(title) {
|
---|
32 | this.titleNode.innerHTML = title;
|
---|
33 | });
|
---|
34 | },
|
---|
35 | toggleFold: function() {
|
---|
36 | if (!this.animation) {
|
---|
37 | if (!domClass.contains(this.domNode, "fold")) {
|
---|
38 | this.previousContentHeight = dojo.marginBox(this.innerNode).h;
|
---|
39 | this.animation = fx.animateProperty({
|
---|
40 | node: this.innerNode,
|
---|
41 | duration: this.foldDuration[0],
|
---|
42 | properties: {
|
---|
43 | height: 1
|
---|
44 | },
|
---|
45 | onEnd: lang.hitch(this, function(){
|
---|
46 | domClass.add(this.domNode, "fold");
|
---|
47 | this.animation = null;
|
---|
48 | })
|
---|
49 | }).play();
|
---|
50 | this.foldButtonNode.iconNode.className = this.foldButtonNode.iconNode.className.replace("rftIconHalfArrowUp", "rftIconHalfArrowDown");
|
---|
51 | } else {
|
---|
52 | this.animation = fx.animateProperty({
|
---|
53 | node: this.innerNode,
|
---|
54 | duration: this.foldDuration[1],
|
---|
55 | properties: {
|
---|
56 | height: this.previousContentHeight
|
---|
57 | },
|
---|
58 | onEnd: lang.hitch(this, function(){
|
---|
59 | domClass.remove(this.domNode, "fold");
|
---|
60 | this.animation = null;
|
---|
61 | })
|
---|
62 | }).play();
|
---|
63 | this.foldButtonNode.iconNode.className = this.foldButtonNode.iconNode.className.replace("rftIconHalfArrowDown", "rftIconHalfArrowUp");
|
---|
64 | }
|
---|
65 | }
|
---|
66 | },
|
---|
67 | _createInnerWidget: function() {
|
---|
68 | // This always creates a textbox as innerwidget pending creation of actual innerWidgets.
|
---|
69 | // Introduce a better way to create these widgets than a switch statement, based on item.widgetType? Perhaps "new eval(item.widgetType)({});" ?
|
---|
70 | switch (this.item.widgetType) {
|
---|
71 | default:
|
---|
72 | this.innerWidget = new TextBox();
|
---|
73 | break;
|
---|
74 | }
|
---|
75 | this.innerWidget.placeAt(this.containerNode);
|
---|
76 | }
|
---|
77 |
|
---|
78 | });
|
---|
79 | });
|
---|