2010-10-20 20:11:15 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 2010, Google Inc.
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are
|
|
|
|
met:
|
|
|
|
|
2011-08-14 03:05:43 +02:00
|
|
|
* Redistributions of source code must retain the above copyright
|
2010-10-20 20:11:15 +02:00
|
|
|
notice, this list of conditions and the following disclaimer.
|
2011-08-14 03:05:43 +02:00
|
|
|
* Redistributions in binary form must reproduce the above
|
2010-10-20 20:11:15 +02:00
|
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
|
|
in the documentation and/or other materials provided with the
|
|
|
|
distribution.
|
2011-08-14 03:05:43 +02:00
|
|
|
* Neither the name of Google Inc. nor the names of its
|
2010-10-20 20:11:15 +02:00
|
|
|
contributors may be used to endorse or promote products derived from
|
|
|
|
this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2011-08-14 03:05:43 +02:00
|
|
|
*/
|
2010-10-20 20:11:15 +02:00
|
|
|
|
2010-02-27 01:16:44 +01:00
|
|
|
function ListFacet(div, config, options, selection) {
|
2011-08-14 03:05:43 +02:00
|
|
|
this._div = div;
|
|
|
|
this._config = config;
|
|
|
|
if (!("invert" in this._config)) {
|
|
|
|
this._config.invert = false;
|
|
|
|
}
|
2020-04-17 23:14:04 +02:00
|
|
|
|
2011-08-14 03:05:43 +02:00
|
|
|
this._options = options || {};
|
|
|
|
if (!("sort" in this._options)) {
|
|
|
|
this._options.sort = "name";
|
|
|
|
}
|
|
|
|
|
|
|
|
this._selection = selection || [];
|
2020-04-17 22:17:20 +02:00
|
|
|
|
|
|
|
this._minimizeState = false;
|
2020-04-17 23:14:04 +02:00
|
|
|
|
2011-08-14 03:05:43 +02:00
|
|
|
this._blankChoice = (config.selectBlank) ? { s : true, c : 0 } : null;
|
|
|
|
this._errorChoice = (config.selectError) ? { s : true, c : 0 } : null;
|
|
|
|
|
|
|
|
this._data = null;
|
|
|
|
|
|
|
|
this._initializeUI();
|
|
|
|
this._update();
|
2010-01-30 02:05:30 +01:00
|
|
|
}
|
|
|
|
|
2010-02-27 01:16:44 +01:00
|
|
|
ListFacet.reconstruct = function(div, uiState) {
|
2011-08-14 03:05:43 +02:00
|
|
|
return new ListFacet(div, uiState.c, uiState.o, uiState.s);
|
2010-02-27 01:16:44 +01:00
|
|
|
};
|
|
|
|
|
2010-04-17 08:58:30 +02:00
|
|
|
ListFacet.prototype.dispose = function() {
|
|
|
|
};
|
|
|
|
|
2010-03-23 19:53:29 +01:00
|
|
|
ListFacet.prototype.reset = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
this._selection = [];
|
|
|
|
this._blankChoice = null;
|
|
|
|
this._errorChoice = null;
|
2010-03-23 19:53:29 +01:00
|
|
|
};
|
|
|
|
|
2010-02-27 01:16:44 +01:00
|
|
|
ListFacet.prototype.getUIState = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
var json = {
|
|
|
|
c: this.getJSON(),
|
|
|
|
o: this._options
|
|
|
|
};
|
|
|
|
|
|
|
|
json.s = json.c.selection;
|
|
|
|
delete json.c.selection;
|
|
|
|
|
|
|
|
return json;
|
2010-04-08 21:52:23 +02:00
|
|
|
};
|
2010-02-27 01:16:44 +01:00
|
|
|
|
2010-01-30 02:05:30 +01:00
|
|
|
ListFacet.prototype.getJSON = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
var o = {
|
|
|
|
type: "list",
|
|
|
|
name: this._config.name,
|
|
|
|
columnName: this._config.columnName,
|
|
|
|
expression: this._config.expression,
|
|
|
|
omitBlank: "omitBlank" in this._config ? this._config.omitBlank : false,
|
2019-02-22 19:38:45 +01:00
|
|
|
omitError: "omitError" in this._config ? this._config.omitError : false,
|
|
|
|
selection: [],
|
|
|
|
selectBlank: this._blankChoice !== null && this._blankChoice.s,
|
|
|
|
selectError: this._errorChoice !== null && this._errorChoice.s,
|
|
|
|
invert: this._config.invert
|
2011-08-14 03:05:43 +02:00
|
|
|
};
|
|
|
|
for (var i = 0; i < this._selection.length; i++) {
|
|
|
|
var choice = {
|
|
|
|
v: cloneDeep(this._selection[i].v)
|
2010-04-08 21:52:23 +02:00
|
|
|
};
|
2011-08-14 03:05:43 +02:00
|
|
|
o.selection.push(choice);
|
|
|
|
}
|
|
|
|
return o;
|
2010-01-30 02:05:30 +01:00
|
|
|
};
|
|
|
|
|
2010-02-01 01:19:41 +01:00
|
|
|
ListFacet.prototype.hasSelection = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
return this._selection.length > 0 ||
|
2019-02-22 19:38:45 +01:00
|
|
|
(this._blankChoice !== null && this._blankChoice.s) ||
|
|
|
|
(this._errorChoice !== null && this._errorChoice.s);
|
2010-02-01 01:19:41 +01:00
|
|
|
};
|
|
|
|
|
2010-01-30 02:05:30 +01:00
|
|
|
ListFacet.prototype.updateState = function(data) {
|
2011-08-14 03:05:43 +02:00
|
|
|
this._data = data;
|
|
|
|
|
|
|
|
if ("choices" in data) {
|
|
|
|
var selection = [];
|
|
|
|
var choices = data.choices;
|
|
|
|
for (var i = 0; i < choices.length; i++) {
|
|
|
|
var choice = choices[i];
|
|
|
|
if (choice.s) {
|
|
|
|
selection.push(choice);
|
|
|
|
}
|
2010-03-12 21:08:50 +01:00
|
|
|
}
|
2011-08-14 03:05:43 +02:00
|
|
|
this._selection = selection;
|
|
|
|
this._reSortChoices();
|
|
|
|
|
|
|
|
this._blankChoice = data.blankChoice || null;
|
|
|
|
this._errorChoice = data.errorChoice || null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._update();
|
2010-01-30 02:05:30 +01:00
|
|
|
};
|
|
|
|
|
2010-02-02 02:36:02 +01:00
|
|
|
ListFacet.prototype._reSortChoices = function() {
|
2017-11-15 19:31:41 +01:00
|
|
|
this._data.choices.sort(this._options.sort === "name" ?
|
2011-08-14 03:05:43 +02:00
|
|
|
function(a, b) {
|
2011-11-12 21:23:39 +01:00
|
|
|
return a.v.l.toLowerCase().localeCompare(b.v.l.toLowerCase());
|
2011-08-14 03:05:43 +02:00
|
|
|
} :
|
|
|
|
function(a, b) {
|
|
|
|
var c = b.c - a.c;
|
|
|
|
return c !== 0 ? c : a.v.l.localeCompare(b.v.l);
|
|
|
|
}
|
|
|
|
);
|
2010-02-02 02:36:02 +01:00
|
|
|
};
|
|
|
|
|
2010-04-21 09:04:44 +02:00
|
|
|
ListFacet.prototype._initializeUI = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
var facet_id = this._div.attr("id");
|
|
|
|
|
|
|
|
this._div.empty().show().html(
|
2020-04-17 22:17:20 +02:00
|
|
|
'<div class="facet-title" bind="facetTitle">' +
|
|
|
|
'<div class="grid-layout layout-tightest layout-full"><table><tr>' +
|
|
|
|
'<td width="1%">' +
|
|
|
|
'<a href="javascript:{}" title="'+$.i18n('core-facets/remove-facet')+'" class="facet-title-remove" bind="removeButton"> </a>' +
|
|
|
|
'</td>' +
|
|
|
|
'<td width="1%">' +
|
|
|
|
'<a href="javascript:{}" title="'+$.i18n('core-facets/minimize-facet')+'" class="facet-title-minimize" bind="minimizeButton"> </a>' +
|
|
|
|
'</td>' +
|
|
|
|
'<td>' +
|
|
|
|
'<a href="javascript:{}" class="facet-choice-link" bind="resetButton">'+$.i18n('core-facets/reset')+'</a>' +
|
|
|
|
'<a href="javascript:{}" class="facet-choice-link" bind="invertButton">'+$.i18n('core-facets/invert')+'</a>' +
|
|
|
|
'<a href="javascript:{}" class="facet-choice-link" bind="changeButton">'+$.i18n('core-facets/change')+'</a>' +
|
|
|
|
'<span bind="titleSpan"></span>' +
|
|
|
|
'</td>' +
|
|
|
|
'</tr></table></div>' +
|
|
|
|
'</div>' +
|
|
|
|
'<div class="facet-expression" bind="expressionDiv" title="'+$.i18n('core-facets/click-to-edit')+'"></div>' +
|
|
|
|
'<div class="facet-controls" bind="controlsDiv" style="display:none;">' +
|
|
|
|
'<a bind="choiceCountContainer" class="action" href="javascript:{}"></a> ' +
|
|
|
|
'<span class="facet-controls-sortControls" bind="sortGroup">'+$.i18n('core-facets/sort-by')+': ' +
|
|
|
|
'<a href="javascript:{}" bind="sortByNameLink">'+$.i18n('core-facets/name')+'</a>' +
|
|
|
|
'<a href="javascript:{}" bind="sortByCountLink">'+$.i18n('core-facets/count')+'</a>' +
|
|
|
|
'</span>' +
|
|
|
|
'<button bind="clusterLink" class="facet-controls-button button">'+$.i18n('core-facets/cluster')+'</button>' +
|
|
|
|
'</div>' +
|
|
|
|
'<div class="facet-body" bind="bodyDiv">' +
|
|
|
|
'<div class="facet-body-inner" bind="bodyInnerDiv"></div>' +
|
|
|
|
'</div>'
|
2011-08-14 03:05:43 +02:00
|
|
|
);
|
|
|
|
this._elmts = DOM.bind(this._div);
|
|
|
|
|
|
|
|
this._elmts.titleSpan.text(this._config.name);
|
2018-11-21 18:30:00 +01:00
|
|
|
this._elmts.changeButton.attr("title",$.i18n('core-facets/current-exp')+": " + this._config.expression).click(function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
self._elmts.expressionDiv.slideToggle(100, function() {
|
|
|
|
if (self._elmts.expressionDiv.css("display") != "none") {
|
|
|
|
self._editExpression();
|
|
|
|
}
|
2010-04-21 09:04:44 +02:00
|
|
|
});
|
2011-08-14 03:05:43 +02:00
|
|
|
});
|
2020-04-17 22:17:20 +02:00
|
|
|
|
2011-08-14 03:05:43 +02:00
|
|
|
this._elmts.expressionDiv.text(this._config.expression).hide().click(function() { self._editExpression(); });
|
|
|
|
this._elmts.removeButton.click(function() { self._remove(); });
|
2020-04-16 09:26:47 +02:00
|
|
|
this._elmts.minimizeButton.click(function() { self._minimize(); });
|
2011-08-14 03:05:43 +02:00
|
|
|
this._elmts.resetButton.click(function() { self._reset(); });
|
|
|
|
this._elmts.invertButton.click(function() { self._invert(); });
|
|
|
|
|
|
|
|
this._elmts.choiceCountContainer.click(function() { self._copyChoices(); });
|
|
|
|
this._elmts.sortByCountLink.click(function() {
|
|
|
|
if (self._options.sort != "count") {
|
|
|
|
self._options.sort = "count";
|
|
|
|
self._reSortChoices();
|
|
|
|
self._update(true);
|
2010-04-21 09:04:44 +02:00
|
|
|
}
|
2011-08-14 03:05:43 +02:00
|
|
|
});
|
|
|
|
this._elmts.sortByNameLink.click(function() {
|
|
|
|
if (self._options.sort != "name") {
|
|
|
|
self._options.sort = "name";
|
|
|
|
self._reSortChoices();
|
|
|
|
self._update(true);
|
2010-04-21 09:04:44 +02:00
|
|
|
}
|
2011-08-14 03:05:43 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
this._elmts.clusterLink.click(function() { self._doEdit(); });
|
|
|
|
if (this._config.expression != "value" && this._config.expression != "grel:value") {
|
|
|
|
this._elmts.clusterLink.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!("scroll" in this._options) || this._options.scroll) {
|
|
|
|
this._elmts.bodyDiv.addClass("facet-body-scrollable");
|
|
|
|
this._elmts.bodyDiv.resizable({
|
|
|
|
minHeight: 30,
|
|
|
|
handles: 's',
|
|
|
|
stop: function(event, ui) {
|
|
|
|
event.target.style.width = "auto"; // don't force the width
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2010-04-21 09:04:44 +02:00
|
|
|
};
|
|
|
|
|
2010-05-06 21:59:26 +02:00
|
|
|
ListFacet.prototype._copyChoices = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
var self = this;
|
|
|
|
var frame = DialogSystem.createDialog();
|
|
|
|
frame.width("600px");
|
|
|
|
|
2018-11-21 18:30:00 +01:00
|
|
|
var header = $('<div></div>').addClass("dialog-header").text($.i18n('core-facets/facet-choices')).appendTo(frame);
|
2011-08-14 03:05:43 +02:00
|
|
|
var body = $('<div></div>').addClass("dialog-body").appendTo(frame);
|
|
|
|
var footer = $('<div></div>').addClass("dialog-footer").appendTo(frame);
|
|
|
|
|
2020-03-10 11:17:23 +01:00
|
|
|
body.html('<textarea disabled wrap="off" bind="textarea" style="display: block; width: 100%; height: 400px;" />');
|
2011-08-14 03:05:43 +02:00
|
|
|
var elmts = DOM.bind(body);
|
|
|
|
|
2018-11-21 18:30:00 +01:00
|
|
|
$('<button class="button"></button>').text($.i18n('core-buttons/close')).click(function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
DialogSystem.dismissUntil(level - 1);
|
|
|
|
}).appendTo(footer);
|
|
|
|
|
|
|
|
var lines = [];
|
|
|
|
for (var i = 0; i < this._data.choices.length; i++) {
|
|
|
|
var choice = this._data.choices[i];
|
|
|
|
lines.push(choice.v.l + "\t" + choice.c);
|
|
|
|
}
|
|
|
|
if (this._blankChoice) {
|
|
|
|
lines.push("(blank)\t" + this._blankChoice.c);
|
|
|
|
}
|
|
|
|
if (this._errorChoice) {
|
|
|
|
lines.push("(error)\t" + this._errorChoice.c);
|
|
|
|
}
|
|
|
|
|
|
|
|
var level = DialogSystem.showDialog(frame);
|
|
|
|
|
|
|
|
var textarea = elmts.textarea[0];
|
|
|
|
textarea.value = lines.join("\n");
|
|
|
|
textarea.focus();
|
|
|
|
textarea.select();
|
2010-05-06 21:59:26 +02:00
|
|
|
};
|
|
|
|
|
2010-04-21 09:04:44 +02:00
|
|
|
ListFacet.prototype._update = function(resetScroll) {
|
2011-08-14 03:05:43 +02:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
var invert = this._config.invert;
|
|
|
|
if (invert) {
|
2017-11-14 14:51:42 +01:00
|
|
|
this._elmts.facetTitle.addClass("facet-title-inverted");
|
2011-08-14 03:05:43 +02:00
|
|
|
this._elmts.bodyInnerDiv.addClass("facet-mode-inverted");
|
|
|
|
this._elmts.invertButton.addClass("facet-mode-inverted");
|
|
|
|
} else {
|
2017-11-14 14:51:42 +01:00
|
|
|
this._elmts.facetTitle.removeClass("facet-title-inverted");
|
2011-08-14 03:05:43 +02:00
|
|
|
this._elmts.bodyInnerDiv.removeClass("facet-mode-inverted");
|
|
|
|
this._elmts.invertButton.removeClass("facet-mode-inverted");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this._data) {
|
|
|
|
//this._elmts.statusDiv.hide();
|
|
|
|
this._elmts.controlsDiv.hide();
|
|
|
|
this._elmts.bodyInnerDiv.empty().append(
|
2018-11-21 18:30:00 +01:00
|
|
|
$('<div>').text($.i18n('core-facets/loading')).addClass("facet-body-message"));
|
2011-08-14 03:05:43 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
} else if ("error" in this._data) {
|
|
|
|
//this._elmts.statusDiv.hide();
|
|
|
|
this._elmts.controlsDiv.hide();
|
|
|
|
|
2017-11-15 19:31:41 +01:00
|
|
|
if (this._data.error === "Too many choices") {
|
2011-08-14 03:05:43 +02:00
|
|
|
this._elmts.bodyInnerDiv.empty();
|
|
|
|
|
|
|
|
var messageDiv = $('<div>')
|
2020-06-14 10:23:23 +02:00
|
|
|
.text($.i18n('core-facets/too-many-choices', this._data.choiceCount))
|
2011-08-14 03:05:43 +02:00
|
|
|
.addClass("facet-body-message")
|
|
|
|
.appendTo(this._elmts.bodyInnerDiv);
|
|
|
|
$('<br>').appendTo(messageDiv);
|
|
|
|
$('<a>')
|
2018-11-21 18:30:00 +01:00
|
|
|
.text($.i18n('core-facets/set-choice-count'))
|
2011-08-14 03:05:43 +02:00
|
|
|
.attr("href", "javascript:{}")
|
|
|
|
.addClass("action")
|
|
|
|
.addClass("secondary")
|
|
|
|
.appendTo(messageDiv)
|
|
|
|
.click(function() {
|
|
|
|
self._setChoiceCountLimit(self._data.choiceCount);
|
|
|
|
});
|
|
|
|
|
|
|
|
this._renderBodyControls();
|
2010-04-29 23:22:28 +02:00
|
|
|
} else {
|
2011-08-14 03:05:43 +02:00
|
|
|
this._elmts.bodyInnerDiv.empty().append(
|
|
|
|
$('<div>')
|
|
|
|
.text(this._data.error)
|
|
|
|
.addClass("facet-body-message"));
|
2010-04-29 23:22:28 +02:00
|
|
|
}
|
2011-08-14 03:05:43 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var scrollTop = 0;
|
|
|
|
if (!resetScroll) {
|
|
|
|
try {
|
|
|
|
scrollTop = this._elmts.bodyInnerDiv[0].scrollTop;
|
|
|
|
} catch (e) {
|
2010-02-02 02:36:02 +01:00
|
|
|
}
|
2011-08-14 03:05:43 +02:00
|
|
|
}
|
|
|
|
|
2014-07-03 15:34:26 +02:00
|
|
|
// FIXME: this is very slow for large numbers of choices (e.g. 18 seconds for 13K choices)
|
2011-08-14 03:05:43 +02:00
|
|
|
this._elmts.bodyInnerDiv.empty();
|
2014-07-03 15:34:26 +02:00
|
|
|
|
|
|
|
// None of the following alternatives are significantly faster
|
|
|
|
|
|
|
|
// this._elmts.bodyInnerDiv.innerHtml = '';
|
|
|
|
|
|
|
|
// this._elmts.bodyInnerDiv.detach();
|
|
|
|
// this._elmts.bodyInnerDiv.children().remove();
|
|
|
|
// this._elmts.bodyInnerDiv.appendTo('.facet-body');
|
|
|
|
|
|
|
|
// this._elmts.bodyInnerDiv.remove();
|
|
|
|
// this._elmts.bodyInnerDiv.html('<div class="facet-body-inner" bind="bodyInnerDiv"></div>');
|
|
|
|
// this._elmts.bodyInnerDiv.appendTo('.facet-body');
|
|
|
|
|
2011-08-14 03:05:43 +02:00
|
|
|
//this._elmts.statusDiv.show();
|
|
|
|
this._elmts.controlsDiv.show();
|
|
|
|
|
|
|
|
var choices = this._data.choices;
|
|
|
|
var selectionCount = this._selection.length +
|
|
|
|
(this._blankChoice !== null && this._blankChoice.s ? 1 : 0) +
|
|
|
|
(this._errorChoice !== null && this._errorChoice.s ? 1 : 0);
|
|
|
|
|
2020-06-14 10:23:23 +02:00
|
|
|
this._elmts.choiceCountContainer.text($.i18n("core-facets/choice-count", choices.length));
|
2011-08-14 03:05:43 +02:00
|
|
|
if (selectionCount > 0) {
|
|
|
|
this._elmts.resetButton.show();
|
|
|
|
this._elmts.invertButton.show();
|
|
|
|
} else {
|
|
|
|
this._elmts.resetButton.hide();
|
|
|
|
this._elmts.invertButton.hide();
|
|
|
|
}
|
|
|
|
|
2017-11-15 19:31:41 +01:00
|
|
|
if (this._options.sort === "name") {
|
2011-08-14 03:05:43 +02:00
|
|
|
this._elmts.sortByNameLink.removeClass("action").addClass("selected");
|
|
|
|
this._elmts.sortByCountLink.removeClass("selected").addClass("action");
|
|
|
|
} else {
|
|
|
|
this._elmts.sortByNameLink.removeClass("selected").addClass("action");
|
|
|
|
this._elmts.sortByCountLink.removeClass("action").addClass("selected");
|
|
|
|
}
|
|
|
|
|
|
|
|
var html = [];
|
|
|
|
var temp = $('<div>');
|
|
|
|
var encodeHtml = function(s) {
|
|
|
|
return temp.text(s).html();
|
|
|
|
};
|
|
|
|
|
2017-11-15 19:31:41 +01:00
|
|
|
var renderEdit = this._config.expression === "value";
|
2011-08-14 03:05:43 +02:00
|
|
|
var renderChoice = function(index, choice, customLabel) {
|
|
|
|
var label = customLabel || choice.v.l;
|
|
|
|
var count = choice.c;
|
|
|
|
|
|
|
|
html.push('<div class="facet-choice' + (choice.s ? ' facet-choice-selected' : '') + '" choiceIndex="' + index + '">');
|
|
|
|
|
|
|
|
// include/exclude link
|
|
|
|
html.push(
|
|
|
|
'<a href="javascript:{}" class="facet-choice-link facet-choice-toggle" ' +
|
|
|
|
'style="visibility: ' + (choice.s ? 'visible' : 'hidden') + '">' +
|
|
|
|
(invert != choice.s ? 'exclude' : 'include') +
|
|
|
|
'</a>'
|
|
|
|
);
|
|
|
|
|
|
|
|
// edit link
|
|
|
|
if (renderEdit) {
|
2018-11-21 18:30:00 +01:00
|
|
|
html.push('<a href="javascript:{}" class="facet-choice-link facet-choice-edit" style="visibility: hidden">'+$.i18n('core-facets/edit')+'</a>');
|
2010-04-21 20:30:27 +02:00
|
|
|
}
|
2011-08-14 03:05:43 +02:00
|
|
|
|
|
|
|
html.push('<a href="javascript:{}" class="facet-choice-label">' + encodeHtml(label) + '</a>');
|
|
|
|
html.push('<span class="facet-choice-count">' + (invert ? "-" : "") + count + '</span>');
|
|
|
|
|
|
|
|
html.push('</div>');
|
|
|
|
};
|
|
|
|
for (var i = 0; i < choices.length; i++) {
|
|
|
|
renderChoice(i, choices[i]);
|
|
|
|
}
|
|
|
|
if (this._blankChoice !== null) {
|
|
|
|
renderChoice(-1, this._blankChoice, "(blank)");
|
|
|
|
}
|
|
|
|
if (this._errorChoice !== null) {
|
|
|
|
renderChoice(-2, this._errorChoice, "(error)");
|
|
|
|
}
|
|
|
|
|
|
|
|
this._elmts.bodyInnerDiv.html(html.join(''));
|
|
|
|
this._renderBodyControls();
|
|
|
|
this._elmts.bodyInnerDiv[0].scrollTop = scrollTop;
|
|
|
|
|
|
|
|
var getChoice = function(elmt) {
|
|
|
|
var index = parseInt(elmt.attr("choiceIndex"),10);
|
2017-11-15 19:31:41 +01:00
|
|
|
if (index === -1) {
|
2011-08-14 03:05:43 +02:00
|
|
|
return self._blankChoice;
|
2017-11-15 19:31:41 +01:00
|
|
|
} else if (index === -2) {
|
2011-08-14 03:05:43 +02:00
|
|
|
return self._errorChoice;
|
2010-04-21 20:30:27 +02:00
|
|
|
} else {
|
2011-08-14 03:05:43 +02:00
|
|
|
return choices[index];
|
2010-04-21 20:30:27 +02:00
|
|
|
}
|
2011-08-14 03:05:43 +02:00
|
|
|
};
|
|
|
|
var findChoice = function(elmt) {
|
|
|
|
return getChoice(elmt.closest('.facet-choice'));
|
|
|
|
};
|
|
|
|
var select = function(choice) {
|
|
|
|
self._select(choice, false);
|
|
|
|
};
|
|
|
|
var selectOnly = function(choice) {
|
|
|
|
self._select(choice, true);
|
|
|
|
};
|
|
|
|
var deselect = function(choice) {
|
|
|
|
self._deselect(choice);
|
|
|
|
};
|
|
|
|
|
|
|
|
var wireEvents = function() {
|
|
|
|
var bodyInnerDiv = self._elmts.bodyInnerDiv;
|
2014-07-03 20:29:46 +02:00
|
|
|
bodyInnerDiv.off(); // remove all old handlers
|
2014-07-03 15:34:26 +02:00
|
|
|
bodyInnerDiv.on('click', '.facet-choice-label', function(e) {
|
|
|
|
e.preventDefault();
|
2011-08-14 03:05:43 +02:00
|
|
|
var choice = findChoice($(this));
|
|
|
|
if (choice.s) {
|
|
|
|
if (selectionCount > 1) {
|
|
|
|
selectOnly(choice);
|
2010-04-21 20:30:27 +02:00
|
|
|
} else {
|
2011-08-14 03:05:43 +02:00
|
|
|
deselect(choice);
|
2010-04-21 20:30:27 +02:00
|
|
|
}
|
2011-08-14 03:05:43 +02:00
|
|
|
} else if (selectionCount > 0) {
|
|
|
|
selectOnly(choice);
|
|
|
|
} else {
|
|
|
|
select(choice);
|
|
|
|
}
|
|
|
|
});
|
2014-07-03 15:34:26 +02:00
|
|
|
bodyInnerDiv.on('click', '.facet-choice-edit', function(e) {
|
|
|
|
e.preventDefault();
|
2011-08-14 03:05:43 +02:00
|
|
|
var choice = findChoice($(this));
|
|
|
|
self._editChoice(choice, $(this).closest('.facet-choice'));
|
|
|
|
});
|
2010-04-21 20:30:27 +02:00
|
|
|
|
2014-07-03 15:34:26 +02:00
|
|
|
bodyInnerDiv.on('mouseenter mouseleave', '.facet-choice', function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var visibility = 'visible';
|
2017-11-15 19:31:41 +01:00
|
|
|
if (e.type === 'mouseleave') {
|
2014-07-03 15:34:26 +02:00
|
|
|
visibility = 'hidden';
|
2011-08-14 03:05:43 +02:00
|
|
|
}
|
2014-07-03 15:34:26 +02:00
|
|
|
$(this).find('.facet-choice-edit').css("visibility", visibility);
|
2011-08-14 03:05:43 +02:00
|
|
|
|
|
|
|
var choice = getChoice($(this));
|
|
|
|
if (!choice.s) {
|
2014-07-03 15:34:26 +02:00
|
|
|
$(this).find('.facet-choice-toggle').css("visibility", visibility);
|
2011-08-14 03:05:43 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-07-03 15:34:26 +02:00
|
|
|
bodyInnerDiv.on('click', '.facet-choice-toggle', function(e) {
|
|
|
|
e.preventDefault();
|
2011-08-14 03:05:43 +02:00
|
|
|
var choice = findChoice($(this));
|
|
|
|
if (choice.s) {
|
|
|
|
deselect(choice);
|
|
|
|
} else {
|
|
|
|
select(choice);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
window.setTimeout(wireEvents, 100);
|
2014-07-03 15:34:26 +02:00
|
|
|
}; // end _update()
|
2010-03-02 20:58:47 +01:00
|
|
|
|
2010-05-24 21:04:55 +02:00
|
|
|
ListFacet.prototype._renderBodyControls = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
var self = this;
|
|
|
|
var bodyControls = $('<div>')
|
|
|
|
.addClass("facet-body-controls")
|
|
|
|
.appendTo(this._elmts.bodyInnerDiv);
|
|
|
|
|
|
|
|
$('<a>')
|
2018-11-21 18:30:00 +01:00
|
|
|
.text($.i18n('core-facets/facet-by-count'))
|
2011-08-14 03:05:43 +02:00
|
|
|
.attr("href", "javascript:{}")
|
|
|
|
.addClass("action")
|
|
|
|
.addClass("secondary")
|
|
|
|
.appendTo(bodyControls)
|
|
|
|
.click(function() {
|
|
|
|
ui.browsingEngine.addFacet(
|
|
|
|
"range",
|
|
|
|
{
|
|
|
|
"name" : self._config.columnName,
|
|
|
|
"columnName" : self._config.columnName,
|
|
|
|
"expression" : self._getMetaExpression(),
|
|
|
|
"mode" : "range"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2010-05-24 21:04:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
ListFacet.prototype._getMetaExpression = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
var r = Scripting.parse(this._config.expression);
|
|
|
|
|
|
|
|
return r.language + ':facetCount(' + [
|
2010-06-15 00:11:34 +02:00
|
|
|
r.expression,
|
2010-05-24 21:04:55 +02:00
|
|
|
JSON.stringify(this._config.expression),
|
|
|
|
JSON.stringify(this._config.columnName)
|
2011-08-14 03:05:43 +02:00
|
|
|
].join(', ') + ')';
|
2011-10-08 01:44:11 +02:00
|
|
|
};
|
2010-05-24 21:04:55 +02:00
|
|
|
|
2010-03-02 20:58:47 +01:00
|
|
|
ListFacet.prototype._doEdit = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
new ClusteringDialog(this._config.columnName, this._config.expression);
|
2010-01-30 02:05:30 +01:00
|
|
|
};
|
|
|
|
|
2010-03-08 20:07:16 +01:00
|
|
|
ListFacet.prototype._editChoice = function(choice, choiceDiv) {
|
2011-08-14 03:05:43 +02:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
var menu = MenuSystem.createMenu().addClass("data-table-cell-editor").width("400px");
|
|
|
|
menu.html(
|
|
|
|
'<textarea class="data-table-cell-editor-editor" bind="textarea" />' +
|
|
|
|
'<div id="data-table-cell-editor-actions">' +
|
|
|
|
'<div class="data-table-cell-editor-action">' +
|
2018-11-21 18:30:00 +01:00
|
|
|
'<button class="button" bind="okButton">'+$.i18n('core-buttons/apply')+'</button>' +
|
|
|
|
'<div class="data-table-cell-editor-key">'+$.i18n('core-buttons/enter')+'</div>' +
|
2011-08-14 03:05:43 +02:00
|
|
|
'</div>' +
|
|
|
|
'<div class="data-table-cell-editor-action">' +
|
2018-11-21 18:30:00 +01:00
|
|
|
'<button class="button" bind="cancelButton">'+$.i18n('core-buttons/cancel')+'</button>' +
|
|
|
|
'<div class="data-table-cell-editor-key">'+$.i18n('core-buttons/esc')+'</div>' +
|
2011-08-14 03:05:43 +02:00
|
|
|
'</div>' +
|
|
|
|
'</div>'
|
|
|
|
);
|
|
|
|
var elmts = DOM.bind(menu);
|
|
|
|
|
|
|
|
MenuSystem.showMenu(menu, function(){});
|
|
|
|
MenuSystem.positionMenuLeftRight(menu, choiceDiv);
|
|
|
|
|
|
|
|
var originalContent;
|
|
|
|
if (choice === this._blankChoice) {
|
|
|
|
originalContent = "(blank)";
|
|
|
|
} else if (choice === this._errorChoice) {
|
|
|
|
originalContent = "(error)";
|
|
|
|
} else {
|
|
|
|
originalContent = choice.v.v;
|
|
|
|
}
|
|
|
|
|
|
|
|
var commit = function() {
|
|
|
|
var text = elmts.textarea[0].value;
|
|
|
|
|
|
|
|
MenuSystem.dismissAll();
|
|
|
|
|
|
|
|
var edit = { to : text };
|
|
|
|
if (choice === self._blankChoice) {
|
|
|
|
edit.fromBlank = true;
|
|
|
|
} else if (choice === self._errorChoice) {
|
|
|
|
edit.fromError = true;
|
2010-04-29 22:18:06 +02:00
|
|
|
} else {
|
2011-08-14 03:05:43 +02:00
|
|
|
edit.from = [ originalContent ];
|
2010-04-29 22:18:06 +02:00
|
|
|
}
|
2011-08-14 03:05:43 +02:00
|
|
|
|
|
|
|
Refine.postCoreProcess(
|
|
|
|
"mass-edit",
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
columnName: self._config.columnName,
|
|
|
|
expression: "value",
|
|
|
|
edits: JSON.stringify([ edit ])
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// limit edits to rows constrained only by the other facets
|
|
|
|
engineConfig: ui.browsingEngine.getJSON(false, self),
|
|
|
|
cellsChanged: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
onDone: function(o) {
|
|
|
|
var selection = [];
|
|
|
|
var gotSelection = false;
|
|
|
|
for (var i = 0; i < self._selection.length; i++) {
|
|
|
|
var choice = self._selection[i];
|
2017-11-15 19:31:41 +01:00
|
|
|
if (choice.v.v === originalContent) {
|
2011-08-14 03:05:43 +02:00
|
|
|
if (gotSelection) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
choice.v.v = text;
|
|
|
|
gotSelection = true; // eliminate duplicated selections due to changing one selected choice to another
|
2010-03-08 20:07:16 +01:00
|
|
|
}
|
2011-08-14 03:05:43 +02:00
|
|
|
selection.push(choice);
|
|
|
|
}
|
|
|
|
self._selection = selection;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
elmts.okButton.click(commit);
|
|
|
|
elmts.textarea
|
|
|
|
.text(originalContent)
|
|
|
|
.keydown(function(evt) {
|
|
|
|
if (!evt.shiftKey) {
|
2017-11-15 19:31:41 +01:00
|
|
|
if (evt.keyCode === 13) {
|
2011-08-14 03:05:43 +02:00
|
|
|
commit();
|
2017-11-15 19:31:41 +01:00
|
|
|
} else if (evt.keyCode === 27) {
|
2010-03-08 20:07:16 +01:00
|
|
|
MenuSystem.dismissAll();
|
2011-08-14 03:05:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.select()
|
|
|
|
.focus();
|
|
|
|
|
|
|
|
elmts.cancelButton.click(function() {
|
|
|
|
MenuSystem.dismissAll();
|
|
|
|
});
|
2010-03-08 20:07:16 +01:00
|
|
|
};
|
|
|
|
|
2010-01-30 02:05:30 +01:00
|
|
|
ListFacet.prototype._select = function(choice, only) {
|
2011-08-14 03:05:43 +02:00
|
|
|
if (only) {
|
|
|
|
this._selection = [];
|
|
|
|
if (this._blankChoice !== null) {
|
|
|
|
this._blankChoice.s = false;
|
2010-01-30 02:05:30 +01:00
|
|
|
}
|
2011-08-14 03:05:43 +02:00
|
|
|
if (this._errorChoice !== null) {
|
|
|
|
this._errorChoice.s = false;
|
2010-02-27 07:59:55 +01:00
|
|
|
}
|
2011-08-14 03:05:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
choice.s = true;
|
2019-02-22 19:38:45 +01:00
|
|
|
if (choice !== this._errorChoice && choice !== this._blankChoice) {
|
2011-08-14 03:05:43 +02:00
|
|
|
this._selection.push(choice);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._updateRest();
|
2010-01-30 02:05:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
ListFacet.prototype._deselect = function(choice) {
|
2019-02-22 19:38:45 +01:00
|
|
|
if (choice === this._errorChoice || choice === this._blankChoice) {
|
2011-08-14 03:05:43 +02:00
|
|
|
choice.s = false;
|
|
|
|
} else {
|
|
|
|
for (var i = this._selection.length - 1; i >= 0; i--) {
|
|
|
|
if (this._selection[i] === choice) {
|
|
|
|
this._selection.splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
2010-01-30 02:05:30 +01:00
|
|
|
}
|
2011-08-14 03:05:43 +02:00
|
|
|
}
|
|
|
|
this._updateRest();
|
2010-01-30 02:05:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
ListFacet.prototype._reset = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
this._selection = [];
|
|
|
|
this._blankChoice = null;
|
|
|
|
this._errorChoice = null;
|
|
|
|
this._config.invert = false;
|
|
|
|
|
|
|
|
this._updateRest();
|
2010-04-29 23:22:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
ListFacet.prototype._invert = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
this._config.invert = !this._config.invert;
|
|
|
|
|
|
|
|
this._updateRest();
|
2010-01-30 02:05:30 +01:00
|
|
|
};
|
|
|
|
|
2010-02-01 01:19:41 +01:00
|
|
|
ListFacet.prototype._remove = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
ui.browsingEngine.removeFacet(this);
|
|
|
|
|
|
|
|
this._div = null;
|
|
|
|
this._config = null;
|
|
|
|
|
|
|
|
this._selection = null;
|
|
|
|
this._blankChoice = null;
|
|
|
|
this._errorChoice = null;
|
|
|
|
this._data = null;
|
2010-02-01 01:19:41 +01:00
|
|
|
};
|
|
|
|
|
2020-04-16 09:26:47 +02:00
|
|
|
ListFacet.prototype._minimize = function() {
|
2020-04-17 10:39:41 +02:00
|
|
|
if(!this._minimizeState) {
|
2020-04-17 22:17:20 +02:00
|
|
|
this._div.addClass("facet-state-minimize");
|
2020-04-16 09:26:47 +02:00
|
|
|
} else {
|
2020-04-17 22:17:20 +02:00
|
|
|
this._div.removeClass("facet-state-minimize");
|
2020-04-16 09:26:47 +02:00
|
|
|
}
|
2020-04-17 10:39:41 +02:00
|
|
|
|
|
|
|
this._minimizeState = !this._minimizeState;
|
2020-04-16 09:26:47 +02:00
|
|
|
};
|
|
|
|
|
2010-01-30 02:05:30 +01:00
|
|
|
ListFacet.prototype._updateRest = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
Refine.update({ engineChanged: true });
|
2010-02-01 01:19:41 +01:00
|
|
|
};
|
2010-04-24 03:19:13 +02:00
|
|
|
|
|
|
|
ListFacet.prototype._editExpression = function() {
|
2011-08-14 03:05:43 +02:00
|
|
|
var self = this;
|
|
|
|
var title = (this._config.columnName) ?
|
2018-11-21 18:30:00 +01:00
|
|
|
($.i18n('core-facets/edit-based-col')+" " + this._config.columnName) :
|
|
|
|
$.i18n('core-facets/edit-facet-exp');
|
2011-08-14 03:05:43 +02:00
|
|
|
|
|
|
|
var column = Refine.columnNameToColumn(this._config.columnName);
|
|
|
|
var o = DataTableView.sampleVisibleRows(column);
|
|
|
|
|
|
|
|
new ExpressionPreviewDialog(
|
|
|
|
title,
|
|
|
|
column ? column.cellIndex : -1,
|
|
|
|
o.rowIndices,
|
|
|
|
o.values,
|
|
|
|
this._config.expression,
|
|
|
|
function(expr) {
|
|
|
|
if (expr != self._config.expression) {
|
|
|
|
self._config.expression = expr;
|
|
|
|
|
|
|
|
self._elmts.expressionDiv.text(self._config.expression);
|
2018-11-21 18:30:00 +01:00
|
|
|
self._elmts.changeButton.attr("title", $.i18n('core-facets/current-exp')+": " + self._config.expression);
|
2017-11-15 19:31:41 +01:00
|
|
|
if (self._config.expression === "value" || self._config.expression === "grel:value") {
|
2011-08-14 03:05:43 +02:00
|
|
|
self._elmts.clusterLink.show();
|
|
|
|
} else {
|
|
|
|
self._elmts.clusterLink.hide();
|
2010-04-24 03:19:13 +02:00
|
|
|
}
|
2011-08-14 03:05:43 +02:00
|
|
|
|
|
|
|
self.reset();
|
|
|
|
self._updateRest();
|
|
|
|
}
|
2013-01-25 21:56:24 +01:00
|
|
|
self._elmts.expressionDiv.hide();
|
2011-08-14 03:05:43 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
ListFacet.prototype._setChoiceCountLimit = function(choiceCount) {
|
|
|
|
var limit = Math.ceil(choiceCount / 1000) * 1000;
|
2018-11-21 18:30:00 +01:00
|
|
|
var s = window.prompt($.i18n('core-facets/set-max-choices'), limit);
|
2011-08-14 03:05:43 +02:00
|
|
|
if (s) {
|
2011-10-08 01:44:11 +02:00
|
|
|
var n = parseInt(s,10);
|
2011-08-14 03:05:43 +02:00
|
|
|
|
|
|
|
if (!isNaN(n)) {
|
|
|
|
var self = this;
|
2019-10-14 15:28:00 +02:00
|
|
|
Refine.postCSRF(
|
2012-10-13 19:47:08 +02:00
|
|
|
"command/core/set-preference",
|
2011-08-14 03:05:43 +02:00
|
|
|
{
|
|
|
|
name : "ui.browsing.listFacet.limit",
|
2019-09-11 18:53:38 +02:00
|
|
|
value : JSON.stringify(n)
|
2011-08-14 03:05:43 +02:00
|
|
|
},
|
|
|
|
function(o) {
|
2017-11-15 19:31:41 +01:00
|
|
|
if (o.code === "ok") {
|
2011-08-14 03:05:43 +02:00
|
|
|
ui.browsingEngine.update();
|
2017-11-15 19:31:41 +01:00
|
|
|
} else if (o.code === "error") {
|
2011-08-14 03:05:43 +02:00
|
|
|
alert(o.message);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|