source: Dev/trunk/src/client/qed-client/pages/survey.js @ 497

Last change on this file since 497 was 495, checked in by hendrikvanantwerpen, 11 years ago
File size: 4.7 KB
Line 
1define([
2    "../app/Router",
3    "../model/classes/surveys",
4    "../model/widgets/QuestionListView",
5    "../model/widgets/TabbedQuestionBrowser",
6    "./_ObjectPage",
7    "dojo/_base/array",
8    "dojo/_base/declare",
9    "dojo/_base/event",
10    "dojo/_base/lang",
11    "dojo/when",
12    "require",
13    "dojo/text!./templates/survey.html"
14], function(Router, surveys, QuestionListView, TabbedQuestionBrowser, _ObjectPage, array, declare, event, lang, when, require, template) {
15    return declare([_ObjectPage],{
16        contextRequire: require,
17        templateString: template,
18        classStore: surveys,
19        questionList: null,
20        startup: function() {
21            if ( this._started ) { return; }
22            this.inherited(arguments);
23            this._setupQuestionBrowser();
24            this._setupListView();
25            this.own(this.questionList.on('change',lang.hitch(this,'_handleQuestionsChange')));
26            this._load();
27        },
28        _setupQuestionBrowser: function() {
29            this.questionBrowser = new TabbedQuestionBrowser({
30                region: 'center',
31                'class': 'blue',
32                include: 'published',
33                getSelectedItemActions: lang.hitch(this,function() {
34                    return {
35                        "Include": {
36                            callback: lang.hitch(this,this._includeQuestion),
37                            icon: "Accept",
38                            description: "Include in survey"
39                        }
40                    };
41                }),
42                getItemActions: lang.hitch(this,function(item) {
43                    return {
44                        "Info": {
45                            callback: lang.hitch(this,function(item){
46                                if ( item.description ) { alert(item.description); }
47                            }),
48                            icon: "Inspect",
49                            description: "Show item description"
50                        }
51                    };
52                })
53            },this.questionBrowser);
54            this.questionBrowser.startup();
55        },
56        _setupListView: function() {
57            this.questionList = new QuestionListView({
58                region: 'center',
59                name: 'questions'
60            },this.surveyListViewNode);
61            this.questionList.startup();
62        },
63        _refresh: function() {
64            this.titleNode.innerHTML = this.object.title || "(set title in properties)";
65            this.propertiesForm.set('value',{survey:this.object},null);
66            this.questionList.set('value',this.object.questions,null);
67        },
68        _includeQuestion: function(question) {
69            this.questionList.appendItem(question);
70        },
71        _handleQuestionsChange: function() {
72            this.object.questions = this.questionList.get('value');
73            this.markDirty();
74            this._refresh();
75        },
76        _onShowProperties: function(evt) {
77            this.propertiesDialog.show();
78            if ( evt ) { event.stop(evt); }
79            return false;
80        },
81        _onPropertiesOk: function(evt) {
82            this.propertiesDialog.hide();
83            lang.mixin(this.object, this.propertiesForm.get('value').survey);
84            this.markDirty();
85            this._refresh();
86            if ( evt ) { event.stop(evt); }
87            return false;
88        },
89        _onPropertiesCancel: function(evt) {
90            this.propertiesDialog.hide();
91            this.propertiesForm.set('value',{survey:this.object});
92            if ( evt ) { event.stop(evt); }
93            return false;
94        },
95        _onSave: function(evt) {
96            this._save();
97            if ( evt ) { event.stop(evt); }
98            return false;
99        },
100        _onSaveAndClose: function(evt) {
101            this._save()
102            .then(function() {
103                Router.go(surveys.getCollectionPath());
104            });
105            event.stop(evt);
106            return false;
107        },
108        _onDiscardAndClose: function(evt) {
109            this.markClean();
110            Router.go(surveys.getCollectionPath());
111        },
112        _onShowPreview: function() {
113            Router.go(surveys.getPreviewPath(this.object),{
114                preview: true
115            });
116        },
117        markDirty: function() {
118            this.saveBtn.set('disabled',false);
119            this.saveAndCloseBtn.set('disabled',false);
120            this.discardBtn.set('label','Discard & Close');
121            this.inherited(arguments);
122        },
123        markClean: function() {
124            this.saveBtn.set('disabled',true);
125            this.saveAndCloseBtn.set('disabled',true);
126            this.discardBtn.set('label','Close');
127            this.inherited(arguments);
128        }
129    });
130});
131
Note: See TracBrowser for help on using the repository browser.