From 13cba558d23ed4960bdd1003cb40dd5df68d9840 Mon Sep 17 00:00:00 2001 From: Janis Hutz Date: Mon, 23 Oct 2023 14:27:21 +0200 Subject: [PATCH] improve voting plugin - more updates incoming! --- .../backend/plugins/others/poll/css/style.css | 2 +- .../plugins/others/poll/html/voting.html | 12 ++++- .../backend/plugins/others/poll/js/voting.js | 45 +++++++++++++------ 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/server/backend/plugins/others/poll/css/style.css b/src/server/backend/plugins/others/poll/css/style.css index f7920e2..25b978f 100644 --- a/src/server/backend/plugins/others/poll/css/style.css +++ b/src/server/backend/plugins/others/poll/css/style.css @@ -6,7 +6,7 @@ body { font-family: monospace; height: 100%; width: 100%; - background-color: lightgray; + background-color: rgb(114, 164, 173); } .title-area { diff --git a/src/server/backend/plugins/others/poll/html/voting.html b/src/server/backend/plugins/others/poll/html/voting.html index 72e63ff..01ac38c 100644 --- a/src/server/backend/plugins/others/poll/html/voting.html +++ b/src/server/backend/plugins/others/poll/html/voting.html @@ -62,18 +62,28 @@ .entry { border: black 2px solid; padding: 1% 10%; + width: 40vw; + display: flex; + justify-content: center; + align-items: center; + flex-direction: column; } .selected { background-color: green; } + + .comment { + width: 50%; + text-align: center; + }

Voting on {{ votingDetails.display ?? 'untitled' }}

-

{{ votingDetails.description }}

+

{{ votingDetails.description }}

diff --git a/src/server/backend/plugins/others/poll/js/voting.js b/src/server/backend/plugins/others/poll/js/voting.js index 1299159..0fda1f5 100644 --- a/src/server/backend/plugins/others/poll/js/voting.js +++ b/src/server/backend/plugins/others/poll/js/voting.js @@ -26,21 +26,38 @@ createApp( { }, save() { if ( this.newSuggestion.comment && this.newSuggestion.title ) { - let fetchOptions = { - method: 'post', - body: JSON.stringify( this.newSuggestion ), - headers: { - 'Content-Type': 'application/json', - 'charset': 'utf-8' - }, - }; - fetch( '/polls/add/' + location.pathname.substring( 7 ), fetchOptions ).then( response => { - if ( response.status !== 200 ) { - alert( 'there was an error updating' ); + let alreadyExists = false; + for ( let el in this.entries ) { + if ( this.entries[ el ][ 'title' ] === this.newSuggestion.title ) { + alreadyExists = true; + } + } + if ( alreadyExists ) { + if ( confirm( 'An element with the same title exists already. Do you really want to add another one?' ) ) { + if ( confirm( 'Are you really sure?' ) ) { + alreadyExists = true; + } else { + alreadyExists = false; + } } - } ); - this.closePopup(); - this.getData(); + } + if ( !alreadyExists ) { + let fetchOptions = { + method: 'post', + body: JSON.stringify( this.newSuggestion ), + headers: { + 'Content-Type': 'application/json', + 'charset': 'utf-8' + }, + }; + fetch( '/voting/add/' + location.pathname.substring( 8 ), fetchOptions ).then( response => { + if ( response.status !== 200 ) { + alert( 'there was an error updating' ); + } + } ); + this.closePopup(); + this.getData(); + } } else { alert( 'Not all required fields are filled out!' ); }