- Timestamp:
- 04/29/13 19:35:10 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/client/qed/model/widgets/QuestionEditorPreviewItem.js
r440 r441 1 1 define([ 2 "./ QuestionWidgetFactory",2 "./questions/Factory", 3 3 "dijit/_Container", 4 4 "dijit/_TemplatedMixin", … … 6 6 "dijit/_WidgetsInTemplateMixin", 7 7 "dojo/_base/declare", 8 "dojo/_base/event", 8 9 "dojo/_base/fx", 9 10 "dojo/_base/lang", … … 13 14 "dojo/on", 14 15 "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) { 16 17 return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, _Container], { 17 18 templateString: template, … … 31 32 lang.hitch(this, 'onToggleFold'))); 32 33 this.own(this.removeButton.on('click', 33 lang.hitch(this, 'on Close')));34 lang.hitch(this, 'onDestroy'))); 34 35 this.own(this.editButton.on('click', 35 36 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'); 40 43 } 41 },42 onClose: function() {},43 _getValueAttr: function(value) {44 44 return this.value; 45 45 }, 46 46 _setValueAttr: function(value) { 47 47 this.value = value; 48 this._destroyInnerWidget();49 48 if ( this._editing ) { 50 49 this._showEditWidget(); … … 53 52 } 54 53 }, 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'); 64 61 this._showViewWidget(); 65 62 } 66 } else { 63 } 64 }, 65 showEdit: function() { 66 if (!this._editing) { 67 67 this._showEditWidget(); 68 68 } 69 69 }, 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 }, 70 79 _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; 74 84 this.innerWidget.placeAt(this.containerNode); 75 85 this.innerWidget.startup(); 76 86 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; 77 91 } 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;82 92 }, 83 93 _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; 87 98 this.innerWidget.placeAt(this.containerNode); 88 99 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; 89 104 } 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;94 105 }, 95 106 _destroyInnerWidget: function() { … … 98 109 } 99 110 }, 100 onToggleFold: function( ) {111 onToggleFold: function(evt) { 101 112 if (!this.animation) { 102 113 if (!domClass.contains(this.domNode, "fold")) { … … 130 141 } 131 142 } 143 evt && event.stop(evt); 144 return false; 132 145 } 133 146
Note: See TracChangeset
for help on using the changeset viewer.