Skip to content
Snippets Groups Projects
Commit 6a2cd4e9 authored by Sven Kästle's avatar Sven Kästle
Browse files

refactor: Move annotation REST requests to seperate file

parent bf6ee4bc
No related branches found
No related tags found
No related merge requests found
/**
* POST: Save an annotation in the database
*
* @param annotationPostRequest The post request
* @param responseHandler The response handler
*/
function createAnnotation(annotationPostRequest, responseHandler) {
var url = "../rest/annotations/";
var json = JSON.stringify(annotationPostRequest);
$.ajax({
url: url,
type: "POST",
data: json,
contentType: "application/json",
dataType: "json",
success: function (response) {
responseHandler(response);
}
});
}
/**
* PATCH: Alter an annotation in database
*
* @param id The annotation id
* @param annotationPatchRequest The patch request
* @param responseHandler The response handler
*/
function alterAnnotation(id, annotationPatchRequest, responseHandler) {
var url = "../rest/annotations/" + id;
var json = JSON.stringify(annotationPatchRequest);
$.ajax({
url: url,
type: "PATCH",
data: json,
contentType: "application/json",
dataType: "json",
success: function (response) {
responseHandler(response);
}
});
}
/**
* DELETE: Delete an annotation from database
*
* @param id The annotation id
*/
function deleteAnnotation(id, responseHandler) {
var url = "../rest/annotations/" + id;
$.ajax({
url: url,
type: "DELETE",
dataType: "json",
success: function (response) {
responseHandler(response)
}
});
}
/**
* GET: Get all annotations from database for a specific target
*
*
* @param targetId The target id
* @param responseHandler The response handler
*/
function getAnnotations(targetId, responseHandler) {
var url = "../rest/annotations/target/" + targetId;
$.ajax({
url: url,
type: "GET",
dataType: "json",
success: function (response) {
// sort the responding annotations by timestamp (DESC)
response.sort(function (a, b) {
return a.timestamp - b.timestamp;
});
// handle the response
responseHandler(response);
}
});
}
\ No newline at end of file
......@@ -12,7 +12,8 @@ var documentText, startCharacter, endCharacter;
*/
$(document).ready(function() {
connect("200");
// connect to websocket on page ready
connect(targetId);
/**
* Context menu handler
......@@ -217,90 +218,6 @@ $( window ).resize(function() {
showAndHideToggleButton();
});
/**
* POST: Save an annotation in the database
*
* @param annotationPostRequest The post request
* @param responseHandler The response handler
*/
function createAnnotation(annotationPostRequest, responseHandler) {
var url = "../rest/annotations/";
var json = JSON.stringify(annotationPostRequest);
$.ajax({
url: url,
type: "POST",
data: json,
contentType: "application/json",
dataType: "json",
success: function (response) {
responseHandler(response);
}
});
}
/**
* PATCH: Alter an annotation in database
*
* @param id The annotation id
* @param annotationPatchRequest The patch request
* @param responseHandler The response handler
*/
function alterAnnotation(id, annotationPatchRequest, responseHandler) {
var url = "../rest/annotations/" + id;
var json = JSON.stringify(annotationPatchRequest);
$.ajax({
url: url,
type: "PATCH",
data: json,
contentType: "application/json",
dataType: "json",
success: function (response) {
responseHandler(response);
}
});
}
/**
* DELETE: Delete an annotation from database
*
* @param id The annotation id
*/
function deleteAnnotation(id, responseHandler) {
var url = "../rest/annotations/" + id;
$.ajax({
url: url,
type: "DELETE",
dataType: "json",
success: function (response) {
responseHandler(response)
}
});
}
/**
* GET: Get all annotations from database for a specific target
*
*
* @param targetId The target id
* @param responseHandler The response handler
*/
function getAnnotations(targetId, responseHandler) {
var url = "../rest/annotations/target/" + targetId;
$.ajax({
url: url,
type: "GET",
dataType: "json",
success: function (response) {
// sort the responding annotations by timestamp (DESC)
response.sort(function (a, b) {
return a.timestamp - b.timestamp;
});
// handle the response
responseHandler(response);
}
});
}
/**
* Display annotation in the list
*
......
......@@ -36,6 +36,8 @@
<script src="../assets/js/utility.js"></script>
<!-- js - annotation websocket script -->
<script src="../assets/js/annotationWebsocket.js"></script>
<!-- js - annotation REST script -->
<script src="../assets/js/annotationRest.js"></script>
<!-- js - annotationScript -->
<script src="../assets/js/annotationScript.js"></script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment