2010-02-02 20:16:09 +01:00
|
|
|
function TextSearchFacet(div, config, options) {
|
|
|
|
this._div = div;
|
|
|
|
this._config = config;
|
|
|
|
this._options = options;
|
|
|
|
|
2010-02-27 01:16:44 +01:00
|
|
|
this._query = config.query || null;
|
2010-02-02 20:16:09 +01:00
|
|
|
this._timerID = null;
|
|
|
|
|
|
|
|
this._initializeUI();
|
|
|
|
}
|
|
|
|
|
2010-02-27 01:16:44 +01:00
|
|
|
TextSearchFacet.reconstruct = function(div, uiState) {
|
|
|
|
return new TextSearchFacet(div, uiState.c, uiState.o);
|
2010-02-02 20:16:09 +01:00
|
|
|
};
|
|
|
|
|
2010-04-17 08:58:30 +02:00
|
|
|
TextSearchFacet.prototype.dispose = function() {
|
|
|
|
};
|
|
|
|
|
2010-03-23 19:53:29 +01:00
|
|
|
TextSearchFacet.prototype.reset = function() {
|
|
|
|
this._query = null;
|
|
|
|
this._div.find(".input-container input").each(function() { this.value = ""; });
|
|
|
|
};
|
|
|
|
|
2010-02-27 01:16:44 +01:00
|
|
|
TextSearchFacet.prototype.getUIState = function() {
|
|
|
|
var json = {
|
|
|
|
c: this.getJSON(),
|
|
|
|
o: this._options
|
|
|
|
};
|
|
|
|
|
|
|
|
return json;
|
2010-04-08 21:52:23 +02:00
|
|
|
};
|
2010-02-27 01:16:44 +01:00
|
|
|
|
2010-02-02 20:16:09 +01:00
|
|
|
TextSearchFacet.prototype.getJSON = function() {
|
2010-02-19 00:27:40 +01:00
|
|
|
var o = {
|
|
|
|
type: "text",
|
|
|
|
name: this._config.name,
|
|
|
|
columnName: this._config.columnName,
|
|
|
|
mode: this._config.mode,
|
|
|
|
caseSensitive: this._config.caseSensitive,
|
|
|
|
query: this._query
|
|
|
|
};
|
2010-02-02 20:16:09 +01:00
|
|
|
return o;
|
|
|
|
};
|
|
|
|
|
|
|
|
TextSearchFacet.prototype.hasSelection = function() {
|
2010-04-09 03:00:44 +02:00
|
|
|
return this._query !== null;
|
2010-02-02 20:16:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
TextSearchFacet.prototype._initializeUI = function() {
|
|
|
|
var self = this;
|
2010-04-18 02:56:09 +02:00
|
|
|
this._div.empty().show().html(
|
2010-03-23 00:01:53 +01:00
|
|
|
'<div class="facet-title">' +
|
2010-04-25 03:08:23 +02:00
|
|
|
'<div class="grid-layout layout-tightest layout-full"><table><tr>' +
|
|
|
|
'<td width="1%"><a href="javascript:{}" title="Remove this facet" class="facet-title-remove" bind="removeButton"> </a></td>' +
|
|
|
|
'<td>' +
|
|
|
|
'<span>' + this._config.name + '</span>' +
|
|
|
|
'</td>' +
|
|
|
|
'</tr></table></div>' +
|
2010-03-23 00:01:53 +01:00
|
|
|
'</div>' +
|
|
|
|
'<div class="facet-text-body"><div class="grid-layout layout-tightest layout-full"><table>' +
|
2010-04-18 02:56:09 +02:00
|
|
|
'<tr><td colspan="4"><div class="input-container"><input bind="input" /></div></td></tr>' +
|
|
|
|
'<tr>' +
|
|
|
|
'<td width="1%"><input type="checkbox" bind="caseSensitiveCheckbox" /></td><td>case sensitive</td>' +
|
|
|
|
'<td width="1%"><input type="checkbox" bind="regexCheckbox" /></td><td>regular expression</td>' +
|
|
|
|
'</tr>' +
|
2010-03-23 00:01:53 +01:00
|
|
|
'</table></div></div>'
|
|
|
|
);
|
2010-02-02 20:16:09 +01:00
|
|
|
|
2010-03-23 00:01:53 +01:00
|
|
|
var elmts = DOM.bind(this._div);
|
2010-02-02 20:16:09 +01:00
|
|
|
|
2010-03-23 00:01:53 +01:00
|
|
|
if (this._config.caseSensitive) {
|
|
|
|
elmts.caseSensitiveCheckbox.attr("checked", "true");
|
|
|
|
}
|
|
|
|
if (this._config.mode == "regex") {
|
|
|
|
elmts.regexCheckbox.attr("checked", "true");
|
|
|
|
}
|
2010-02-02 20:16:09 +01:00
|
|
|
|
2010-03-23 00:01:53 +01:00
|
|
|
elmts.removeButton.click(function() { self._remove(); });
|
|
|
|
|
|
|
|
elmts.caseSensitiveCheckbox.bind("change", function() {
|
|
|
|
self._config.caseSensitive = this.checked;
|
2010-04-09 03:00:44 +02:00
|
|
|
if (self._query !== null && self._query.length > 0) {
|
2010-03-23 00:01:53 +01:00
|
|
|
self._scheduleUpdate();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
elmts.regexCheckbox.bind("change", function() {
|
|
|
|
self._config.mode = this.checked ? "regex" : "text";
|
2010-04-09 03:00:44 +02:00
|
|
|
if (self._query !== null && self._query.length > 0) {
|
2010-03-23 00:01:53 +01:00
|
|
|
self._scheduleUpdate();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-05-14 21:33:59 +02:00
|
|
|
if (this._query) {
|
|
|
|
elmts.input[0].value = this._query;
|
|
|
|
}
|
2010-03-23 00:01:53 +01:00
|
|
|
elmts.input.keyup(function(evt) {
|
2010-02-02 20:16:09 +01:00
|
|
|
self._query = this.value;
|
|
|
|
self._scheduleUpdate();
|
2010-03-23 00:01:53 +01:00
|
|
|
}).focus();
|
2010-02-02 20:16:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
TextSearchFacet.prototype.updateState = function(data) {
|
|
|
|
};
|
|
|
|
|
|
|
|
TextSearchFacet.prototype.render = function() {
|
|
|
|
this._setRangeIndicators();
|
|
|
|
};
|
|
|
|
|
|
|
|
TextSearchFacet.prototype._reset = function() {
|
2010-02-27 01:16:44 +01:00
|
|
|
this._query = null;
|
2010-02-02 20:16:09 +01:00
|
|
|
this._updateRest();
|
|
|
|
};
|
|
|
|
|
|
|
|
TextSearchFacet.prototype._remove = function() {
|
|
|
|
ui.browsingEngine.removeFacet(this);
|
|
|
|
|
|
|
|
this._div = null;
|
|
|
|
this._config = null;
|
|
|
|
this._options = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
TextSearchFacet.prototype._scheduleUpdate = function() {
|
2010-04-08 22:16:08 +02:00
|
|
|
if (!this._timerID) {
|
2010-02-02 20:16:09 +01:00
|
|
|
var self = this;
|
|
|
|
this._timerID = window.setTimeout(function() {
|
|
|
|
self._timerID = null;
|
|
|
|
self._updateRest();
|
|
|
|
}, 500);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TextSearchFacet.prototype._updateRest = function() {
|
2010-02-26 22:56:41 +01:00
|
|
|
Gridworks.update({ engineChanged: true });
|
2010-02-02 20:16:09 +01:00
|
|
|
};
|