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

Last change on this file since 508 was 503, checked in by hendrikvanantwerpen, 11 years ago

Don't delete elements from certain lists if they are disabled
or readOnly. Didn't include this in ListWidget?.removeItem, since
programmatically things should keep working even when disabled, I would
say. So this needs to be done in the place of the event.

File size: 4.7 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.questionList.set('readOnly',true);
73            }
74        },
75        _includeQuestion: function(question) {
76            this.questionList.appendItem(question);
77        },
78        _handleQuestionsChange: function() {
79            this.object.questions = this.questionList.get('value');
80            this.markDirty();
81            this._refresh();
82        },
83        _handlePropertiesChange: function() {
84            lang.mixin(this.object, this.propertiesForm.get('value').survey);
85            this.markDirty();
86            this._refresh();
87            this.layout();
88        },
89        _onSave: function(evt) {
90            this._save();
91            if ( evt ) { event.stop(evt); }
92            return false;
93        },
94        _onSaveAndClose: function(evt) {
95            this._save()
96            .then(function() {
97                Router.go(surveys.getCollectionPath());
98            });
99            event.stop(evt);
100            return false;
101        },
102        _onDiscardAndClose: function(evt) {
103            this.markClean();
104            Router.go(surveys.getCollectionPath());
105        },
106        _onShowPreview: function() {
107            Router.go(surveys.getPreviewPath(this.object),{
108                preview: true
109            });
110        },
111        markDirty: function() {
112            this.saveBtn.set('disabled',false);
113            this.saveAndCloseBtn.set('disabled',false);
114            this.discardBtn.set('label','Discard & Close');
115            this.inherited(arguments);
116        },
117        markClean: function() {
118            this.saveBtn.set('disabled',true);
119            this.saveAndCloseBtn.set('disabled',true);
120            this.discardBtn.set('label','Close');
121            this.inherited(arguments);
122        },
123        _ignore: function(evt) {
124            event.stop(evt);
125            return false;
126        }
127    });
128});
129
Note: See TracBrowser for help on using the repository browser.