2010-10-20 20:11:15 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 2010, Google Inc.
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are
|
|
|
|
met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
|
|
in the documentation and/or other materials provided with the
|
|
|
|
distribution.
|
|
|
|
* Neither the name of Google Inc. nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived from
|
|
|
|
this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2010-02-03 10:27:53 +01:00
|
|
|
function ExpressionPreviewDialog(title, cellIndex, rowIndices, values, expression, onDone) {
|
|
|
|
this._onDone = onDone;
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
var frame = DialogSystem.createDialog();
|
2010-02-07 10:02:22 +01:00
|
|
|
frame.width("700px");
|
2010-02-03 10:27:53 +01:00
|
|
|
|
|
|
|
var header = $('<div></div>').addClass("dialog-header").text(title).appendTo(frame);
|
|
|
|
var body = $('<div></div>').addClass("dialog-body").appendTo(frame);
|
|
|
|
var footer = $('<div></div>').addClass("dialog-footer").appendTo(frame);
|
2010-03-03 19:08:35 +01:00
|
|
|
var html = $(ExpressionPreviewDialog.generateWidgetHtml()).appendTo(body);
|
2010-02-03 10:27:53 +01:00
|
|
|
|
2010-02-23 01:33:39 +01:00
|
|
|
this._elmts = DOM.bind(html);
|
2010-02-03 10:27:53 +01:00
|
|
|
|
2018-11-21 18:30:00 +01:00
|
|
|
$('<button class="button"></button>').html($.i18n('core-buttons/ok')).click(function() {
|
2010-02-07 10:02:22 +01:00
|
|
|
DialogSystem.dismissUntil(self._level - 1);
|
2010-03-03 22:21:38 +01:00
|
|
|
self._onDone(self._previewWidget.getExpression(true));
|
2010-02-03 10:27:53 +01:00
|
|
|
}).appendTo(footer);
|
|
|
|
|
2018-11-21 18:30:00 +01:00
|
|
|
$('<button class="button"></button>').text($.i18n('core-buttons/cancel')).click(function() {
|
2010-02-07 10:02:22 +01:00
|
|
|
DialogSystem.dismissUntil(self._level - 1);
|
2010-02-03 10:27:53 +01:00
|
|
|
}).appendTo(footer);
|
2010-02-23 01:33:39 +01:00
|
|
|
|
|
|
|
this._level = DialogSystem.showDialog(frame);
|
2010-03-03 19:08:35 +01:00
|
|
|
this._previewWidget = new ExpressionPreviewDialog.Widget(
|
|
|
|
this._elmts,
|
|
|
|
cellIndex,
|
|
|
|
rowIndices,
|
|
|
|
values,
|
|
|
|
expression
|
|
|
|
);
|
2010-04-08 21:52:23 +02:00
|
|
|
}
|
2010-03-03 19:08:35 +01:00
|
|
|
|
|
|
|
ExpressionPreviewDialog.generateWidgetHtml = function() {
|
2010-06-21 23:59:53 +02:00
|
|
|
var html = DOM.loadHTML("core", "scripts/dialogs/expression-preview-dialog.html");
|
|
|
|
|
2010-06-15 00:11:34 +02:00
|
|
|
var languageOptions = [];
|
|
|
|
for (var prefix in theProject.scripting) {
|
|
|
|
if (theProject.scripting.hasOwnProperty(prefix)) {
|
|
|
|
var info = theProject.scripting[prefix];
|
|
|
|
languageOptions.push('<option value="' + prefix + '">' + info.name + '</option>');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-21 23:59:53 +02:00
|
|
|
return html.replace("$LANGUAGE_OPTIONS$", languageOptions.join(""));
|
2010-03-03 19:08:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
ExpressionPreviewDialog.Widget = function(
|
|
|
|
elmts,
|
|
|
|
cellIndex,
|
|
|
|
rowIndices,
|
|
|
|
values,
|
|
|
|
expression
|
|
|
|
) {
|
2010-10-07 07:19:35 +02:00
|
|
|
var language = "grel";
|
2010-05-27 03:13:11 +02:00
|
|
|
if (!(expression)) {
|
|
|
|
language = $.cookie("scripting.lang");
|
2010-10-07 07:19:35 +02:00
|
|
|
if (language == "gel") { // backward compatible
|
|
|
|
language = "grel";
|
|
|
|
}
|
|
|
|
|
2010-06-15 00:11:34 +02:00
|
|
|
if (!(language) || !(language.toLowerCase() in theProject.scripting)) {
|
2010-10-07 07:19:35 +02:00
|
|
|
language = "grel";
|
2010-05-27 03:13:11 +02:00
|
|
|
}
|
2010-06-15 00:11:34 +02:00
|
|
|
this.expression = theProject.scripting[language].defaultExpression;
|
2010-05-27 03:13:11 +02:00
|
|
|
} else {
|
|
|
|
this.expression = expression;
|
|
|
|
|
|
|
|
var colon = expression.indexOf(":");
|
|
|
|
if (colon > 0) {
|
|
|
|
var l = expression.substring(0, colon);
|
2010-06-15 00:11:34 +02:00
|
|
|
if (l.toLowerCase() in theProject.scripting) {
|
2010-05-27 03:13:11 +02:00
|
|
|
this.expression = expression.substring(colon + 1);
|
|
|
|
language = l;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-03 19:08:35 +01:00
|
|
|
this._elmts = elmts;
|
|
|
|
this._cellIndex = cellIndex;
|
|
|
|
this._rowIndices = rowIndices;
|
|
|
|
this._values = values;
|
|
|
|
|
|
|
|
this._results = null;
|
|
|
|
this._timerID = null;
|
|
|
|
|
2010-02-23 01:33:39 +01:00
|
|
|
$("#expression-preview-tabs").tabs();
|
2010-03-04 03:45:54 +01:00
|
|
|
|
|
|
|
this._elmts.expressionPreviewLanguageSelect[0].value = language;
|
2010-05-27 03:13:11 +02:00
|
|
|
this._elmts.expressionPreviewLanguageSelect.bind("change", function() {
|
|
|
|
$.cookie("scripting.lang", this.value);
|
|
|
|
self.update();
|
|
|
|
});
|
2010-02-23 01:33:39 +01:00
|
|
|
|
2010-03-03 19:08:35 +01:00
|
|
|
var self = this;
|
|
|
|
this._elmts.expressionPreviewTextarea
|
|
|
|
.attr("value", this.expression)
|
2013-06-23 19:37:29 +02:00
|
|
|
.bind("keyup change input",function(){
|
2010-03-03 19:08:35 +01:00
|
|
|
self._scheduleUpdate();
|
|
|
|
})
|
|
|
|
.select()
|
|
|
|
.focus();
|
2010-11-03 20:15:48 +01:00
|
|
|
|
|
|
|
this._tabContentWidth = this._elmts.expressionPreviewPreviewContainer.width() + "px";
|
2010-03-03 19:08:35 +01:00
|
|
|
|
2018-11-21 18:30:00 +01:00
|
|
|
this._elmts.or_dialog_expr.html($.i18n('core-dialogs/expression'));
|
|
|
|
this._elmts.or_dialog_lang.html($.i18n('core-dialogs/language'));
|
|
|
|
this._elmts.or_dialog_preview.html($.i18n('core-dialogs/preview'));
|
|
|
|
this._elmts.or_dialog_history.html($.i18n('core-dialogs/history'));
|
|
|
|
this._elmts.or_dialog_starred.html($.i18n('core-dialogs/starred'));
|
|
|
|
this._elmts.or_dialog_help.html($.i18n('core-dialogs/help'));
|
2013-07-04 11:51:04 +02:00
|
|
|
|
2010-03-04 03:25:42 +01:00
|
|
|
this.update();
|
2010-03-03 22:21:38 +01:00
|
|
|
this._renderExpressionHistoryTab();
|
2011-06-06 20:49:36 +02:00
|
|
|
this._renderStarredExpressionsTab();
|
2010-02-23 01:33:39 +01:00
|
|
|
this._renderHelpTab();
|
2010-02-07 10:02:22 +01:00
|
|
|
};
|
|
|
|
|
2010-03-03 22:21:38 +01:00
|
|
|
ExpressionPreviewDialog.Widget.prototype.getExpression = function(commit) {
|
|
|
|
var s = $.trim(this.expression || "");
|
2010-04-08 22:16:08 +02:00
|
|
|
if (!s.length) {
|
2010-03-03 22:21:38 +01:00
|
|
|
return null;
|
|
|
|
}
|
2010-03-04 03:45:54 +01:00
|
|
|
|
|
|
|
s = this._getLanguage() + ":" + s;
|
2010-03-03 22:21:38 +01:00
|
|
|
if (commit) {
|
|
|
|
$.post(
|
2014-11-11 11:41:55 +01:00
|
|
|
"command/core/log-expression?" + $.param({ project: theProject.id }),
|
|
|
|
{ expression: s },
|
2010-03-03 22:21:38 +01:00
|
|
|
function(data) {
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
};
|
|
|
|
|
2010-03-04 03:45:54 +01:00
|
|
|
ExpressionPreviewDialog.Widget.prototype._getLanguage = function() {
|
|
|
|
return this._elmts.expressionPreviewLanguageSelect[0].value;
|
2010-04-08 21:52:23 +02:00
|
|
|
};
|
2010-03-04 03:45:54 +01:00
|
|
|
|
2010-03-03 19:08:35 +01:00
|
|
|
ExpressionPreviewDialog.Widget.prototype._renderHelpTab = function() {
|
2010-02-07 10:02:22 +01:00
|
|
|
var self = this;
|
|
|
|
$.getJSON(
|
2012-10-13 19:47:08 +02:00
|
|
|
"command/core/get-expression-language-info",
|
2010-02-07 10:02:22 +01:00
|
|
|
null,
|
|
|
|
function(data) {
|
2010-02-23 01:33:39 +01:00
|
|
|
self._renderHelp(data);
|
2010-02-07 10:02:22 +01:00
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2010-03-03 19:08:35 +01:00
|
|
|
ExpressionPreviewDialog.Widget.prototype._renderHelp = function(data) {
|
2010-11-03 20:15:48 +01:00
|
|
|
var elmt = this._elmts.expressionPreviewHelpTabBody.empty().width(this._tabContentWidth);
|
2010-02-07 10:02:22 +01:00
|
|
|
|
2010-02-23 20:06:58 +01:00
|
|
|
$('<h3></h3>').text("Variables").appendTo(elmt);
|
2010-11-03 20:15:48 +01:00
|
|
|
var varTable = $('<table cellspacing="5"></table>').appendTo(elmt)[0];
|
2010-02-23 20:06:58 +01:00
|
|
|
var vars = [
|
|
|
|
{ name: "cell",
|
2018-11-21 18:30:00 +01:00
|
|
|
description: $.i18n('core-dialogs/cell-fields')
|
2010-02-23 20:06:58 +01:00
|
|
|
},
|
|
|
|
{ name: "value",
|
2018-11-21 18:30:00 +01:00
|
|
|
description: $.i18n('core-dialogs/cell-value')
|
2010-02-23 20:06:58 +01:00
|
|
|
},
|
|
|
|
{ name: "row",
|
2018-11-21 18:30:00 +01:00
|
|
|
description: $.i18n('core-dialogs/row-fields')
|
2010-02-23 20:06:58 +01:00
|
|
|
},
|
|
|
|
{ name: "cells",
|
2018-11-21 18:30:00 +01:00
|
|
|
description: $.i18n('core-dialogs/cells-of-row')
|
2010-02-23 20:06:58 +01:00
|
|
|
},
|
|
|
|
{ name: "rowIndex",
|
2018-11-21 18:30:00 +01:00
|
|
|
description: $.i18n('core-dialogs/row-index')
|
2019-07-20 21:52:21 +02:00
|
|
|
},
|
|
|
|
{ name: "record",
|
|
|
|
description: $.i18n('core-dialogs/record-fields')
|
2010-02-23 20:06:58 +01:00
|
|
|
}
|
|
|
|
];
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2010-02-23 02:40:06 +01:00
|
|
|
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);
|
|
|
|
|
2010-02-23 20:06:58 +01:00
|
|
|
$(tr0.insertCell(0)).addClass("expression-preview-doc-item-title").text(name);
|
|
|
|
$(tr0.insertCell(1)).addClass("expression-preview-doc-item-params").text("(" + entry.params + ")");
|
2010-02-23 02:40:06 +01:00
|
|
|
|
|
|
|
$(tr1.insertCell(0));
|
2018-11-21 18:30:00 +01:00
|
|
|
$(tr1.insertCell(1)).addClass("expression-preview-doc-item-returns").text($.i18n('core-dialogs/returns')+": " + entry.returns);
|
2010-02-23 02:40:06 +01:00
|
|
|
|
|
|
|
$(tr2.insertCell(0));
|
2010-02-23 20:06:58 +01:00
|
|
|
$(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]);
|
|
|
|
}
|
2010-02-23 02:40:06 +01:00
|
|
|
};
|
2010-02-07 10:02:22 +01:00
|
|
|
|
2010-02-23 02:40:06 +01:00
|
|
|
$('<h3></h3>').text("Functions").appendTo(elmt);
|
2010-02-23 20:06:58 +01:00
|
|
|
var functionTable = $('<table width="100%" cellspacing="5"></table>').appendTo(elmt)[0];
|
|
|
|
renderEntries(functionTable, data.functions);
|
2010-02-07 10:02:22 +01:00
|
|
|
|
|
|
|
$('<h3></h3>').text("Controls").appendTo(elmt);
|
2010-02-23 20:06:58 +01:00
|
|
|
var controlTable = $('<table width="100%" cellspacing="5"></table>').appendTo(elmt)[0];
|
|
|
|
renderEntries(controlTable, data.controls);
|
2010-02-07 10:02:22 +01:00
|
|
|
};
|
|
|
|
|
2010-03-03 22:21:38 +01:00
|
|
|
ExpressionPreviewDialog.Widget.prototype._renderExpressionHistoryTab = function() {
|
|
|
|
var self = this;
|
|
|
|
$.getJSON(
|
2012-10-13 19:47:08 +02:00
|
|
|
"command/core/get-expression-history?" + $.param({ project: theProject.id }),
|
2010-03-03 22:21:38 +01:00
|
|
|
null,
|
|
|
|
function(data) {
|
|
|
|
self._renderExpressionHistory(data);
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
ExpressionPreviewDialog.Widget.prototype._renderExpressionHistory = function(data) {
|
|
|
|
var self = this;
|
2010-11-03 20:15:48 +01:00
|
|
|
var elmt = this._elmts.expressionPreviewHistoryContainer.empty().width(this._tabContentWidth);
|
2010-03-03 22:21:38 +01:00
|
|
|
|
|
|
|
var table = $(
|
2010-11-03 20:15:48 +01:00
|
|
|
'<table>' +
|
2018-11-21 18:30:00 +01:00
|
|
|
'<tr><th></th><th></th><th>'+$.i18n('core-dialogs/from')+'</th><th colspan="2">'+$.i18n('core-dialogs/expression')+'</th><th></th></tr>' +
|
2011-06-06 20:49:36 +02:00
|
|
|
'</table>'
|
|
|
|
).appendTo($('<div>').addClass("expression-preview-table-wrapper").appendTo(elmt))[0];
|
|
|
|
|
|
|
|
var renderEntry = function(self,tr,entry) {
|
|
|
|
$(tr).empty();
|
|
|
|
var o = Scripting.parse(entry.code);
|
|
|
|
$('<a href="javascript:{}"> </a>')
|
|
|
|
.addClass(entry.starred ? "data-table-star-on" : "data-table-star-off")
|
|
|
|
.appendTo(tr.insertCell(0))
|
|
|
|
.click(function() {
|
|
|
|
$.post(
|
2012-10-13 19:47:08 +02:00
|
|
|
"command/core/toggle-starred-expression",
|
2011-06-06 20:49:36 +02:00
|
|
|
{ expression: entry.code },
|
|
|
|
function(data) {
|
|
|
|
entry.starred = !entry.starred;
|
|
|
|
renderEntry(self,tr,entry);
|
|
|
|
self._renderStarredExpressionsTab();
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-11-21 18:30:00 +01:00
|
|
|
$('<a href="javascript:{}">'+$.i18n('core-dialogs/reuse')+'</a>').appendTo(tr.insertCell(1)).click(function() {
|
2011-06-06 20:49:36 +02:00
|
|
|
self._elmts.expressionPreviewTextarea[0].value = o.expression;
|
|
|
|
self._elmts.expressionPreviewLanguageSelect[0].value = o.language;
|
|
|
|
|
|
|
|
$("#expression-preview-tabs").tabs('option', 'selected', 0);
|
|
|
|
|
|
|
|
self._elmts.expressionPreviewTextarea.select().focus();
|
|
|
|
|
|
|
|
self.update();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$(tr.insertCell(2)).html(entry.global ? "Other projects" : "This project");
|
|
|
|
$(tr.insertCell(3)).text(o.language + ":");
|
|
|
|
$(tr.insertCell(4)).text(o.expression);
|
|
|
|
};
|
|
|
|
|
|
|
|
for (var i = 0; i < data.expressions.length; i++) {
|
|
|
|
var tr = table.insertRow(table.rows.length);
|
|
|
|
var entry = data.expressions[i];
|
|
|
|
renderEntry(self,tr,entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
ExpressionPreviewDialog.Widget.prototype._renderStarredExpressionsTab = function() {
|
|
|
|
var self = this;
|
|
|
|
$.getJSON(
|
2012-10-13 19:47:08 +02:00
|
|
|
"command/core/get-starred-expressions",
|
2011-06-06 20:49:36 +02:00
|
|
|
null,
|
|
|
|
function(data) {
|
|
|
|
self._renderStarredExpressions(data);
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
ExpressionPreviewDialog.Widget.prototype._renderStarredExpressions = function(data) {
|
|
|
|
var self = this;
|
|
|
|
var elmt = this._elmts.expressionPreviewStarredContainer.empty().width(this._tabContentWidth);
|
|
|
|
|
|
|
|
var table = $(
|
|
|
|
'<table>' +
|
2018-11-21 18:30:00 +01:00
|
|
|
'<tr><th></th><th></th><th colspan="2">'+$.i18n('core-dialogs/expression')+'</th><th></th></tr>' +
|
2010-03-03 22:21:38 +01:00
|
|
|
'</table>'
|
2010-11-03 20:15:48 +01:00
|
|
|
).appendTo($('<div>').addClass("expression-preview-table-wrapper").appendTo(elmt))[0];
|
2010-03-03 22:21:38 +01:00
|
|
|
|
|
|
|
var renderEntry = function(entry) {
|
|
|
|
var tr = table.insertRow(table.rows.length);
|
2010-03-04 08:18:23 +01:00
|
|
|
var o = Scripting.parse(entry.code);
|
2010-03-03 22:21:38 +01:00
|
|
|
|
2018-11-21 18:30:00 +01:00
|
|
|
$('<a href="javascript:{}">'+$.i18n('core-dialogs/remove')+'</a>').appendTo(tr.insertCell(0)).click(function() {
|
2011-06-06 20:49:36 +02:00
|
|
|
$.post(
|
2012-10-13 19:47:08 +02:00
|
|
|
"command/core/toggle-starred-expression",
|
2011-06-06 20:49:36 +02:00
|
|
|
{ expression: entry.code, returnList: true },
|
|
|
|
function(data) {
|
|
|
|
self._renderStarredExpressions(data);
|
|
|
|
self._renderExpressionHistoryTab();
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
$('<a href="javascript:{}">Reuse</a>').appendTo(tr.insertCell(1)).click(function() {
|
2010-03-04 08:18:23 +01:00
|
|
|
self._elmts.expressionPreviewTextarea[0].value = o.expression;
|
|
|
|
self._elmts.expressionPreviewLanguageSelect[0].value = o.language;
|
|
|
|
|
|
|
|
$("#expression-preview-tabs").tabs('option', 'selected', 0);
|
|
|
|
|
2010-03-03 22:21:38 +01:00
|
|
|
self._elmts.expressionPreviewTextarea.select().focus();
|
2010-03-04 08:18:23 +01:00
|
|
|
|
2010-03-04 03:25:42 +01:00
|
|
|
self.update();
|
2010-03-03 22:21:38 +01:00
|
|
|
});
|
2010-03-16 19:11:08 +01:00
|
|
|
|
2010-05-27 03:13:11 +02:00
|
|
|
$(tr.insertCell(2)).text(o.language + ":");
|
|
|
|
$(tr.insertCell(3)).text(o.expression);
|
2010-03-03 22:21:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
for (var i = 0; i < data.expressions.length; i++) {
|
|
|
|
var entry = data.expressions[i];
|
|
|
|
renderEntry(entry);
|
|
|
|
}
|
2011-10-08 01:44:11 +02:00
|
|
|
};
|
|
|
|
|
2010-03-03 19:08:35 +01:00
|
|
|
ExpressionPreviewDialog.Widget.prototype._scheduleUpdate = function() {
|
2010-04-09 03:00:44 +02:00
|
|
|
if (this._timerID !== null) {
|
2010-02-03 10:27:53 +01:00
|
|
|
window.clearTimeout(this._timerID);
|
|
|
|
}
|
|
|
|
var self = this;
|
2010-03-04 03:25:42 +01:00
|
|
|
this._timerID = window.setTimeout(function() { self.update(); }, 300);
|
2010-02-03 10:27:53 +01:00
|
|
|
};
|
|
|
|
|
2010-03-04 03:25:42 +01:00
|
|
|
ExpressionPreviewDialog.Widget.prototype.update = function() {
|
2010-02-03 10:27:53 +01:00
|
|
|
var self = this;
|
2010-03-03 19:08:35 +01:00
|
|
|
var expression = this.expression = $.trim(this._elmts.expressionPreviewTextarea[0].value);
|
2010-03-04 03:25:42 +01:00
|
|
|
var params = {
|
|
|
|
project: theProject.id,
|
|
|
|
cellIndex: this._cellIndex
|
|
|
|
};
|
|
|
|
this._prepareUpdate(params);
|
2010-02-03 10:27:53 +01:00
|
|
|
|
|
|
|
$.post(
|
2012-10-13 19:47:08 +02:00
|
|
|
"command/core/preview-expression?" + $.param(params),
|
2010-02-03 10:27:53 +01:00
|
|
|
{
|
2014-11-11 11:41:55 +01:00
|
|
|
expression: this._getLanguage() + ":" + expression,
|
2010-02-03 10:27:53 +01:00
|
|
|
rowIndices: JSON.stringify(this._rowIndices)
|
|
|
|
},
|
|
|
|
function(data) {
|
|
|
|
if (data.code != "error") {
|
|
|
|
self._results = data.results;
|
|
|
|
} else {
|
|
|
|
self._results = null;
|
|
|
|
}
|
2010-02-27 06:48:33 +01:00
|
|
|
self._renderPreview(expression, data);
|
2010-02-03 10:27:53 +01:00
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2010-03-04 03:25:42 +01:00
|
|
|
ExpressionPreviewDialog.Widget.prototype._prepareUpdate = function(params) {
|
|
|
|
};
|
|
|
|
|
2010-03-03 19:08:35 +01:00
|
|
|
ExpressionPreviewDialog.Widget.prototype._renderPreview = function(expression, data) {
|
2010-11-03 20:15:48 +01:00
|
|
|
var container = this._elmts.expressionPreviewPreviewContainer.empty().width(this._tabContentWidth);
|
|
|
|
|
|
|
|
var table = $('<table></table>').appendTo(
|
|
|
|
$('<div>').addClass("expression-preview-table-wrapper").appendTo(container))[0];
|
2010-02-07 04:36:40 +01:00
|
|
|
|
2014-11-11 11:41:55 +01:00
|
|
|
var truncExpression = expression.length > 30 ? expression.substring(0, 30) + ' ...' : expression;
|
|
|
|
|
2010-02-03 10:27:53 +01:00
|
|
|
var tr = table.insertRow(0);
|
2010-02-07 04:36:40 +01:00
|
|
|
$(tr.insertCell(0)).addClass("expression-preview-heading").text("row");
|
|
|
|
$(tr.insertCell(1)).addClass("expression-preview-heading").text("value");
|
2014-11-11 11:41:55 +01:00
|
|
|
$(tr.insertCell(2)).addClass("expression-preview-heading").text(truncExpression);
|
2010-02-07 04:36:40 +01:00
|
|
|
|
|
|
|
var renderValue = function(td, v) {
|
2010-02-07 10:02:22 +01:00
|
|
|
if (v !== null && v !== undefined) {
|
2010-04-06 07:35:48 +02:00
|
|
|
if ($.isPlainObject(v)) {
|
2018-11-21 18:30:00 +01:00
|
|
|
$('<span></span>').addClass("expression-preview-special-value").text($.i18n('core-dialogs/error')+": " + v.message).appendTo(td);
|
2010-02-07 10:02:22 +01:00
|
|
|
} else {
|
2010-04-06 07:35:48 +02:00
|
|
|
td.text(v);
|
2010-02-07 10:02:22 +01:00
|
|
|
}
|
2010-02-07 04:36:40 +01:00
|
|
|
} else {
|
2010-03-01 01:21:13 +01:00
|
|
|
$('<span>null</span>').addClass("expression-preview-special-value").appendTo(td);
|
2010-02-07 04:36:40 +01:00
|
|
|
}
|
|
|
|
};
|
2010-02-03 10:27:53 +01:00
|
|
|
|
2010-04-09 03:00:44 +02:00
|
|
|
if (this._results !== null) {
|
2018-11-21 18:30:00 +01:00
|
|
|
this._elmts.expressionPreviewParsingStatus.empty().removeClass("error").text($.i18n('core-dialogs/no-syntax-err')+".");
|
2010-03-03 19:08:35 +01:00
|
|
|
} else {
|
2018-11-21 18:30:00 +01:00
|
|
|
var message = (data.type == "parser") ? data.message : $.i18n('core-dialogs/internal-err');
|
2010-10-25 19:27:38 +02:00
|
|
|
this._elmts.expressionPreviewParsingStatus.empty().addClass("error").text(message);
|
2010-03-03 19:08:35 +01:00
|
|
|
}
|
|
|
|
|
2010-02-03 10:27:53 +01:00
|
|
|
for (var i = 0; i < this._values.length; i++) {
|
|
|
|
var tr = table.insertRow(table.rows.length);
|
|
|
|
|
2010-02-07 04:36:40 +01:00
|
|
|
$(tr.insertCell(0)).attr("width", "1%").html((this._rowIndices[i] + 1) + ".");
|
|
|
|
|
2010-07-26 23:12:40 +02:00
|
|
|
renderValue($(tr.insertCell(1)).addClass("expression-preview-value"), this._values[i]);
|
2010-02-07 04:36:40 +01:00
|
|
|
|
2010-07-26 23:12:40 +02:00
|
|
|
var tdValue = $(tr.insertCell(2)).addClass("expression-preview-value");
|
2010-04-09 03:00:44 +02:00
|
|
|
if (this._results !== null) {
|
2010-02-03 10:27:53 +01:00
|
|
|
var v = this._results[i];
|
2010-02-07 04:36:40 +01:00
|
|
|
renderValue(tdValue, v);
|
2010-02-03 10:27:53 +01:00
|
|
|
}
|
|
|
|
}
|
2014-01-26 12:01:39 +01:00
|
|
|
};
|