function ListFacet(div, config, options, selection) { this._div = div; this._config = config; this._options = options || {}; if (!("sort" in this._options)) { this._options.sort = "name"; } this._selection = selection || []; this._blankChoice = null; this._errorChoice = null; this._data = null; this.render(); } ListFacet.reconstruct = function(div, uiState) { return new ListFacet(div, uiState.c, uiState.o, uiState.s); }; ListFacet.prototype.reset = function() { 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; } 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 } for (var i = 0; i < this._selection.length; i++) { var choice = { v: cloneDeep(this._selection[i].v) }; 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); }; 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.render(); }; 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) { return b.c - a.c; } ); }; ListFacet.prototype.render = function() { var self = this; var scrollTop = 0; try { scrollTop = this._div[0].childNodes[1].scrollTop; } catch (e) { } var container = this._div.empty(); var headerDiv = $('
').addClass("facet-title").appendTo(container); $('').text(this._config.name).appendTo(headerDiv); var removeButton = $('') .attr("src", "images/close.png") .attr("title", "Remove this facet") .addClass("facet-choice-link") .click(function() { self._remove(); }).prependTo(headerDiv); var bodyDiv = $('').addClass("facet-body"); if (!("scroll" in this._options) || this._options.scroll) { bodyDiv.addClass("facet-body-scrollable"); } if (this._data == null) { $('' + '' + ' | ' + '||
' +
' ' + 'Enter' + ' | ' +
'' +
' ' + 'Esc' + ' | ' +
'' + ' | ' + '