source: Dev/branches/rest-dojo-ui/client/rft/ui/QuestionEditorPreviewItem.js @ 384

Last change on this file since 384 was 381, checked in by jkraaijeveld, 13 years ago

Created the IntegerInput? inner widget. Stores properly and allows for a lot of customization.

File size: 3.9 KB
Line 
1define([
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        'rft/ui/InnerWidgetFactory',
12        'dojo/text!./templates/QuestionEditorPreviewItem.html',
13        ], function(declare, fx, _WidgetBase, domClass, lang, on, _TemplatedMixin, _WidgetsInTemplateMixin, TextBox, InnerWidgetFactory, templateFull) {
14                return declare("rft.ui.QuestionEditorPreviewItem", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
15
16                        version: "full",
17                        templateString: templateFull,
18                        baseClass: "surveyEditorPreviewItem",
19                        previousContentHeight: 200,
20                        innerWidget: null,
21                        foldDuration: [250, 250],
22                        animation: null,
23                        _editing: false,
24
25                        postCreate: function() {
26                                this.foldButtonNode.onClick = lang.hitch(this, this.toggleFold);
27                                this.removeButtonNode.onClick = lang.hitch(this, this.removeObject);
28                                this.editButtonNode.onClick = lang.hitch(this, this.toggleEdit);
29                                if (this.item) {
30                                        this._createInnerWidget();
31                                } else {
32                                        throw "No data supplied to create an innerWidget off of!";
33                                }
34
35                                on(this.innerWidget, "onSetTitle", function(title) {
36                                        this.titleNode.innerHTML = title;
37                                });
38                        },
39                        toggleEdit: function() {
40                                if(this._editing) {
41                                        this.editButtonNode.iconNode.className = this.editButtonNode.iconNode.className.replace("rftIconAccept", "rftIconEdit");
42                                        this.editButtonNode.set("label", "Edit");
43                                        this.innerWidget.save();
44                                }
45                                else {
46                                        this.editButtonNode.iconNode.className = this.editButtonNode.iconNode.className.replace("rftIconEdit", "rftIconAccept");
47                                        this.editButtonNode.set("label", "Save");
48                                        this.innerWidget.edit();
49                                }
50                                this._editing = !this._editing;
51                        },
52                        toggleFold: function() {
53                                if (!this.animation) {
54                                        if (!domClass.contains(this.domNode, "fold")) {
55                                                this.previousContentHeight = dojo.marginBox(this.innerNode).h;
56                                                this.animation = fx.animateProperty({
57                                                        node: this.innerNode,
58                                                        duration: this.foldDuration[0],
59                                                        properties: {
60                                                                height: 1                                               
61                                                        },
62                                                        onEnd: lang.hitch(this, function(){
63                                                                domClass.add(this.domNode, "fold");
64                                                                this.animation = null;
65                                                        })
66                                                }).play();
67                                                this.foldButtonNode.iconNode.className = this.foldButtonNode.iconNode.className.replace("rftIconHalfArrowUp", "rftIconHalfArrowDown");
68                                        } else {
69                                                this.animation = fx.animateProperty({
70                                                        node: this.innerNode,
71                                                        duration: this.foldDuration[1],
72                                                        properties: {
73                                                                height: this.previousContentHeight                             
74                                                        },
75                                                        onEnd: lang.hitch(this, function(){
76                                                                domClass.remove(this.domNode, "fold");
77                                                                this.animation = null;
78                                                        })
79                                                }).play();
80                                                this.foldButtonNode.iconNode.className = this.foldButtonNode.iconNode.className.replace("rftIconHalfArrowDown", "rftIconHalfArrowUp");
81                                        }
82                                }
83                        },
84                        getContent: function() {
85                                return this.innerWidget.getObject();
86                        },
87                        removeObject: function(widget) {
88                                this.destroyRecursive();
89                        },
90                        _createInnerWidget: function() {
91                                // This always creates a textbox as innerwidget pending creation of actual innerWidgets.
92                                // Introduce a better way to create these widgets than a switch statement, based on item.widgetType? Perhaps "new eval(item.widgetType)({});" ?
93
94                                this.innerWidget = new InnerWidgetFactory().createWidget( this.item );
95                                /*
96                                this.innerWidget = eval("new "+ this.item.type + "({ disabled: true });");
97                                this.innerWidget.setContent(this.item.data);
98                                this.titleNode.innerHTML = this.item.type;
99                                /*
100                                switch (this.item.widgetType) {
101                                        default:
102                                        this.innerWidget = new HeaderItem({ disabled: true });
103                                        this.titleNode.innerHTML = "Header";
104                                        break;
105                                }*/
106                                this.innerWidget.startup();
107                                this.innerWidget.placeAt(this.containerNode);
108                        }
109
110                });
111});
Note: See TracBrowser for help on using the repository browser.