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

Last change on this file since 399 was 399, checked in by hendrikvanantwerpen, 13 years ago

Added survey viewer page.

Added view.html page to view surveys. Widgets from the questions are
displayed, no answers are saved yet.

The content module is split for index.html and view.html, so viewers
cannot navigate to other pages. Widgets to pre-load are now seperated
in stddeps.js module and shared between run.js & view.js.

File size: 5.7 KB
Line 
1define([
2    'dojo/_base/declare',
3    'dojo/_base/fx',
4    'dojo/_base/lang',
5    'dojo/dom-class',
6    'dojo/on',
7    'dijit/_Container',
8    'dijit/_TemplatedMixin',
9    'dijit/_WidgetBase',
10    'dijit/_WidgetsInTemplateMixin',
11    './content/ContentWidgetFactory',
12    'dojo/text!./templates/QuestionEditorPreviewItem.html',
13    ], function(declare, fx, lang, domClass, on, _Container, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, ContentWidgetFactory, template) {
14        return declare("rft.ui.QuestionEditorPreviewItem", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, _Container], {
15            version: "full",
16            templateString: template,
17            baseClass: "surveyEditorPreviewItem",
18            previousContentHeight: 200,
19            item: null,
20            innerWidget: null,
21            foldDuration: [250, 250],
22            animation: null,
23            _editing: false,
24
25            startup: function() {
26                this.inherited(arguments);
27                this.foldButtonNode.onClick = lang.hitch(this, this.toggleFold);
28                this.removeButtonNode.onClick = lang.hitch(this, "onClose");
29                this.editButtonNode.onClick = lang.hitch(this, this.toggleEdit);
30                if (this.item) {
31                    this._showViewWidget();
32                } else {
33                    throw "No data supplied to create an innerWidget!";
34                }
35            },
36            _destroyInnerWidget: function() {
37                if ( this.innerWidget !== null ) {
38                    this.innerWidget.destroyRecursive();
39                }
40            },
41            _showViewWidget: function() {
42                var factory = new ContentWidgetFactory();
43                this.innerWidget = factory.createViewWidget( this.item );
44                if ( this.innerWidget !== null ) {
45                    this.innerWidget.placeAt(this.containerNode);
46                    this.innerWidget.startup();
47                    this.innerWidget.set('readOnly',true);
48                }
49                this.titleNode.innerHTML = this.item.type+" [preview]";
50            },
51            _showEditWidget: function() {
52                var factory = new ContentWidgetFactory();
53                this.innerWidget = factory.createEditWidget( this.item );
54                if ( this.innerWidget !== null ) {
55                    this.innerWidget.placeAt(this.containerNode);
56                    this.innerWidget.startup();
57                }
58                this.titleNode.innerHTML = this.item.type+" [editing]";
59            },
60            onClose: function() {},
61            _getValueAttr: function(value) {
62                return this.item;
63            },
64            _setValueAttr: function(value) {
65                this.item = value;
66                this._destroyInnerWidget();
67                if ( this._editing ) {
68                    this._showEditWidget();
69                } else {
70                    this._showViewWidget();
71                }
72            },
73            toggleEdit: function() {
74                if(this._editing) {
75                    if ( this.innerWidget !== null ) {
76                        this.item = this.innerWidget.get('value');
77                    }
78                    this._destroyInnerWidget();
79                    this._showViewWidget();
80                    this.editButtonNode.iconNode.className = this.editButtonNode.iconNode.className.replace("rftIconAccept", "rftIconEdit");
81                    this.editButtonNode.set("label", "Edit");
82                } else {
83                    this._destroyInnerWidget();
84                    this._showEditWidget();
85                    this.editButtonNode.iconNode.className = this.editButtonNode.iconNode.className.replace("rftIconEdit", "rftIconAccept");
86                    this.editButtonNode.set("label", "Save");
87                }
88                this._editing = !this._editing;
89            },
90            toggleFold: function() {
91                if (!this.animation) {
92                    if (!domClass.contains(this.domNode, "fold")) {
93                        this.previousContentHeight = dojo.marginBox(this.innerNode).h;
94                        this.animation = fx.animateProperty({
95                            node: this.innerNode,
96                            duration: this.foldDuration[0],
97                            properties: {
98                                height: 1                       
99                            },
100                            onEnd: lang.hitch(this, function(){
101                                domClass.add(this.domNode, "fold");
102                                this.animation = null;
103                            })
104                        }).play();
105                        this.foldButtonNode.iconNode.className = this.foldButtonNode.iconNode.className.replace("rftIconHalfArrowUp", "rftIconHalfArrowDown");
106                    } else {
107                        this.animation = fx.animateProperty({
108                            node: this.innerNode,
109                            duration: this.foldDuration[1],
110                            properties: {
111                                height: this.previousContentHeight               
112                            },
113                            onEnd: lang.hitch(this, function(){
114                                domClass.remove(this.domNode, "fold");
115                                this.animation = null;
116                            })
117                        }).play();
118                        this.foldButtonNode.iconNode.className = this.foldButtonNode.iconNode.className.replace("rftIconHalfArrowDown", "rftIconHalfArrowUp");
119                    }
120                }
121            }
122
123        });
124    });
Note: See TracBrowser for help on using the repository browser.