Ignore:
Timestamp:
08/06/12 17:39:05 (13 years ago)
Author:
hendrikvanantwerpen
Message:
File:
1 edited

Legend:

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

    r387 r389  
    55    'dojo/dom-class',
    66    'dojo/on',
     7    'dijit/_Container',
    78    'dijit/_TemplatedMixin',
    89    'dijit/_WidgetBase',
    910    'dijit/_WidgetsInTemplateMixin',
    10     'rft/ui/ContentWidgetFactory',
     11    './content/ContentWidgetFactory',
    1112    '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 
     13    ], function(declare, fx, lang, domClass, on, _Container, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, ContentWidgetFactory, template) {
     14        return declare("rft.ui.QuestionEditorPreviewItem", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, _Container], {
    1515            version: "full",
    1616            templateString: template,
    1717            baseClass: "surveyEditorPreviewItem",
    1818            previousContentHeight: 200,
     19            item: null,
    1920            innerWidget: null,
    2021            foldDuration: [250, 250],
     
    2223            _editing: false,
    2324
    24             postCreate: function() {
     25            startup: function() {
    2526                this.inherited(arguments);
    2627                this.foldButtonNode.onClick = lang.hitch(this, this.toggleFold);
    27                 this.removeButtonNode.onClick = lang.hitch(this, this.removeObject);
     28                this.removeButtonNode.onClick = lang.hitch(this, "onClose");
    2829                this.editButtonNode.onClick = lang.hitch(this, this.toggleEdit);
    2930                if (this.item) {
    30                     this._createInnerWidget();
     31                    this._showViewWidget();
    3132                } else {
    32                     throw "No data supplied to create an innerWidget off of!";
     33                    throw "No data supplied to create an innerWidget!";
    3334                }
    34 
    35                 on(this.innerWidget, "onSetTitle", function(title) {
    36                     this.titleNode.innerHTML = title;
    37                 });
     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                }
     48                this.titleNode.innerHTML = "[preview]";
     49            },
     50            _showEditWidget: function() {
     51                var factory = new ContentWidgetFactory();
     52                this.innerWidget = factory.createEditWidget( this.item );
     53                if ( this.innerWidget !== null ) {
     54                    this.innerWidget.placeAt(this.containerNode);
     55                    this.innerWidget.startup();
     56                }
     57                this.titleNode.innerHTML = "[editing]";
     58            },
     59            onClose: function() {},
     60            _getValueAttr: function(value) {
     61                return this.item;
     62            },
     63            _setValueAttr: function(value) {
     64                this.item = value;
     65                this._destroyInnerWidget();
     66                if ( this._editing ) {
     67                    this._showEditWidget();
     68                } else {
     69                    this._showViewWidget();
     70                }
    3871            },
    3972            toggleEdit: function() {
    4073                if(this._editing) {
     74                    if ( this.innerWidget !== null ) {
     75                        this.item = this.innerWidget.get('value');
     76                    }
     77                    this._destroyInnerWidget();
     78                    this._showViewWidget();
    4179                    this.editButtonNode.iconNode.className = this.editButtonNode.iconNode.className.replace("rftIconAccept", "rftIconEdit");
    4280                    this.editButtonNode.set("label", "Edit");
    43                     this.innerWidget.save();
    44                 }
    45                 else {
     81                } else {
     82                    this._destroyInnerWidget();
     83                    this._showEditWidget();
    4684                    this.editButtonNode.iconNode.className = this.editButtonNode.iconNode.className.replace("rftIconEdit", "rftIconAccept");
    4785                    this.editButtonNode.set("label", "Save");
    48                     this.innerWidget.edit();
    4986                }
    5087                this._editing = !this._editing;
     
    81118                    }
    82119                }
    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();
    94120            }
    95121
Note: See TracChangeset for help on using the changeset viewer.