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

50 lines
1.7 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 (inputLinks, program) {
const url = ApiClient.getUrl('LispPlayground');
return this.ajax({
type: 'POST',
url: url,
dataType: 'json',
contentType: 'application/json; charset=UTF-8',
data: JSON.stringify({
InputLinks: inputLinks,
Program: 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 editInputLinks = document.querySelector('#LispPlaygroundInputLinks');
const editProgram = document.querySelector('#LispPlaygroundEditProgram');
ApiClient.runLispProgram(editInputLinks.value, editProgram.value).then(function (r) {
fillForm(r);
Dashboard.hideLoadingMsg();
});
});
}