source: Dev/branches/rest-dojo-ui/client/rft/pages/survey.js @ 384

Last change on this file since 384 was 384, checked in by hendrikvanantwerpen, 13 years ago
  • Cleanup of the differen ListViews?, List & OrderedList?. Based QuestionListView? on these base classes as well. Removed duplicate code.
  • Destroy busy indicator of TabbedQuestionBrowser? (because it's placed outside of the widgets DOM tree, this is not done automatically).
  • Use dojo/date/stamp module for uniform and parsable date formatting.
  • Added docs/ directory for database format documentation etc.
File size: 3.9 KB
Line 
1define([
2    'dojo/_base/array',
3    'dojo/_base/declare',
4    'dojo/_base/Deferred',
5    'dojo/_base/event',
6    'dojo/_base/lang',
7    'rft/content',
8    'rft/store',
9    'rft/ui/_Page',
10    'rft/ui/QuestionListView',
11    'rft/ui/TabbedQuestionBrowser'
12    ],
13    function(array,declare,Deferred,event,lang,content,store,_Page,
14             QuestionListView,TabbedQuestionBrowser){
15        return declare('rft.pages.survey',[_Page],{
16            survey: null,
17            questionList: null,
18            _dataMap: null,
19            constructor: function(){
20                this._dataMap = {};
21            },
22            onVisit: function() {
23                if ( this.pageArgs.uid ) {
24                    this._setupQuestionBrowser();
25                    this._setupListView();
26                    Deferred.when(store.get(this.pageArgs.uid))
27                    .then(lang.hitch(this,function(obj){
28                        this.survey = obj;
29                        this.refresh();
30                    }));
31                } else {
32                    throw "No valid uid or survey passed!";
33                }
34            },
35            _setupQuestionBrowser: function() {
36                this.questionBrowser = new TabbedQuestionBrowser({
37                    region: 'center',
38                    'class': 'blue',
39                    selectedActions: {
40                        "Include": {
41                            callback: lang.hitch(this,this._includeQuestion),
42                            icon: "Accept",
43                            description: "Include in survey"
44                        }
45                    },
46                    itemActions: {
47                        "Info": {
48                            callback: function(item){ item.description && alert(item.description); },
49                            icon: "Inspect",
50                            description: "Show item description"
51                        }
52                    }
53                },this.questionBrowser);
54                this.questionBrowser.startup();
55            },
56            _includeQuestion: function(question) {
57                this.questionList.insertItem(question);
58            },
59            _setupListView: function() {
60                this.questionList = new QuestionListView({
61                    region: 'center'
62                }).placeAt(this.surveyListViewNode);
63                this.questionList.startup();
64            },
65            refresh: function() {
66                this.titleNode.innerHTML = this.survey.title || "(set title in properties)";
67                this.propertiesForm.set('value',this.survey);
68                store.query(null,{keys:this.survey.questions,include_docs:true})
69                .forEach(lang.hitch(this.questionList,'appendItem'));
70            },
71            _onShowProperties: function(evt) {
72                this.propertiesDialog.show();
73            },
74            _onPropertiesOk: function(evt) {
75                this.propertiesDialog.hide();
76                lang.mixin(this.survey, this.propertiesForm.get('value'));
77                this.refresh();
78                event.stop(evt);
79                return false;
80            },
81            _onPropertiesCancel: function(evt) {
82                this.propertiesDialog.hide();
83                this.propertiesForm.set('value',this.survey);
84                event.stop(evt);
85                return false;
86            },
87            _onSave: function(evt) {
88                this.survey.questions = array.map(this.questionList.getItems(),function(item){
89                    return store.getIdentity(item);
90                });
91                store.put(this.survey)
92                .then(function() {
93                    content.goTo('surveys');
94                });
95                event.stop(evt);
96                return false;
97            },
98            _onDiscard: function(evt) {
99            },
100            _onShowPreview: function() {
101                content.goTo('surveyAdvanced', {uid: store.getIdentity(this.survey)});
102            }
103        });
104});
105
Note: See TracBrowser for help on using the repository browser.