- Timestamp:
- 08/06/12 17:39:05 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/rest-dojo-ui/client/rft/ui/QuestionEditorPreviewItem.js
r387 r389 5 5 'dojo/dom-class', 6 6 'dojo/on', 7 'dijit/_Container', 7 8 'dijit/_TemplatedMixin', 8 9 'dijit/_WidgetBase', 9 10 'dijit/_WidgetsInTemplateMixin', 10 ' rft/ui/ContentWidgetFactory',11 './content/ContentWidgetFactory', 11 12 '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], { 15 15 version: "full", 16 16 templateString: template, 17 17 baseClass: "surveyEditorPreviewItem", 18 18 previousContentHeight: 200, 19 item: null, 19 20 innerWidget: null, 20 21 foldDuration: [250, 250], … … 22 23 _editing: false, 23 24 24 postCreate: function() {25 startup: function() { 25 26 this.inherited(arguments); 26 27 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"); 28 29 this.editButtonNode.onClick = lang.hitch(this, this.toggleEdit); 29 30 if (this.item) { 30 this._ createInnerWidget();31 this._showViewWidget(); 31 32 } else { 32 throw "No data supplied to create an innerWidget off of!";33 throw "No data supplied to create an innerWidget!"; 33 34 } 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 } 38 71 }, 39 72 toggleEdit: function() { 40 73 if(this._editing) { 74 if ( this.innerWidget !== null ) { 75 this.item = this.innerWidget.get('value'); 76 } 77 this._destroyInnerWidget(); 78 this._showViewWidget(); 41 79 this.editButtonNode.iconNode.className = this.editButtonNode.iconNode.className.replace("rftIconAccept", "rftIconEdit"); 42 80 this.editButtonNode.set("label", "Edit"); 43 this.innerWidget.save();44 }45 else {81 } else { 82 this._destroyInnerWidget(); 83 this._showEditWidget(); 46 84 this.editButtonNode.iconNode.className = this.editButtonNode.iconNode.className.replace("rftIconEdit", "rftIconAccept"); 47 85 this.editButtonNode.set("label", "Save"); 48 this.innerWidget.edit();49 86 } 50 87 this._editing = !this._editing; … … 81 118 } 82 119 } 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();94 120 } 95 121
Note: See TracChangeset
for help on using the changeset viewer.