var detail;
var membranes;
var methods;
var url_prefix = window.location.protocol + "//" + window.location.host;
/**
* Creates new message span
*
* @param {string} message - Message text
* @param {string} type - success/warning/danger
*/
function add_message(message, type="success")
{
var valid_types = ['success', 'warning', 'danger'];
// Checks valid message type
if(!valid_types.includes(type))
{
console.log('Wrong message type.');
return;
}
var target = $("#alert-column");
var res = '
';
$(target).append(res);
}
/**
* Ajax request function
* Sends request to given uri
*
* @param {string} uri
* @param {object} params
* @param {string} method - GET/POST only
*/
function ajax_request(uri, params, method = "GET", required_content_type = "json")
{
method = method.toUpperCase();
var valid_methods = ['GET', 'POST'];
switch(required_content_type.toLowerCase())
{
case 'html':
accept = 'text/html';
break;
default:
accept = 'application/json';
}
if(!valid_methods.includes(method))
{
console.log('Wrong method type for ajax request.');
return false;
}
// Make uri
uri = url_prefix + "/api/" + uri;
uri = uri.replace(/\&+$/, '');
var result;
// Send request
$.ajax({
url: uri,
contentType: 'application/json',
type: method,
headers:{
"Authorization": "Basic " + $('#api_internal_token').val(),
Accept: accept
},
async: false,
data: params,
success: function(data)
{
if(data)
{
result = data;
}
else
{
result = null;
}
},
error: function(data)
{
add_message("Error ("+ data.status + ") ocurred during ajax request.", "danger");
console.log(data);
result = false;
}
});
return result;
}
var show_overlay;
var hide_overlay;
var set_overlay_text;
/**** SET FULLSCREEN OVERLAY ****/
$(document).ready(function()
{
var overlay = $('#fs-overlay');
var overlay_text = $('#fs-overlay-text');
/**
* Displays overlay
*/
show_overlay = async function()
{
$(overlay).show();
await sleep(10);
}
/**
* Hides overlay
*/
hide_overlay = async function()
{
$(overlay_text).html('');
$(overlay).hide();
await sleep(10);
}
/**
* Set overlay text
*
* @param {string} text
*/
set_overlay_text = async function(text)
{
text = text.trim();
$(overlay_text).html(text);
// Set position to the middle
var width = $(overlay_text).width();
var parent = $(overlay_text).parent();
var margin = (width/2) * -1;
$(parent).css('margin-left', margin);
await sleep(10);
}
})
/**
* Appends html content to the given parent
* + init all