function loadAdminPage() {
topFunction();
var html = '
';
html += ``;
html += '
';
html += '';
html += '
';
html += '';
html += '';
document.getElementById("setup").innerHTML = html;
getTimezones();
}
function set_wrapperr_settings_call() {
var wrapperr_root_original = wrapperr_root;
document.getElementById("set_wrapperr_settings_form_button").disabled = true;
document.getElementById("set_wrapperr_settings_form_button").style.opacity = '0.5';
wrapped_start = new Date(document.getElementById('wrapped_start').value);
wrapped_end = new Date(document.getElementById('wrapped_end').value);
use_cache = document.getElementById('use_cache').checked;
use_logs = document.getElementById('use_logs').checked;
plex_auth = document.getElementById('plex_auth').checked;
basic_auth = document.getElementById('basic_auth').checked;
wrapperr_root = document.getElementById('wrapperr_root').value;
application_name_str = document.getElementById('application_name_str').value;
application_url_str = document.getElementById('application_url_str').value;
create_share_links = document.getElementById('create_share_links').checked;
timezone = document.getElementById('timezone').value;
clear_cache = document.getElementById('clear_cache').checked;
winter_theme = document.getElementById('winter_theme').checked;
if(wrapperr_root_original !== wrapperr_root) {
if(!confirm("You have changed the Wrapperr root/base URL. Wrapperr will attempt to restart and the interface to access this webpage will change. If you are using an URL base you must use a trailing '/' at the end of your new URL.")){
return;
}
}
if(wrapperr_root !== "") {
var wrapperr_root_last_char = wrapperr_root.charAt(wrapperr_root.length-1);
var wrapperr_root_first_char = wrapperr_root.charAt(0);
if(wrapperr_root_last_char == "/" || wrapperr_root_first_char == "/") {
document.getElementById("set_wrapperr_settings_form_button").disabled = false;
document.getElementById("set_wrapperr_settings_form_button").style.opacity = '1';
alert("No trailing or initial '/' needed for URL base.");
document.getElementById('wrapperr_root').focus();
return;
}
}
if(timezone === '') {
document.getElementById("set_wrapperr_settings_form_button").disabled = false;
document.getElementById("set_wrapperr_settings_form_button").style.opacity = '1';
alert('Timezone is required for Wrapperr to function.');
document.getElementById('timezone').focus();
return;
}
if(wrapped_end < wrapped_start) {
document.getElementById("set_wrapperr_settings_form_button").disabled = false;
document.getElementById("set_wrapperr_settings_form_button").style.opacity = '1';
alert('The wrapped end period must be later than the wrapped start period.');
document.getElementById('wrapped_end').focus();
return;
}
if(wrapped_end === '') {
document.getElementById("set_wrapperr_settings_form_button").disabled = false;
document.getElementById("set_wrapperr_settings_form_button").style.opacity = '1';
alert('Ending of wrapped period is required for Wrapperr to function.');
document.getElementById('wrapped_end').focus();
return;
}
if(wrapped_start === '') {
document.getElementById("set_wrapperr_settings_form_button").disabled = false;
document.getElementById("set_wrapperr_settings_form_button").style.opacity = '1';
alert('Start of wrapped period is required for Wrapperr to function.');
document.getElementById('wrapped_start').focus();
return;
}
wrapperr_settings_form = {
"clear_cache" : clear_cache,
"data_type" : "wrapperr_data",
"tautulli_config" : [],
"wrapperr_customize" : {},
"wrapperr_data" : {
"use_cache" : use_cache,
"use_logs" : use_logs,
"plex_auth" : plex_auth,
"basic_auth" : basic_auth,
"wrapperr_root" : wrapperr_root,
"create_share_links" : create_share_links,
"timezone" : timezone,
"application_name" : application_name_str,
"application_url" : application_url_str,
"wrapped_start" : Math.round(wrapped_start.getTime() / 1000),
"wrapped_end" : Math.round(wrapped_end.getTime() / 1000),
"winter_theme" : winter_theme
}
};
var wrapperr_settings_data = JSON.stringify(wrapperr_settings_form);
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
try {
var result= JSON.parse(this.responseText);
} catch(error) {
alert('Failed to parse API response.');
console.log('Failed to parse API response. Response: ' + this.responseText);
document.getElementById("set_wrapperr_settings_form_button").disabled = false;
document.getElementById("set_wrapperr_settings_form_button").style.opacity = '1';
return;
}
if(result.error) {
alert(result.error);
document.getElementById("set_wrapperr_settings_form_button").disabled = false;
document.getElementById("set_wrapperr_settings_form_button").style.opacity = '1';
} else {
AdminPageRedirect();
}
}
};
xhttp.withCredentials = true;
xhttp.open("post", api_url + "set/config");
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.setRequestHeader("Authorization", cookie);
xhttp.send(wrapperr_settings_data);
return;
}
function getTimezones() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
try {
var result= JSON.parse(this.responseText);
} catch(error) {
alert('Failed to parse API response.');
console.log('Failed to parse API response. Response: ' + this.responseText);
return;
}
if(result.error) {
alert(result.error);
} else {
placeTimezones(result.data);
}
}
};
xhttp.withCredentials = true;
xhttp.open("post", api_url + "get/timezones");
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.setRequestHeader("Authorization", cookie);
xhttp.send();
return;
}
function placeTimezones(timezoneArray) {
dataList = document.getElementById("timezones");
timezoneArray.forEach(function(item){
var option = document.createElement('option');
option.value = item;
option.name = item;
dataList.appendChild(option);
});
}