Ignore:
Timestamp:
03/10/14 00:47:38 (11 years ago)
Author:
hendrikvanantwerpen
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/src/client/qed-client/model/widgets/TabbedQuestionBrowser.js

    r490 r495  
    11define([
    2     "../../widgets/Selector",
     2    "../../widgets/TabbedBrowser",
    33    "../classes/categories",
    44    "../classes/questions",
    55    "../classes/topics",
    6     "dijit/layout/ContentPane",
    7     "dijit/layout/TabContainer",
     6    "dojo/_base/array",
    87    "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],{
     8    "dojo/_base/lang"
     9], function(TabbedBrowser, categories, questions, topics, array, declare, lang) {
     10    return declare([TabbedBrowser],{
    1411        tabPosition: 'left-h',
    15         include: 'all',
    16 
    17         selectedActions: null,
    18         itemActions: null,
     12        include: null,
    1913        dndType: "question",
    20 
    21         _dataMap: null,
    22         _busyCount: 0,
    23         constructor: function(){
    24             this.inherited(arguments);
    25             this._dataMap = {};
     14        getCategories: function(){
     15            return categories.query();
    2616        },
    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);
     17        getCategoryName: function(category){ return category.name; },
     18        getCategoryCount: function(category){ return category.count; },
     19        getTopics: function(category) {
     20            return topics.query({category:category.name});
     21        },
     22        getTopicName: function(topic){ return topic.name; },
     23        getTopicCount: function(topic){ return topic.count; },
     24        getItems: function(category,topic) {
     25            return questions.query({category:category.name,topic:topic.name})
     26            .then(lang.hitch(this,function(items){
     27                return array.filter(items, function(item){
     28                    return (this.include === 'published' && item.publicationDate) ||
     29                           (this.include === 'drafts' && !item.publicationDate) ||
     30                           true;
     31                }, this);
    4132            }));
    4233        },
    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) {
     34        getItemName: function(item) {
    8935            var title = '['+item.code+']'+item.title;
    90             if ( this.include === 'all' ) {
    91                 title += (item.publicationDate?' (published on '+item.publicationDate+')':' (unpublished)');
     36            if ( !this.include ) {
     37                title += (item.publicationDate ?' (published on '+item.publicationDate+')':' (unpublished)');
    9238            }
    9339            return title;
    9440        },
    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);
     41        areItemsEqual: function(i1,i2) {
     42            return questions.getId(i1) === questions.getId(i2);
    12843        }
    12944    });
Note: See TracChangeset for help on using the changeset viewer.