Changeset 362


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.

Location:
Dev/branches/rest-dojo-ui/client
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • Dev/branches/rest-dojo-ui/client/config/db.js

    r361 r362  
    2020    parser.parse();
    2121
    22     query("#log").forEach(function(n){ logNode = n; });
     22    query("#log").forEach(function(n){logNode = n;});
    2323    usernameInput = registry.byId('username');
    2424    passwordInput = registry.byId('password');
     
    3131
    3232    log("Give CouchDB admin username & password and click 'Configure' to start.\nIf the database already exists, rft_admin password will suffice.",true);
    33 
    3433   
    3534    function configure(){
     35        var docs;
     36
    3637        log("Configuring CouchDB for RFT:",true);
    3738
     
    4041        var reset = resetInput.get('value');
    4142
    42         var docs = json.fromJson(docsJson);
     43        log("Downloading most recent configuration.");
     44        xhr('GET',{
     45            url: 'docs.json',
     46            handleAs: 'json',
     47            sync: true
     48        },true)
     49        .then(function(result){
     50            docs = result;
     51        });
    4352
    4453        function req(method,url,body) {
     
    4756                contentType: 'application/json',
    4857                handleAs: 'json',
    49                 sync: true,
    50                 error: function(err) {
    51                     log("ERROR: "+err);
    52                 }
     58                sync: true
    5359            };
    5460            if ( !body || lang.isObject(body) ) {
  • 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        });
  • Dev/branches/rest-dojo-ui/client/rft/store.js

    r359 r362  
    9797                if ( query === undefined ) {
    9898                    query = '_all_docs';
    99                     queryOpts.include_docs = true;
    10099                }
    101100
     
    126125
    127126                // Custom options
    128                 if (options.key) {
     127                if (options.key !== undefined) {
    129128                    queryOpts.key = options.key;
    130                 } else if (options.keys) {
     129                } else if (options.keys !== undefined) {
    131130                    queryOpts.keys = options.keys;
    132                 } else if (options.startkey || options.endkey) {
     131                } else if (options.startkey !== undefined || options.endkey !== undefined) {
    133132                    queryOpts.startkey = options.startkey;
    134133                    queryOpts.endkey = options.endkey;
     134                }
     135                if (options.include_docs !== undefined) {
     136                    queryOpts.include_docs = options.include_docs;
     137                }
     138                if (options.reduce !== undefined) {
     139                    queryOpts.reduce = options.reduce;
     140                }
     141                if (options.group !== undefined) {
     142                    queryOpts.group = options.group;
     143                    if (options.group_level !== undefined) {
     144                        queryOpts.group_level = options.group_level;
     145                    }
    135146                }
    136147
     
    152163                        dfd.resolve(
    153164                            array.map(result.rows,
    154                                       function(result){ return result.value; }));
     165                                      function(result){
     166                                          return [result.key, options.include_docs === true ? result.doc : result.value];
     167                                      }));
    155168                    }
    156169                },function(err){
    157170                    dfd.reject(err);
    158171                });
    159                         return QueryResults(dfd.promise);
     172                        return CouchResults(dfd.promise);
    160173            }
    161174        });
    162175
     176        function CouchResults(results) {
     177            if (!results) {
     178                return results;
     179            }
     180
     181                if(results.then){
     182                        results = lang.delegate(results);
     183                }
     184
     185            if (!results.forEach) {
     186                results.forEach = function(callback) {
     187                    return Deferred.when(results, function(results) {
     188                        array.forEach(results, function(result) {
     189                            callback(result[1],result[0]);
     190                        });
     191                    });
     192                }
     193            }
     194
     195            return results;
     196        }
     197
    163198        return new CouchStore({target: 'data/rft/'});
    164199
  • Dev/branches/rest-dojo-ui/client/rft/ui/Selector.js

    r360 r362  
    6464                    actions: {
    6565                        "Toggle dropdown" : {
    66                             callback: lang.hitch(this, this._onToggleDropdown),
     66                            callback: lang.hitch(this, this.onToggle),
    6767                            properties: {
    6868                                blockButton: true,
     
    7575                },this.selectedItemNode);
    7676                this._selectorLine.startup();
     77                this._selectorLine.on('click',lang.hitch(this, this.onToggle));
    7778
    7879                fx.wipeOut({
     
    8283            _onSelect: function(item, widget) {
    8384                this._selectedItem = item;
    84                 this._onToggleDropdown();
     85                this.onToggle();
    8586                this._selectorLine.set("title", item.title);
    8687                baseArray.forEach(this.optionsNode.childNodes, function(node){
     
    101102                }
    102103            },
    103             _onToggleDropdown: function(evt) {
     104            onToggle: function(evt) {
    104105                if (this._folded) {
    105106                    var downArrowIcon = dojo.query(".rftBlockButton .rftIconHalfArrowDown", this._selectorLine.buttonsNode)[0];
Note: See TracChangeset for help on using the changeset viewer.