268 lines
6.8 KiB
JavaScript
268 lines
6.8 KiB
JavaScript
function show_error(api_error){
|
|
alert("Fehler "+api_error.error.code+" aufgetreten: "+api_error.error.description);
|
|
}
|
|
|
|
function is_ok(data){
|
|
if(data == null){
|
|
return true;
|
|
}else if(typeof data !== 'object') {
|
|
return true;
|
|
}else{
|
|
if('error' in data){
|
|
show_error(data);
|
|
return false;
|
|
}else{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
function check_for_permission(callback, permission, entity_id){
|
|
let optional_entity = "";
|
|
if(entity_id){
|
|
optional_entity = "&entity_id="+entity_id;
|
|
}
|
|
|
|
$.ajax({
|
|
type: "GET",
|
|
url: "/api/info/caller/permissions?permission="+permission+optional_entity,
|
|
contentType: 'application/json',
|
|
timeout: 3000,
|
|
error: function () {
|
|
alert("Verbindung zum Server unterbrochen!");
|
|
},
|
|
success: function (data) {
|
|
if(is_ok(data)) {
|
|
callback(data);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
async function check_for_permission_async(permission, entity_id){
|
|
let optional_entity = "";
|
|
if(entity_id){
|
|
optional_entity = "&entity_id="+entity_id;
|
|
}
|
|
|
|
const res = $.ajax({
|
|
type: "GET",
|
|
url: "/api/info/caller/permissions?permission="+permission+optional_entity,
|
|
contentType: 'application/json',
|
|
timeout: 3000,
|
|
error: function () {
|
|
alert("Verbindung zum Server unterbrochen!");
|
|
},
|
|
});
|
|
if(is_ok(res)) {
|
|
return res;
|
|
}
|
|
}
|
|
|
|
let get_member = async function (entity_id){
|
|
const res = await $.ajax({
|
|
type: "GET",
|
|
url: "/api/members/" + entity_id,
|
|
contentType: 'application/json',
|
|
timeout: 3000,
|
|
error: function () {
|
|
alert("Verbindung zum Server unterbrochen!");
|
|
},
|
|
});
|
|
if (is_ok(res)) {
|
|
return res;
|
|
}
|
|
};
|
|
|
|
let get_vehicle = async function (entity_id){
|
|
const res = await $.ajax({
|
|
type: "GET",
|
|
url: "/api/resources/vehicles/" + entity_id,
|
|
contentType: 'application/json',
|
|
timeout: 3000,
|
|
error: function () {
|
|
alert("Verbindung zum Server unterbrochen!");
|
|
},
|
|
});
|
|
if (is_ok(res)) {
|
|
return res;
|
|
}
|
|
};
|
|
let load_positions_for_instance = async function(instance_id){
|
|
const res = await $.ajax({
|
|
url: '/api/events/instances/'+instance_id+'/positions',
|
|
type: 'GET',
|
|
contentType: 'application/json',
|
|
timeout: 3000,
|
|
error: function () {
|
|
alert("Verbindung zum Server unterbrochen!");
|
|
}
|
|
});
|
|
if (is_ok(res)) {
|
|
return res;
|
|
}
|
|
};
|
|
let load_vehicle_positions_for_instance = async function(instance_id){
|
|
const res = await $.ajax({
|
|
url: '/api/events/instances/'+instance_id+'/vehicle_positions',
|
|
type: 'GET',
|
|
contentType: 'application/json',
|
|
timeout: 3000,
|
|
error: function () {
|
|
alert("Verbindung zum Server unterbrochen!");
|
|
}
|
|
});
|
|
if (is_ok(res)) {
|
|
return res;
|
|
}
|
|
};
|
|
let remove_instance = function(){
|
|
let caller = this;
|
|
let instance = $(caller).closest(".instance");
|
|
let instance_id = instance.data("instance-id");
|
|
|
|
$.ajax({
|
|
url: '/api/events/instances/'+instance_id,
|
|
type: 'DELETE',
|
|
contentType: 'application/json',
|
|
success: function (data) {
|
|
if (is_ok(data)) {
|
|
instance.remove();
|
|
}
|
|
},
|
|
timeout: 3000,
|
|
error: function () {
|
|
alert("Es ist ein Fehler aufgetreten!");
|
|
}
|
|
});
|
|
}
|
|
let add_entity_to_position = function(instance, position, entity){
|
|
$.ajax({
|
|
url: '/api/events/instances/'+instance+'/positions/'+position+'/entities/'+entity,
|
|
type: 'PUT',
|
|
contentType: 'application/json',
|
|
success: function (data) {
|
|
if (is_ok(data)) {
|
|
}
|
|
},
|
|
timeout: 3000,
|
|
error: function () {
|
|
alert("Es ist ein Fehler aufgetreten!");
|
|
}
|
|
});
|
|
};
|
|
let remove_entity_from_position = function(instance, position){
|
|
$.ajax({
|
|
url: '/api/events/instances/'+instance+'/positions/'+position+'/entities/',
|
|
type: 'DELETE',
|
|
contentType: 'application/json',
|
|
success: function (data) {
|
|
if (is_ok(data)) {
|
|
}
|
|
},
|
|
timeout: 3000,
|
|
error: function () {
|
|
alert("Es ist ein Fehler aufgetreten!");
|
|
}
|
|
});
|
|
};
|
|
|
|
|
|
let get_organiser = async function(entity_id){
|
|
const res = await $.ajax({
|
|
type: "GET",
|
|
url: "/api/event_organisers/" + entity_id,
|
|
contentType: 'application/json',
|
|
timeout: 3000,
|
|
error: function () {
|
|
alert("Verbindung zum Server unterbrochen!");
|
|
},
|
|
});
|
|
if (is_ok(res)) {
|
|
return res;
|
|
}
|
|
};
|
|
|
|
let load_event_types = function(callback){
|
|
$.ajax({
|
|
url: '/api/events/types',
|
|
type: 'GET',
|
|
contentType: 'application/json',
|
|
success: function (data) {
|
|
if (is_ok(data)) {
|
|
callback(data);
|
|
}
|
|
},
|
|
timeout: 3000,
|
|
error: function () {
|
|
alert("Verbindung zum Server unterbrochen!");
|
|
}
|
|
});
|
|
};
|
|
let load_groups = function(callback){
|
|
$.ajax({
|
|
url: '/api/groups',
|
|
type: 'GET',
|
|
contentType: 'application/json',
|
|
success: function (data) {
|
|
if (is_ok(data)) {
|
|
callback(data);
|
|
}
|
|
|
|
},
|
|
timeout: 3000,
|
|
error: function () {
|
|
alert("Verbindung zum Server unterbrochen!");
|
|
}
|
|
});
|
|
};
|
|
let load_event_types_async = async function(){
|
|
const res = await $.ajax({
|
|
url: '/api/events/types',
|
|
type: 'GET',
|
|
contentType: 'application/json',
|
|
timeout: 3000,
|
|
error: function () {
|
|
alert("Verbindung zum Server unterbrochen!");
|
|
}
|
|
});
|
|
if (is_ok(res)) {
|
|
return res;
|
|
}
|
|
};
|
|
let load_groups_async = async function(){
|
|
const res = await $.ajax({
|
|
url: '/api/groups',
|
|
type: 'GET',
|
|
contentType: 'application/json',
|
|
timeout: 3000,
|
|
error: function () {
|
|
alert("Verbindung zum Server unterbrochen!");
|
|
}
|
|
});
|
|
if (is_ok(res)) {
|
|
return res.groups;
|
|
}
|
|
};
|
|
let check_position_requirements = async function(position_id, member_id){
|
|
const res = await $.ajax({
|
|
url: '/api/events/units/positions/'+position_id+'/check_requirements?target_to_check='+member_id,
|
|
type: 'GET',
|
|
contentType: 'application/json',
|
|
timeout: 3000,
|
|
error: function () {
|
|
alert("Es ist ein Fehler aufgetreten!");
|
|
}
|
|
});
|
|
if (is_ok(res)) {
|
|
return res.requirements_fulfilled;
|
|
}
|
|
};
|
|
|
|
$(document).ajaxStart(function() {
|
|
$(".loading_animation").show();
|
|
});
|
|
|
|
$(document).ajaxStop(function() {
|
|
$(".loading_animation").hide();
|
|
}); |