-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
156 lines (129 loc) · 5.49 KB
/
Copy pathscript.js
File metadata and controls
156 lines (129 loc) · 5.49 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
"use strict";
// Selecting all our project elements so we can manipulate the DOM and change the UI.
const searchBtn = document.getElementById("search-btn");
const bandName = document.getElementById("band-name");
const cityName = document.getElementById("city");
const priceValue = document.getElementById("price");
const feedback = document.querySelector(".feedback");
const loading = document.querySelector(".loading");
const ticketList = document.querySelector(".tickets-list");
const ticketForm = document.getElementById("tickets-form");
// Setting some bands in order to later put thier pictures to the user.
const bands = [
"metallica",
"slipknot",
"opeth",
"slayer",
"jinjer",
"death",
"megadeth",
"ghost",
"nirvana",
"anthrax",
"foo fighters",
"slaughter to prevail",
"Amon Amarth",
"rammstein",
"ac-dc",
"black sabbath",
"children of bodom",
"disturbed",
"dream theater",
"evanescence",
"iron maiden",
"lamb of god",
"linkin park",
"marilyn manson",
"pantera",
"gojira",
];
// Our main class app initialization.
class App {
constructor() {
// Calling some of the functions inside of our constructor function of the class in order so that they be called whenever we have children class creation.
searchBtn.disabled = true;
// Our main function call when the user hit get to serach for a ticket, we bind the this keyword in order so that it refer to the same class that we are calling it on.
searchBtn.addEventListener("click", this._loadingResult.bind(this));
// Calling our inital input fields function.
this._editInputFields();
}
// This function is responsible for checking our input fields, and then it dose some UI changes on it, in case they are empty or filled.
_cheakInputFields() {
const allInputs = [bandName, cityName, priceValue];
allInputs.map((currentFiled) => {
if (currentFiled.value.trim() === "") {
currentFiled.classList.remove("complete");
currentFiled.classList.add("fail");
}
if (currentFiled.value.trim() !== "") {
currentFiled.classList.add("complete");
currentFiled.classList.remove("fail");
}
});
if (/\d/.test(priceValue.value) === false) {
priceValue.classList.remove("complete");
priceValue.classList.add("fail");
}
const completeFields = document.querySelectorAll(".complete");
// If all our inputs are filled and complete we enable the get button
if (completeFields.length === 3) searchBtn.disabled = false;
// If not all of them are filled we then disabled.
if (completeFields.length !== 3) searchBtn.disabled = true;
}
// This function will call our checkInputFields function for us on the blur event, but this function editInputFields will be called in the constructor function.
_editInputFields() {
const allInputs = [bandName, cityName, priceValue];
allInputs.map((currentFiled) =>
currentFiled.addEventListener("blur", this._cheakInputFields)
);
}
// This function is very simple, it gonna show some loading phrase for us as well as s loading spinner for 4 seconds, then it will call the add newTicket function for us, This function the loadingResult will also be called for us inside the constructor function.
_loadingResult(e) {
e.preventDefault();
feedback.classList.add("showItem", "alert", "alert-success");
loading.classList.add("showItem");
const theApp = this;
setTimeout(function () {
feedback.classList.remove("showItem", "alert", "alert-success");
loading.classList.remove("showItem");
// Calling the addNewTicket function.
theApp._addNewTicket();
}, 4000);
}
// Our main addNewTicket function that will add a new ticket for us on the UI after the user decied to get a new ticket.
_addNewTicket() {
// Making the name of the image flexible and dynamic in order to show different pictures.
const testImg = bands.includes(bandName.value) ? bandName.value : "metal";
const div = document.createElement("div");
div.classList.add("col-11", "mx-auto", "col-md-6", "my-3", "col-lg-4");
div.innerHTML = `<div class="card text-left">
<img src="./img/${testImg}.jpg" class="card-img-top" alt="">
<div class="card-body">
<!-- customer name -->
<h6 class="text-capitalize "><span class="badge badge-warning mr-2">Band Name :</span><span class="customer-name">${bandName.value}</span></h6>
<!-- end of customer name -->
<!-- customer name -->
<h6 class="text-capitalize my-3"><span class="badge badge-success mr-2">City :</span><span class="customer-course">
${cityName.value}
</span></h6>
<!-- end of customer name -->
<!-- customer name -->
<h6 class="text-capitalize"><span class="badge badge-danger mr-2">Price :</span><span class="course-author">${priceValue.value}$</span></h6>
<!-- end of customer name -->
</div>
</div>`;
ticketList.appendChild(div);
this._clearInputs();
}
// This function is responsible of cleaning all the inputs, remove the complete class and disable the button again after the user gets an new ticket, it will be called for us inside of addNewTicket function.
_clearInputs() {
const allInputs = [bandName, cityName, priceValue];
allInputs.map((currentFiled) => {
currentFiled.value = "";
currentFiled.classList.remove("complete");
searchBtn.disabled = true;
});
}
}
// Our main class creation to make the whole thing work and called out!
const createApp = new App();