function FacetBasedEditDialog(columnName, expression, entries) { this._columnName = columnName; this._expression = expression; this._entries = entries; this._createDialog(); this._cluster(); } FacetBasedEditDialog.prototype._createDialog = function() { var self = this; var frame = DialogSystem.createDialog(); frame.width("800px"); var header = $('
').addClass("dialog-header").text("Facet-based edit of column " + this._columnName).appendTo(frame); var body = $('
').addClass("dialog-body").appendTo(frame); var footer = $('
').addClass("dialog-footer").appendTo(frame); var html = $( '
' + '
' + '
' + ' ' + ' ' + '
' + '
' ).appendTo(body); this._elmts = DOM.bind(html); this._elmts.clusterButton.click(function() { self._cluster(); }); this._elmts.unclusterButton.click(function() { self._uncluster(); }); $('').text("OK").click(function() { self._onOK(); }).appendTo(footer); $('').text("Cancel").click(function() { self._dismiss(); }).appendTo(footer); this._level = DialogSystem.showDialog(frame); $("#recon-dialog-tabs").tabs(); $("#recon-dialog-tabs-strict").css("display", ""); }; FacetBasedEditDialog.prototype._renderTable = function() { var self = this; var container = this._elmts.tableContainer.empty(); var table = $('
').addClass("facet-based-edit-dialog-entry-table").appendTo(container)[0]; var trHead = table.insertRow(table.rows.length); trHead.className = "header"; $(trHead.insertCell(0)).text("Current facet choices"); $(trHead.insertCell(1)).text("Edit?"); $(trHead.insertCell(2)).text("New cell value"); var renderCluster = function(cluster) { var tr = table.insertRow(table.rows.length); tr.className = table.rows.length % 2 == 0 ? "odd" : "even"; var ul = $(tr.insertCell(0)); var choices = cluster.choices; for (var c = 0; c < choices.length; c++) { var choice = choices[c]; var li = $('
  • ').appendTo(ul); $('').text(choice.v.l).appendTo(li); $('').text(" (" + choice.c + ")").appendTo(li); } var editCheck = $('') .appendTo(tr.insertCell(1)) .click(function() { cluster.edit = !cluster.edit; }); if (cluster.edit) { editCheck.attr("checked", "true"); } var input = $('') .attr("value", cluster.value) .appendTo(tr.insertCell(2)) .keyup(function() { cluster.value = this.value; }); }; for (var i = 0; i < this._clusters.length; i++) { renderCluster(this._clusters[i]); } }; FacetBasedEditDialog.prototype._cluster = function() { var clusters = []; var map = {}; $.each(this._entries, function() { var choice = { v: this.v, c: this.c }; var s = this.v.l.toLowerCase().replace(/\W/g, ' ').replace(/\s+/g, ' ').split(" ").sort().join(" "); if (s in map) { map[s].choices.push(choice); } else { map[s] = { edit: false, choices: [ choice ] }; clusters.push(map[s]); } }); $.each(clusters, function() { if (this.choices.length > 1) { this.choices.sort(function(a, b) { var c = b.c - a.c; return c != 0 ? c : a.v.l.localeCompare(b.v.l); }); this.edit = true; } this.value = this.choices[0].v.l; }); clusters.sort(function(a, b) { var c = b.choices.length - a.choices.length; return c != 0 ? c : a.value.localeCompare(b.value); }); this._clusters = clusters; this._renderTable(); }; FacetBasedEditDialog.prototype._uncluster = function() { var clusters = []; $.each(this._entries, function() { var cluster = { edit: false, choices: [{ v: this.v, c: this.c }], value: this.v.l }; clusters.push(cluster); }); this._clusters = clusters; this._renderTable(); }; FacetBasedEditDialog.prototype._onOK = function() { var edits = []; for (var i = 0; i < this._clusters.length; i++) { var cluster = this._clusters[i]; if (cluster.edit) { var values = []; for (var j = 0; j < cluster.choices.length; j++) { values.push(cluster.choices[j].v.v); } edits.push({ from: values, to: cluster.value }); } } if (edits.length > 0) { Gridworks.postProcess( "facet-based-edit", {}, { columnName: this._columnName, expression: this._expression, edits: JSON.stringify(edits) }, { cellsChanged: true } ); this._dismiss(); } else { alert("You must check some Edit? checkboxes for your edits to be applied."); } }; FacetBasedEditDialog.prototype._dismiss = function() { DialogSystem.dismissUntil(this._level - 1); };