-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
174 lines (151 loc) · 5.71 KB
/
index.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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();
today = yyyy + '-' + mm + '-' + dd;
//console.log(today);
var objForm = [{
sku: 13245,
descontinuado: false,
articulo: "Celular",
marca: "Iphone",
modelo: "nuevo",
departamento: 1,
clase : 12,
familia : 123,
stock : 45,
cantidad : 20,
fechaAlta : today,
fechaBaja : "1900-01-01"
}];
objForm.push({
sku: 44433,
descontinuado: false,
articulo: "Celular",
marca: "Huawei",
modelo: "antiguo",
departamento: 1,
clase : 12,
familia : 123,
stock : 50,
cantidad : 10,
fechaAlta : today,
fechaBaja : "1900-01-01"})
//---------- getting values of the inputs ---------------//
const getForm = document.querySelector("#form");
const getSku = document.querySelector("#sku");
const getCheck = document.querySelector("#descontinuado-check");
const getArticule = document.querySelector("#articulo");
const getDepartment = document.querySelector("#departamento");
const getBrand = document.querySelector("#marca");
const getModel = document.querySelector("#modelo");
const getClase = document.querySelector("#clase");
const getFamily = document.querySelector("#familia");
const getStock = document.querySelector("#stock");
const getQuantity = document.querySelector("#cantidad");
const getDateUp = document.querySelector("#fecha-alta");
const getDateDown = document.querySelector("#fecha-baja");
const getBtnDelete = document.querySelector(".btn-form-delete");
const getBtnUpdate = document.querySelector(".btn-form-update");
getForm.addEventListener("submit", btnFunction)
function compareQuantityVsStock(){
if(getStock.value >= getQuantity.value){
return 0;
} else {
return alert("La cantidad no debe superar el Stock");
}
}
function isSkuEmpty(){
if(sku.value == ""){
return alert("No hay SKU capturado");
}
}
function btnFunction(event){
event.preventDefault();
compareQuantityVsStock();
isSkuEmpty();
if(objForm[0].sku == parseInt(getSku.value)){
alert("Este SKU ya existe. Favor de ingresar otro");
getArticule.value = objForm[0].articulo;
getDepartment.value = objForm[0].departamento;
getFamily.value = objForm[0].familia;
getStock.value = objForm[0].stock;
getClase.value = objForm[0].clase;
getQuantity.value = objForm[0].cantidad;
getBrand.value = objForm[0].marca;
getModel.value = objForm[0].modelo;
getDateUp.value = objForm[0].fechaAlta;
getDateDown.value = objForm[0].fechaBaja;
getClase.setAttribute("disabled", "");
getArticule.setAttribute("disabled", "");
getDepartment.setAttribute("disabled", "");
getFamily.setAttribute("disabled", "");
getStock.setAttribute("disabled", "");
getQuantity.setAttribute("disabled", "");
getBrand.setAttribute("disabled", "");
getModel.setAttribute("disabled", "");
getBtnDelete.classList.remove("inactive");
getBtnUpdate.classList.remove("inactive");
//objForm.pop();
} else {
console.log("no ok");
getClase.removeAttribute("disabled");
getArticule.removeAttribute("disabled");
getDepartment.removeAttribute("disabled");
getFamily.removeAttribute("disabled");
getStock.removeAttribute("disabled");
getQuantity.removeAttribute("disabled");
getBrand.removeAttribute("disabled");
getModel.removeAttribute("disabled");
/*console.log(getClase.value,"clase");
//console.log(getArticule.value,"articulo");
//console.log(getDepartment.value, "departament");
//console.log(getFamily.value,"family");
//console.log(getStock.value,"stock");
//console.log(getQuantity.value,"quantity");
//console.log(getBrand.value, "brand");
//console.log(getModel.value, "model");
//console.log(getDateDown.value, "fecha baja");*/
isFormEmpty();
}
}
function isFormEmpty(){
objForm.push({
sku : parseInt(getSku.value),
clase: getClase.value,
articulo: getArticule.value,
departamento: getDepartment.value,
familia: getFamily.value,
stock: getStock.value,
cantidad: getQuantity.value,
marca: getBrand.value,
modelo: getModel.value,
fechaAlta: today,
fechaBaja: "1900-01-01",
});
}
function btnDeleteFunction(event){
event.preventDefault();
getClase.setAttribute("disabled", "");
getArticule.setAttribute("disabled", "");
getDepartment.setAttribute("disabled", "");
getFamily.setAttribute("disabled", "");
getStock.setAttribute("disabled", "");
getQuantity.setAttribute("disabled", "");
getBrand.setAttribute("disabled", "");
getModel.setAttribute("disabled", "");
confirm("¿Estás seguro que quieres eliminar este elemento?")
console.log(getSku.value)
}
function btnUpdateFunction(event){
event.preventDefault();
getClase.removeAttribute("disabled");
getArticule.removeAttribute("disabled");
getDepartment.removeAttribute("disabled");
getFamily.removeAttribute("disabled");
getStock.removeAttribute("disabled");
getQuantity.removeAttribute("disabled");
getBrand.removeAttribute("disabled");
getModel.removeAttribute("disabled");
getCheck.removeAttribute("disabled");
}