diff --git a/main/src/com/google/refine/browsing/facets/ListFacet.java b/main/src/com/google/refine/browsing/facets/ListFacet.java index 6c6a2e34f..2c0941f02 100644 --- a/main/src/com/google/refine/browsing/facets/ListFacet.java +++ b/main/src/com/google/refine/browsing/facets/ListFacet.java @@ -107,6 +107,7 @@ public class ListFacet implements Facet { writer.key("error"); writer.value(_errorMessage); } else if (_choices.size() > getLimit()) { writer.key("error"); writer.value("Too many choices"); + writer.key("choiceCount"); writer.value(_choices.size()); } else { writer.key("choices"); writer.array(); for (NominalFacetChoice choice : _choices) { diff --git a/main/webapp/modules/core/scripts/facets/list-facet.js b/main/webapp/modules/core/scripts/facets/list-facet.js index b8a42f3a4..b9c285a81 100644 --- a/main/webapp/modules/core/scripts/facets/list-facet.js +++ b/main/webapp/modules/core/scripts/facets/list-facet.js @@ -7,13 +7,13 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. @@ -29,645 +29,693 @@ 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. -*/ + */ function ListFacet(div, config, options, selection) { - this._div = div; - this._config = config; - if (!("invert" in this._config)) { - this._config.invert = false; - } - - this._options = options || {}; - if (!("sort" in this._options)) { - this._options.sort = "name"; - } - - this._selection = selection || []; - 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(); + this._div = div; + this._config = config; + if (!("invert" in this._config)) { + this._config.invert = false; + } + + this._options = options || {}; + if (!("sort" in this._options)) { + this._options.sort = "name"; + } + + this._selection = selection || []; + 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(); } ListFacet.reconstruct = function(div, uiState) { - return new ListFacet(div, uiState.c, uiState.o, uiState.s); + return new ListFacet(div, uiState.c, uiState.o, uiState.s); }; ListFacet.prototype.dispose = function() { }; ListFacet.prototype.reset = function() { - this._selection = []; - this._blankChoice = null; - this._errorChoice = null; + this._selection = []; + this._blankChoice = null; + this._errorChoice = null; }; ListFacet.prototype.getUIState = function() { - var json = { - c: this.getJSON(), - o: this._options - }; - - json.s = json.c.selection; - delete json.c.selection; - - return json; + var json = { + c: this.getJSON(), + o: this._options + }; + + json.s = json.c.selection; + delete json.c.selection; + + return json; }; ListFacet.prototype.getJSON = function() { - 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, - 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 + 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, + 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 + }; + for (var i = 0; i < this._selection.length; i++) { + var choice = { + v: cloneDeep(this._selection[i].v) }; - for (var i = 0; i < this._selection.length; i++) { - var choice = { - v: cloneDeep(this._selection[i].v) - }; - o.selection.push(choice); - } - return o; + o.selection.push(choice); + } + return o; }; ListFacet.prototype.hasSelection = function() { - return this._selection.length > 0 || - (this._blankChoice !== null && this._blankChoice.s) || - (this._errorChoice !== null && this._errorChoice.s); + return this._selection.length > 0 || + (this._blankChoice !== null && this._blankChoice.s) || + (this._errorChoice !== null && this._errorChoice.s); }; ListFacet.prototype.updateState = function(data) { - 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); - } - } - this._selection = selection; - this._reSortChoices(); - - this._blankChoice = data.blankChoice || null; - this._errorChoice = data.errorChoice || null; + 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); + } } - - this._update(); + this._selection = selection; + this._reSortChoices(); + + this._blankChoice = data.blankChoice || null; + this._errorChoice = data.errorChoice || null; + } + + this._update(); }; ListFacet.prototype._reSortChoices = function() { - this._data.choices.sort(this._options.sort == "name" ? - function(a, b) { - return a.v.l.localeCompare(b.v.l); - } : - function(a, b) { - var c = b.c - a.c; - return c !== 0 ? c : a.v.l.localeCompare(b.v.l); - } - ); + this._data.choices.sort(this._options.sort == "name" ? + function(a, b) { + return a.v.l.localeCompare(b.v.l); + } : + function(a, b) { + var c = b.c - a.c; + return c !== 0 ? c : a.v.l.localeCompare(b.v.l); + } + ); }; ListFacet.prototype._initializeUI = function() { - var self = this; - - var facet_id = this._div.attr("id"); - - this._div.empty().show().html( - '
' + - '
' + - '' + - '' + - '
 ' + - 'reset' + - 'invert' + - 'change' + - '' + - '
' + - '
' + - '
' + - '' + - '
' + - '
' + - '
' - ); - this._elmts = DOM.bind(this._div); - - this._elmts.titleSpan.text(this._config.name); - this._elmts.changeButton.attr("title","Current Expression: " + this._config.expression).click(function() { - self._elmts.expressionDiv.slideToggle(100, function() { - if (self._elmts.expressionDiv.css("display") != "none") { - self._editExpression(); - } - }); - }); - this._elmts.expressionDiv.text(this._config.expression).hide().click(function() { self._editExpression(); }); - this._elmts.removeButton.click(function() { self._remove(); }); - this._elmts.resetButton.click(function() { self._reset(); }); - this._elmts.invertButton.click(function() { self._invert(); }); + var self = this; - 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); - } + var facet_id = this._div.attr("id"); + + this._div.empty().show().html( + '
' + + '
' + + '' + + '' + + '
 ' + + 'reset' + + 'invert' + + 'change' + + '' + + '
' + + '
' + + '
' + + '' + + '
' + + '
' + + '
' + ); + this._elmts = DOM.bind(this._div); + + this._elmts.titleSpan.text(this._config.name); + this._elmts.changeButton.attr("title","Current Expression: " + this._config.expression).click(function() { + self._elmts.expressionDiv.slideToggle(100, function() { + if (self._elmts.expressionDiv.css("display") != "none") { + self._editExpression(); + } }); - this._elmts.sortByNameLink.click(function() { - if (self._options.sort != "name") { - self._options.sort = "name"; - self._reSortChoices(); - self._update(true); - } + }); + this._elmts.expressionDiv.text(this._config.expression).hide().click(function() { self._editExpression(); }); + this._elmts.removeButton.click(function() { self._remove(); }); + 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); + } + }); + this._elmts.sortByNameLink.click(function() { + if (self._options.sort != "name") { + self._options.sort = "name"; + self._reSortChoices(); + self._update(true); + } + }); + + 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 + } }); - - 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 - } - }); - } + } }; ListFacet.prototype._copyChoices = function() { - var self = this; - var frame = DialogSystem.createDialog(); - frame.width("600px"); - - var header = $('
').addClass("dialog-header").text("Facet Choices as Tab Separated Values").appendTo(frame); - var body = $('
').addClass("dialog-body").appendTo(frame); - var footer = $('
').addClass("dialog-footer").appendTo(frame); - - body.html('