Changeset 426 for Dev/trunk/client/qed/model/widgets
- Timestamp:
- 03/13/13 17:07:58 (12 years ago)
- Location:
- Dev/trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk
- Property svn:ignore
-
old new 1 1 data 2 2 nbproject 3 node_modules
-
- Property svn:ignore
-
Dev/trunk/client
- Property svn:externals
-
old new 1 dojo http://svn.dojotoolkit.org/src/tags/release-1.8. 0/dojo2 dijit http://svn.dojotoolkit.org/src/tags/release-1.8. 0/dijit3 dojox http://svn.dojotoolkit.org/src/tags/release-1.8. 0/dojox4 util http://svn.dojotoolkit.org/src/tags/release-1.8. 0/util1 dojo http://svn.dojotoolkit.org/src/tags/release-1.8.3/dojo 2 dijit http://svn.dojotoolkit.org/src/tags/release-1.8.3/dijit 3 dojox http://svn.dojotoolkit.org/src/tags/release-1.8.3/dojox 4 util http://svn.dojotoolkit.org/src/tags/release-1.8.3/util
-
- Property svn:externals
-
Dev/trunk/client/qed/model/widgets/CategoryListView.js
r417 r426 2 2 'dojo/_base/declare', 3 3 'dojo/_base/lang', 4 'dojo/dom-construct', 4 5 '../../widgets/LineWithActionsWidget', 5 6 '../../widgets/list/List' 6 ],function( 7 declare, 8 lang, 9 LineWithActionsWidget, 10 List 11 ) { 7 ],function(declare, lang, domConstruct, LineWithActionsWidget, List) { 12 8 return declare([List],{ 13 9 baseClass: 'rftLineListView', 14 10 15 11 _createAvatarNode: function(item) { 16 var node = document.createElement("div"); 17 node.className = "dragAvatar"; 18 node.innerHTML = item.title; 12 var node = domConstruct.create("div",{ 13 className: "dragAvatar", 14 innerHTML: item.title 15 }); 19 16 return node; 20 17 }, -
Dev/trunk/client/qed/model/widgets/QuestionEditorToolkit.js
r417 r426 14 14 './CategoryListView', 15 15 'dojo/text!./templates/QuestionEditorToolkit.html' 16 ], function(declare, lang, Source, domConstruct, Memory, _Container, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, Button, ComboBox, store, CategoryListView, template) { 17 return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, _Container], { 16 ], function(declare, lang, Source, domConstruct, Memory, _Container, 17 _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, Button, 18 ComboBox, store, CategoryListView, template) { 19 return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, _Container], { 18 20 19 20 21 22 23 24 25 21 templateString: template, 22 _list: null, 23 _categorySelect: null, 24 _categoryStore: null, 25 _topicSelect: null, 26 _topicStore: null, 27 _categories : null, 26 28 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 29 _contentItems: [ 30 { type: "Header" }, 31 { type: "Text" }, 32 { type: "Image" }, 33 { type: "ExternalMedia" }, 34 { type: "Divider" } 35 ], 36 _inputsItems: [ 37 { type: "StringInput" }, 38 { type: "TextInput" }, 39 { type: "IntegerInput" }, 40 { type: "ScaleInput" }, 41 { type: "MultipleChoiceInput" } 42 ], 43 _labelMap: { 44 "Header": "Header", 45 "Text": "Text", 46 "Image": "Image", 47 "ExternalMedia": "External media", 48 "Divider": "Divider", 49 "StringInput": "Text line", 50 "TextInput": "Free text", 51 "IntegerInput": "Integer number", 52 "ScaleInput": "Scale", 53 "MultipleChoiceInput": "Multiple choice" 54 }, 55 _iconMap: { 56 "Header": "Header", 57 "Text": "TextBox", 58 "Image": "Image", 59 "ExternalMedia": "External", 60 "Divider": "Divider", 61 "StringInput": "Text", 62 "TextInput": "Text", 63 "IntegerInput": "Integer", 64 "ScaleInput": "Scale", 65 "MultipleChoiceInput": "MultipleChoice" 66 }, 65 67 66 postCreate: function(){ 67 this.inherited(arguments); 68 var creator = lang.hitch(this,"_creator"); 69 this.contentSource = new Source(this.ToolkitContentSourceNode, { 70 accept: [], 71 copyOnly: true, 72 selfAccept: false, 73 singular: true, 74 creator: creator 68 postCreate: function(){ 69 this.inherited(arguments); 70 var creator = lang.hitch(this,"_creator"); 71 this.contentSource = new Source(this.ToolkitContentSourceNode, { 72 accept: [], 73 copyOnly: true, 74 selfAccept: false, 75 singular: true, 76 creator: creator 77 }); 78 this.inputsSource = new Source(this.ToolkitInputsSourceNode, { 79 accept: [], 80 copyOnly: true, 81 selfAccept: false, 82 singular: true, 83 creator: creator 84 }); 85 this.contentSource.insertNodes(false, this._contentItems); 86 this.inputsSource.insertNodes(false, this._inputsItems); 87 }, 88 _setValueAttr: function(question) { 89 this.propertiesForm.set('value', question); 90 this._categories = question.categories || []; 91 this._setupListView(); 92 this._setupCategories(); 93 this._setupTopic(question.topic); 94 }, 95 _getValueAttr: function() { 96 var value = this.propertiesForm.get('value'); 97 value.categories = this._categories; 98 return value; 99 }, 100 onCategoryAdd: function() { 101 this._addCategory(this._categorySelect.get('displayedValue')); 102 this._categorySelect.reset(); 103 }, 104 _creator: function(item, hint) { 105 var node; 106 if (hint === "avatar") { 107 node = domConstruct.create('span',{ 108 innerHTML: this._labelMap[item.type] || item.type 75 109 }); 76 this.inputsSource = new Source(this.ToolkitInputsSourceNode, { 77 accept: [], 78 copyOnly: true, 79 selfAccept: false, 80 singular: true, 81 creator: creator 110 } else { 111 var w = new Button({ 112 baseClass: "rftLargeButton", 113 iconClass: "rftIcon rftIcon"+(this._iconMap[item.type]||"Unknown"), 114 label: this._labelMap[item.type] || item.type, 115 showLabel: true, 116 'class': "newline" 82 117 }); 83 this.contentSource.insertNodes(false, this._contentItems); 84 this.inputsSource.insertNodes(false, this._inputsItems); 85 }, 86 _setValueAttr: function(question) { 87 this.propertiesForm.set('value', question); 88 this._categories = question.categories || []; 89 this._setupListView(); 90 this._setupCategories(); 91 this._setupTopic(question.topic); 92 }, 93 _getValueAttr: function() { 94 var value = this.propertiesForm.get('value'); 95 value.categories = this._categories; 96 return value; 97 }, 98 onCategoryAdd: function() { 99 this._addCategory(this._categorySelect.get('displayedValue')); 100 this._categorySelect.reset(); 101 }, 102 _creator: function(item, hint) { 103 var node; 104 if (hint == "avatar") { 105 node = domConstruct.create('span',{ 106 innerHTML: this._labelMap[item.type] || item.type 107 }); 108 } else { 109 var w = new Button({ 110 baseClass: "rftLargeButton", 111 iconClass: "rftIcon rftIcon"+(this._iconMap[item.type]||"Unknown"), 112 label: this._labelMap[item.type] || item.type, 113 showLabel: true, 114 'class': "newline" 115 }); 116 node = w.domNode; 117 } 118 return {node: node, data: item, type: ["questionContent"]}; 119 }, 120 _setupListView: function() { 121 this._list = new CategoryListView( { 122 removeCallback: lang.hitch(this, this._removeCategory) 123 }).placeAt(this.listNode); 124 this._list.startup(); 125 for (var category in this._categories) { 126 this._list.appendItem(this._categories[category]); 127 } 128 }, 129 _setupCategories: function() { 130 this._categoryStore = new Memory({data: [] }); 131 store.query("_design/questions/_view/all", {reduce:true, group:false, group_level:1}) 132 .forPairs(lang.hitch(this, function(value, key) { 133 this._categoryStore.put({ id: key[0] }); 134 })); 135 this._categorySelect = new ComboBox( { 136 name: "categories", 137 store: this._categoryStore, 138 searchAttr: "id" 139 }, this.categoriesBoxNode); 140 this._supportingWidgets.push(this._categorySelect); 118 node = w.domNode; 119 } 120 return {node: node, data: item, type: ["questionContent"]}; 121 }, 122 _setupListView: function() { 123 this._list = new CategoryListView( { 124 removeCallback: lang.hitch(this, this._removeCategory) 125 }).placeAt(this.listNode); 126 this._list.startup(); 127 for (var category in this._categories) { 128 this._list.appendItem(this._categories[category]); 129 } 130 }, 131 _setupCategories: function() { 132 this._categoryStore = new Memory({data: [] }); 133 store.query("_design/questions/_view/all", {reduce:true, group:false, group_level:1}) 134 .forPairs(lang.hitch(this, function(value, key) { 135 this._categoryStore.put({ id: key[0] }); 136 })); 137 this._categorySelect = new ComboBox( { 138 name: "categories", 139 store: this._categoryStore, 140 searchAttr: "id" 141 }, this.categoriesBoxNode); 142 this._supportingWidgets.push(this._categorySelect); 141 143 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 144 }, 145 _setupTopic: function(topic) { 146 this._topicStore = new Memory( {data: [] }); 147 store.query("_design/questions/_view/all_topics", {reduce:true, group:true}) 148 .forPairs(lang.hitch(this, function(value, key) { 149 this._topicStore.put({ id: key }); 150 })); 151 this._topicSelect = new ComboBox( { 152 name: "topic", 153 store: this._topicStore, 154 searchAttr: "id", 155 value: topic 156 }, this.topicBoxNode); 157 this._supportingWidgets.push(this._topicSelect); 158 }, 159 _addCategory: function(item) { 160 this._categories.push(item); 161 this._list.appendItem(item); 162 }, 163 _removeCategory: function(item) { 164 this._categories.splice(this._categories.indexOf(item), 1); 165 } 164 166 165 });166 167 }); 168 }); -
Dev/trunk/client/qed/model/widgets/QuestionListView.js
r417 r426 36 36 }, 37 37 "Info" : { 38 callback: function(){ item.description && alert(item.description); }, 38 callback: function(){ 39 if ( item.description ) { alert(item.description); } 40 }, 39 41 properties: { 40 42 blockButton: false, -
Dev/trunk/client/qed/model/widgets/QuestionWidget.js
r417 r426 2 2 'dijit/_TemplatedMixin','dijit/_WidgetsInTemplateMixin', 3 3 'dojo/text!./templates/QuestionWidget.html','dijit/form/TextBox', 4 'dijit/form/Textarea','../../widgets/MultipleChoiceWidget'], 5 function(declare,lang,domConstruct,_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,templateString,TextBox,Textarea,MultipleChoiceWidget){ 6 return declare([_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin],{ 7 templateString: templateString, 8 mode: 'view', // view || edit 9 name: '', 10 value: null, 11 _scale: null, 12 _widgetCache: null, 13 constructor: function() { 14 this.inherited(arguments); 15 this.value = {}; 16 this._widgetCache = {}; 17 }, 18 postCreate: function() { 19 this._resetValue = this.value; 20 this.scaleSelector.set('disabled', this.mode == 'edit'); 21 }, 22 _setValueAttr: function(value) { 23 this.value = value; 24 this._onTypeChange(value.scale || 'string'); 25 this.ourForm.set('value',value); 26 }, 27 _getValueAttr: function() { 28 var value = this.ourForm.get('value'); 29 lang.mixin(this.value,value); 30 return this.value; 31 }, 32 _onTypeChange: function(scale) { 33 if ( this._scale == scale ) return; 34 this._scale = scale; 35 domConstruct.empty(this.scaleDetails); 36 var widget = this._getTypeWidget(scale); 37 widget && widget.placeAt(this.scaleDetails,'only'); 38 }, 39 _getTypeWidget: function(scale) { 40 var widget = this._widgetCache[scale]; 41 if (!widget) { 42 switch(scale) { 43 case 'string': 44 widget = new TextBox({ 45 name: 'answers', 46 disabled: this.mode == 'view' 47 }); 48 break; 49 case 'text': 50 widget = new Textarea({ 51 name: 'answers', 52 disabled: this.mode == 'view', 53 style: 'min-height: 120px' 54 }); 55 break; 56 case 'singleChoice': 57 case 'multipleChoice': 58 widget = new MultipleChoiceWidget({ 59 name: 'answers', 60 mode: this.mode, 61 allowMultiple: scale == 'multipleChoice' 62 }); 63 break; 64 } 65 this._widgetCache[scale] = widget; 4 'dijit/form/Textarea','../../widgets/MultipleChoiceWidget' 5 ], function(declare,lang,domConstruct,_WidgetBase,_TemplatedMixin, 6 _WidgetsInTemplateMixin,templateString,TextBox,Textarea,MultipleChoiceWidget){ 7 return declare([_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin],{ 8 templateString: templateString, 9 mode: 'view', // view || edit 10 name: '', 11 value: null, 12 _scale: null, 13 _widgetCache: null, 14 constructor: function() { 15 this.inherited(arguments); 16 this.value = {}; 17 this._widgetCache = {}; 18 }, 19 postCreate: function() { 20 this._resetValue = this.value; 21 this.scaleSelector.set('disabled', this.mode === 'edit'); 22 }, 23 _setValueAttr: function(value) { 24 this.value = value; 25 this._onTypeChange(value.scale || 'string'); 26 this.ourForm.set('value',value); 27 }, 28 _getValueAttr: function() { 29 var value = this.ourForm.get('value'); 30 lang.mixin(this.value,value); 31 return this.value; 32 }, 33 _onTypeChange: function(scale) { 34 if ( this._scale === scale ) { return; } 35 this._scale = scale; 36 domConstruct.empty(this.scaleDetails); 37 var widget = this._getTypeWidget(scale); 38 if ( widget ) { widget.placeAt(this.scaleDetails,'only'); } 39 }, 40 _getTypeWidget: function(scale) { 41 var widget = this._widgetCache[scale]; 42 if (!widget) { 43 switch(scale) { 44 case 'string': 45 widget = new TextBox({ 46 name: 'answers', 47 disabled: this.mode === 'view' 48 }); 49 break; 50 case 'text': 51 widget = new Textarea({ 52 name: 'answers', 53 disabled: this.mode === 'view', 54 style: 'min-height: 120px' 55 }); 56 break; 57 case 'singleChoice': 58 case 'multipleChoice': 59 widget = new MultipleChoiceWidget({ 60 name: 'answers', 61 mode: this.mode, 62 allowMultiple: scale === 'multipleChoice' 63 }); 64 break; 66 65 } 67 return widget; 68 }, 69 reset: function() { 70 this.ourForm.reset(); 71 this._setValueAttr(this._resetValue); 66 this._widgetCache[scale] = widget; 72 67 } 73 }); 68 return widget; 69 }, 70 reset: function() { 71 this.ourForm.reset(); 72 this._setValueAttr(this._resetValue); 73 } 74 74 }); 75 }); -
Dev/trunk/client/qed/model/widgets/QuestionWidgetFactory.js
r421 r426 30 30 var fun = this['create'+options.type+'EditWidget']; 31 31 var view = fun !== undefined ? fun() : null; 32 if (view)32 if (view) { 33 33 view.set('value', options); 34 } 34 35 return view; 35 36 }, … … 272 273 var table = new TableContainer({ cols: 1, customClass: "labelsAndValues"} ); 273 274 274 var ctor = this.options.multiple === true ? CheckBox : RadioButton;275 array.forEach(this.options.items || [], function(item){276 table.addChild(new ctor({277 278 275 var Ctor = this.options.multiple === true ? CheckBox : RadioButton; 276 array.forEach(this.options.items || [], function(item){ 277 table.addChild(new Ctor({ 278 name: this.options.code || '', 279 title: item 279 280 })); 280 281 },this); … … 342 343 w.startup(); 343 344 w.set('value',item); 344 w.on('delete',lang.hitch(this,'_onRemove',w ));345 w.on('delete',lang.hitch(this,'_onRemove',w,item)); 345 346 return w.domNode; 346 347 }, 347 _onRemove: function(w ) {348 _onRemove: function(w,item) { 348 349 w.destroyRecursive(); 349 this.removeCallback && this.removeCallback(item);350 if ( this.removeCallback ) { this.removeCallback(item); } 350 351 this.source.sync(); 351 352 }
Note: See TracChangeset
for help on using the changeset viewer.