Ignore:
Timestamp:
07/25/12 16:04:02 (13 years ago)
Author:
jkraaijeveld
Message:

Started the QuestionEditorPreview? bit - now works with headers and texts, fully stores and restores this in order properly.

Note: there must be a better way for this, but seeing as all content pieces can differ greatly I couldn't think of a way to make it properly generic. @Hendrik: need discussion about this.

Note2: Currently I don't use any internal events in the question editor. Not sure if it would be a lot better we would.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/branches/rest-dojo-ui/client/rft/ui/QuestionEditorPreviewItem.js

    r370 r376  
    99        'dijit/_WidgetsInTemplateMixin',
    1010        'dijit/form/TextBox',
     11        'rft/ui/PreviewWidgets/HeaderItem',
     12        'rft/ui/PreviewWidgets/TextItem',
    1113        'dojo/text!./templates/QuestionEditorPreviewItem.html',
    12         ], function(declare, fx, _WidgetBase, domClass, lang, on, _TemplatedMixin, _WidgetsInTemplateMixin, TextBox, templateFull) {
     14        ], function(declare, fx, _WidgetBase, domClass, lang, on, _TemplatedMixin, _WidgetsInTemplateMixin, TextBox, HeaderItem, TextItem, templateFull) {
    1315                return declare("rft.ui.QuestionEditorPreviewItem", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
    1416
     
    2022                        foldDuration: [250, 250],
    2123                        animation: null,
    22                        
     24                        _editing: false,
     25
    2326                        postCreate: function() {
    2427                                this.foldButtonNode.onClick = lang.hitch(this, this.toggleFold);
     28                                this.removeButtonNode.onClick = lang.hitch(this, this.removeObject);
     29                                this.editButtonNode.onClick = lang.hitch(this, this.toggleEdit);
    2530                                if (this.item) {
    2631                                        this._createInnerWidget();
     
    3237                                        this.titleNode.innerHTML = title;
    3338                                });
     39                        },
     40                        toggleEdit: function() {
     41                                if(this._editing) {
     42                                        this.editButtonNode.iconNode.className = this.editButtonNode.iconNode.className.replace("rftIconAccept", "rftIconEdit");
     43                                        this.editButtonNode.set("label", "Edit");
     44                                        this.innerWidget.save();
     45                                }
     46                                else {
     47                                        this.editButtonNode.iconNode.className = this.editButtonNode.iconNode.className.replace("rftIconEdit", "rftIconAccept");
     48                                        this.editButtonNode.set("label", "Save");
     49                                        this.innerWidget.edit();
     50                                }
     51                                this._editing = !this._editing;
    3452                        },
    3553                        toggleFold: function() {
     
    6583                                }
    6684                        },
     85                        getContent: function() {
     86                                return {        data: this.innerWidget.getContent(),
     87                                                        type: this.item.type };
     88                        },
     89                        removeObject: function(widget) {
     90                                this.destroyRecursive();
     91                        },
    6792                        _createInnerWidget: function() {
    6893                                // This always creates a textbox as innerwidget pending creation of actual innerWidgets.
    6994                                // Introduce a better way to create these widgets than a switch statement, based on item.widgetType? Perhaps "new eval(item.widgetType)({});" ?
     95                                this.innerWidget = eval("new "+ this.item.type + "({ disabled: true });");
     96                                this.innerWidget.setContent(this.item.data);
     97                                this.titleNode.innerHTML = this.item.type;
     98                                /*
    7099                                switch (this.item.widgetType) {
    71100                                        default:
    72                                         this.innerWidget = new TextBox();
     101                                        this.innerWidget = new HeaderItem({ disabled: true });
     102                                        this.titleNode.innerHTML = "Header";
    73103                                        break;
    74                                 }
     104                                }*/
    75105                                this.innerWidget.placeAt(this.containerNode);
    76106                        }
Note: See TracChangeset for help on using the changeset viewer.