source: Dev/branches/rest-dojo-ui/client/rft/pages/viewSurvey.js @ 406

Last change on this file since 406 was 406, checked in by hendrikvanantwerpen, 13 years ago

Lots of small fixes.

Make it possible to read survey answers (when a question code is
provided), it is now displayed in place of the survey. More to come.

Some whitespace fixes.

File size: 1.9 KB
Line 
1define([
2    'dojo/_base/array',
3    'dojo/_base/declare',
4    'dojo/_base/Deferred',
5    'dojo/_base/event',
6    'dojo/_base/lang',
7    '../store',
8    '../ui/_Page',
9    '../ui/content/ContentWidgetFactory'
10    ],
11    function(array,declare,Deferred,event,lang,store,_Page,ContentWidgetFactory){
12        return declare('rft.pages.viewSurvey',[_Page],{
13            survey: null,
14            constructor: function(){
15                this._dataMap = {};
16            },
17            onVisit: function() {
18                if ( this.pageArgs.uid ) {
19                    Deferred.when(store.get(this.pageArgs.uid))
20                    .then(lang.hitch(this,function(obj){
21                        var f = new ContentWidgetFactory();
22                        this.survey = obj;
23                        store.query(null,{keys:this.survey.questions,include_docs:true})
24                        .forEach(function(question){
25                            array.forEach(question.content || [],function(item){
26                                var w = f.createViewWidget(item,{
27                                    name: question.code+'.'+item.code
28                                });
29                                if ( w !== null ) {
30                                    w.placeAt(this.questionsAnchor,'before');
31                                }
32                            },this);
33                        },this);
34                    }));
35                } else {
36                    throw "No valid uid or survey passed!";
37                }
38            },
39            _onSubmit: function(evt) {
40                var value = this.questionsForm.get('value');
41                this.questionsPane.set('content','<pre>'+JSON.stringify(value)+'</pre>');
42                event.stop(evt);
43                return false;
44            },
45            _onCancel: function(evt) {
46                event.stop(evt);
47                return false;
48            }
49        });
50});
51
Note: See TracBrowser for help on using the repository browser.