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

Last change on this file since 382 was 379, checked in by hendrikvanantwerpen, 13 years ago

Changed SurveyListView? to more general OrderedDndList?.
Survey page has rudimentary properties dialog and saves included questions.
Fixed bug in store for null question.

File size: 4.0 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/OrderedDndList',
11    'rft/ui/TabbedQuestionBrowser'
12    ],
13    function(array,declare,Deferred,event,lang,content,store,_Page,
14             OrderedDndList,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 OrderedDndList({
61                    type: 'question',
62                    region: 'center'
63                }).placeAt(this.surveyListViewNode);
64                this.questionList.startup();
65            },
66            refresh: function() {
67                this.titleNode.innerHTML = this.survey.title || "(set title in properties)";
68                this.propertiesForm.set('value',this.survey);
69                store.query(null,{keys:this.survey.questions,include_docs:true})
70                .forEach(lang.hitch(this.questionList,'appendItem'));
71            },
72            _onShowProperties: function(evt) {
73                this.propertiesDialog.show();
74            },
75            _onPropertiesOk: function(evt) {
76                this.propertiesDialog.hide();
77                lang.mixin(this.survey, this.propertiesForm.get('value'));
78                this.refresh();
79                event.stop(evt);
80                return false;
81            },
82            _onPropertiesCancel: function(evt) {
83                this.propertiesDialog.hide();
84                this.propertiesForm.set('value',this.survey);
85                event.stop(evt);
86                return false;
87            },
88            _onSave: function(evt) {
89                this.survey.questions = array.map(this.questionList.getItems(),function(item){
90                    return store.getIdentity(item);
91                });
92                store.put(this.survey)
93                .then(function() {
94                    content.goTo('surveys');
95                });
96                event.stop(evt);
97                return false;
98            },
99            _onDiscard: function(evt) {
100            },
101            _onShowPreview: function() {
102                content.goTo('surveyAdvanced', {uid: store.getIdentity(this.survey)});
103            }
104        });
105});
106
Note: See TracBrowser for help on using the repository browser.