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

Last change on this file was 512, checked in by hendrikvanantwerpen, 11 years ago

Small fixes fir urls and validation.

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