[#88,state][s]: (and finally) introduce a recline.View.DataExplorer.restore function that restores from a serialized state.

* remove getState in favour of just using direct access to state object.
This commit is contained in:
Rufus Pollock
2012-04-15 22:47:16 +01:00
parent 7743534eac
commit 2a93aeb2c1
2 changed files with 45 additions and 13 deletions

View File

@@ -318,10 +318,12 @@ my.DataExplorer = Backbone.View.extend({
var graphState = qs['view-graph'] || qs.graph;
graphState = graphState ? JSON.parse(graphState) : {};
var stateData = _.extend({
readOnly: false,
query: query,
'view-graph': graphState,
currentView: null
backend: this.model.backend.__type__,
dataset: this.model.toJSON(),
currentView: null,
readOnly: false
},
initialState);
this.state.set(stateData);
@@ -353,16 +355,34 @@ my.DataExplorer = Backbone.View.extend({
});
}
});
},
// ### getState
//
// Get the current state of dataset and views (see discussion of state above)
getState: function() {
return this.state;
}
});
// ## restore
//
// Restore a DataExplorer instance from a serialized state including the associated dataset
my.DataExplorer.restore = function(state) {
// hack-y - restoring a memory dataset does not mean much ...
var dataset = null;
if (state.backend === 'memory') {
dataset = recline.Backend.createDataset(
[{stub: 'this is a stub dataset because we do not restore memory datasets'}],
[],
state.dataset
);
} else {
dataset = new recline.Model.Dataset(
state.dataset,
state.backend
);
}
var explorer = new my.DataExplorer({
model: dataset,
state: state
});
return explorer;
}
my.QueryEditor = Backbone.View.extend({
className: 'recline-query-editor',
template: ' \