Ignore:
Timestamp:
03/12/14 15:16:54 (11 years ago)
Author:
hendrikvanantwerpen
Message:
  • Factored out general object mapping and iteration.
  • Split widgets for multiplechoice and singlechoice.
  • Restored readOnly/disabled setting for QuestionEditorPreviewItem? on innerWidget (since view innerWidget is not a form anymore, we cannot just set it on that, we iterate over all form children now).
File:
1 edited

Legend:

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

    r508 r510  
    66    "dijit/_WidgetBase",
    77    "dijit/_WidgetsInTemplateMixin",
     8    "dojo/_base/array",
    89    "dojo/_base/declare",
    910    "dojo/_base/event",
     
    1516    "dojo/on",
    1617    "dojo/text!./templates/QuestionEditorPreviewItem.html"
    17 ], function(_ComplexValueWidget, QuestionWidgetFactory, _Container, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, declare, event, fx, lang, domClass, domGeom, domStyle, on, template) {
     18], function(_ComplexValueWidget, QuestionWidgetFactory, _Container, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, array, declare, event, fx, lang, domClass, domGeom, domStyle, on, template) {
    1819    return declare([_ComplexValueWidget], {
    1920        templateString: template,
     
    2425        foldDuration: [250, 250],
    2526        animation: null,
    26         _editing: false,
     27        _editing: null,
    2728        _factory: new QuestionWidgetFactory(),
    2829
     
    3637            this.own(this.editButton.on('click',
    3738                        lang.hitch(this, 'onToggleEdit')));
    38             this.showEdit();
     39            this.showView();
    3940        },
    4041        _handleDestroy: function(evt) {
     
    4445        },
    4546        _getValueAttr: function(value) {
    46             if ( this._editing ) {
     47            if ( this._editing === true ) {
    4748                this.value = this.innerWidget.get('value');
    4849            }
     
    5152        _setValueAttr: function(value) {
    5253            this.value = value;
    53             if ( this._editing ) {
     54            if ( this._editing  === true ) {
    5455                this._showEditWidget();
    5556            } else {
     
    5758            }
    5859        },
    59         _setReadOnlyAttr: function() {
    60             this.inherited(arguments);
     60        _setReadOnlyAttr: function(readOnly) {
     61            this._set('readOnly',readOnly);
     62            this._setReadOnlyChildren(this.readOnly);
    6163            this._updateRemoveBtn();
    6264        },
    63         _setDisabledAttr: function() {
    64             this.inherited(arguments);
     65        _setDisabledAttr: function(disabled) {
     66            this._set('disabled',disabled);
     67            this._setDisabledChildren(this.disabled);
    6568            this._updateRemoveBtn();
    6669        },
    6770        _updateRemoveBtn: function() {
     71            var node = this.removeButton.domNode;
    6872            if ( this.readOnly || this.disabled ) {
    69                 domClass.add(this.removeButton.domNode, 'dijitHidden');
     73                domClass.add(node, 'dijitHidden');
    7074            } else {
    71                 domClass.remove(this.removeButton.domNode, 'dijitHidden');
     75                domClass.remove(node, 'dijitHidden');
    7276            }
    7377        },
     78        _setDisabledChildren: function(disabled) {
     79            array.forEach(this._getDescendantFormWidgets(),function(widget){
     80                widget.set('disabled',disabled);
     81            });
     82        },
     83        _setReadOnlyChildren: function(readOnly) {
     84            array.forEach(this._getDescendantFormWidgets(),function(widget){
     85                widget.set('readOnly',readOnly);
     86            });
     87        },
    7488        validate: function() {
    75             return !this._editing || this.innerWidget.validate();
     89            return this._editing === false || this.innerWidget.validate();
    7690        },
    7791        focus: function() {
    78             if ( this._editing ) {
     92            if ( this._editing === true ) {
    7993                this.innerWidget.focus();
    8094            }
    8195        },
    8296        showView: function() {
    83             if ( this._editing ) {
     97            if ( this._editing === true ) {
    8498                if (!this.innerWidget.validate || this.innerWidget.validate() ) {
    8599                    this.value = this.innerWidget.get('value');
     
    89103        },
    90104        showEdit: function() {
    91             if (!this._editing) {
     105            if ( this._editing === false ) {
    92106                this._showEditWidget();
    93107            }
    94108        },
    95109        onToggleEdit: function(evt) {
    96             if (this._editing) {
     110            if ( this._editing === true ) {
    97111                this.showView();
    98112            } else {
     
    106120            // on it,but we don't know the actual code here.
    107121            var newWidget = this._factory.createViewWidget( lang.mixin({code:""},this.value) );
    108             if ( newWidget !== null ) {
     122            if ( newWidget ) {
    109123                this._destroyInnerWidget();
    110124                this.innerWidget = newWidget;
    111                 this.innerWidget.set('readOnly',true);
    112125                this.addChild(this.innerWidget);
     126                this._setReadOnlyChildren(true);
     127                this._setDisabledChildren(true);
    113128                this.titleNode.innerHTML = this.value.type+" [preview]";
    114129                domClass.replace(this.editButton.iconNode, "rftIconEdit", "rftIconAccept");
     
    119134        _showEditWidget: function() {
    120135            var newWidget = this._factory.createEditWidget( this.value );
    121             if ( newWidget !== null ) {
     136            if ( newWidget ) {
    122137                this._destroyInnerWidget();
    123138                this.innerWidget = newWidget;
    124                 this.innerWidget.set('readOnly',this.readOnly);
    125                 this.innerWidget.set('disabled',this.disabled);
    126139                this.addChild(this.innerWidget);
     140                this._setReadOnlyChildren(this.readOnly);
     141                this._setDisabledChildren(this.disabled);
    127142                this.titleNode.innerHTML = this.value.type+" [editing]";
    128143                domClass.replace(this.editButton.iconNode, "rftIconAccept", "rftIconEdit");
Note: See TracChangeset for help on using the changeset viewer.