Ignore:
Timestamp:
04/29/13 19:35:10 (12 years ago)
Author:
hendrikvanantwerpen
Message:

Big cleanup of the question content.

  • Replaced old list implementations with a new one that behaves like a form widget.
  • All question content is now in separate widgets, not in the factory itself.
  • Added form and widget validation for question editing.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/client/qed/model/widgets/QuestionEditorPreviewItem.js

    r440 r441  
    11define([
    2     "./QuestionWidgetFactory",
     2    "./questions/Factory",
    33    "dijit/_Container",
    44    "dijit/_TemplatedMixin",
     
    66    "dijit/_WidgetsInTemplateMixin",
    77    "dojo/_base/declare",
     8    "dojo/_base/event",
    89    "dojo/_base/fx",
    910    "dojo/_base/lang",
     
    1314    "dojo/on",
    1415    "dojo/text!./templates/QuestionEditorPreviewItem.html"
    15 ], function(QuestionWidgetFactory, _Container, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, declare, fx, lang, domClass, domGeom, domStyle, on, template) {
     16], function(QuestionWidgetFactory, _Container, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, declare, event, fx, lang, domClass, domGeom, domStyle, on, template) {
    1617    return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, _Container], {
    1718        templateString: template,
     
    3132                        lang.hitch(this, 'onToggleFold')));
    3233            this.own(this.removeButton.on('click',
    33                         lang.hitch(this, 'onClose')));
     34                        lang.hitch(this, 'onDestroy')));
    3435            this.own(this.editButton.on('click',
    3536                        lang.hitch(this, 'onToggleEdit')));
    36             if (this.value) {
    37                 this._showEditWidget();
    38             } else {
    39                 throw "No data supplied to create an innerWidget!";
     37            this.showEdit();
     38        },
     39        onDestroy: function() {},
     40        _getValueAttr: function(value) {
     41            if ( this._editing ) {
     42                this.value = this.innerWidget.get('value');
    4043            }
    41         },
    42         onClose: function() {},
    43         _getValueAttr: function(value) {
    4444            return this.value;
    4545        },
    4646        _setValueAttr: function(value) {
    4747            this.value = value;
    48             this._destroyInnerWidget();
    4948            if ( this._editing ) {
    5049                this._showEditWidget();
     
    5352            }
    5453        },
    55         onToggleEdit: function() {
    56             if (this._editing) {
    57                 if ( this.innerWidget !== null ) {
    58                     if (!this.innerWidget.validate ||
    59                         this.innerWidget.validate() ) {
    60                         this.value = this.innerWidget.get('value');
    61                         this._showViewWidget();
    62                     }
    63                 } else {
     54        validate: function() {
     55            return !this._editing || this.innerWidget.validate();
     56        },
     57        showView: function() {
     58            if ( this._editing ) {
     59                if (!this.innerWidget.validate || this.innerWidget.validate() ) {
     60                    this.value = this.innerWidget.get('value');
    6461                    this._showViewWidget();
    6562                }
    66             } else {
     63            }
     64        },
     65        showEdit: function() {
     66            if (!this._editing) {
    6767                this._showEditWidget();
    6868            }
    6969        },
     70        onToggleEdit: function(evt) {
     71            if (this._editing) {
     72                this.showView();
     73            } else {
     74                this.showEdit();
     75            }
     76            evt && event.stop(evt);
     77            return false;
     78        },
    7079        _showViewWidget: function() {
    71             this._destroyInnerWidget();
    72             this.innerWidget = this._factory.createViewWidget( this.value );
    73             if ( this.innerWidget !== null ) {
     80            var newWidget = this._factory.createViewWidget( this.value );
     81            if ( newWidget !== null ) {
     82                this._destroyInnerWidget();
     83                this.innerWidget = newWidget;
    7484                this.innerWidget.placeAt(this.containerNode);
    7585                this.innerWidget.startup();
    7686                this.innerWidget.set('readOnly',true);
     87                this.titleNode.innerHTML = this.value.type+" [preview]";
     88                domClass.replace(this.editButton.iconNode, "rftIconEdit", "rftIconAccept");
     89                this.editButton.set("label", "Edit");
     90                this._editing = false;
    7791            }
    78             this.titleNode.innerHTML = this.value.type+" [preview]";
    79             domClass.replace(this.editButton.iconNode, "rftIconEdit", "rftIconAccept");
    80             this.editButton.set("label", "Edit");
    81             this._editing = false;
    8292        },
    8393        _showEditWidget: function() {
    84             this._destroyInnerWidget();
    85             this.innerWidget = this._factory.createEditWidget( this.value );
    86             if ( this.innerWidget !== null ) {
     94            var newWidget = this._factory.createEditWidget( this.value );
     95            if ( newWidget !== null ) {
     96                this._destroyInnerWidget();
     97                this.innerWidget = newWidget;
    8798                this.innerWidget.placeAt(this.containerNode);
    8899                this.innerWidget.startup();
     100                this.titleNode.innerHTML = this.value.type+" [editing]";
     101                domClass.replace(this.editButton.iconNode, "rftIconAccept", "rftIconEdit");
     102                this.editButton.set("label", "Done");
     103                this._editing = true;
    89104            }
    90             this.titleNode.innerHTML = this.value.type+" [editing]";
    91             domClass.replace(this.editButton.iconNode, "rftIconAccept", "rftIconEdit");
    92             this.editButton.set("label", "Done");
    93             this._editing = true;
    94105        },
    95106        _destroyInnerWidget: function() {
     
    98109            }
    99110        },
    100         onToggleFold: function() {
     111        onToggleFold: function(evt) {
    101112            if (!this.animation) {
    102113                if (!domClass.contains(this.domNode, "fold")) {
     
    130141                }
    131142            }
     143            evt && event.stop(evt);
     144            return false;
    132145        }
    133146
Note: See TracChangeset for help on using the changeset viewer.