source: Dev/branches/rest-dojo-ui/client/rft/elastic/ElasticReadStore.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: 1.7 KB
Line 
1define([
2    'dojo/_base/declare',
3    "dojo/_base/json",
4    'dojo/_base/lang',
5    'dojo/_base/xhr',
6    'dojox/data/QueryReadStore'
7    ],function(declare, json, lang, xhr, QueryReadStore) {
8
9        return declare("rft.elastic.ElasticReadStore", QueryReadStore, {
10            fetch:function(request){
11                var attr = Object.keys(request.query)[0];
12                if (request.query[attr].length == 0) {
13                        return 0;
14                }
15                var q = request.query[attr];
16
17                request.serverQuery = json.toJson({
18                                                                query:
19                                                                {
20                                                                        query_string:
21                                                                        {
22                                                                                default_field: attr,
23                                                                                query: q
24                                                                        }
25                                                                }
26                                                        });
27                    // Call superclasses' fetch
28                    return this.inherited("fetch", arguments);
29                  },
30                _fetchItems: function(request, fetchHandler, errorHandler){
31                        var serverQuery = request.serverQuery;
32                        var xhrHandler = xhr.post({
33                url: this.url,
34                handleAs: "json",
35                postData: serverQuery
36            });
37                        request.abort = function(){
38                                xhrHandler.cancel();
39                        };
40                        xhrHandler.addCallback(lang.hitch(this, function(data){
41                                this._xhrFetchHandler(data, request, fetchHandler, errorHandler);
42                        }));
43                        xhrHandler.addErrback(function(error){
44                                errorHandler(error, request);
45                        });
46                },
47                _xhrFetchHandler: function(data, request, fetchHandler, errorHandler) {
48                        data = this._filterResponse(data);
49                        this._items = [];
50                        var numHits = data.hits.total || -1;
51                        if(numHits > 0) {
52                                this._items.push({i:data.hits.hits[0]._source, r:this, n:0});
53                        }
54                        fetchHandler(this._items, request, data.hits.total);
55                        this._numRows = data.hits.total;
56                }
57        });
58})
Note: See TracBrowser for help on using the repository browser.