source: Dev/trunk/client/qed/pages/survey.js @ 442

Last change on this file since 442 was 441, checked in by hendrikvanantwerpen, 12 years ago

Big cleanup of the question content.

  • Replaced old list implementations with a new one that behaves like a form widget.
  • All question content is now in separate widgets, not in the factory itself.
  • Added form and widget validation for question editing.
File size: 4.0 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){
46                            if ( item.description ) { alert(item.description); }
47                        },
48                        icon: "Inspect",
49                        description: "Show item description"
50                    }
51                }
52            },this.questionBrowser);
53            this.questionBrowser.startup();
54        },
55        _setupListView: function() {
56            this.questionList = new QuestionListView({
57                region: 'center',
58                name: 'questions'
59            },this.surveyListViewNode);
60            this.questionList.startup();
61        },
62        _loadSurvey: function() {
63            if ( this.surveyId === "new" ) {
64                this.survey = Survey.create();
65                this.refresh();
66            } else {
67                when(store.get(this.surveyId))
68                .then(lang.hitch(this,function(survey){
69                    this.survey = survey;
70                    this.questionList.set('value',
71                                          Survey.Questions.get(this.survey));
72                    this.refresh();
73                }));
74            }
75        },
76        _includeQuestion: function(question) {
77            this.questionList.appendItem(question);
78        },
79        refresh: function() {
80            this.titleNode.innerHTML = Survey.DisplayTitle.get(this.survey) || "(set title in properties)";
81            this.propertiesDialog.set('value',this.survey);
82        },
83        _onShowProperties: function(evt) {
84            this.propertiesDialog.show();
85        },
86        _onPropertiesOk: function(evt) {
87            this.propertiesDialog.hide();
88            lang.mixin(this.survey, this.propertiesDialog.get('value'));
89            this.refresh();
90            event.stop(evt);
91            return false;
92        },
93        _onPropertiesCancel: function(evt) {
94            this.propertiesDialog.hide();
95            this.propertiesDialog.reset('value',this.survey);
96            event.stop(evt);
97            return false;
98        },
99        _onSave: function(evt) {
100            this.survey.questions = this.questionList.get('value');
101            store.put(this.survey)
102            .then(function() {
103                Router.go('/surveys');
104            });
105            event.stop(evt);
106            return false;
107        },
108        _onDiscard: function(evt) {
109            Router.go('/surveys');
110        },
111        _onShowPreview: function() {
112            Router.go('/previewSurvey/'+store.getIdentity(this.survey),{
113                preview: true
114            });
115        }
116    });
117});
118
Note: See TracBrowser for help on using the repository browser.