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

Last change on this file since 427 was 426, checked in by hendrikvanantwerpen, 12 years ago

Added grunt tasks and code cleanup.

Added grunt for less and jshint procesing.
Cleanup of code to pass jshint (one bug found :).

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            },this.surveyListViewNode);
59            this.questionList.startup();
60        },
61        _loadSurvey: function() {
62            if ( this.surveyId === "new" ) {
63                this.survey = Survey.create();
64                this.refresh();
65            } else {
66                when(store.get(this.surveyId))
67                .then(lang.hitch(this,function(survey){
68                    this.survey = survey;
69                    array.forEach(Survey.Questions.get(this.survey),
70                        lang.hitch(this.questionList,'appendItem'));
71                    this.refresh();
72                }));
73            }
74        },
75        _includeQuestion: function(question) {
76            this.questionList.insertItem(question);
77        },
78        refresh: function() {
79            this.titleNode.innerHTML = Survey.DisplayTitle.get(this.survey) || "(set title in properties)";
80            this.propertiesDialog.set('value',this.survey);
81        },
82        _onShowProperties: function(evt) {
83            this.propertiesDialog.show();
84        },
85        _onPropertiesOk: function(evt) {
86            this.propertiesDialog.hide();
87            lang.mixin(this.survey, this.propertiesDialog.get('value'));
88            this.refresh();
89            event.stop(evt);
90            return false;
91        },
92        _onPropertiesCancel: function(evt) {
93            this.propertiesDialog.hide();
94            this.propertiesDialog.reset('value',this.survey);
95            event.stop(evt);
96            return false;
97        },
98        _onSave: function(evt) {
99            this.survey.questions = this.questionList.getItems();
100            store.put(this.survey)
101            .then(function() {
102                Router.go('/surveys');
103            });
104            event.stop(evt);
105            return false;
106        },
107        _onDiscard: function(evt) {
108            Router.go('/surveys');
109        },
110        _onShowPreview: function() {
111            Router.go('/previewSurvey/'+store.getIdentity(this.survey),{
112                preview: true
113            });
114        }
115    });
116});
117
Note: See TracBrowser for help on using the repository browser.