2010-01-29 01:46:15 +01:00
|
|
|
function BrowsingEngine(div) {
|
|
|
|
this._div = div;
|
|
|
|
this._facets = [];
|
2010-01-30 02:05:30 +01:00
|
|
|
|
|
|
|
this._initializeUI();
|
2010-01-29 01:46:15 +01:00
|
|
|
}
|
|
|
|
|
2010-01-30 02:05:30 +01:00
|
|
|
BrowsingEngine.prototype._initializeUI = function() {
|
2010-01-29 01:46:15 +01:00
|
|
|
var self = this;
|
|
|
|
var container = this._div.empty();
|
|
|
|
};
|
|
|
|
|
|
|
|
BrowsingEngine.prototype.getJSON = function() {
|
|
|
|
var a = { facets: [] };
|
|
|
|
for (var i = 0; i < this._facets.length; i++) {
|
2010-01-30 02:05:30 +01:00
|
|
|
a.facets.push(this._facets[i].facet.getJSON());
|
2010-01-29 01:46:15 +01:00
|
|
|
}
|
|
|
|
return a;
|
|
|
|
};
|
2010-01-30 02:05:30 +01:00
|
|
|
|
2010-02-02 02:36:02 +01:00
|
|
|
BrowsingEngine.prototype.addFacet = function(type, config, options) {
|
2010-01-30 02:05:30 +01:00
|
|
|
var div = $('<div></div>').addClass("facet-container").appendTo(this._div);
|
|
|
|
var facet;
|
|
|
|
switch (type) {
|
2010-02-02 02:36:02 +01:00
|
|
|
case "range":
|
|
|
|
facet = new RangeFacet(div, config, options);
|
|
|
|
break;
|
2010-01-30 02:05:30 +01:00
|
|
|
default:
|
2010-02-02 02:36:02 +01:00
|
|
|
facet = new ListFacet(div, config, options);
|
2010-01-30 02:05:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this._facets.push({ elmt: div, facet: facet });
|
|
|
|
this.update();
|
|
|
|
};
|
|
|
|
|
2010-02-01 01:19:41 +01:00
|
|
|
BrowsingEngine.prototype.removeFacet = function(facet) {
|
|
|
|
var update = facet.hasSelection();
|
|
|
|
for (var i = this._facets.length - 1;i >= 0; i--) {
|
|
|
|
if (this._facets[i].facet === facet) {
|
|
|
|
this._facets[i].elmt.remove();
|
|
|
|
this._facets.splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update) {
|
|
|
|
this.update();
|
|
|
|
ui.dataTableView.update(true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-01-30 02:05:30 +01:00
|
|
|
BrowsingEngine.prototype.update = function() {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
$.post(
|
|
|
|
"/command/compute-facets?" + $.param({ project: theProject.id }),
|
|
|
|
{ engine: JSON.stringify(ui.browsingEngine.getJSON()) },
|
|
|
|
function(data) {
|
|
|
|
var facetData = data.facets;
|
|
|
|
|
|
|
|
for (var i = 0; i < facetData.length; i++) {
|
|
|
|
self._facets[i].facet.updateState(facetData[i]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
};
|