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

Last change on this file since 388 was 387, checked in by hendrikvanantwerpen, 13 years ago
File size: 4.5 KB
Line 
1define([
2    'dojo/_base/declare',
3    'dojo/_base/fx',
4    'dojo/_base/lang',
5    'dojo/dom-class',
6    'dojo/on',
7    'dijit/_TemplatedMixin',
8    'dijit/_WidgetBase',
9    'dijit/_WidgetsInTemplateMixin',
10    'rft/ui/ContentWidgetFactory',
11    'dojo/text!./templates/QuestionEditorPreviewItem.html',
12    ], function(declare, fx, lang, domClass, on, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, ContentWidgetFactory, template) {
13        return declare("rft.ui.QuestionEditorPreviewItem", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
14
15            version: "full",
16            templateString: template,
17            baseClass: "surveyEditorPreviewItem",
18            previousContentHeight: 200,
19            innerWidget: null,
20            foldDuration: [250, 250],
21            animation: null,
22            _editing: false,
23
24            postCreate: function() {
25                this.inherited(arguments);
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(evt) {
88                this.destroyRecursive();
89            },
90            _createInnerWidget: function() {
91                this.innerWidget = new ContentWidgetFactory().createWidget( this.item );
92                this.innerWidget.placeAt(this.containerNode);
93                this.innerWidget.startup();
94            }
95
96        });
97    });
Note: See TracBrowser for help on using the repository browser.