-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascriptArticle.js
More file actions
109 lines (88 loc) · 3.23 KB
/
Copy pathjavascriptArticle.js
File metadata and controls
109 lines (88 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { render } from "mustache";
function table() {
var checkBox = document.getElementById("Doyoubuygames");
var text = document.getElementById("text");
if (checkBox.checked == true) {
text.style.display = "block";
} else {
text.style.display = "none";
}
}
function tablereset() {
var text = document.getElementById("text");
text.style.display = "none";
}
/////////////////dotanik/////////////////
function opinion2html(opinion) {
opinion.createdDate = new Date(opinion.created).toDateString();
opinion.willReturnMessage = opinion.willReturn
? "I will return to this page."
: "Sorry, one visit was enough.";
const template = document.getElementById("mTmplOneOpinion").innerHTML;
const htmlWOp = render(template, opinion);
delete opinion.createdDate;
delete opinion.willReturnMessage;
return htmlWOp;
}
function opinionArray2html(sourceData) {
return sourceData.reduce(
(htmlWithOpinions, opn) => htmlWithOpinions + opinion2html(opn),
""
);
}
let opinions = [];
const opinionsElm = document.getElementById("opinionsContainer"); /////////////////////////////
if (localStorage.myTreesComments) {
opinions = JSON.parse(localStorage.myTreesComments);
}
opinionsElm.innerHTML = opinionArray2html(opinions);
let myFrmElm = document.getElementById("formmenu");
myFrmElm.addEventListener("submit", processOpnFrmData);
// story
function processOpnFrmData(event) {
event.preventDefault();
nopBoughgame = "Never Bought Game";
// Read and adjust data from the form
const nopOpn = document.getElementById("story").value.trim();
const nopName = document.getElementById("name").value.trim();
const nopEmail = document.getElementById("email").value.trim();
const nopGender = document.getElementById("Gender").value.trim();
const nopDoyoubuygames = document.getElementById("Doyoubuygames").checked;
if (document.getElementById("Doyoubuygames").checked) {
nopBoughgame = document.querySelector('input[name="Boughtgame"]:checked')
.value;
}
const game = document.querySelector('input[name="Typeofgame"]:checked').value;
const nopWhatgamedoyouplathemost = document.querySelector(
'input[name="Gameplayedthemost"]:checked'
).value;
// var rates = document.getElementsByName('Boughtgame'); da sa aj takto
// var rate_value;
// for(var i = 0; i < rates.length; i++){
// if(rates[i].checked){
// rate_value = rates[i].value;
// }
// }
if (nopOpn == "" || nopName == "" || nopEmail == "") {
window.alert("Please, enter both your name and opinion");
return;
}
const newOpinion = {
Name: nopName,
Email: nopEmail,
Gender: nopGender,
Gameplayedmost: nopWhatgamedoyouplathemost,
Typeofgame: game,
Boughtgame: nopDoyoubuygames,
RadioBoughtgame: nopBoughgame,
Textbox: nopOpn,
Created: new Date()
};
opinions.push(newOpinion);
localStorage.myTreesComments = JSON.stringify(opinions);
opinionsElm.innerHTML += opinion2html(newOpinion);
// window.alert("Your opinion has been stored. Look to the console");
// console.log("New opinion added");
// console.log(opinions);
myFrmElm.reset(); //resets the form
}