source: Dev/branches/rest-dojo-ui/client/rft/ui/TabbedQuestionBrowser.js @ 383

Last change on this file since 383 was 382, checked in by hendrikvanantwerpen, 13 years ago
  • Added description to survey properties form.
  • Added crude loading indicator to TabbedQuestionWidget?.
  • Organized run.js: dependencies in alpha order and only declaratively used widgets, removed other dependencies, they should be in the modules where they are used.
  • ElasticReadStore? and ElasticSearchFilteringSelect? was a mix of old dojo.declare/dojo.require and new AMD style. Changed it completely to AMD style (benefits builds later as well).
  • Changed questions view so questions without topics/categories show up as well in the view.
File size: 4.6 KB
Line 
1define([
2    'dojo/_base/declare',
3    'dojo/_base/lang',
4    'dojo/_base/window',
5    'dijit/layout/ContentPane',
6    'dijit/layout/TabContainer',
7    'dojox/widget/Standby',
8    'rft/store',
9    'rft/ui/Selector',
10    'dojo/domReady!'
11    ],
12    function(declare,lang,win,ContentPane,TabContainer,Standby,store,Selector){
13        return declare('rft.ui.TabbedQuestionBrowser',[TabContainer],{
14            tabPosition: 'left-h',
15
16            selectedActions: null,
17            itemActions: null,
18
19            _dataMap: null,
20            _busyCount: 0,
21            constructor: function(){
22                this._dataMap = {};
23            },
24            startup: function() {
25                this._busyWidget = new Standby({
26                    target: this.domNode,
27                    duration: 200
28                }).placeAt(win.body());
29                this._busyWidget.startup();
30                this.watch("selectedChildWidget",lang.hitch(this,function(name,oldTab,newTab){
31                    this._fillCategoryTab(newTab.__category);
32                }));
33                store.query('_design/default/_view/questions', {reduce:true,group:true,group_level:1})
34                .forPairs(lang.hitch(this,function(value,key){
35                    this._createCategoryTab(key[0],value);
36                }));
37            },
38            _createCategoryTab: function(category,count) {
39                if (this._dataMap[category] === undefined) {
40                    var categoryTab = new ContentPane({
41                        __category: category,
42                        title: category+" ("+count+")"
43                    });
44                    categoryTab.startup();
45                    this._dataMap[category] = {
46                        _widget: categoryTab
47                    };
48                    this.addChild(categoryTab);
49                }
50            },
51            _fillCategoryTab: function(category) {
52                var categoryMap = this._dataMap[category];
53                if (!categoryMap._filled) {
54                    this._busy();
55                    categoryMap._filled = true;
56                    store.query('_design/default/_view/questions', {reduce:true,group:true,group_level:2,startkey:[category],endkey:[category,{}]})
57                    .forPairs(lang.hitch(this,function(value,key){
58                        this._createTopicSelector(key[1],category,value);
59                    })).then(lang.hitch(this,function(){
60                        this._done();
61                    }));
62                }
63            },
64            _createTopicSelector: function(topic,category,count){
65                var categoryMap = this._dataMap[category];
66                if (categoryMap[topic] === undefined) {
67                    var w = new Selector({
68                        __category: category,
69                        __topic: topic,
70                        title: topic+" ("+count+")",
71                        selectedActions: this.selectedActions,
72                        itemActions: this.itemActions
73                    }).placeAt(categoryMap._widget.containerNode);
74                    w.startup();
75                    categoryMap[topic] = {
76                        _widget: w
77                    };
78                    this._fillTopicSelector(topic,category);
79                    w.on('include',lang.hitch(this,this.onSelect));
80                }
81            },
82            _fillTopicSelector: function(topic,category) {
83                var categoryMap = this._dataMap[category];
84                var topicMap = categoryMap[topic];
85                if (!topicMap._filled) {
86                    topicMap._filled = true;
87                    this._busy();
88                    store.query('_design/default/_view/questions', {reduce:false,include_docs:true,key:[category,topic]})
89                    .forEach(lang.hitch(this,function(value){
90                        topicMap._widget.addItem(value);
91                    })).then(lang.hitch(this,function(){
92                        this._done();
93                    }));
94                }
95            },
96            _busy: function() {
97                if ( this._busyCount === 0 ) {
98                    this._busyWidget.show();
99                }
100                this._busyCount++;
101            },
102            _done: function() {
103                if ( this._busyCount > 0 ) {
104                    this._busyCount--;
105                    if ( this._busyCount === 0 ) {
106                        this._busyWidget.hide();
107                    }
108                } else {
109                    console.warn('Busycount <= 0 when _done is called.');
110                }
111            },
112            onSelect: function(question) {}
113        });
114    });
Note: See TracBrowser for help on using the repository browser.