Ignore:
Timestamp:
07/16/12 16:27:40 (13 years ago)
Author:
hendrikvanantwerpen
Message:

Selector can be clicked on whole line now.
Question editor in survey page does lazy loading per
category and displays total number of questions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/branches/rest-dojo-ui/client/rft/pages/survey.js

    r360 r362  
    33    'dojo/_base/event',
    44    'dojo/_base/Deferred',
     5    'dojo/on',
    56    'rft/ui/Selector',
    67    'rft/ui/SurveyListView',
     
    1112    'dojo/store/Cache',
    1213    'dojo/store/Memory' ],
    13     function(declare,lang,event,Deferred,Selector,SurveyListView,ContentPane,store,_Page,content,Cache,Memory){
     14    function(declare,lang,event,Deferred,on,Selector,SurveyListView,ContentPane,store,_Page,content,Cache,Memory){
    1415        return declare('rft.pages.survey',[_Page],{
    1516            object: null,
     
    2627                        return Deferred.when( obj.creator && store.dereference(obj.creator) );
    2728                    }));
    28                     this._createListView();
    29                     this._createQuestionBrowser();
    3029                    this._setupButtons();
     30                    this._setupQuestionBrowser();
     31                    this._setupListView();
    3132                } else {
    3233                    throw "No valid uid or survey passed!";
     
    4041                this.btnPreview.on("click", lang.hitch(this, this._goToPreview));
    4142            },
    42             _createQuestionBrowser: function() {
    43                 store.query('_design/default/_view/by_type', {key:'Question'})
    44                 .forEach(function(question){
    45                     this._insertQuestion(question);
    46                 },this);
     43            _setupQuestionBrowser: function() {
     44                this.tabList.watch("selectedChildWidget",lang.hitch(this,function(name,oldTab,newTab){
     45                    this._fillCategoryTab(newTab.__category);
     46                }));
     47                store.query('_design/default/_view/questions', {reduce:true,group:true,group_level:1})
     48                .forEach(lang.hitch(this,function(value,key){
     49                    this._createCategoryTab(key[0],value);
     50                }));
    4751            },
    48             _insertQuestion: function(question) {
    49                 for (var c in question.categories) {
    50                     var cat = question.categories[c];
    51                     if (this._dataMap[cat] === undefined) {
    52                         this._dataMap[cat] = {
    53                             widget: this._createCategoryTab(cat),
    54                             topics: {}
    55                         }
    56                     }
    57                     this._insertIntoCategory(question,this._dataMap[cat]);
     52            _createCategoryTab: function(category,count) {
     53                if (this._dataMap[category] === undefined) {
     54                    var categoryTab = new ContentPane({
     55                        __category: category,
     56                        title: category+" ("+count+")"
     57                    });
     58                    categoryTab.startup();
     59                    this._dataMap[category] = {
     60                        _widget: categoryTab
     61                    };
     62                    this.tabList.addChild(categoryTab);
    5863                }
    5964            },
    60             _createCategoryTab: function(category) {
    61                 var categoryTab = new ContentPane({
    62                     title: category
    63                 });
    64                 categoryTab.startup();
    65                 this.tabList.addChild(categoryTab);
    66                 return categoryTab;
     65            _fillCategoryTab: function(category) {
     66                var categoryMap = this._dataMap[category];
     67                if (!categoryMap._filled) {
     68                    categoryMap._filled = true;
     69                    store.query('_design/default/_view/questions', {reduce:true,group:true,group_level:2,startkey:[category],endkey:[category,{}]})
     70                    .forEach(lang.hitch(this,function(value,key){
     71                        this._createTopicSelector(key[1],category,value);
     72                    }));
     73                }
    6774            },
    68             _insertIntoCategory: function(question, categoryMap) {
    69                 if (categoryMap[question.topic] === undefined) {
     75            _createTopicSelector: function(topic,category,count){
     76                var categoryMap = this._dataMap[category];
     77                if (categoryMap[topic] === undefined) {
    7078                    var w = new Selector({
    71                         title: question.topic
    72                     }).placeAt(categoryMap.widget.containerNode);
     79                        __category: category,
     80                        __topic: topic,
     81                        title: topic+" ("+count+")"
     82                    }).placeAt(categoryMap._widget.containerNode);
    7383                    w.startup();
     84                    categoryMap[topic] = {
     85                        _widget: w
     86                    };
     87                    this._fillTopicSelector(topic,category);
    7488                    w.on('include',lang.hitch(this,this.includeQuestion));
    75                     categoryMap[question.topic] = {
    76                         widget: w
    77                     };
    7889                }
    79                 categoryMap[question.topic].widget.addItem(question);
     90            },
     91            _fillTopicSelector: function(topic,category) {
     92                var categoryMap = this._dataMap[category];
     93                var topicMap = categoryMap[topic];
     94                if (!topicMap._filled) {
     95                    store.query('_design/default/_view/questions', {reduce:false,include_docs:true,key:[category,topic]})
     96                    .forEach(lang.hitch(this,function(value,key){
     97                        topicMap._widget.addItem(value);
     98                    }));
     99                }
    80100            },
    81101            /* ListView code */
    82             _createListView: function() {
     102            includeQuestion: function(question) {
     103                this.listView.insertItem(question);
     104            },
     105            _setupListView: function() {
    83106                this.listView = new SurveyListView({
    84107                    controller: this
    85108                }).placeAt(this.surveyListViewNode);
    86109                this.listView.startup();
    87             },
    88             includeQuestion: function(question) {
    89                 this.listView.insertItem(question);
    90110            }
    91111        });
Note: See TracChangeset for help on using the changeset viewer.