source: Dev/branches/rest-dojo-ui/client/qed/pages/survey.js @ 421

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

We can store answers for surveys now!

Introduces SurveyRun?, which can be edited. Workflow not quite clear yet. A
running survey can be accessed to leave a response. When the response
has an ID, it is loaded (used for closed surveys and continuations). A
researcher cannot create responses yet. He should also be able to add
comments to responses (that he creates).

Introduced caching of store requests.

Factored out path matching and formatting.

Put object creation in separate classes, to localize model/storage
dependency. Not consistent at the moment.

File size: 3.9 KB
Line 
1define([
2    'dojo/_base/array',
3    'dojo/_base/declare',
4    'dojo/_base/event',
5    'dojo/_base/lang',
6    'dojo/when',
7    '../app/Router',
8    '../store',
9    '../app/Page',
10    '../model/classes/Survey',
11    '../model/widgets/QuestionListView',
12    '../model/widgets/TabbedQuestionBrowser',
13    'dojo/text!./templates/survey.html'
14],function(array,declare,event,lang,when,Router,store,Page,Survey,
15         QuestionListView,TabbedQuestionBrowser,template){
16    return declare([Page],{
17        templateString: template,
18        survey: null,
19        questionList: null,
20        startup: function() {
21            if ( this._started ) { return; }
22            this.inherited(arguments);
23            if ( this.surveyId ) {
24                this._setupQuestionBrowser();
25                this._setupListView();
26                this._loadSurvey();
27            } else {
28                throw "No valid uid or survey passed!";
29            }
30        },
31        _setupQuestionBrowser: function() {
32            this.questionBrowser = new TabbedQuestionBrowser({
33                region: 'center',
34                'class': 'blue',
35                include: 'published',
36                selectedActions: {
37                    "Include": {
38                        callback: lang.hitch(this,this._includeQuestion),
39                        icon: "Accept",
40                        description: "Include in survey"
41                    }
42                },
43                itemActions: {
44                    "Info": {
45                        callback: function(item){ item.description && alert(item.description); },
46                        icon: "Inspect",
47                        description: "Show item description"
48                    }
49                }
50            },this.questionBrowser);
51            this.questionBrowser.startup();
52        },
53        _setupListView: function() {
54            this.questionList = new QuestionListView({
55                region: 'center'
56            },this.surveyListViewNode);
57            this.questionList.startup();
58        },
59        _loadSurvey: function() {
60            if ( this.surveyId === "new" ) {
61                this.survey = Survey.create();
62                this.refresh();
63            } else {
64                when(store.get(this.surveyId))
65                .then(lang.hitch(this,function(survey){
66                    this.survey = survey;
67                    array.forEach(Survey.Questions.get(this.survey),
68                        lang.hitch(this.questionList,'appendItem'));
69                    this.refresh();
70                }));
71            }
72        },
73        _includeQuestion: function(question) {
74            this.questionList.insertItem(question);
75        },
76        refresh: function() {
77            this.titleNode.innerHTML = Survey.DisplayTitle.get(this.survey) || "(set title in properties)";
78            this.propertiesDialog.set('value',this.survey);
79        },
80        _onShowProperties: function(evt) {
81            this.propertiesDialog.show();
82        },
83        _onPropertiesOk: function(evt) {
84            this.propertiesDialog.hide();
85            lang.mixin(this.survey, this.propertiesDialog.get('value'));
86            this.refresh();
87            event.stop(evt);
88            return false;
89        },
90        _onPropertiesCancel: function(evt) {
91            this.propertiesDialog.hide();
92            this.propertiesDialog.reset('value',this.survey);
93            event.stop(evt);
94            return false;
95        },
96        _onSave: function(evt) {
97            this.survey.questions = this.questionList.getItems();
98            store.put(this.survey)
99            .then(function() {
100                Router.go('/surveys');
101            });
102            event.stop(evt);
103            return false;
104        },
105        _onDiscard: function(evt) {
106            Router.go('/surveys');
107        },
108        _onShowPreview: function() {
109            Router.go('/previewSurvey/'+store.getIdentity(this.survey),{
110                preview: true
111            });
112        }
113    });
114});
115
Note: See TracBrowser for help on using the repository browser.