Skip to content
Snippets Groups Projects
Commit 1745dce7 authored by eeonaaah's avatar eeonaaah
Browse files

Merge branch 'javascript-comments' into 'staging'

JavaScript comments

See merge request !56
parents ec546845 e28cdbd5
No related branches found
No related tags found
2 merge requests!57Staging,!56JavaScript comments
Pipeline #5225 passed
......@@ -12,7 +12,7 @@ async function createTable() {
// Removes the old table so only up-to-date data will be shown
if (oldTable) {
div.removeChild(old_table);
div.removeChild(oldTable);
}
// Creates a new table
......@@ -40,7 +40,11 @@ async function createTable() {
}
}
/** Creates the heading row based on suggestion keys */
/**
* Creates the heading row based on suggestion keys
* @param {*} content
* @return {*} heading row
*/
function createHeadingRow(content) {
const tr = document.createElement('tr');
......@@ -54,7 +58,11 @@ function createHeadingRow(content) {
return tr;
}
/** Creates the heading row based on suggestion values */
/**
* Creates the heading row based on suggestion values
* @param {*} content
* @return {*} content row
*/
function createContentRow(content) {
const id = content['id'];
const tr = document.createElement('tr');
......@@ -96,9 +104,11 @@ function createContentRow(content) {
return tr;
}
/** Changes the child text node
/**
* Changes the child text node
* to an input field with the value set to the original text.
* Registers a 'focusout' event listener to change the field back to text node.
* @param {*} parent
*/
function activateEditMode(parent) {
// If already editing, return
......@@ -125,8 +135,11 @@ function activateEditMode(parent) {
input.focus();
}
/** Removes the input element and sets the parent's text content
* to match the input field's valu
/**
* Removes the input element and sets the parent's text content
* to match the input field's value
* @param {*} input
* @param {*} parent
*/
function deactivateEditMode(input, parent) {
const text = input.value;
......@@ -134,8 +147,10 @@ function deactivateEditMode(input, parent) {
parent.textContent = text;
}
/** Packages the edited entity data into an object
/**
* Packages the edited entity data into an object
* and calls to create a put request to update the data
* @param {*} tr
*/
async function saveContent(tr) {
const entity = {};
......@@ -158,16 +173,20 @@ async function saveContent(tr) {
createTable();
}
/** Packages the entity data into an object
/**
* Packages the entity data into an object
* and calls to create a delete request
* @param {*} tr
*/
async function deleteContent(tr) {
const entity = {};
// Iterates through every cell on the row,
// and appends the data to the entity object
// with the key parsed from the element's id attribute
// and value from the cell's text content
/*
Iterates through every cell on the row,
and appends the data to the entity object
with the key parsed from the element's id attribute
and value from the cell's text content
*/
for (const node of tr.childNodes) {
const idString = node.id;
if (!node.id) continue;
......
......@@ -27,6 +27,8 @@ const GreenIcon = L.Icon.extend({
/**
* Adds a green marker to mark a place for a possible suggestion.
* @param {*} map
* @param {*} latlng
*/
function addSuggestionMarker(map, latlng) {
if (!selectionMarker) {
......@@ -59,6 +61,7 @@ function openSuggestionPopup() {
/**
* Creates a form that can be used to submit suggestions
* from inside the popup.
* @return {*} suggestion form
*/
function createSuggestionForm() {
const form = document.createElement('form');
......@@ -116,6 +119,7 @@ function createSuggestionForm() {
* Creates a link with an image
* @param {string} link page to redirect
* @param {string} image button icon
* @return {*} shareButton
*/
function createShareButton(link, image) {
const shareButton = document.createElement('a');
......@@ -129,6 +133,9 @@ function createShareButton(link, image) {
* Submits the suggested location to server. Updates popup content
* depending on the result. Saves a new marker if addition successful.
* @param {*} name
* @param {*} person
* @param {*} keeper
* @param {*} email
*/
async function submitSuggestion(name, person, keeper, email) {
// Get location data from the selection markers current position
......@@ -155,8 +162,6 @@ async function submitSuggestion(name, person, keeper, email) {
setTimeout(() => {
addedMarker.closePopup();
// Other information to frontend?
popup.setContent(updatePopupName(suggestion.name));
}, 2000);
} catch (error) {
......@@ -168,7 +173,10 @@ async function submitSuggestion(name, person, keeper, email) {
/**
* Saves a new suggestion. This function is called after the server
* responds with a success
* @param {string} name
* @param {*} lat latitude
* @param {*} lng longitude
* @param {*} suggestion name
* @return {*} added marker
*/
function saveSuggestion(lat, lng, suggestion) {
console.log(suggestion);
......@@ -187,14 +195,22 @@ function saveSuggestion(lat, lng, suggestion) {
return addedMarker;
}
/** Updates popup */
/**
* Updates popup
* @param {*} text
* @return {*} created popup
*/
function updatePopupContent(text) {
const p = document.createElement('p');
p.textContent = text;
return p;
}
/** Updates popup */
/**
* Updates popup
* @param {*} text
* @return {*} created popup
*/
function updatePopupName(text) {
const div = document.createElement('div');
const item = document.createElement('h2');
......@@ -224,7 +240,7 @@ async function initializeMarkers() {
const lat = suggestion.lat;
const lng = suggestion.lng;
const marker = addMarker(lat, lng);
const popup = L.popup().setContent(updatePopupContent(suggestion.name));
const popup = L.popup().setContent(updatePopupName(suggestion.name));
marker.bindPopup(popup);
});
} catch (e) {
......@@ -232,7 +248,12 @@ async function initializeMarkers() {
}
}
/** Adds a marker to the map */
/**
* Adds a marker to the map
* @param {*} lat
* @param {*} lng
* @return {*} marker
*/
function addMarker(lat, lng) {
const marker = L.marker({lat, lng}).addTo(map);
return marker;
......
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