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

Last change on this file since 490 was 490, checked in by hendrikvanantwerpen, 11 years ago
  • Mark content as dirty to prevent moving away from unsaved data.
  • Better change propagation from lists and our own widgets.
  • Generate notifications for errors and show correct message.
  • Moved all path/url generation to the class stores, not everywhere we use it.
  • Give user always a choice between Save and Save & Close.
  • Better refresh behaviour on form changes and saves.
  • Don't generate duplicate code error when existing object is the one you're storing.
File size: 3.9 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._load();
26        },
27        _setupQuestionBrowser: function() {
28            this.questionBrowser = new TabbedQuestionBrowser({
29                region: 'center',
30                'class': 'blue',
31                include: 'published',
32                selectedActions: {
33                    "Include": {
34                        callback: lang.hitch(this,this._includeQuestion),
35                        icon: "Accept",
36                        description: "Include in survey"
37                    }
38                },
39                itemActions: {
40                    "Info": {
41                        callback: function(item){
42                            if ( item.description ) { alert(item.description); }
43                        },
44                        icon: "Inspect",
45                        description: "Show item description"
46                    }
47                }
48            },this.questionBrowser);
49            this.questionBrowser.startup();
50        },
51        _setupListView: function() {
52            this.questionList = new QuestionListView({
53                region: 'center',
54                name: 'questions'
55            },this.surveyListViewNode);
56            this.questionList.startup();
57        },
58        _refresh: function() {
59            this.titleNode.innerHTML = this.object.title || "(set title in properties)";
60            this.propertiesDialog.set('value',this.object);
61            this.questionList.set('value',
62                                  this.object.questions);
63        },
64        _save: function() {
65            this.object.questions = this.questionList.get('value');
66            return this.inherited(arguments);
67        },
68        _includeQuestion: function(question) {
69            this.questionList.appendItem(question);
70        },
71        _onShowProperties: function(evt) {
72            this.propertiesDialog.show();
73            if ( evt ) { event.stop(evt); }
74            return false;
75        },
76        _onPropertiesOk: function(evt) {
77            this.propertiesDialog.hide();
78            lang.mixin(this.object, this.propertiesDialog.get('value'));
79            this.markDirty();
80            this._refresh();
81            if ( evt ) { event.stop(evt); }
82            return false;
83        },
84        _onPropertiesCancel: function(evt) {
85            this.propertiesDialog.hide();
86            this.propertiesDialog.set('value',this.object);
87            if ( evt ) { event.stop(evt); }
88            return false;
89        },
90        _onSave: function(evt) {
91            this._save();
92            if ( evt ) { event.stop(evt); }
93            return false;
94        },
95        _onSaveAndClose: function(evt) {
96            this._save()
97            .then(function() {
98                Router.go(surveys.getCollectionPath());
99            });
100            event.stop(evt);
101            return false;
102        },
103        _onDiscardAndClose: function(evt) {
104            this.markClean();
105            Router.go(surveys.getCollectionPath());
106        },
107        _onShowPreview: function() {
108            Router.go(surveys.getPreviewPath(this.object),{
109                preview: true
110            });
111        }
112    });
113});
114
Note: See TracBrowser for help on using the repository browser.