CameraTrigger/ts/api.ts

71 lines
2.4 KiB
TypeScript

/*
* SPDX-FileCopyrightText: 2023 Sascha Nitsch (@grumpydevelop@contentnation.net) https://contentnation.net/en/grumpydevelop
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
/// <reference path="cameratrigger.ts" />
class Api {
/**
* ajax get call
* @param {string} path url path to call
* @param {object} parameter parameters to pass to api call
* @param {object} context optional parameter for setting the context the success and error function will be called
* @param {function} success optional success callback function
* @param {function} error optional error callback function
*/
static get(path: string, parameter, context, success, error) {
jQuery.ajax({
url : "api" + (path[0] != '/' ? '/' : '') + path,
dataType : 'json',
type : "GET",
data : parameter,
success : success,
error : error,
context : context
});
};
/**
* brief ajax post call api
* @param {string} path url path to call
* @param {object} parameter parameters to pass to api call
* @param {object} context optional parameter for setting the context the success and error function will be called
* @param {function} success optional success callback function
* @param {function} error optional error callback function
*/
static post(path: string, parameter, context, success, error) {
jQuery.ajax({
url : "api" + (path[0] != '/' ? '/' : '') + path,
dataType : 'json',
type : "POST",
data : parameter,
processData: !(parameter instanceof FormData),
success : success,
error : error,
context : context,
contentType: parameter instanceof FormData ? false : "application/x-www-form-urlencoded; charset=UTF-8"
});
};
/**
* brief ajax del call api
* @param {string} path url path to call
* @param {object} parameter parameters to pass to api call
* @param {object} context optional parameter for setting the context the success and error function will be called
* @param {function} success optional success callback function
* @param {function} error optional error callback function
*/
static del(path: string, context, success, error) {
jQuery.ajax({
url : "api" + (path[0] != '/' ? '/' : '') + path,
dataType : 'json',
type : "DELETE",
success : success,
error : error,
context : context
});
};
}