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

Last change on this file since 502 was 502, checked in by hendrikvanantwerpen, 11 years ago
  • ListWidget? can be disabled/readOnyl now.
  • Disable question and survey pages when published.
  • Removed weird dialog from survey page and just put a form there. Not very nice, but more consistent with the rest I would say.
File size: 4.8 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.own(this.propertiesForm.on('change',lang.hitch(this,'_handlePropertiesChange')));
27            this._load();
28        },
29        _setupQuestionBrowser: function() {
30            this.questionBrowser = new TabbedQuestionBrowser({
31                region: 'center',
32                'class': 'blue',
33                include: 'published',
34                getSelectedItemActions: lang.hitch(this,function() {
35                    return {
36                        "Include": {
37                            callback: lang.hitch(this,this._includeQuestion),
38                            icon: "Accept",
39                            description: "Include in survey"
40                        }
41                    };
42                }),
43                getItemActions: lang.hitch(this,function(item) {
44                    return {
45                        "Info": {
46                            callback: lang.hitch(this,function(item){
47                                if ( item.description ) { alert(item.description); }
48                            }),
49                            icon: "Inspect",
50                            description: "Show item description"
51                        }
52                    };
53                })
54            },this.questionBrowser);
55            this.questionBrowser.startup();
56        },
57        _setupListView: function() {
58            this.questionList = new QuestionListView({
59                region: 'center',
60                name: 'questions'
61            },this.surveyListViewNode);
62            this.questionList.startup();
63        },
64        _refresh: function(initial) {
65            if ( initial === true ) {
66                this.propertiesForm.set('value',{survey:this.object},null);
67                this.questionList.set('value',this.object.questions,null);
68            }
69            this.titleNode.innerHTML = this.object.title || "(set title in properties)";
70            if ( this.object.publicationDate ) {
71                this.propertiesForm.set('readOnly',true);
72                this.propertiesForm.set('disabled',true);
73                this.questionList.set('readOnly',true);
74                this.questionList.set('disabled',true);
75            }
76        },
77        _includeQuestion: function(question) {
78            this.questionList.appendItem(question);
79        },
80        _handleQuestionsChange: function() {
81            this.object.questions = this.questionList.get('value');
82            this.markDirty();
83            this._refresh();
84        },
85        _handlePropertiesChange: function() {
86            lang.mixin(this.object, this.propertiesForm.get('value').survey);
87            this.markDirty();
88            this._refresh();
89            this.layout();
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        _ignore: function(evt) {
126            event.stop(evt);
127            return false;
128        }
129    });
130});
131
Note: See TracBrowser for help on using the repository browser.