-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
115 lines (67 loc) · 2.63 KB
/
app.js
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
let imageUrl;
document.querySelector("#productform").addEventListener("submit",
function (e) {
const productname =document.querySelector ("#productname").value;
const productmodel =document.querySelector ("#productmodel").value;
const productprice =document.querySelector ("#productprice").value;
const product = new Products(productname, productmodel, productprice);
const ui = new UI ();
if(productname == "" || productprice == "" || productmodel == "" ){
ui.alerts("Boş alan bırakmayınız !", "error")
}else{
ui.productadd(product);
ui.alerts("Ürün Ekleme Başarılı!", "confirmation")
ui.formclean();
}
e.preventDefault();
})
var openFile = function(event) {
var input = event.target;
var reader = new FileReader();
reader.onload = function(){
var dataURL = reader.result;
console.log('dataURL', dataURL)
imageUrl = dataURL;
};
reader.readAsDataURL(input.files[0]);
};
function Products(productname, productmodel, productprice){
this.productname = productname;
this.productmodel = productmodel;
this.productprice = productprice;
}
function UI() {}
UI.prototype.productadd = function (product){
const list = document.querySelector(".productlists");
const ull= document.createElement("ul");
ull.innerHTML =`<li><a href=${imageUrl} rel="lightbox [group]"> <img id='output'src=${imageUrl} /></a></li><li>${product.productname}</li> <li>${product.productmodel}</li><li>${product.productprice}</li><i class="fas fa-trash-alt" id="icons"></i></li>`;
list.appendChild(ull);
}
UI.prototype.formclean = function(){
document.querySelector("#productname").value= "";
document.querySelector("#productmodel").value= "";
document.querySelector("#productprice").value= "";
}
UI.prototype.alerts = function(message, classnames ){
const div = document.createElement("div");
div.className= `warn ${classnames}`
const text = document.createTextNode(message)
div.appendChild(text);
const form = document.querySelector("#productform");
document.body.insertBefore(div, form);
setTimeout(()=> {
document.querySelector(".warn").remove();
}, 3000);
}
UI.prototype.productlistsdelete = function(targets){
if(targets.className == "fas fa-trash-alt"){
result = confirm("Ürünü silmeyi onaylıyor musunuz?");
targets.parentElement.remove();
}
}
document.querySelector(".productlists").addEventListener("click", function(e){
const ui = new UI();
ui.productlistsdelete(e.target);
ui.alerts("Silme İşlemi Başarılı!", "deletes");
e.preventDefault();
});