- Timestamp:
- 03/12/14 15:16:54 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/src/client/qed-client/model/widgets/QuestionEditorPreviewItem.js
r508 r510 6 6 "dijit/_WidgetBase", 7 7 "dijit/_WidgetsInTemplateMixin", 8 "dojo/_base/array", 8 9 "dojo/_base/declare", 9 10 "dojo/_base/event", … … 15 16 "dojo/on", 16 17 "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) { 18 19 return declare([_ComplexValueWidget], { 19 20 templateString: template, … … 24 25 foldDuration: [250, 250], 25 26 animation: null, 26 _editing: false,27 _editing: null, 27 28 _factory: new QuestionWidgetFactory(), 28 29 … … 36 37 this.own(this.editButton.on('click', 37 38 lang.hitch(this, 'onToggleEdit'))); 38 this.show Edit();39 this.showView(); 39 40 }, 40 41 _handleDestroy: function(evt) { … … 44 45 }, 45 46 _getValueAttr: function(value) { 46 if ( this._editing ) {47 if ( this._editing === true ) { 47 48 this.value = this.innerWidget.get('value'); 48 49 } … … 51 52 _setValueAttr: function(value) { 52 53 this.value = value; 53 if ( this._editing ) {54 if ( this._editing === true ) { 54 55 this._showEditWidget(); 55 56 } else { … … 57 58 } 58 59 }, 59 _setReadOnlyAttr: function() { 60 this.inherited(arguments); 60 _setReadOnlyAttr: function(readOnly) { 61 this._set('readOnly',readOnly); 62 this._setReadOnlyChildren(this.readOnly); 61 63 this._updateRemoveBtn(); 62 64 }, 63 _setDisabledAttr: function() { 64 this.inherited(arguments); 65 _setDisabledAttr: function(disabled) { 66 this._set('disabled',disabled); 67 this._setDisabledChildren(this.disabled); 65 68 this._updateRemoveBtn(); 66 69 }, 67 70 _updateRemoveBtn: function() { 71 var node = this.removeButton.domNode; 68 72 if ( this.readOnly || this.disabled ) { 69 domClass.add( this.removeButton.domNode, 'dijitHidden');73 domClass.add(node, 'dijitHidden'); 70 74 } else { 71 domClass.remove( this.removeButton.domNode, 'dijitHidden');75 domClass.remove(node, 'dijitHidden'); 72 76 } 73 77 }, 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 }, 74 88 validate: function() { 75 return !this._editing|| this.innerWidget.validate();89 return this._editing === false || this.innerWidget.validate(); 76 90 }, 77 91 focus: function() { 78 if ( this._editing ) {92 if ( this._editing === true ) { 79 93 this.innerWidget.focus(); 80 94 } 81 95 }, 82 96 showView: function() { 83 if ( this._editing ) {97 if ( this._editing === true ) { 84 98 if (!this.innerWidget.validate || this.innerWidget.validate() ) { 85 99 this.value = this.innerWidget.get('value'); … … 89 103 }, 90 104 showEdit: function() { 91 if ( !this._editing) {105 if ( this._editing === false ) { 92 106 this._showEditWidget(); 93 107 } 94 108 }, 95 109 onToggleEdit: function(evt) { 96 if ( this._editing) {110 if ( this._editing === true ) { 97 111 this.showView(); 98 112 } else { … … 106 120 // on it,but we don't know the actual code here. 107 121 var newWidget = this._factory.createViewWidget( lang.mixin({code:""},this.value) ); 108 if ( newWidget !== null) {122 if ( newWidget ) { 109 123 this._destroyInnerWidget(); 110 124 this.innerWidget = newWidget; 111 this.innerWidget.set('readOnly',true);112 125 this.addChild(this.innerWidget); 126 this._setReadOnlyChildren(true); 127 this._setDisabledChildren(true); 113 128 this.titleNode.innerHTML = this.value.type+" [preview]"; 114 129 domClass.replace(this.editButton.iconNode, "rftIconEdit", "rftIconAccept"); … … 119 134 _showEditWidget: function() { 120 135 var newWidget = this._factory.createEditWidget( this.value ); 121 if ( newWidget !== null) {136 if ( newWidget ) { 122 137 this._destroyInnerWidget(); 123 138 this.innerWidget = newWidget; 124 this.innerWidget.set('readOnly',this.readOnly);125 this.innerWidget.set('disabled',this.disabled);126 139 this.addChild(this.innerWidget); 140 this._setReadOnlyChildren(this.readOnly); 141 this._setDisabledChildren(this.disabled); 127 142 this.titleNode.innerHTML = this.value.type+" [editing]"; 128 143 domClass.replace(this.editButton.iconNode, "rftIconAccept", "rftIconEdit");
Note: See TracChangeset
for help on using the changeset viewer.