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

Last change on this file since 494 was 494, checked in by hendrikvanantwerpen, 11 years ago
  • Removed all Coffeescript from codebase (build process is still there).
  • Nicer message on failed login.
  • Own all event subscriptions from widgets.
  • Update objects in _ObjectPage with invalid info too, or our refresh will overwrite what user did.
File size: 4.5 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                selectedActions: {
34                    "Include": {
35                        callback: lang.hitch(this,this._includeQuestion),
36                        icon: "Accept",
37                        description: "Include in survey"
38                    }
39                },
40                itemActions: {
41                    "Info": {
42                        callback: function(item){
43                            if ( item.description ) { alert(item.description); }
44                        },
45                        icon: "Inspect",
46                        description: "Show item description"
47                    }
48                }
49            },this.questionBrowser);
50            this.questionBrowser.startup();
51        },
52        _setupListView: function() {
53            this.questionList = new QuestionListView({
54                region: 'center',
55                name: 'questions'
56            },this.surveyListViewNode);
57            this.questionList.startup();
58        },
59        _refresh: function() {
60            this.titleNode.innerHTML = this.object.title || "(set title in properties)";
61            this.propertiesForm.set('value',{survey:this.object},null);
62            this.questionList.set('value',this.object.questions,null);
63        },
64        _includeQuestion: function(question) {
65            this.questionList.appendItem(question);
66        },
67        _handleQuestionsChange: function() {
68            this.object.questions = this.questionList.get('value');
69            this.markDirty();
70            this._refresh();
71        },
72        _onShowProperties: function(evt) {
73            this.propertiesDialog.show();
74            if ( evt ) { event.stop(evt); }
75            return false;
76        },
77        _onPropertiesOk: function(evt) {
78            this.propertiesDialog.hide();
79            lang.mixin(this.object, this.propertiesForm.get('value').survey);
80            this.markDirty();
81            this._refresh();
82            if ( evt ) { event.stop(evt); }
83            return false;
84        },
85        _onPropertiesCancel: function(evt) {
86            this.propertiesDialog.hide();
87            this.propertiesForm.set('value',{survey:this.object});
88            if ( evt ) { event.stop(evt); }
89            return false;
90        },
91        _onSave: function(evt) {
92            this._save();
93            if ( evt ) { event.stop(evt); }
94            return false;
95        },
96        _onSaveAndClose: function(evt) {
97            this._save()
98            .then(function() {
99                Router.go(surveys.getCollectionPath());
100            });
101            event.stop(evt);
102            return false;
103        },
104        _onDiscardAndClose: function(evt) {
105            this.markClean();
106            Router.go(surveys.getCollectionPath());
107        },
108        _onShowPreview: function() {
109            Router.go(surveys.getPreviewPath(this.object),{
110                preview: true
111            });
112        },
113        markDirty: function() {
114            this.saveBtn.set('disabled',false);
115            this.saveAndCloseBtn.set('disabled',false);
116            this.discardBtn.set('label','Discard & Close');
117            this.inherited(arguments);
118        },
119        markClean: function() {
120            this.saveBtn.set('disabled',true);
121            this.saveAndCloseBtn.set('disabled',true);
122            this.discardBtn.set('label','Close');
123            this.inherited(arguments);
124        }
125    });
126});
127
Note: See TracBrowser for help on using the repository browser.