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

Last change on this file since 492 was 492, checked in by hendrikvanantwerpen, 11 years ago
  • Enable/disable buttons on content change.
  • One place to do date formatting, because it was going wrong again.
  • Serialize questions in survey properly.
  • _ComplexValueMixin consumes submit events, but does trigger outer forms if present.
  • Trigger dialog show/hide for login only after previous effect is finished.
  • Check that documents are actually valid, not just that validator returned a result.
  • Validate email and timestamp formats.
  • Prepared for live runs.
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.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});
62            this.questionList.set('value',
63                                  this.object.questions);
64        },
65        _includeQuestion: function(question) {
66            this.questionList.appendItem(question);
67        },
68        _handleQuestionsChange: function() {
69            this.object.questions = this.questionList.get('value');
70            this.markDirty();
71            this._refresh();
72        },
73        _onShowProperties: function(evt) {
74            this.propertiesDialog.show();
75            if ( evt ) { event.stop(evt); }
76            return false;
77        },
78        _onPropertiesOk: function(evt) {
79            this.propertiesDialog.hide();
80            lang.mixin(this.object, this.propertiesForm.get('value').survey);
81            this.markDirty();
82            this._refresh();
83            if ( evt ) { event.stop(evt); }
84            return false;
85        },
86        _onPropertiesCancel: function(evt) {
87            this.propertiesDialog.hide();
88            this.propertiesForm.set('value',{survey:this.object});
89            if ( evt ) { event.stop(evt); }
90            return false;
91        },
92        _onSave: function(evt) {
93            this._save();
94            if ( evt ) { event.stop(evt); }
95            return false;
96        },
97        _onSaveAndClose: function(evt) {
98            this._save()
99            .then(function() {
100                Router.go(surveys.getCollectionPath());
101            });
102            event.stop(evt);
103            return false;
104        },
105        _onDiscardAndClose: function(evt) {
106            this.markClean();
107            Router.go(surveys.getCollectionPath());
108        },
109        _onShowPreview: function() {
110            Router.go(surveys.getPreviewPath(this.object),{
111                preview: true
112            });
113        },
114        markDirty: function() {
115            this.saveBtn.set('disabled',false);
116            this.saveAndCloseBtn.set('disabled',false);
117            this.discardBtn.set('label','Discard & Close');
118            this.inherited(arguments);
119        },
120        markClean: function() {
121            this.saveBtn.set('disabled',true);
122            this.saveAndCloseBtn.set('disabled',true);
123            this.discardBtn.set('label','Close');
124            this.inherited(arguments);
125        }
126    });
127});
128
Note: See TracBrowser for help on using the repository browser.