[refactor,model,view][s]: add explicit query start, done and fail events for dataset and use them in DataExplorer to generate notifications.
This commit is contained in:
parent
3c9bd368da
commit
aaa01b2191
@ -39,6 +39,7 @@ my.Dataset = Backbone.Model.extend({
|
||||
// Resulting DocumentList are used to reset this.currentDocuments and are
|
||||
// also returned.
|
||||
query: function(queryObj) {
|
||||
this.trigger('query:start');
|
||||
var self = this;
|
||||
this.queryState.set(queryObj, {silent: true});
|
||||
var dfd = $.Deferred();
|
||||
@ -50,9 +51,11 @@ my.Dataset = Backbone.Model.extend({
|
||||
return _doc;
|
||||
});
|
||||
self.currentDocuments.reset(docs);
|
||||
self.trigger('query:done');
|
||||
dfd.resolve(self.currentDocuments);
|
||||
})
|
||||
.fail(function(arguments) {
|
||||
self.trigger('query:fail', arguments);
|
||||
dfd.reject(arguments);
|
||||
});
|
||||
return dfd.promise();
|
||||
|
||||
29
src/view.js
29
src/view.js
@ -101,33 +101,30 @@ my.DataExplorer = Backbone.View.extend({
|
||||
this.router = new Backbone.Router();
|
||||
this.setupRouting();
|
||||
|
||||
this.model.bind('query:start', function(eventName) {
|
||||
my.notify('Loading data', {loader: true});
|
||||
});
|
||||
this.model.bind('query:done', function(eventName) {
|
||||
my.clearNotifications();
|
||||
my.notify('Data loaded', {category: 'success'});
|
||||
});
|
||||
this.model.bind('query:fail', function(eventName, error) {
|
||||
my.clearNotifications();
|
||||
my.notify(error.message, {category: 'error', persist: true});
|
||||
});
|
||||
|
||||
// retrieve basic data like fields etc
|
||||
// note this.model and dataset returned are the same
|
||||
this.model.fetch()
|
||||
.done(function(dataset) {
|
||||
self.el.find('.doc-count').text(self.model.docCount || 'Unknown');
|
||||
self.query();
|
||||
self.model.query();
|
||||
})
|
||||
.fail(function(error) {
|
||||
my.notify(error.message, {category: 'error', persist: true});
|
||||
});
|
||||
},
|
||||
|
||||
// TODO: listen for being query and end query events on the dataset ...
|
||||
// (This is no longer called by anything ...)
|
||||
query: function() {
|
||||
my.notify('Loading data', {loader: true});
|
||||
this.model.query()
|
||||
.done(function() {
|
||||
my.clearNotifications();
|
||||
my.notify('Data loaded', {category: 'success'});
|
||||
})
|
||||
.fail(function(error) {
|
||||
my.clearNotifications();
|
||||
my.notify(error.message, {category: 'error', persist: true});
|
||||
});
|
||||
},
|
||||
|
||||
setReadOnly: function() {
|
||||
this.el.addClass('read-only');
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user