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

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

Created widgets for several input types.
Work on multiplechoice widget, see if we can make OrderedList? work with
form items? Maybe make the item the widget iso a data item.

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    '../content',
8    '../store',
9    '../ui/_Page',
10    '../ui/lists/QuestionListView',
11    '../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                        store.query(null,{keys:this.survey.questions,include_docs:true})
30                        .forEach(lang.hitch(this.questionList,'appendItem'));
31                        this.refresh();
32                    }));
33                } else {
34                    throw "No valid uid or survey passed!";
35                }
36            },
37            _setupQuestionBrowser: function() {
38                this.questionBrowser = new TabbedQuestionBrowser({
39                    region: 'center',
40                    'class': 'blue',
41                    selectedActions: {
42                        "Include": {
43                            callback: lang.hitch(this,this._includeQuestion),
44                            icon: "Accept",
45                            description: "Include in survey"
46                        }
47                    },
48                    itemActions: {
49                        "Info": {
50                            callback: function(item){ item.description && alert(item.description); },
51                            icon: "Inspect",
52                            description: "Show item description"
53                        }
54                    }
55                },this.questionBrowser);
56                this.questionBrowser.startup();
57            },
58            _includeQuestion: function(question) {
59                this.questionList.insertItem(question);
60            },
61            _setupListView: function() {
62                this.questionList = new QuestionListView({
63                    region: 'center'
64                },this.surveyListViewNode);
65                this.questionList.startup();
66            },
67            refresh: function() {
68                this.titleNode.innerHTML = this.survey.title || "(set title in properties)";
69                this.propertiesForm.set('value',this.survey);
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('viewSurvey', {uid: store.getIdentity(this.survey)});
102            }
103        });
104});
105
Note: See TracBrowser for help on using the repository browser.