source: Dev/trunk/client/qed/model/widgets/questions/MultipleChoiceInputConfigWidget.js @ 441

Last change on this file since 441 was 441, checked in by hendrikvanantwerpen, 12 years ago

Big cleanup of the question content.

  • Replaced old list implementations with a new one that behaves like a form widget.
  • All question content is now in separate widgets, not in the factory itself.
  • Added form and widget validation for question editing.
File size: 2.4 KB
Line 
1define([
2    "../../../widgets/ListWidget",
3    "../../../widgets/_ComplexValueWidget",
4    "dijit/_TemplatedMixin",
5    "dijit/_WidgetBase",
6    "dijit/_WidgetsInTemplateMixin",
7    "dojo/_base/declare",
8    "dojo/_base/event",
9    "dojo/_base/lang",
10    "dojo/dom-construct",
11    "dojo/text!./templates/MultipleChoiceInputConfigRowWidget.html",
12    "dojo/text!./templates/MultipleChoiceInputConfigWidget.html"
13], function(ListWidget, _ComplexValueWidget, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, declare, event, lang, domConstruct, rowTemplate, template) {
14
15    var Row = declare([_ComplexValueWidget],{
16        templateString: rowTemplate,
17        onDestroy: function(evt) {}
18    });
19   
20    return declare([_ComplexValueWidget],{
21        type: 'MultipleChoiceInput',
22        templateString: template,
23        buildRendering: function() {
24            this.inherited(arguments);
25            this.itemsWidget = new ListWidget({
26                name: "items",
27                type: "MultipleChoiceItem",
28                skipForm: true,
29                delay: 5,
30                createListElement: lang.hitch(this, "_createRow"),
31                createAvatar: lang.hitch(this, "_createAvatar")
32            }, this.itemsNode);
33        },
34        _createRow: function(id, item) {
35            var widget = new Row({
36                id: id,
37                value: item,
38                onDestroy: lang.hitch(this,function(evt){
39                    this.itemsWidget.removeItem(id);
40                    event.stop(evt);
41                    return false;
42                })
43            });
44            widget.startup();
45            return widget;
46        },
47        _createAvatar: function(id, item) {
48            return domConstruct.create("div", {
49                innerHTML: item.text || "(empty)"
50            });
51        },
52        _getValueAttr: function() {
53            var value = this.inherited(arguments);
54            value.allowMultiple = value.allowMultiple && value.allowMultiple.length > 0;
55            value.type = this.type;
56            return value;
57        },
58        _setValueAttr: function(value) {
59            value.allowMultiple = value.allowMultiple === true ? ["on"] : [];
60            this.inherited(arguments);
61        },
62        onAddItem: function(evt) {
63            this.itemsWidget.appendItem({});
64            event.stop(evt);
65            return false;
66        }
67    });
68});
Note: See TracBrowser for help on using the repository browser.