source: Dev/trunk/src/client/qed-client/model/widgets/SurveyRenderWidget.js

Last change on this file was 513, checked in by hendrikvanantwerpen, 11 years ago
  • Another shot at getting change events right for _ComplexValueMixin. Our previous approach made it impossible to detect if a change was cause during startup. Now we work purely with widget 'change' events. Children are connected during postCreate, addChild. If you add children otherwise you need to call connectChildsChanges yourself. Also to make sure events are generated, use _setValueInternal if you really need to set the value attribute yourself.
  • Removed unused widget.
File size: 1.8 KB
RevLine 
[443]1define([
[457]2    "../../widgets/_ComplexValueWidget",
[443]3    "./questions/Factory",
4    "dojo/_base/array",
5    "dojo/_base/declare",
[511]6    "dojo/_base/lang",
[443]7    "dojo/dom-construct",
[457]8    "dojo/text!./templates/SurveyRenderWidget.html"
[511]9], function(_ComplexValueWidget, QuestionWidgetFactory, array, declare, lang, domConstruct, template) {
[457]10    return declare([_ComplexValueWidget],{
[443]11        templateString: template,
12        survey: null,
13        startup: function() {
14            if ( this._started ) { return; }
15            this.inherited(arguments);
16            if ( this.survey ) {
17                this._setSurveyAttr(this.survey);
18            }
19        },
20        _setSurveyAttr: function(survey) {
21            domConstruct.empty(this.domNode);
22            this.survey = survey;
23            var f = new QuestionWidgetFactory();
[508]24            array.forEach(this.survey.questions,function(question){
25                array.forEach(question.content || [], function(item){
26                    item.code = question.code;
[443]27                    var w = f.createViewWidget(item);
28                    if ( w !== null ) {
29                        w.placeAt(this.domNode);
[508]30                        w.startup();
[443]31                    }
32                },this);
33            },this);
[511]34        },
35        _getValueAttr: function() {
36            var newValue = {};
37            array.forEach(this._getDescendantFormWidgets(),function(widget){
38                lang.mixin(newValue,widget.get('value'));
39            },this);
[513]40            return newValue;
[511]41        },
[513]42        _setValueAttr: function(value,priorityChange) {
43            this._setValueInternal(value,priorityChange);
[511]44            array.forEach(this._getDescendantFormWidgets(),function(widget){
45                widget.set('value',value);
46            },this);
[443]47        }
48    });
49});
Note: See TracBrowser for help on using the repository browser.