- Timestamp:
- 07/30/12 00:19:37 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/rest-dojo-ui/client/rft/ui/QuestionEditorPreviewItem.js
r381 r387 1 1 define([ 2 'dojo/_base/declare', 3 'dojo/_base/fx', 4 'dijit/_WidgetBase', 5 'dojo/dom-class', 6 'dojo/_base/lang', 7 'dojo/on', 8 'dijit/_TemplatedMixin', 9 'dijit/_WidgetsInTemplateMixin', 10 'dijit/form/TextBox', 11 'rft/ui/InnerWidgetFactory', 12 'dojo/text!./templates/QuestionEditorPreviewItem.html', 13 ], function(declare, fx, _WidgetBase, domClass, lang, on, _TemplatedMixin, _WidgetsInTemplateMixin, TextBox, InnerWidgetFactory, templateFull) { 14 return declare("rft.ui.QuestionEditorPreviewItem", [_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], { 2 'dojo/_base/declare', 3 'dojo/_base/fx', 4 'dojo/_base/lang', 5 'dojo/dom-class', 6 'dojo/on', 7 'dijit/_TemplatedMixin', 8 'dijit/_WidgetBase', 9 'dijit/_WidgetsInTemplateMixin', 10 'rft/ui/ContentWidgetFactory', 11 '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], { 15 14 16 17 templateString: templateFull,18 19 20 21 22 23 15 version: "full", 16 templateString: template, 17 baseClass: "surveyEditorPreviewItem", 18 previousContentHeight: 200, 19 innerWidget: null, 20 foldDuration: [250, 250], 21 animation: null, 22 _editing: false, 24 23 25 postCreate: function() { 26 this.foldButtonNode.onClick = lang.hitch(this, this.toggleFold); 27 this.removeButtonNode.onClick = lang.hitch(this, this.removeObject); 28 this.editButtonNode.onClick = lang.hitch(this, this.toggleEdit); 29 if (this.item) { 30 this._createInnerWidget(); 31 } else { 32 throw "No data supplied to create an innerWidget off of!"; 33 } 24 postCreate: function() { 25 this.inherited(arguments); 26 this.foldButtonNode.onClick = lang.hitch(this, this.toggleFold); 27 this.removeButtonNode.onClick = lang.hitch(this, this.removeObject); 28 this.editButtonNode.onClick = lang.hitch(this, this.toggleEdit); 29 if (this.item) { 30 this._createInnerWidget(); 31 } else { 32 throw "No data supplied to create an innerWidget off of!"; 33 } 34 34 35 on(this.innerWidget, "onSetTitle", function(title) { 36 this.titleNode.innerHTML = title; 37 }); 38 }, 39 toggleEdit: function() { 40 if(this._editing) { 41 this.editButtonNode.iconNode.className = this.editButtonNode.iconNode.className.replace("rftIconAccept", "rftIconEdit"); 42 this.editButtonNode.set("label", "Edit"); 43 this.innerWidget.save(); 44 } 45 else { 46 this.editButtonNode.iconNode.className = this.editButtonNode.iconNode.className.replace("rftIconEdit", "rftIconAccept"); 47 this.editButtonNode.set("label", "Save"); 48 this.innerWidget.edit(); 49 } 50 this._editing = !this._editing; 51 }, 52 toggleFold: function() { 53 if (!this.animation) { 54 if (!domClass.contains(this.domNode, "fold")) { 55 this.previousContentHeight = dojo.marginBox(this.innerNode).h; 56 this.animation = fx.animateProperty({ 57 node: this.innerNode, 58 duration: this.foldDuration[0], 59 properties: { 60 height: 1 61 }, 62 onEnd: lang.hitch(this, function(){ 63 domClass.add(this.domNode, "fold"); 64 this.animation = null; 65 }) 66 }).play(); 67 this.foldButtonNode.iconNode.className = this.foldButtonNode.iconNode.className.replace("rftIconHalfArrowUp", "rftIconHalfArrowDown"); 68 } else { 69 this.animation = fx.animateProperty({ 70 node: this.innerNode, 71 duration: this.foldDuration[1], 72 properties: { 73 height: this.previousContentHeight 74 }, 75 onEnd: lang.hitch(this, function(){ 76 domClass.remove(this.domNode, "fold"); 77 this.animation = null; 78 }) 79 }).play(); 80 this.foldButtonNode.iconNode.className = this.foldButtonNode.iconNode.className.replace("rftIconHalfArrowDown", "rftIconHalfArrowUp"); 81 } 82 } 83 }, 84 getContent: function() { 85 return this.innerWidget.getObject(); 86 }, 87 removeObject: function(widget) { 88 this.destroyRecursive(); 89 }, 90 _createInnerWidget: function() { 91 // This always creates a textbox as innerwidget pending creation of actual innerWidgets. 92 // Introduce a better way to create these widgets than a switch statement, based on item.widgetType? Perhaps "new eval(item.widgetType)({});" ? 35 on(this.innerWidget, "onSetTitle", function(title) { 36 this.titleNode.innerHTML = title; 37 }); 38 }, 39 toggleEdit: function() { 40 if(this._editing) { 41 this.editButtonNode.iconNode.className = this.editButtonNode.iconNode.className.replace("rftIconAccept", "rftIconEdit"); 42 this.editButtonNode.set("label", "Edit"); 43 this.innerWidget.save(); 44 } 45 else { 46 this.editButtonNode.iconNode.className = this.editButtonNode.iconNode.className.replace("rftIconEdit", "rftIconAccept"); 47 this.editButtonNode.set("label", "Save"); 48 this.innerWidget.edit(); 49 } 50 this._editing = !this._editing; 51 }, 52 toggleFold: function() { 53 if (!this.animation) { 54 if (!domClass.contains(this.domNode, "fold")) { 55 this.previousContentHeight = dojo.marginBox(this.innerNode).h; 56 this.animation = fx.animateProperty({ 57 node: this.innerNode, 58 duration: this.foldDuration[0], 59 properties: { 60 height: 1 61 }, 62 onEnd: lang.hitch(this, function(){ 63 domClass.add(this.domNode, "fold"); 64 this.animation = null; 65 }) 66 }).play(); 67 this.foldButtonNode.iconNode.className = this.foldButtonNode.iconNode.className.replace("rftIconHalfArrowUp", "rftIconHalfArrowDown"); 68 } else { 69 this.animation = fx.animateProperty({ 70 node: this.innerNode, 71 duration: this.foldDuration[1], 72 properties: { 73 height: this.previousContentHeight 74 }, 75 onEnd: lang.hitch(this, function(){ 76 domClass.remove(this.domNode, "fold"); 77 this.animation = null; 78 }) 79 }).play(); 80 this.foldButtonNode.iconNode.className = this.foldButtonNode.iconNode.className.replace("rftIconHalfArrowDown", "rftIconHalfArrowUp"); 81 } 82 } 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 } 93 95 94 this.innerWidget = new InnerWidgetFactory().createWidget( this.item ); 95 /* 96 this.innerWidget = eval("new "+ this.item.type + "({ disabled: true });"); 97 this.innerWidget.setContent(this.item.data); 98 this.titleNode.innerHTML = this.item.type; 99 /* 100 switch (this.item.widgetType) { 101 default: 102 this.innerWidget = new HeaderItem({ disabled: true }); 103 this.titleNode.innerHTML = "Header"; 104 break; 105 }*/ 106 this.innerWidget.startup(); 107 this.innerWidget.placeAt(this.containerNode); 108 } 109 110 }); 111 }); 96 }); 97 });
Note: See TracChangeset
for help on using the changeset viewer.