').text("Loading...").addClass("facet-body-message").appendTo(bodyDiv);
bodyDiv.appendTo(container);
} else if ("error" in this._data) {
$('
').text(this._data.error).addClass("facet-body-message").appendTo(bodyDiv);
bodyDiv.appendTo(container);
} else {
var selectionCount = this._selection.length
+ (this._blankChoice !== null && this._blankChoice.s ? 1 : 0)
+ (this._errorChoice !== null && this._errorChoice.s ? 1 : 0);
if (selectionCount > 0) {
var reset = function() {
self._reset();
};
removeButton.after(
$('
').addClass("facet-choice-link").text("reset").click(reset)
);
}
var renderEdit = this._config.expression == "value";
var renderChoice = function(choice, customLabel) {
var label = customLabel || choice.v.l;
var count = choice.c;
var choiceDiv = $('
').addClass("facet-choice").appendTo(bodyDiv);
if (choice.s) {
choiceDiv.addClass("facet-choice-selected");
}
var a = $('
').addClass("facet-choice-label").text(label).appendTo(choiceDiv);
$('
').addClass("facet-choice-count").text(count).appendTo(choiceDiv);
var select = function() {
self._select(choice, false);
};
var selectOnly = function() {
self._select(choice, true);
};
var deselect = function() {
self._deselect(choice);
};
if (choice.s) { // selected
if (selectionCount > 1) {
// select only
a.click(selectOnly);
} else {
// deselect
a.click(deselect);
}
// remove link
$('
').addClass("facet-choice-link").text("remove").click(deselect).prependTo(choiceDiv);
} else if (selectionCount > 0) {
a.click(selectOnly);
// include link
$('
').addClass("facet-choice-link").text("include").click(select).prependTo(choiceDiv);
} else {
a.click(select);
}
if (renderEdit && customLabel === undefined) {
// edit link
var editLink = $('
').addClass("facet-choice-edit").text("edit").click(function() {
self._editChoice(choice, choiceDiv);
}).appendTo(choiceDiv);
choiceDiv
.mouseenter(function() {
editLink.css("visibility", "visible");
})
.mouseleave(function() {
editLink.css("visibility", "hidden");
});
}
};
var choices = this._data.choices;
for (var i = 0; i < choices.length; i++) {
renderChoice(choices[i]);
}
if (this._blankChoice !== null) {
renderChoice(this._blankChoice, "(blank)");
}
if (this._errorChoice !== null) {
renderChoice(this._errorChoice, "(error)");
}
bodyDiv.appendTo(container);
bodyDiv[0].scrollTop = scrollTop;
var footerDiv = $('
').addClass("facet-footer").appendTo(container);
$('
').text(choices.length + " choices: ").appendTo(footerDiv);
if (this._options.sort == "name") {
$('').addClass("action").text("re-sort by count").click(function() {
self._options.sort = "count";
self._reSortChoices();
self.render();
}).appendTo(footerDiv);
} else {
$('').addClass("action").text("re-sort by name").click(function() {
self._options.sort = "name";
self._reSortChoices();
self.render();
}).appendTo(footerDiv);
}
if (this._config.expression == "value") {
$('').html(" • ").appendTo(footerDiv);
$('').addClass("action").text("cluster").click(function() {
self._doEdit();
}).appendTo(footerDiv);
}
}
};
ListFacet.prototype._doEdit = function() {
new ClusteringDialog(this._config.columnName, this._config.expression);
};
ListFacet.prototype._editChoice = function(choice, choiceDiv) {
var self = this;
var menu = MenuSystem.createMenu().addClass("data-table-cell-editor").width("400px");
menu.html(
'' +
'' +
'' +
'' +
' | ' +
'
' +
'' +
'' +
' ' +
'Enter' +
' | ' +
'' +
' ' +
'Esc' +
' | ' +
'' +
' | ' +
'
' +
'
'
);
var elmts = DOM.bind(menu);
MenuSystem.showMenu(menu, function(){});
MenuSystem.positionMenuLeftRight(menu, choiceDiv);
var originalContent = choice.v.v;
var commit = function() {
var text = elmts.textarea[0].value;
MenuSystem.dismissAll();
Gridworks.postProcess(
"mass-edit",
{},
{
columnName: self._config.columnName,
expression: "value",
edits: JSON.stringify([{
from: [ originalContent ],
to: text
}])
},
{
includeEngine: false, // we're really changing all rows, not just the visible ones
cellsChanged: true
},
{
onDone: function(o) {
var selection = [];
var gotSelection = false;
for (var i = 0; i < self._selection.length; i++) {
var choice = self._selection[i];
if (choice.v.v == originalContent) {
if (gotSelection) {
continue;
}
choice.v.v = text;
gotSelection = true; // eliminate duplicated selections due to changing one selected choice to another
}
selection.push(choice);
}
self._selection = selection;
}
}
);
};
elmts.okButton.click(commit);
elmts.textarea
.text(originalContent)
.keydown(function(evt) {
if (!evt.shiftKey) {
if (evt.keyCode == 13) {
commit();
} else if (evt.keyCode == 27) {
MenuSystem.dismissAll();
}
}
})
.select()
.focus();
elmts.cancelButton.click(function() {
MenuSystem.dismissAll();
});
};
ListFacet.prototype._select = function(choice, only) {
if (only) {
this._selection = [];
if (this._blankChoice !== null) {
this._blankChoice.s = false;
}
if (this._errorChoice !== null) {
this._errorChoice.s = false;
}
}
choice.s = true;
if (choice !== this._errorChoice && choice !== this._blankChoice) {
this._selection.push(choice);
}
this._updateRest();
};
ListFacet.prototype._deselect = function(choice) {
if (choice === this._errorChoice || choice === this._blankChoice) {
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;
}
}
}
this._updateRest();
};
ListFacet.prototype._reset = function() {
this._selection = [];
this._blankChoice = null;
this._errorChoice = null;
this._updateRest();
};
ListFacet.prototype._remove = function() {
ui.browsingEngine.removeFacet(this);
this._div = null;
this._config = null;
this._selection = null;
this._blankChoice = null;
this._errorChoice = null;
this._data = null;
};
ListFacet.prototype._updateRest = function() {
Gridworks.update({ engineChanged: true });
};