1 | define([ |
---|
2 | "../../widgets/_ComplexValueWidget", |
---|
3 | "./questions/Factory", |
---|
4 | "dojo/_base/array", |
---|
5 | "dojo/_base/declare", |
---|
6 | "dojo/_base/lang", |
---|
7 | "dojo/dom-construct", |
---|
8 | "dojo/text!./templates/SurveyRenderWidget.html" |
---|
9 | ], function(_ComplexValueWidget, QuestionWidgetFactory, array, declare, lang, domConstruct, template) { |
---|
10 | return declare([_ComplexValueWidget],{ |
---|
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(); |
---|
24 | array.forEach(this.survey.questions,function(question){ |
---|
25 | array.forEach(question.content || [], function(item){ |
---|
26 | item.code = question.code; |
---|
27 | var w = f.createViewWidget(item); |
---|
28 | if ( w !== null ) { |
---|
29 | w.placeAt(this.domNode); |
---|
30 | w.startup(); |
---|
31 | } |
---|
32 | },this); |
---|
33 | },this); |
---|
34 | }, |
---|
35 | _getValueAttr: function() { |
---|
36 | var newValue = {}; |
---|
37 | array.forEach(this._getDescendantFormWidgets(),function(widget){ |
---|
38 | lang.mixin(newValue,widget.get('value')); |
---|
39 | },this); |
---|
40 | return newValue; |
---|
41 | }, |
---|
42 | _setValueAttr: function(value,priorityChange) { |
---|
43 | this._setValueInternal(value,priorityChange); |
---|
44 | array.forEach(this._getDescendantFormWidgets(),function(widget){ |
---|
45 | widget.set('value',value); |
---|
46 | },this); |
---|
47 | } |
---|
48 | }); |
---|
49 | }); |
---|