Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sib-polls-component
Manage
Activity
Members
Labels
Plan
Issues
9
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Applications
etuc
sib-polls-component
Commits
c25d2e85
Commit
c25d2e85
authored
4 years ago
by
Maxime
Browse files
Options
Downloads
Patches
Plain Diff
clean console logs && replace any try catch's
parent
aff0bf84
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!16
Merge red-line functionalities to master
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
js/main.js
+27
-85
27 additions, 85 deletions
js/main.js
js/polls-math.js
+11
-24
11 additions, 24 deletions
js/polls-math.js
with
38 additions
and
109 deletions
js/main.js
+
27
−
85
View file @
c25d2e85
...
...
@@ -14,69 +14,33 @@ function firstLoad(){
//listeners for all forms
const
allForms
=
document
.
querySelectorAll
(
"
solid-form[id]
"
);
allForms
.
forEach
(
form
=>
{
form
.
addEventListener
(
"
populate
"
,()
=>
{
console
.
log
(
"
form loaded
"
,
form
);
globalFormListener
();
//
console.log("form loaded",form);
globalForm
Sumbit
Listener
();
});
});
//
Scripts dedicated to
voting form
//
Listener for
voting form
document
.
querySelector
(
"
solid-form#poll-votes-form
"
).
addEventListener
(
"
populate
"
,()
=>
{
//console.log("Vote form is populating");
disableVotes
();
});
//const mainPollSection = document.querySelectorAll("#poll-listing,#poll-page,#add-survey");
//console.log("section is",mainPollSection);
//console.log("Main.js : Page",mainPollSection, "is populating");
//loadFormValidityScript();
////console.log("about to clear form");
//clearFormErrors(mainPollSection);
function
globalFormListener
(){
function
globalFormSumbitListener
(){
//event listener on all forms
let
submitButtons
=
document
.
querySelectorAll
(
"
input[type=submit]
"
);
console
.
log
(
"
setting event listener for
"
,
submitButtons
);
submitButtons
.
forEach
(
button
=>
{
//listen on click & not submit to be able to check the data in the form
button
.
addEventListener
(
"
click
"
,()
=>
{
//console.log("submit button clicked");
let
clickedFormId
=
button
.
parentElement
.
parentElement
.
id
;
//console.log("form id of click is :",clickedFormId);
let
clickedFormId
=
button
.
parentElement
.
parentElement
.
id
;
//console.log("form id of click is :",clickedFormId);
checkFormValidity
(
clickedFormId
);
});
//event listener on voting forms specifically if needed
/*
let voteForms = document.querySelectorAll("solid-form[id=poll-votes-form]");
voteForms.forEach(voteForm => {
//console.log("listing for votes on : ",voteForm);
try {
let voteButtons = voteForm.querySelector("input[type=submit]");
//console.log("the buttons are",voteButtons);
let clickedFormId = voteButtons.parentElement.parentElement.id;
voteButtons.addEventListener("click",()=>{
//console.log("voting button clicked");
checkFormValidity(clickedFormId);
});
} catch (error) {
//console.log(error);
}
});
*/
});
}
};
/* ===================
JS For Tabs
================== */
...
...
@@ -113,8 +77,7 @@ function showHideBlocks(activeCTAClass,inactiveCTAClass,diplayBlockClass,hideBlo
for
(
m
=
0
;
m
<
inactiveCTAClass
.
length
;
m
++
)
{
inactiveCTAClass
[
m
].
classList
.
remove
(
"
active-tab
"
);
}
}
}
/* ===================
Add survey form
...
...
@@ -133,30 +96,14 @@ function newOptionContent(){
for
(
y
=
0
;
y
<
button
.
length
;
y
++
)
{
let
buttonContent
=
button
[
i
].
textContent
;
//console.log("the content",buttonContent );
button
[
i
].
textContent
=
"
Add option
"
;
//open 2 first options
//console.log("Open first option");
button
[
i
].
click
();
//console.log("Open second option");
button
[
i
].
click
();
}
}
}
/*
SHARE POLL BY EMAIL
*/
function
sharePollEmail
(){
let
shareEmails
=
document
.
querySelector
(
"
#share-emails
"
).
value
;
let
emailTitle
=
document
.
querySelector
(
"
h1
"
).
innerText
;
let
emailSubject
=
"
Donnez votre avis sur
"
+
emailTitle
;
let
pollURL
=
window
.
location
.
href
;
let
emailContent
=
"
Bonjour, je vous invite à participer au vote sur
"
+
emailTitle
+
"
.
\n
Venez sur la page suivante pour voter :
"
+
pollURL
;
emailContent
=
encodeURIComponent
(
emailContent
);
window
.
open
(
"
mailto:
"
+
shareEmails
+
"
?subject=
"
+
emailSubject
+
"
&body=
"
+
emailContent
);
}
/*=======================================
Form validation scripts
=======================================*/
...
...
@@ -165,15 +112,12 @@ function sharePollEmail(){
// select all forms
***********/
function
checkFormValidity
(
clickedFormId
){
let
formId
=
clickedFormId
;
let
form
=
document
.
querySelector
(
"
solid-form[id=
"
+
formId
+
"
]
"
);
console
.
log
(
"
current form id is :
"
,
formId
);
//console.log("current form id is : ",formId);
var
currenErrors
=
[];
//console.log("errors are", currenErrors);
//console.log("errors are", currenErrors);
var
errorDiv
=
form
.
nextElementSibling
;
console
.
log
(
"
error div is
"
,
errorDiv
);
//check the fiels of the wanted forms
switch
(
formId
){
case
"
add-survey-form
"
:
...
...
@@ -188,11 +132,8 @@ function sharePollEmail(){
CheckMandatoryRadioField
(
"
Choose an option to vote
"
);
break
;
default
:
//
console.log("form not taken into account");
console
.
log
(
"
form not taken into account
"
);
}
// check if any email fields & if format ok
//display errors
showErrors
(
currenErrors
,
errorDiv
,
formId
);
...
...
@@ -265,7 +206,6 @@ function sharePollEmail(){
this
.
ErrorValue
=
ErrorValue
;
//select all inputs
let
formInput
=
form
.
querySelectorAll
(
"
input[type=radio]
"
);
console
.
log
(
formInput
);
let
checkedButton
=
false
;
//see if any are checked buttons
formInput
.
forEach
(
input
=>
{
...
...
@@ -287,7 +227,7 @@ function sharePollEmail(){
***********/
function
showErrors
(
errors
,
formId
){
this
.
formId
=
formId
;
console
.
log
(
"
h
er
her
"
,
errors
);
//
console.log("er
rors are
",errors);
if
(
errors
.
length
==
1
)
{
errorDiv
.
innerHTML
=
"
The field
\"
"
+
currenErrors
.
join
(
"
,
"
)
+
"
\"
is mandatory
"
;
errorDiv
.
classList
.
add
(
"
show
"
,
"
validation-error-style
"
);
...
...
@@ -304,7 +244,7 @@ function sharePollEmail(){
else
{
errorDiv
.
classList
.
remove
(
"
show
"
,
"
validation-error-style
"
);
errorDiv
.
classList
.
add
(
"
validate
"
);
console
.
log
(
"
the form ID is
"
,
formId
);
//
console.log("the form ID is",formId);
//personnalise confimation message depending on the form
if
(
formId
=
"
poll-votes-form
"
){
...
...
@@ -320,17 +260,6 @@ function sharePollEmail(){
},
10000
);
}
}
function
clearFormErrors
(
mainPollSection
){
//console.log("clear form started");
try
{
let
mainPollSection
=
mainPollSection
;
mainPollSection
.
forEach
(
section
=>
{
});
}
catch
(
error
)
{
//console.log("clearing error div's went wrong : ",error);
}
}
/***********
disable voting if the startdate hasn't arrived or if the enddate has passed
...
...
@@ -382,4 +311,17 @@ function disableVotes(){
submitButton
.
nextElementSibling
.
remove
();
}
}
}
\ No newline at end of file
}
/*
SHARE POLL BY EMAIL
*/
function
sharePollEmail
(){
let
shareEmails
=
document
.
querySelector
(
"
#share-emails
"
).
value
;
let
emailTitle
=
document
.
querySelector
(
"
h1
"
).
innerText
;
let
emailSubject
=
"
Donnez votre avis sur
"
+
emailTitle
;
let
pollURL
=
window
.
location
.
href
;
let
emailContent
=
"
Bonjour, je vous invite à participer au vote sur
"
+
emailTitle
+
"
.
\n
Venez sur la page suivante pour voter :
"
+
pollURL
;
emailContent
=
encodeURIComponent
(
emailContent
);
window
.
open
(
"
mailto:
"
+
shareEmails
+
"
?subject=
"
+
emailSubject
+
"
&body=
"
+
emailContent
);
}
This diff is collapsed.
Click to expand it.
js/polls-math.js
+
11
−
24
View file @
c25d2e85
...
...
@@ -34,27 +34,18 @@ function firstLoad(){
Updates on navigate
*/
document
.
querySelector
(
"
solid-router
"
).
addEventListener
(
"
navigate
"
,()
=>
{
////console.log("updating on navigation - math.js");
try
{
getPollTotalInfo
(
dataSourceDomain
);
updateFormSource
();
}
catch
(
error
)
{
//console.log("error on navigation : ",error);
}
getPollTotalInfo
(
dataSourceDomain
);
updateFormSource
();
});
//refresh display of total votes on a poll
document
.
querySelector
(
"
#poll-votes-values
"
).
addEventListener
(
"
populate
"
,()
=>
{
//console.log("refreshing total vote now");
refreshTotalVotes
();
});
//refresh total votes when user votes
document
.
querySelector
(
"
solid-form#poll-votes-form
"
).
addEventListener
(
"
save
"
,()
=>
{
////console.log("submitted new vote");
setTimeout
(
function
(){
refreshVoteDataSrc
();
},
500
);
refreshVoteDataSrc
();
});
/*********
...
...
@@ -62,13 +53,15 @@ function firstLoad(){
*********/
function
getPollTotalInfo
(
dataSourceDomain
){
//get value of data-scr linked to poll page
const
pollPage
=
document
.
querySelector
All
(
"
#pollPage
"
)
[
0
]
;
const
pollPage
=
document
.
querySelector
(
"
#pollPage
"
);
const
pageTitle
=
pollPage
.
querySelectorAll
(
"
solid-display[id=title]
"
);
////console.log("page title is",pageTitle);
//console.log("getting total poll info for the domaine",dataSourceDomain);
for
(
let
i
=
0
;
i
<
pageTitle
.
length
;
i
++
){
try
{
//if to deal with error
if
(
pageTitle
[
i
]
==
""
||
null
)
continue
//get the data src node of first sib display & extract the url
const
dataSrc
=
pageTitle
[
i
].
dataset
.
src
;
//extract current poll ID from the data src
...
...
@@ -79,11 +72,7 @@ function firstLoad(){
push it to the total polls data-src
*/
setCurrentPollOptions
(
dataSourceDomain
,
pollPage
,
pollId
);
setTotalResultId
(
dataSourceDomain
,
pollPage
,
pollId
);
}
catch
(
error
)
{
////console.log("Poll total cannot be display due to : ",error);
}
setTotalResultId
(
dataSourceDomain
,
pollPage
,
pollId
);
}
}
/**
...
...
@@ -107,9 +96,7 @@ function firstLoad(){
//add the poll option number within the URL of the options
//get the form block
const
formContent
=
currentPage
.
querySelector
(
"
[id=poll-votes-form]
"
);
if
(
formContent
==
null
){
throw
"
there's no formContent with the id poll-votes-form
"
;
}
if
(
formContent
==
null
)
throw
"
there's no formContent with the id poll-votes-form
"
;
//get the range for option choices
const
newOptionRange
=
dataSourceDomain
+
"
/polls/
"
+
currentId
+
"
/pollOptions/
"
;
//push new
...
...
@@ -141,7 +128,7 @@ function firstLoad(){
totalCount
=
totalCount
+
currentValue
;
}
else
{
////
console.log("it's Cheese NaN");
console
.
log
(
"
it's Cheese NaN
"
);
}
}
//launch function to display the number of votes in HTML
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment