source: Dev/trunk/src/client/qed-client/model/widgets/TabbedQuestionBrowser.js @ 493

Last change on this file since 493 was 490, checked in by hendrikvanantwerpen, 11 years ago
  • Mark content as dirty to prevent moving away from unsaved data.
  • Better change propagation from lists and our own widgets.
  • Generate notifications for errors and show correct message.
  • Moved all path/url generation to the class stores, not everywhere we use it.
  • Give user always a choice between Save and Save & Close.
  • Better refresh behaviour on form changes and saves.
  • Don't generate duplicate code error when existing object is the one you're storing.
File size: 4.6 KB
Line 
1define([
2    "../../widgets/Selector",
3    "../classes/categories",
4    "../classes/questions",
5    "../classes/topics",
6    "dijit/layout/ContentPane",
7    "dijit/layout/TabContainer",
8    "dojo/_base/declare",
9    "dojo/_base/lang",
10    "dojo/_base/window",
11    "dojox/widget/Standby"
12], function(Selector, categories, questions, topics, ContentPane, TabContainer, declare, lang, win, Standby) {
13    return declare([TabContainer],{
14        tabPosition: 'left-h',
15        include: 'all',
16
17        selectedActions: null,
18        itemActions: null,
19        dndType: "question",
20
21        _dataMap: null,
22        _busyCount: 0,
23        constructor: function(){
24            this.inherited(arguments);
25            this._dataMap = {};
26        },
27        startup: function() {
28            if ( this._started ){ return; }
29            this.inherited(arguments);
30            this._busyWidget = new Standby({
31                target: this.domNode,
32                duration: 200
33            }).placeAt(win.body());
34            this._busyWidget.startup();
35            this.watch("selectedChildWidget",lang.hitch(this,function(name,oldTab,newTab){
36                this._fillCategoryTab(newTab.__category);
37            }));
38            categories.query()
39            .forEach(lang.hitch(this,function(cat){
40                this._createCategoryTab(cat.name,cat.count);
41            }));
42        },
43        _createCategoryTab: function(category,count) {
44            if (this._dataMap[category] === undefined) {
45                var categoryTab = new ContentPane({
46                    __category: category,
47                    title: (category || '[No category]')+" ("+count+")"
48                });
49                categoryTab.startup();
50                this._dataMap[category] = {
51                    _widget: categoryTab
52                };
53                this.addChild(categoryTab);
54            }
55        },
56        _fillCategoryTab: function(category) {
57            var categoryMap = this._dataMap[category];
58            if (!categoryMap._filled) {
59                this._busy();
60                categoryMap._filled = true;
61                topics.query({category:category})
62                .forEach(lang.hitch(this,function(topic){
63                    this._createTopicSelector(topic.name,category,topic.count);
64                })).then(lang.hitch(this,function(){
65                    this._done();
66                }));
67            }
68        },
69        _createTopicSelector: function(topic,category,count){
70            var categoryMap = this._dataMap[category];
71            if (categoryMap[topic] === undefined) {
72                var w = new Selector({
73                    __category: category,
74                    __topic: topic,
75                    dndType: this.dndType,
76                    title: (topic || '[No topic]')+" ("+count+")",
77                    selectedActions: this.selectedActions,
78                    itemActions: this.itemActions,
79                    itemTitle: this._itemTitle
80                }).placeAt(categoryMap._widget.containerNode);
81                w.startup();
82                categoryMap[topic] = {
83                    _widget: w
84                };
85                this._fillTopicSelector(topic,category);
86            }
87        },
88        _itemTitle: function(item) {
89            var title = '['+item.code+']'+item.title;
90            if ( this.include === 'all' ) {
91                title += (item.publicationDate?' (published on '+item.publicationDate+')':' (unpublished)');
92            }
93            return title;
94        },
95        _fillTopicSelector: function(topic,category) {
96            var categoryMap = this._dataMap[category];
97            var topicMap = categoryMap[topic];
98            if (!topicMap._filled) {
99                topicMap._filled = true;
100                this._busy();
101                questions.query({category:category,topic:topic})
102                .forEach(lang.hitch(this,function(value){
103                    topicMap._widget.addItem(value);
104                })).then(lang.hitch(this,function(){
105                    this._done();
106                }));
107            }
108        },
109        _busy: function() {
110            if ( this._busyCount === 0 ) {
111                this._busyWidget.show();
112            }
113            this._busyCount++;
114        },
115        _done: function() {
116            if ( this._busyCount > 0 ) {
117                this._busyCount--;
118                if ( this._busyCount === 0 ) {
119                    this._busyWidget.hide();
120                }
121            } else {
122                console.warn('_done() was called more times than _busy().');
123            }
124        },
125        destroy: function() {
126            this._busyWidget.destroyRecursive();
127            this.inherited(arguments);
128        }
129    });
130});
Note: See TracBrowser for help on using the repository browser.