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

Last change on this file since 500 was 500, checked in by hendrikvanantwerpen, 11 years ago
  • Indicate of refresh is due to load or due to save in _ObjectPage.
  • _ComplexValueMixin & ListWidget? catch all change events and drops them if still being created.
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._load();
27        },
28        _setupQuestionBrowser: function() {
29            this.questionBrowser = new TabbedQuestionBrowser({
30                region: 'center',
31                'class': 'blue',
32                include: 'published',
33                getSelectedItemActions: lang.hitch(this,function() {
34                    return {
35                        "Include": {
36                            callback: lang.hitch(this,this._includeQuestion),
37                            icon: "Accept",
38                            description: "Include in survey"
39                        }
40                    };
41                }),
42                getItemActions: lang.hitch(this,function(item) {
43                    return {
44                        "Info": {
45                            callback: lang.hitch(this,function(item){
46                                if ( item.description ) { alert(item.description); }
47                            }),
48                            icon: "Inspect",
49                            description: "Show item description"
50                        }
51                    };
52                })
53            },this.questionBrowser);
54            this.questionBrowser.startup();
55        },
56        _setupListView: function() {
57            this.questionList = new QuestionListView({
58                region: 'center',
59                name: 'questions'
60            },this.surveyListViewNode);
61            this.questionList.startup();
62        },
63        _refresh: function(initial) {
64            if ( initial === true ) {
65                this.propertiesForm.set('value',{survey:this.object},null);
66                this.questionList.set('value',this.object.questions,null);
67            }
68            this.titleNode.innerHTML = this.object.title || "(set title in properties)";
69        },
70        _includeQuestion: function(question) {
71            this.questionList.appendItem(question);
72        },
73        _handleQuestionsChange: function() {
74            this.object.questions = this.questionList.get('value');
75            this.markDirty();
76            this._refresh();
77        },
78        _onShowProperties: function(evt) {
79            this.propertiesDialog.show();
80            if ( evt ) { event.stop(evt); }
81            return false;
82        },
83        _onPropertiesOk: function(evt) {
84            this.propertiesDialog.hide();
85            lang.mixin(this.object, this.propertiesForm.get('value').survey);
86            this.markDirty();
87            this._refresh();
88            if ( evt ) { event.stop(evt); }
89            return false;
90        },
91        _onPropertiesCancel: function(evt) {
92            this.propertiesDialog.hide();
93            this.propertiesForm.set('value',{survey:this.object});
94            if ( evt ) { event.stop(evt); }
95            return false;
96        },
97        _onSave: function(evt) {
98            this._save();
99            if ( evt ) { event.stop(evt); }
100            return false;
101        },
102        _onSaveAndClose: function(evt) {
103            this._save()
104            .then(function() {
105                Router.go(surveys.getCollectionPath());
106            });
107            event.stop(evt);
108            return false;
109        },
110        _onDiscardAndClose: function(evt) {
111            this.markClean();
112            Router.go(surveys.getCollectionPath());
113        },
114        _onShowPreview: function() {
115            Router.go(surveys.getPreviewPath(this.object),{
116                preview: true
117            });
118        },
119        markDirty: function() {
120            this.saveBtn.set('disabled',false);
121            this.saveAndCloseBtn.set('disabled',false);
122            this.discardBtn.set('label','Discard & Close');
123            this.inherited(arguments);
124        },
125        markClean: function() {
126            this.saveBtn.set('disabled',true);
127            this.saveAndCloseBtn.set('disabled',true);
128            this.discardBtn.set('label','Close');
129            this.inherited(arguments);
130        }
131    });
132});
133
Note: See TracBrowser for help on using the repository browser.