31 lines
810 B
JavaScript
31 lines
810 B
JavaScript
function toggle_outlet(svg) {
|
|
let sub_dev = get_object_from_svg(svg).parentElement;
|
|
let params = {
|
|
device_id: sub_dev.parentElement.parentElement.id,
|
|
sub_dev_id: sub_dev.id
|
|
};
|
|
let query = Object.keys(params)
|
|
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(params[k]))
|
|
.join('&');
|
|
fetch(window.location.href + 'toggle?' + query)
|
|
.then(function(response) {
|
|
if (!response.ok) {
|
|
throw new Error('HTTP error, status = ' + response.status);
|
|
}
|
|
return response.json();
|
|
})
|
|
.then(function(json) {
|
|
console.log(json);
|
|
});
|
|
}
|
|
|
|
function get_object_from_svg(svg) {
|
|
var all_objects = document.getElementsByTagName("object");
|
|
for (var i=0; i < all_objects.length; i++) {
|
|
if (svg === all_objects[i].getSVGDocument().firstElementChild) {
|
|
return all_objects[i];
|
|
}
|
|
}
|
|
return null;
|
|
}
|