1 | define([ |
---|
2 | 'dojo/_base/array', |
---|
3 | 'dojo/_base/declare', |
---|
4 | 'dojo/_base/Deferred', |
---|
5 | 'dojo/_base/event', |
---|
6 | 'dojo/_base/lang', |
---|
7 | '../store', |
---|
8 | '../app/Page', |
---|
9 | '../ui/content/ContentWidgetFactory', |
---|
10 | 'dojo/text!./viewSurvey.html' |
---|
11 | ],function(array,declare,Deferred,event,lang,store,Page,ContentWidgetFactory,template){ |
---|
12 | return declare([Page],{ |
---|
13 | templateString: template, |
---|
14 | survey: null, |
---|
15 | constructor: function(){ |
---|
16 | this._dataMap = {}; |
---|
17 | }, |
---|
18 | startup: function() { |
---|
19 | if ( this._started ) { return; } |
---|
20 | this.inherited(arguments); |
---|
21 | if ( this.surveyId ) { |
---|
22 | Deferred.when(store.get(this.surveyId)) |
---|
23 | .then(lang.hitch(this,function(obj){ |
---|
24 | var f = new ContentWidgetFactory(); |
---|
25 | this.survey = obj; |
---|
26 | store.query(null,{keys:this.survey.questions,include_docs:true}) |
---|
27 | .forEach(function(question){ |
---|
28 | array.forEach(question.content || [],function(item){ |
---|
29 | var w = f.createViewWidget(item,{ |
---|
30 | name: question.code+'.'+item.code |
---|
31 | }); |
---|
32 | if ( w !== null ) { |
---|
33 | w.placeAt(this.questionsAnchor,'before'); |
---|
34 | } |
---|
35 | },this); |
---|
36 | },this); |
---|
37 | })); |
---|
38 | } else { |
---|
39 | throw "No valid uid or survey passed!"; |
---|
40 | } |
---|
41 | }, |
---|
42 | _onSubmit: function(evt) { |
---|
43 | var value = this.questionsForm.get('value'); |
---|
44 | this.questionsPane.set('content','<pre>'+JSON.stringify(value)+'</pre>'); |
---|
45 | event.stop(evt); |
---|
46 | return false; |
---|
47 | }, |
---|
48 | _onCancel: function(evt) { |
---|
49 | event.stop(evt); |
---|
50 | return false; |
---|
51 | } |
---|
52 | }); |
---|
53 | }); |
---|