diff --git a/myServer.js b/myServer.js index 5626cb348f..c93dabaa84 100644 --- a/myServer.js +++ b/myServer.js @@ -14,6 +14,7 @@ const session = require("express-session"); const methodOverride = require("method-override"); const matrix = require("./src/oi/matrix"); const db = require("./src/oi/sqliteDb"); +const svg = require("./src/oi/DrawSvg"); const app = express(); const http = express(); @@ -100,25 +101,7 @@ app.get("/getIdeas", checkAuthenticated, async function (req, res) { //get svgs app.get("/svgTest", async function (req, res) { let ideaData = await db.getIdea(req.query.IdeaID, true); - var SVG = ` - - - #${ideaData.ID} - #${ideaData.ID} - #${ideaData.ID} - ${ideaData.title} - ${ideaData.title} - ${ideaData.title} - - `; + let SVG = svg.draw(ideaData); res.type("svg"); res.send(SVG); }); diff --git a/src/oi/DrawIdeas.js b/src/oi/DrawIdeas.js index 5d3107fc04..aec72a8398 100644 --- a/src/oi/DrawIdeas.js +++ b/src/oi/DrawIdeas.js @@ -1,6 +1,17 @@ +/** + * @fileOverview this file provides functions to generate, filter and display ideas as entities + * @name DrawIdeas.js + * @author Jannis Dohm + * @license MIT + */ import { Entity } from './../og/entity/Entity.js'; import { Vector } from './../og/layer/Vector.js'; +/** + * function to create and display entities representing the ideas on the globe + * @param {Object} pointLayer - created entities will be added to this layer + * @param {string[]} [filter] - placeholder + */ function draw(pointLayer, filter) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { @@ -26,6 +37,13 @@ function draw(pointLayer, filter) { } export{ draw } +/** + * function to filter ideas, an empty filter will result in the display of all ideas. + * adding strings (tags) to the filter array will reduce the displayed ideas to these + * matching one of the strings. + * @param {Object} pointLayer - containing the idea entities to be filtered + * @param {string[]} filter - array of strings which contain the filter keywords. + */ function filterIdeas(pointLayer, filter) { //if filter is set check filter if(filter !== null && filter.length !== 0) { diff --git a/src/oi/DrawSvg.js b/src/oi/DrawSvg.js index 977d594924..514a53c90d 100644 --- a/src/oi/DrawSvg.js +++ b/src/oi/DrawSvg.js @@ -1,48 +1,38 @@ - -function draw(id){ - var doc = document.implementation.createDocument("", "", null); - - var svg = doc.createElement("svg"); - svg.setAttribute("xmlns", "http://www.w3.org/2000/svg"); - svg.setAttribute("xmlns:sodipodi", "http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"); - svg.setAttribute("xmlns:inkscape", "http://www.inkscape.org/namespaces/inkscape"); - svg.setAttribute("width", "150"); - svg.setAttribute("height", "150"); - svg.setAttribute("viewBox", "0 0 150 150"); - svg.setAttribute("version", "1.1"); - - var newRect = document.createElementNS("http://www.w3.org/2000/svg", "rect"); - newRect.setAttributeNS(null,"width", "150"); - newRect.setAttributeNS(null,"height", "150"); - newRect.setAttributeNS(null,"fill", "#FFFFFF"); - svg.appendChild(newRect); - - setID(svg,id); - - svg.appendChild(setText({x:25, y:100, fill:'#000000', transform:'rotate(-90, 25,100)'}, "test")); - svg.appendChild(setText({x:75, y:100, fill:'#000000', transform:'rotate(-90, 75,100)'}, "test")); - svg.appendChild(setText({x:125, y:100, fill:'#000000', transform:'rotate(-90, 125,100)'}, "test")); - - // return svg; - return testSVG; +/** + * @fileOverview this file provides a svg which can be used as a texture for the idea entities + * @name DrawSvg.js + * @author Jannis Dohm + * @license MIT + */ + +/** + * function to create and return svg + * @param {Object} ideaData + * @param {number} ideaData.ID - number of idea + * @param {string} ideaData.title - title of idea + */ +function draw(ideaData){ + var SVG = ` + + + #${ideaData.ID} + #${ideaData.ID} + #${ideaData.ID} + ${ideaData.title} + ${ideaData.title} + ${ideaData.title} + + `; + return SVG; } -export {draw} - - - -function setID(svg, id) { - svg.appendChild(setText({x:0, y:50, fill:'#000000'}, "#"+id)); - svg.appendChild(setText({x:50, y:50, fill:'#000000'}, "#"+id)); - svg.appendChild(setText({x:100, y:50, fill:'#000000'}, "#"+id)); -} - -var svgNS = "http://www.w3.org/2000/svg"; -function setText(v, t) { - let elem = document.createElementNS("http://www.w3.org/2000/svg", 'text'); - for (var p in v) - elem.setAttributeNS(null, p, v[p]); - elem.textContent = t; - return elem; -} - -var testSVG = ` ` +module.exports = { + draw, +}; diff --git a/src/oi/SideIdea.js b/src/oi/SideIdea.js index 1f9484faab..e7eb320002 100644 --- a/src/oi/SideIdea.js +++ b/src/oi/SideIdea.js @@ -1,51 +1,70 @@ +/** + * @fileOverview this file provides functions to create new ideas + * @name SideIdea.js + * @author Jannis Dohm + * @license MIT + */ 'use strict'; -var tagsArray = []; -var skillsArray = []; - -function save(lon, lat){ - if(!document.forms.idea_form.nameText.checkValidity()) { - document.getElementById("nameText").className += " invalid"; - return; - } - if(!document.forms.idea_form.ideaText.checkValidity()) { - document.getElementById("ideaText").className += " invalid"; - return; +let tagsArray = []; +let skillsArray = []; + +/** + * function to send data of new idea to the server + * idea title, description, tags, skills and the information + * if the user wants to publish the idea on mastodon + * will be read from the form created by the show function + * @param {string} lon - lon component of coordinate + * @param {string} lat - lat component of coordinate + */ +function save(lon, lat) { + if (!document.forms.idea_form.nameText.checkValidity()) { + document.getElementById("nameText").className += " invalid"; + return; + } + if (!document.forms.idea_form.ideaText.checkValidity()) { + document.getElementById("ideaText").className += " invalid"; + return; + } + myHideMark(); + let xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + let obj = JSON.parse(this.responseText); + if (obj) { + if (obj == "error") alert("error - are you still logged in?"); + else { + myCreateIdea(lon, lat, obj, 0, _tags, _skills, window.ulogin); + SidePanel.hide(); + } + } } - myHideMark(); - var xhttp = new XMLHttpRequest(); - xhttp.onreadystatechange = function() { - if (this.readyState == 4 && this.status == 200) { - var obj = JSON.parse(this.responseText); - if(obj) { - if(obj == "error") alert("error - are you still logged in?"); - else { - myCreateIdea( lon, lat, obj, 0, _tags, _skills, window.ulogin); - SidePanel.hide(); - } - } - }}; - var nameText = document.getElementById("nameText").value; - var ideaText = document.getElementById("ideaText").value; - var _tags = tagsArray.toString(); - var _skills = skillsArray.toString(); - var _mastodon = document.getElementById("mastodon").checked; - xhttp.open("POST", "submitIdea", true); - xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - xhttp.send("nameText="+nameText+"&ideaText="+ideaText+"&lon="+lon+"&lat="+lat+"&tags="+_tags+"&skills="+_skills+"&mastodon="+_mastodon); + }; + let nameText = document.getElementById("nameText").value; + let ideaText = document.getElementById("ideaText").value; + let _tags = tagsArray.toString(); + let _skills = skillsArray.toString(); + let _mastodon = document.getElementById("mastodon").checked; + xhttp.open("POST", "submitIdea", true); + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xhttp.send("nameText=" + nameText + "&ideaText=" + ideaText + "&lon=" + lon + "&lat=" + lat + "&tags=" + _tags + "&skills=" + _skills + "&mastodon=" + _mastodon); }; -export { save }; +export {save}; +/** + * function to show form to create new ideas in side panel + * @param {Object} ll - object containing the coordinates, where the idea will be created + */ function show(ll) { myUpdateMarkPos(ll); - var lon = ll.lon; - var lat = ll.lat; + let lon = ll.lon; + let lat = ll.lat; tagsArray.length = 0; skillsArray.length = 0; - var htmlIdea = - ` + let htmlIdea = + `
@@ -123,7 +142,7 @@ function show(ll) {
`; - var htmlNotLoggedIn = ` + let htmlNotLoggedIn = `

To create a new idea, you need to login or register

@@ -138,182 +157,187 @@ function show(ll) {
`; - if(ulogin == "false") {SidePanel.show(htmlNotLoggedIn);} - else {SidePanel.show(htmlIdea); - M.updateTextFields(); - - - document.getElementById('tag_adder_collection').addEventListener('click', () => { - let stringT = {id:""}; - stringT.id = document.getElementById("categoriesText").value; - //Capitalize and remove Whitespaces in topics - stringT.id = stringT.id.replace(/(^\w{1})|(\s+\w{1})/g, letter => letter.toUpperCase()).replace(/\s+/g, ''); - - //generate chipt and display it - const chip = generateChip(stringT); - chip.appendChild(generateTagsIcon(stringT)); - document.getElementById('tag_adder_chips').appendChild(chip); - document.getElementById('tag_adder').add(generateOption(stringT)); - tagsArray.push(stringT.id); - console.log("topics to add to new idea: " + tagsArray); - - document.getElementById('categoriesText').value = ''; - document.getElementById('tag_adder_collection').classList.add('hide'); - }); - -const generateTagsIcon = _ => { - const i = document.createElement('i'); - i.addEventListener('click', () => { - Array.from(document.getElementById('tag_adder').options).forEach(option => { - if (option.dataset.id === _.id) { - //remove tag from filterstring - tagsArray = tagsArray.filter(item => item !== _.id); - console.log("topics to add to new idea: " + tagsArray); - option.remove(); - document.querySelector(`.chipTagAdder-${_.id}`).remove(); - } - }); - }); - i.classList.add('close'); - i.classList.add('material-icons'); - i.innerText = 'close'; - return i; -}; - -new autoComplete({ - noResults: (dataFeedback, generateList) => { - document.getElementById('tag_adder_collection').classList.remove('hide'); - }, - data: { - src: async () => search(document.getElementById('categoriesText').value), - key: ['id'], - cache: false, - }, - query: { - manipulate: (query) => { - document.getElementById('tag_adder_collection').classList.add('hide'); - - return query; - } - }, - onSelection: feedback => { - let stringT = feedback.selection.value; - //Capitalize and remove Whitespaces in topics - stringT.id = stringT.id.replace(/(^\w{1})|(\s+\w{1})/g, letter => letter.toUpperCase()).replace(/\s+/g, ''); - - //generate chipt and display it - const chip = generateTagAdderChip(stringT); - chip.appendChild(generateTagsIcon(stringT)); - document.getElementById('tag_adder_chips').appendChild(chip); - document.getElementById('tag_adder').add(generateOption(stringT)); - tagsArray.push(stringT.id); - console.log("topics to add to new idea: " + tagsArray); - - document.getElementById('categoriesText').value = ''; - }, - resultsList: { - render: true, - container: source => { - source.classList.add('tag-collection-wrapper'); - }, - destination: "#tag_adder_collection-wrapper", - position: "beforeend", - element: "ul" - }, - highlight: true, - trigger: query => query.length > 0, - maxResults: 5, - threshold: 1, - debounce: 500, - selector: "#categoriesText", -}); - -//autocomplete skills - document.getElementById('skill_adder_collection').addEventListener('click', () => { - let stringT = {id:""}; - stringT.id = document.getElementById("skillsText").value; - //Capitalize and remove Whitespaces in topics - stringT.id = stringT.id.replace(/(^\w{1})|(\s+\w{1})/g, letter => letter.toUpperCase()).replace(/\s+/g, ''); - - //generate chipt and display it - const chip = generateSkillAdderChip(stringT); - chip.appendChild(generateSkillIcon(stringT)); - document.getElementById('skill_adder_chips').appendChild(chip); - document.getElementById('skill_adder').add(generateOption(stringT)); - skillsArray.push(stringT.id); - console.log("needed skill to add to new idea: " + skillsArray); - - document.getElementById('skillsText').value = ''; - document.getElementById('skill_adder_collection').classList.add('hide'); - }); - -const generateSkillIcon = _ => { - const i = document.createElement('i'); - i.addEventListener('click', () => { - Array.from(document.getElementById('skill_adder').options).forEach(option => { - if (option.dataset.id === _.id) { - //remove tag from filterstring - skillsArray = skillsArray.filter(item => item !== _.id); - console.log("needed skills to add to new idea: " + skillsArray); - option.remove(); - document.querySelector(`.chipSkillAdder-${_.id}`).remove(); - } - }); - }); - i.classList.add('close'); - i.classList.add('material-icons'); - i.innerText = 'close'; - return i; -}; - -new autoComplete({ - noResults: (dataFeedback, generateList) => { - document.getElementById('skill_adder_collection').classList.remove('hide'); - }, - data: { - src: async () => searchSkills(document.getElementById('skillsText').value), - key: ['id'], - cache: false, - }, - query: { - manipulate: (query) => { - document.getElementById('skill_adder_collection').classList.add('hide'); - - return query; + if (ulogin == "false") { + SidePanel.show(htmlNotLoggedIn); + } else { + SidePanel.show(htmlIdea); + M.updateTextFields(); + + + document.getElementById('tag_adder_collection').addEventListener('click', () => { + let stringT = { + id: "" + }; + stringT.id = document.getElementById("categoriesText").value; + //Capitalize and remove Whitespaces in topics + stringT.id = stringT.id.replace(/(^\w{1})|(\s+\w{1})/g, letter => letter.toUpperCase()).replace(/\s+/g, ''); + + //generate chipt and display it + const chip = generateChip(stringT); + chip.appendChild(generateTagsIcon(stringT)); + document.getElementById('tag_adder_chips').appendChild(chip); + document.getElementById('tag_adder').add(generateOption(stringT)); + tagsArray.push(stringT.id); + console.log("topics to add to new idea: " + tagsArray); + + document.getElementById('categoriesText').value = ''; + document.getElementById('tag_adder_collection').classList.add('hide'); + }); + + const generateTagsIcon = _ => { + const i = document.createElement('i'); + i.addEventListener('click', () => { + Array.from(document.getElementById('tag_adder').options).forEach(option => { + if (option.dataset.id === _.id) { + //remove tag from filterstring + tagsArray = tagsArray.filter(item => item !== _.id); + console.log("topics to add to new idea: " + tagsArray); + option.remove(); + document.querySelector(`.chipTagAdder-${_.id}`).remove(); + } + }); + }); + i.classList.add('close'); + i.classList.add('material-icons'); + i.innerText = 'close'; + return i; + }; + + new autoComplete({ + noResults: (dataFeedback, generateList) => { + document.getElementById('tag_adder_collection').classList.remove('hide'); + }, + data: { + src: async () => search(document.getElementById('categoriesText').value), + key: ['id'], + cache: false, + }, + query: { + manipulate: (query) => { + document.getElementById('tag_adder_collection').classList.add('hide'); + + return query; + } + }, + onSelection: feedback => { + let stringT = feedback.selection.value; + //Capitalize and remove Whitespaces in topics + stringT.id = stringT.id.replace(/(^\w{1})|(\s+\w{1})/g, letter => letter.toUpperCase()).replace(/\s+/g, ''); + + //generate chipt and display it + const chip = generateTagAdderChip(stringT); + chip.appendChild(generateTagsIcon(stringT)); + document.getElementById('tag_adder_chips').appendChild(chip); + document.getElementById('tag_adder').add(generateOption(stringT)); + tagsArray.push(stringT.id); + console.log("topics to add to new idea: " + tagsArray); + + document.getElementById('categoriesText').value = ''; + }, + resultsList: { + render: true, + container: source => { + source.classList.add('tag-collection-wrapper'); + }, + destination: "#tag_adder_collection-wrapper", + position: "beforeend", + element: "ul" + }, + highlight: true, + trigger: query => query.length > 0, + maxResults: 5, + threshold: 1, + debounce: 500, + selector: "#categoriesText", + }); + + //autocomplete skills + document.getElementById('skill_adder_collection').addEventListener('click', () => { + let stringT = { + id: "" + }; + stringT.id = document.getElementById("skillsText").value; + //Capitalize and remove Whitespaces in topics + stringT.id = stringT.id.replace(/(^\w{1})|(\s+\w{1})/g, letter => letter.toUpperCase()).replace(/\s+/g, ''); + + //generate chipt and display it + const chip = generateSkillAdderChip(stringT); + chip.appendChild(generateSkillIcon(stringT)); + document.getElementById('skill_adder_chips').appendChild(chip); + document.getElementById('skill_adder').add(generateOption(stringT)); + skillsArray.push(stringT.id); + console.log("needed skill to add to new idea: " + skillsArray); + + document.getElementById('skillsText').value = ''; + document.getElementById('skill_adder_collection').classList.add('hide'); + }); + + const generateSkillIcon = _ => { + const i = document.createElement('i'); + i.addEventListener('click', () => { + Array.from(document.getElementById('skill_adder').options).forEach(option => { + if (option.dataset.id === _.id) { + //remove tag from filterstring + skillsArray = skillsArray.filter(item => item !== _.id); + console.log("needed skills to add to new idea: " + skillsArray); + option.remove(); + document.querySelector(`.chipSkillAdder-${_.id}`).remove(); + } + }); + }); + i.classList.add('close'); + i.classList.add('material-icons'); + i.innerText = 'close'; + return i; + }; + + new autoComplete({ + noResults: (dataFeedback, generateList) => { + document.getElementById('skill_adder_collection').classList.remove('hide'); + }, + data: { + src: async () => searchSkills(document.getElementById('skillsText').value), + key: ['id'], + cache: false, + }, + query: { + manipulate: (query) => { + document.getElementById('skill_adder_collection').classList.add('hide'); + + return query; + } + }, + onSelection: feedback => { + let stringT = feedback.selection.value; + //Capitalize and remove Whitespaces in topics + stringT.id = stringT.id.replace(/(^\w{1})|(\s+\w{1})/g, letter => letter.toUpperCase()).replace(/\s+/g, ''); + + //generate chipt and display it + const chip = generateChip(stringT); + chip.appendChild(generateSkillIcon(stringT)); + document.getElementById('skill_adder_chips').appendChild(chip); + document.getElementById('skill_adder').add(generateOption(stringT)); + skillsArray.push(stringT.id); + console.log("needed skill to add to new idea: " + skillsArray); + + document.getElementById('skillsText').value = ''; + }, + resultsList: { + render: true, + container: source => { + source.classList.add('skill-collection-wrapper'); + }, + destination: "#skill_adder_collection-wrapper", + position: "beforeend", + element: "ul" + }, + highlight: true, + trigger: query => query.length > 0, + maxResults: 5, + threshold: 1, + debounce: 500, + selector: "#skillsText", + }); } - }, - onSelection: feedback => { - let stringT = feedback.selection.value; - //Capitalize and remove Whitespaces in topics - stringT.id = stringT.id.replace(/(^\w{1})|(\s+\w{1})/g, letter => letter.toUpperCase()).replace(/\s+/g, ''); - - //generate chipt and display it - const chip = generateChip(stringT); - chip.appendChild(generateSkillIcon(stringT)); - document.getElementById('skill_adder_chips').appendChild(chip); - document.getElementById('skill_adder').add(generateOption(stringT)); - skillsArray.push(stringT.id); - console.log("needed skill to add to new idea: " + skillsArray); - - document.getElementById('skillsText').value = ''; - }, - resultsList: { - render: true, - container: source => { - source.classList.add('skill-collection-wrapper'); - }, - destination: "#skill_adder_collection-wrapper", - position: "beforeend", - element: "ul" - }, - highlight: true, - trigger: query => query.length > 0, - maxResults: 5, - threshold: 1, - debounce: 500, - selector: "#skillsText", -}); -} }; - -export { show }; +export {show}; diff --git a/src/oi/SideLoginRegister.js b/src/oi/SideLoginRegister.js index 52ab426ece..7fe69bc75b 100644 --- a/src/oi/SideLoginRegister.js +++ b/src/oi/SideLoginRegister.js @@ -1,34 +1,49 @@ +/** + * @fileOverview this file provides function to display a login or register panel + * inside the side panel + * @name SideLoginRegister.js + * @author Jannis Dohm + * @license MIT + */ 'use strict'; +/** + * function to send login information to the server + * also displays errors and handles login on client side plus hides the panel on succes + * information will be read from login form + */ function sendLogin() { - if(!document.forms.login_form.email.checkValidity()) { - document.getElementById("email").className += " invalid"; - return false; + if (!document.forms.login_form.email.checkValidity()) { + document.getElementById("email").className += " invalid"; + return false; + } + if (!document.forms.login_form.password.checkValidity()) { + document.getElementById("password").className += " invalid"; + return false; + } + let xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + let obj = JSON.parse(this.responseText); + if (obj.hasOwnProperty("message")) { + document.getElementById("error_server").innerHTML = obj.message; + } else { + myLogin(obj); + SidePanel.hide(); } - if(!document.forms.login_form.password.checkValidity()) { - document.getElementById("password").className += " invalid"; - return false; - } - var xhttp = new XMLHttpRequest(); - xhttp.onreadystatechange = function() { - if (this.readyState == 4 && this.status == 200) { - var obj = JSON.parse(this.responseText); - if(obj.hasOwnProperty("message")) { - document.getElementById("error_server").innerHTML = obj.message; - } - else { - myLogin(obj); - SidePanel.hide(); - } - }}; - xhttp.open("POST", "submitLogin", true); - xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - xhttp.send("email="+document.getElementById("email").value+"&password="+document.getElementById("password").value); + } + }; + xhttp.open("POST", "submitLogin", true); + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xhttp.send("email=" + document.getElementById("email").value + "&password=" + document.getElementById("password").value); }; -export { sendLogin }; +export {sendLogin}; +/** + * function to show login form in side panel + */ function showLogin() { - var html = ` + let html = `
@@ -62,58 +77,63 @@ function showLogin() {
` SidePanel.show(html); - document.getElementById("password").addEventListener('keypress', function (e) { + document.getElementById("password").addEventListener('keypress', function(e) { if (e.key === 'Enter') { SideLoginRegister.sendLogin(); } }); M.updateTextFields(); }; -export { showLogin }; - +export {showLogin}; +/** + * function to send register information to the server + * also displays errors and hides the panel on succes + * information will be read from register form + */ function sendRegister() { - if(!document.forms.register_form.email.checkValidity()) { - document.getElementById("email").className += " invalid"; - return false; - } - if(!document.forms.register_form.name.checkValidity()) { + if (!document.forms.register_form.email.checkValidity()) { + document.getElementById("email").className += " invalid"; + return false; + } + if (!document.forms.register_form.name.checkValidity()) { + document.getElementById("name").className += " invalid"; + return false; + } + if (!document.forms.register_form.password.checkValidity()) { + document.getElementById("password").className += " invalid"; + return false; + } + let xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + let obj = JSON.parse(this.responseText); + if (obj.hasOwnProperty("message")) { + if (obj.message.search("name") >= 1) { + document.getElementById("error_name").innerHTML = "Username already in use."; document.getElementById("name").className += " invalid"; - return false; - } - if(!document.forms.register_form.password.checkValidity()) { - document.getElementById("password").className += " invalid"; - return false; - } - var xhttp = new XMLHttpRequest(); - xhttp.onreadystatechange = function() { - if (this.readyState == 4 && this.status == 200) { - var obj = JSON.parse(this.responseText); - if(obj.hasOwnProperty("message")) { - if(obj.message.search("name") >= 1) { - document.getElementById("error_name").innerHTML = "Username already in use."; - document.getElementById("name").className += " invalid"; - } - else if(obj.message.search("email") >= 1){ - document.getElementById("error_mail").innerHTML = "Email already in use."; - document.getElementById("email").className += " invalid"; - } - else alert(obj.message); - } - else { - SidePanel.hide(); - } - }}; - xhttp.open("POST", "submitRegister", true); - xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - xhttp.send("name="+document.getElementById("name").value+"&email="+document.getElementById("email").value+"&password="+document.getElementById("password").value); + } else if (obj.message.search("email") >= 1) { + document.getElementById("error_mail").innerHTML = "Email already in use."; + document.getElementById("email").className += " invalid"; + } else alert(obj.message); + } else { + SidePanel.hide(); + } + } + }; + xhttp.open("POST", "submitRegister", true); + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xhttp.send("name=" + document.getElementById("name").value + "&email=" + document.getElementById("email").value + "&password=" + document.getElementById("password").value); }; -export { sendRegister }; +export {sendRegister}; +/** + * function to show register form in side panel + */ function showRegister() { - var html = - ` + let html = + `
@@ -155,12 +175,11 @@ function showRegister() {
`; SidePanel.show(html); - document.getElementById("password").addEventListener('keypress', function (e) { + document.getElementById("password").addEventListener('keypress', function(e) { if (e.key === 'Enter') { SideLoginRegister.sendRegister(); } }); M.updateTextFields(); }; - -export { showRegister }; +export {showRegister}; diff --git a/src/oi/SidePanel.js b/src/oi/SidePanel.js index 79a0be51fb..c68668345e 100644 --- a/src/oi/SidePanel.js +++ b/src/oi/SidePanel.js @@ -1,22 +1,32 @@ +/** + * @fileOverview this file provides functions to open a side panel, + * which can be used to display idea informations, login, register... + * @name SidePanel.js + * @author Jannis Dohm + * @license MIT + */ 'use strict'; -var first = '
'; - - -var last = '
'; +let first = '
'; +let last = '
'; +/** + * function to show side panel, this can be used to + * display informations about an idea, a login screen ... + * this side panel will check the screen width and proportions to determine + * if the side panel will be 30% or 50% of the screen, or even the whole screen + * @param {string} html - content which will be displayed inside the side panel + */ function show(html) { - if(document.documentElement.clientWidth > document.documentElement.clientHeight && document.documentElement.clientWidth > 800) { - if(document.documentElement.clientWidth > document.documentElement.clientHeight && document.documentElement.clientWidth > 1400) { + if (document.documentElement.clientWidth > document.documentElement.clientHeight && document.documentElement.clientWidth > 800) { + if (document.documentElement.clientWidth > document.documentElement.clientHeight && document.documentElement.clientWidth > 1400) { document.getElementById("earth").style["width"] = "70%"; document.getElementById("idea").style["width"] = "30%"; + } else { + document.getElementById("earth").style["width"] = "50%"; + document.getElementById("idea").style["width"] = "50%"; } - else { - document.getElementById("earth").style["width"] = "50%"; - document.getElementById("idea").style["width"] = "50%"; - } - } - else { + } else { document.getElementById("earth").style["width"] = "0%"; document.getElementById("idea").style["width"] = "100%"; } @@ -24,7 +34,10 @@ function show(html) { }; -function hide(){ +/** + * function to hide the side panel + */ +function hide() { document.getElementById("earth").style["width"] = "100%"; document.getElementById("idea").style["width"] = "0%"; document.getElementById("idea").innerHTML = ""; diff --git a/src/oi/SideShowIdea.js b/src/oi/SideShowIdea.js index 92c1766f39..190f88dff6 100644 --- a/src/oi/SideShowIdea.js +++ b/src/oi/SideShowIdea.js @@ -1,58 +1,82 @@ -'use strict'; -function show(IdeaID) { - /*---------------------------------| - | get Infos for Idea from server | - |---------------------------------*/ - var xhttp = new XMLHttpRequest(); - var self = this; - xhttp.onreadystatechange = function() { - if (this.readyState == 4 && this.status == 200) { - var obj = JSON.parse(this.responseText); - +/** + * @fileOverview this file provides functions to display ideas in side panel + * @name SideShowIdea.js + * @author Jannis Dohm + * @license MIT + */ - var ulogin = this.getResponseHeader("login"); - if (ulogin == "false") { - document.getElementById("id_vote").innerHTML = LoginRegister; - document.getElementById("up-btn").style.opacity = "0.4"; - document.getElementById("up-btn").onclick = function () {SideLoginRegister.showLogin();}; - document.getElementById("down-btn").style.opacity = "0.4"; - document.getElementById("down-btn").onclick = function () {SideLoginRegister.showLogin();}; - document.getElementById("commentForm").textContent = "Comments:"; - document.getElementById("commentForm").classList.add("cactus-comment"); - } +'use strict'; - //cactus chat - initComments({ - node: document.getElementById("comment-section"), - defaultHomeserverUrl: "https://matrix.cactus.chat:8448", - serverName: "cactus.chat", - siteName: "openidea.io", - commentSectionId: "Idea#" + IdeaID - }); - //cactus chat end - document.getElementById("id_title").innerHTML = obj.title; - document.getElementById("id_title").addEventListener('click', () => { - document.getElementById("id_title").classList.add('hide'); - document.getElementById("id_title2").classList.remove('hide'); - }); - document.getElementById("id_title2").innerHTML = obj.title; - document.getElementById("id_description").innerHTML = obj.description; - document.getElementById("id_tags").innerHTML = "Topics: "; - obj.tags.forEach((dat) => {document.getElementById("id_tags").innerHTML += '
' + dat + '
';}); - document.getElementById("id_skills").innerHTML = "Needed skills: "; - obj.skills.forEach((dat) => {document.getElementById("id_skills").innerHTML += '
' + dat + '
';}); - document.getElementById("id_user").innerHTML = "Idea by: "; - obj.user.forEach((dat) => {document.getElementById("id_user").innerHTML += '
' + dat + '
';}); +/** + * function to open Idea in side panel + * If users isn't logged in, this function will blur out the vote buttons and the comment editor. + * Instead the user get the possibility to go to login/register + * @param {number} IdeaID - number of idea which will be displayed + */ +function show(IdeaID) { + /*---------------------------------| + | get Infos for Idea from server | + |---------------------------------*/ + let xhttp = new XMLHttpRequest(); + let self = this; + xhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + let obj = JSON.parse(this.responseText); + + + let ulogin = this.getResponseHeader("login"); + if (ulogin == "false") { + document.getElementById("id_vote").innerHTML = LoginRegister; + document.getElementById("up-btn").style.opacity = "0.4"; + document.getElementById("up-btn").onclick = function() { + SideLoginRegister.showLogin(); + }; + document.getElementById("down-btn").style.opacity = "0.4"; + document.getElementById("down-btn").onclick = function() { + SideLoginRegister.showLogin(); + }; + document.getElementById("commentForm").textContent = "Comments:"; + document.getElementById("commentForm").classList.add("cactus-comment"); } - }; - xhttp.open("POST", "getIdea", true); - xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - xhttp.send("IdeaID="+IdeaID); - /*---------------------------------| - | get Infos for Idea from server | - |---------------------------------*/ - var html = - ` + + //cactus chat + initComments({ + node: document.getElementById("comment-section"), + defaultHomeserverUrl: "https://matrix.cactus.chat:8448", + serverName: "cactus.chat", + siteName: "openidea.io", + commentSectionId: "Idea#" + IdeaID + }); + //cactus chat end + document.getElementById("id_title").innerHTML = obj.title; + document.getElementById("id_title").addEventListener('click', () => { + document.getElementById("id_title").classList.add('hide'); + document.getElementById("id_title2").classList.remove('hide'); + }); + document.getElementById("id_title2").innerHTML = obj.title; + document.getElementById("id_description").innerHTML = obj.description; + document.getElementById("id_tags").innerHTML = "Topics: "; + obj.tags.forEach((dat) => { + document.getElementById("id_tags").innerHTML += '
' + dat + '
'; + }); + document.getElementById("id_skills").innerHTML = "Needed skills: "; + obj.skills.forEach((dat) => { + document.getElementById("id_skills").innerHTML += '
' + dat + '
'; + }); + document.getElementById("id_user").innerHTML = "Idea by: "; + obj.user.forEach((dat) => { + document.getElementById("id_user").innerHTML += '
' + dat + '
'; + }); + } + }; + xhttp.open("POST", "getIdea", true); + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xhttp.send("IdeaID=" + IdeaID); + /*---------------------------------| + | get Infos for Idea from server | + |---------------------------------*/ + let html = + `

Share idea!Vote Upthumb_up