jellyfin-smart-playlist/Jellyfin.Plugin.SmartPlaylist/Pages/lispPlayground.js

46 lines
1.5 KiB
JavaScript

function fillForm(o) {
const output = document.querySelector('#LispPlaygroundOutput');
const return_ = document.querySelector('#LispPlaygroundReturn');
output.value = (o.hasOwnProperty("Output")) ? o.Output : o.Traceback;
return_.value = (o.hasOwnProperty("FinalExpression")) ? o.FinalExpression : '';
}
ApiClient.runLispProgram = function (program) {
const url = ApiClient.getUrl('LispPlayground');
return this.ajax({
type: 'POST',
url: url,
dataType: 'json',
contentType: 'text/plain; charset=UTF-8',
data: program,
});
}
function initial_load() {
Dashboard.showLoadingMsg();
Dashboard.hideLoadingMsg();
}
export default function (view, params) {
view.addEventListener('viewshow', function() {
initial_load(null);
});
view.addEventListener('viewhide', function (_e) {});
view.addEventListener('viewdestroy', function (_e) {});
document.querySelector('#LispPlaygroundConfigPage')
.addEventListener('pageshow', function() {
initial_load();
});
document.querySelector('#LispPlaygroundConfigForm')
.addEventListener('submit', function (e) {
e.preventDefault();
Dashboard.showLoadingMsg();
const editProgram = document.querySelector('#LispPlaygroundEditProgram');
ApiClient.runLispProgram(editProgram.value).then(function (r) {
fillForm(r);
Dashboard.hideLoadingMsg();
});
});
}