';
};
ExpressionPreviewDialog.Widget = function(
elmts,
cellIndex,
rowIndices,
values,
expression
) {
this._elmts = elmts;
this._cellIndex = cellIndex;
this._rowIndices = rowIndices;
this._values = values;
this.expression = expression;
this._results = null;
this._timerID = null;
$("#expression-preview-tabs").tabs();
$("#expression-preview-tabs-history").css("display", "");
$("#expression-preview-tabs-help").css("display", "");
var language = "gel";
var colon = expression.indexOf(":");
if (colon > 0) {
var l = expression.substring(0, colon);
if (l == "gel" || l == "jython" || l == "clojure") {
expression = expression.substring(colon + 1);
language = l;
}
}
this._elmts.expressionPreviewLanguageSelect[0].value = language;
this._elmts.expressionPreviewLanguageSelect.bind("change", function() { self.update(); });
var self = this;
this._elmts.expressionPreviewTextarea
.attr("value", this.expression)
.keyup(function(){
self._scheduleUpdate();
})
.select()
.focus();
this.update();
this._renderExpressionHistoryTab();
this._renderHelpTab();
};
ExpressionPreviewDialog.Widget.prototype.getExpression = function(commit) {
var s = $.trim(this.expression || "");
if (s.length == 0) {
return null;
}
s = this._getLanguage() + ":" + s;
if (commit) {
$.post(
"/command/log-expression?" + $.param({ project: theProject.id, expression: s }),
null,
function(data) {
},
"json"
);
}
return s;
};
ExpressionPreviewDialog.Widget.prototype._getLanguage = function() {
return this._elmts.expressionPreviewLanguageSelect[0].value;
}
ExpressionPreviewDialog.Widget.prototype._renderHelpTab = function() {
var self = this;
$.getJSON(
"/command/get-expression-language-info",
null,
function(data) {
self._renderHelp(data);
},
"json"
);
};
ExpressionPreviewDialog.Widget.prototype._renderHelp = function(data) {
var elmt = this._elmts.expressionPreviewHelpTabBody.empty();
$('').text("Variables").appendTo(elmt);
var varTable = $('
').appendTo(elmt)[0];
var vars = [
{ name: "cell",
description: "The current cell. It has a few fields: 'value' and 'recon'."
},
{ name: "value",
description: "The current cell's value. This is a shortcut for 'cell.value'."
},
{ name: "row",
description: "The current row. It has 4 fields: 'flagged', 'starred', 'index', and 'cells'."
},
{ name: "cells",
description: "The cells of the current row. This is a shortcut for 'row.cells'. " +
"A particular cell can be retrieved with 'cells.' if the is a single word, " +
"or with 'cells[\"\"] otherwise."
},
{ name: "rowIndex",
description: "The current row's index. This is a shortcut for 'row.index'."
}
];
for (var i = 0; i < vars.length; i++) {
var variable = vars[i];
var tr = varTable.insertRow(varTable.rows.length);
$(tr.insertCell(0)).addClass("expression-preview-doc-item-title").text(variable.name);
$(tr.insertCell(1)).addClass("expression-preview-doc-item-desc").text(variable.description);
}
var renderEntry = function(table, name, entry) {
var tr0 = table.insertRow(table.rows.length);
var tr1 = table.insertRow(table.rows.length);
var tr2 = table.insertRow(table.rows.length);
$(tr0.insertCell(0)).addClass("expression-preview-doc-item-title").text(name);
$(tr0.insertCell(1)).addClass("expression-preview-doc-item-params").text("(" + entry.params + ")");
$(tr1.insertCell(0));
$(tr1.insertCell(1)).addClass("expression-preview-doc-item-returns").text("returns: " + entry.returns);
$(tr2.insertCell(0));
$(tr2.insertCell(1)).addClass("expression-preview-doc-item-desc").text(entry.description);
};
var renderEntries = function(table, map) {
var names = [];
for (var n in map) {
if (map.hasOwnProperty(n)) {
names.push(n);
}
}
names.sort();
for (var i = 0; i < names.length; i++) {
var name = names[i];
renderEntry(table, name, map[name]);
}
};
$('').text("Functions").appendTo(elmt);
var functionTable = $('
').appendTo(elmt)[0];
renderEntries(functionTable, data.functions);
$('').text("Controls").appendTo(elmt);
var controlTable = $('