Added custom dialog box for create column operation (with a field for the new column name).

git-svn-id: http://google-refine.googlecode.com/svn/trunk@180 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-03-04 00:12:39 +00:00
parent 2fe8f98e4e
commit 5a0a8bea4f
2 changed files with 65 additions and 21 deletions

View File

@ -136,7 +136,7 @@ public class ColumnAdditionOperation extends EngineDependentOperation {
ExpressionUtils.bind(bindings, row, rowIndex, cell); ExpressionUtils.bind(bindings, row, rowIndex, cell);
Object v = eval.evaluate(bindings); Object v = eval.evaluate(bindings);
if (v != null) { if (ExpressionUtils.isNonBlankData(v)) {
Cell newCell = new Cell(v, null); Cell newCell = new Cell(v, null);
cellsAtRows.add(new CellAtRow(rowIndex, newCell)); cellsAtRows.add(new CellAtRow(rowIndex, newCell));

View File

@ -605,27 +605,71 @@ DataTableColumnHeaderUI.prototype._doSearchToMatch = function() {
DataTableColumnHeaderUI.prototype._doAddColumn = function(initialExpression) { DataTableColumnHeaderUI.prototype._doAddColumn = function(initialExpression) {
var self = this; var self = this;
DataTableView.promptExpressionOnVisibleRows( var frame = DialogSystem.createDialog();
this._column, frame.width("700px");
"Add Column Based on Column " + this._column.headerLabel,
initialExpression, var header = $('<div></div>').addClass("dialog-header").text("Add Column Based on Column " + this._column.headerLabel).appendTo(frame);
function(expression) { var body = $('<div></div>').addClass("dialog-body").appendTo(frame);
var headerLabel = window.prompt("Enter header label for new column:"); var footer = $('<div></div>').addClass("dialog-footer").appendTo(frame);
if (headerLabel != null) {
Gridworks.postProcess( body.html(
"add-column", '<table class="expression-preview-layout" cols="2">' +
{ '<tr>' +
baseColumnName: self._column.headerLabel, '<td width="1%" style="white-space: pre;">' +
expression: expression, 'New column name' +
headerLabel: headerLabel, '</td>' +
columnInsertIndex: self._columnIndex + 1 '<td>' +
}, '<input bind="columnNameInput" size="40" />' +
null, '</td>' +
{ modelsChanged: true } '</tr>' +
); '<tr>' +
} '<td colspan="2">' + ExpressionPreviewDialog.generateWidgetHtml() + '</td>' +
} '</tr>' +
'</table>'
); );
var bodyElmts = DOM.bind(body);
footer.html(
'<button bind="okButton">&nbsp;&nbsp;OK&nbsp;&nbsp;</button>' +
'<button bind="cancelButton">Cancel</button>'
);
var footerElmts = DOM.bind(footer);
var level = DialogSystem.showDialog(frame);
var dismiss = function() {
DialogSystem.dismissUntil(level - 1);
};
footerElmts.okButton.click(function() {
var columnName = $.trim(bodyElmts.columnNameInput[0].value);
if (columnName.length == 0) {
alert("You must enter a column name.");
return;
}
Gridworks.postProcess(
"add-column",
{
baseColumnName: self._column.headerLabel,
expression: previewWidget.getExpression(true),
headerLabel: columnName,
columnInsertIndex: self._columnIndex + 1
},
null,
{ modelsChanged: true }
);
dismiss();
})
footerElmts.cancelButton.click(dismiss);
var o = DataTableView.sampleVisibleRows(this._column);
var previewWidget = new ExpressionPreviewDialog.Widget(
bodyElmts,
this._column.cellIndex,
o.rowIndices,
o.values,
"value"
);
}; };
DataTableColumnHeaderUI.prototype._doRemoveColumn = function() { DataTableColumnHeaderUI.prototype._doRemoveColumn = function() {