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

Last change on this file since 369 was 369, checked in by jkraaijeveld, 13 years ago

Now shows e-mails in the account: field in a session on the session page.

File size: 5.1 KB
Line 
1define(['dojo/_base/declare',
2    'dojo/_base/lang',
3    'dojo/_base/event',
4    'dojo/_base/Deferred',
5    'dojo/on',
6    'rft/ui/Selector',
7    'rft/ui/SurveyListView',
8    'dijit/layout/ContentPane',
9    'rft/store',
10    'rft/ui/_Page',
11    'rft/content',
12    'dojo/store/Cache',
13    'dojo/store/Memory' ],
14    function(declare,lang,event,Deferred,on,Selector,SurveyListView,ContentPane,store,_Page,content,Cache,Memory){
15        return declare('rft.pages.survey',[_Page],{
16            object: null,
17            listView: null,
18            _dataMap: null,
19            constructor: function(){
20                this._dataMap = {};
21            },
22            onVisit: function() {
23                if ( this.pageArgs.uid ) {
24                    Deferred.when(store.get(this.pageArgs.uid))
25                    .then(lang.hitch(this,function(obj){
26                        this.object = obj;
27                        return Deferred.when( obj.creator && store.dereference(obj.creator) );
28                    }));
29                    this._setupButtons();
30                    this._setupQuestionBrowser();
31                    this._setupListView();
32                } else {
33                    throw "No valid uid or survey passed!";
34                }
35            },
36            onProperties: function(evt) {
37
38            },
39            onSave: function(evt) {
40//                lang.mixin(this.object, this.propertiesForm.get('value'));
41                store.put(this.object)
42                .then(function() {
43                    content.goTo('surveys');
44                });
45                event.stop(evt);
46                return false;
47            },
48            _goToPreview: function() {
49                content.goTo('surveyAdvanced', {uid: this.object._id});
50            },
51            _setupButtons: function() {
52                this.btnSave.on("click", lang.hitch(this, this.onSave));
53                this.btnPreview.on("click", lang.hitch(this, this._goToPreview));
54            },
55            _setupQuestionBrowser: function() {
56                this.tabList.watch("selectedChildWidget",lang.hitch(this,function(name,oldTab,newTab){
57                    this._fillCategoryTab(newTab.__category);
58                }));
59                store.query('_design/default/_view/questions', {reduce:true,group:true,group_level:1})
60                .forPairs(lang.hitch(this,function(value,key){
61                    this._createCategoryTab(key[0],value);
62                }));
63            },
64            _createCategoryTab: function(category,count) {
65                if (this._dataMap[category] === undefined) {
66                    var categoryTab = new ContentPane({
67                        __category: category,
68                        title: category+" ("+count+")"
69                    });
70                    categoryTab.startup();
71                    this._dataMap[category] = {
72                        _widget: categoryTab
73                    };
74                    this.tabList.addChild(categoryTab);
75                }
76            },
77            _fillCategoryTab: function(category) {
78                var categoryMap = this._dataMap[category];
79                if (!categoryMap._filled) {
80                    categoryMap._filled = true;
81                    store.query('_design/default/_view/questions', {reduce:true,group:true,group_level:2,startkey:[category],endkey:[category,{}]})
82                    .forPairs(lang.hitch(this,function(value,key){
83                        this._createTopicSelector(key[1],category,value);
84                    }));
85                }
86            },
87            _createTopicSelector: function(topic,category,count){
88                var categoryMap = this._dataMap[category];
89                if (categoryMap[topic] === undefined) {
90                    var w = new Selector({
91                        __category: category,
92                        __topic: topic,
93                        title: topic+" ("+count+")"
94                    }).placeAt(categoryMap._widget.containerNode);
95                    w.startup();
96                    categoryMap[topic] = {
97                        _widget: w
98                    };
99                    this._fillTopicSelector(topic,category);
100                    w.on('include',lang.hitch(this,this.includeQuestion));
101                }
102            },
103            _fillTopicSelector: function(topic,category) {
104                var categoryMap = this._dataMap[category];
105                var topicMap = categoryMap[topic];
106                if (!topicMap._filled) {
107                    store.query('_design/default/_view/questions', {reduce:false,include_docs:true,key:[category,topic]})
108                    .forEach(lang.hitch(this,function(value){
109                        topicMap._widget.addItem(value);
110                    }));
111                }
112            },
113            /* ListView code */
114            includeQuestion: function(question) {
115                var item = this.listView.insertItem(question);
116            },
117            _setupListView: function() {
118                this.listView = new SurveyListView({
119                    controller: this
120                }).placeAt(this.surveyListViewNode);
121                this.listView.startup();
122            }
123        });
124});
125
Note: See TracBrowser for help on using the repository browser.