|
@@ -0,0 +1,260 @@
|
|
1
|
+//Basic shit to understand
|
|
2
|
+//all_artesanos is the json that has the file that contains all the artesanos, this includes the studd they do,municipio,telefono,email and name
|
|
3
|
+//x is going to be what is displayed in the app, it basically has the same infromation as all_artesanos
|
|
4
|
+//THe basic mechanic is to display each artist in the search tab whenever something of them is found
|
|
5
|
+//You need at least 3 characters in one of the searchbars for it to display something
|
|
6
|
+//If nothing is written then it will display every artists
|
|
7
|
+//Some of these functions also try to make sure that the inputs are the same format as the thing they're looking up so that they dont have to follow a specific syntax to look for stuff
|
|
8
|
+
|
|
9
|
+//Tries to filter by the type of work that the artists do, if what they wrote in inputarte is included in one of them then the artists is displayed in the search bar
|
|
10
|
+function filter_artesanias(inputarte){
|
|
11
|
+ var x = document.getElementsByClassName('artists');
|
|
12
|
+ for (var i = 0; i < all_artesanos.length; i++){
|
|
13
|
+ var especificaciones = all_artesanos[i].Especificacion;
|
|
14
|
+ especificaciones = especificaciones.trim().toLowerCase();
|
|
15
|
+ especificaciones = acento_replace(especificaciones);
|
|
16
|
+ if (especificaciones.search(inputarte) != -1){
|
|
17
|
+ x[i].style.display = "list-item";
|
|
18
|
+ }
|
|
19
|
+ //before it did this down here but im keeping it just in case...
|
|
20
|
+ //especificaciones = especificaciones.split(',');
|
|
21
|
+ //for (var j = 0; j < especificaciones.length; j++){
|
|
22
|
+ //var especificacion = especificaciones[j];
|
|
23
|
+ //especificacion = especificacion.trim().toLowerCase();
|
|
24
|
+ //especificacion = acento_replace(especificacion);
|
|
25
|
+ //if (especificacion.search(inputarte) != -1){
|
|
26
|
+ //x[i].style.display = "list-item";
|
|
27
|
+ //break;
|
|
28
|
+ //}
|
|
29
|
+
|
|
30
|
+ }
|
|
31
|
+ return;
|
|
32
|
+}
|
|
33
|
+
|
|
34
|
+//Tries to filter by the municipio that they reside in or work in (not sure which one of the two it is)
|
|
35
|
+function filter_municipios(inputmuni){
|
|
36
|
+ var x = document.getElementsByClassName('artists');
|
|
37
|
+ for (var i = 0; i < all_artesanos.length; i++){
|
|
38
|
+ var municipio = all_artesanos[i].Municipio;
|
|
39
|
+ municipio = municipio.trim().toLowerCase();
|
|
40
|
+ municipio = acento_replace(municipio);
|
|
41
|
+ if (municipio.search(inputmuni)!= -1){
|
|
42
|
+ x[i].style.display = "list-item";
|
|
43
|
+ }
|
|
44
|
+ }
|
|
45
|
+ return;
|
|
46
|
+}
|
|
47
|
+
|
|
48
|
+//Tries to filter by any kind of information provided (name,artesania,municipio,telefono,email)
|
|
49
|
+function filter_any(input){
|
|
50
|
+ var x = document.getElementsByClassName('artists');
|
|
51
|
+ for (var i = 0; i < all_artesanos.length; i++){
|
|
52
|
+ if (find_name(i,input)){
|
|
53
|
+ x[i].style.display = "list-item";
|
|
54
|
+ continue;
|
|
55
|
+ }
|
|
56
|
+ else if (find_artesania(i,input)){
|
|
57
|
+ x[i].style.display = "list-item";
|
|
58
|
+ continue;
|
|
59
|
+ }
|
|
60
|
+ else if (find_municipio(i,input)){
|
|
61
|
+ x[i].style.display = "list-item";
|
|
62
|
+ continue;
|
|
63
|
+ }
|
|
64
|
+ else if (find_telefono(i,input)){
|
|
65
|
+ x[i].style.display = "list-item";
|
|
66
|
+ continue;
|
|
67
|
+ }
|
|
68
|
+ else if (find_email(i,input)){
|
|
69
|
+ x[i].style.display = "list-item";
|
|
70
|
+ continue;
|
|
71
|
+ }
|
|
72
|
+ }
|
|
73
|
+ return;
|
|
74
|
+}
|
|
75
|
+
|
|
76
|
+//Te trata de buscar si cualquiera de ellos tienen el input que se dio aplica a ese artista especifico (i)
|
|
77
|
+function find_any(i,input){
|
|
78
|
+ //if you find any of these in that space then return 1 if you didnt find that anything matched with the input then return 0
|
|
79
|
+ if (find_name(i,input) || find_telefono(i,input) || find_email(i,input) || find_artesania(i,input) || find_municipio(i,input)){
|
|
80
|
+ return 1;
|
|
81
|
+ }
|
|
82
|
+ else{
|
|
83
|
+ return 0;
|
|
84
|
+ }
|
|
85
|
+}
|
|
86
|
+
|
|
87
|
+//Trata de ver si el input es parte del nombre del artista i
|
|
88
|
+//Mayuscula y acento proof
|
|
89
|
+function find_name(i,input){
|
|
90
|
+ var name = all_artesanos[i].Nombre;
|
|
91
|
+ name = name.trim().toLowerCase();
|
|
92
|
+ name = acento_replace(name);
|
|
93
|
+ if(name.search(input) != -1){
|
|
94
|
+ return 1;
|
|
95
|
+ }
|
|
96
|
+ return 0;
|
|
97
|
+}
|
|
98
|
+
|
|
99
|
+//trata de ver si el input es parte de alguna artesania que trabaja el artista i
|
|
100
|
+//Mayuscula y acento proof
|
|
101
|
+function find_artesania(i,input){
|
|
102
|
+ var artesanias = all_artesanos[i].Especificacion;
|
|
103
|
+ artesanias = artesanias.trim().toLowerCase();
|
|
104
|
+ artesanias = acento_replace(artesanias);
|
|
105
|
+ if(artesanias.search(input) != -1){
|
|
106
|
+ return 1;
|
|
107
|
+ }
|
|
108
|
+ //artesanias = artesanias.split(',');
|
|
109
|
+ //for (var j = 0; j < artesanias.length; j++){
|
|
110
|
+ //var artesania = artesanias[j];
|
|
111
|
+ //artesania = artesania.trim().toLowerCase();
|
|
112
|
+ //artesania = acento_replace(artesania);
|
|
113
|
+ //if (artesania.search(input) != -1){
|
|
114
|
+ //return 1;
|
|
115
|
+ //}
|
|
116
|
+ //}
|
|
117
|
+ return 0;
|
|
118
|
+}
|
|
119
|
+
|
|
120
|
+//trata de ver si el input es parte del municipio del artista i
|
|
121
|
+//Mayuscula y acento proof
|
|
122
|
+function find_municipio(i,input){
|
|
123
|
+ var mun = all_artesanos[i].Municipio;
|
|
124
|
+ mun = mun.trim().toLowerCase();
|
|
125
|
+ mun = acento_replace(mun);
|
|
126
|
+ if(mun.search(input) != -1){
|
|
127
|
+ return 1;
|
|
128
|
+ }
|
|
129
|
+ return 0;
|
|
130
|
+}
|
|
131
|
+
|
|
132
|
+//trata de ver si el input es parte del telefono del artista i
|
|
133
|
+//'(',')','-' and ' ' proof
|
|
134
|
+function find_telefono(i,input){
|
|
135
|
+ var tel = all_artesanos[i]["Telefono 1"];
|
|
136
|
+ tel = tel.trim();
|
|
137
|
+ //To make sure they're both the same im taking out spaces,'(',')' and '-' to make sure they're both the same format
|
|
138
|
+ tel = tel.replace(/\s/g,'').replace(/\u0028/g,'').replace(/\u0029/g,'').replace(/\u002D/g,'');
|
|
139
|
+ input = input.replace(/\s/g,'').replace(/\u0028/g,'').replace(/\u0029/g,'').replace(/\u002D/g,'');
|
|
140
|
+ if(tel.search(input) != -1){
|
|
141
|
+ return 1;
|
|
142
|
+ }
|
|
143
|
+ return 0;
|
|
144
|
+}
|
|
145
|
+
|
|
146
|
+//trata de ver si el input es parte del email del artista i
|
|
147
|
+//Mayuscula and acento proof
|
|
148
|
+function find_email(i,input){
|
|
149
|
+ var email = all_artesanos[i]["E-mail"];
|
|
150
|
+ email = email.trim().toLowerCase();
|
|
151
|
+ email = acento_replace(email);
|
|
152
|
+ if(email.search(input) != -1){
|
|
153
|
+ return 1;
|
|
154
|
+ }
|
|
155
|
+ return 0;
|
|
156
|
+}
|
|
157
|
+
|
|
158
|
+//Esta funcion trata de coger el numero de caso que se esta buscando, esto es para saber que
|
|
159
|
+//caso del switch para considerar
|
|
160
|
+//LOs casos dependen de lo que esta escrito en cada search bar, cada vez que se escribe en uno nuevo o cuando se borra completamente uno entonces es un caso nuevo
|
|
161
|
+function getcasenum(input,inputarte,inputmuni){
|
|
162
|
+ //this will get the case number
|
|
163
|
+ //think of this as 3 binary numbers where 001 would mean that only its input muni
|
|
164
|
+ //010 is only inputarte and 100 is only input
|
|
165
|
+ //max number is 7
|
|
166
|
+ var casenum = 0;
|
|
167
|
+ if (input.length != 0){
|
|
168
|
+ casenum += 4;
|
|
169
|
+ }
|
|
170
|
+ if (inputarte.length != 0){
|
|
171
|
+ casenum += 2;
|
|
172
|
+ }
|
|
173
|
+ if (inputmuni.length != 0){
|
|
174
|
+ casenum += 1;
|
|
175
|
+ }
|
|
176
|
+ return casenum;
|
|
177
|
+}
|
|
178
|
+
|
|
179
|
+//case 3: artesania y municipio
|
|
180
|
+//Busca todos los artistas que trabajan con esa artesania y en ese municipio
|
|
181
|
+function search_art_mun(inputarte,inputmuni){
|
|
182
|
+ var x = document.getElementsByClassName('artists');
|
|
183
|
+ for (var i = 0; i < all_artesanos.length; i++){
|
|
184
|
+ if (find_artesania(i,inputarte) && find_municipio(i,inputmuni)){
|
|
185
|
+ x[i].style.display = "list-item";
|
|
186
|
+ }
|
|
187
|
+ }
|
|
188
|
+}
|
|
189
|
+
|
|
190
|
+//Busca todos los artistas que salen con el primer input y trabajan en ese municipio
|
|
191
|
+function search_any_mun(input,inputmuni){
|
|
192
|
+ var x = document.getElementsByClassName('artists');
|
|
193
|
+ for (var i = 0; i < all_artesanos.length; i++){
|
|
194
|
+ if(find_any(i,input) && find_municipio(i,inputmuni)){
|
|
195
|
+ x[i].style.display = "list-item";
|
|
196
|
+ }
|
|
197
|
+ }
|
|
198
|
+}
|
|
199
|
+
|
|
200
|
+//Busca todos los artistas que salen con el primer input y trabajan con esa artesania
|
|
201
|
+function search_any_art(input,inputarte){
|
|
202
|
+ var x = document.getElementsByClassName('artists');
|
|
203
|
+ for (var i = 0; i < all_artesanos.length; i++){
|
|
204
|
+ if(find_any(i,input) && find_artesania(i,inputarte)){
|
|
205
|
+ x[i].style.display = "list-item";
|
|
206
|
+ }
|
|
207
|
+ }
|
|
208
|
+}
|
|
209
|
+
|
|
210
|
+//Busca todos los artistas que salen con el primer input, trabajan con esa artesania y trabajan en ese municipio
|
|
211
|
+function search_any_art_mun(input,inputarte,inputmuni){
|
|
212
|
+ var x = document.getElementsByClassName('artists');
|
|
213
|
+ for (var i = 0; i < all_artesanos.length; i++){
|
|
214
|
+ if(find_any(i,input) && find_artesania(i,inputarte) && find_municipio(i,inputmuni)){
|
|
215
|
+ x[i].style.display = "list-item";
|
|
216
|
+ }
|
|
217
|
+ }
|
|
218
|
+}
|
|
219
|
+
|
|
220
|
+//Replacing special characters with non special characters in case input doesnt include it
|
|
221
|
+function acento_replace(string){
|
|
222
|
+ var precstring = "";
|
|
223
|
+ var poststring = "";
|
|
224
|
+ for( i = 0; i < string.length ; i++){
|
|
225
|
+ if (string.charAt(i) == 'á' || string.charAt(i) == 'é' || string.charAt(i) == 'í'|| string.charAt(i) == 'ó' || string.charAt(i) == 'ú' || string.charAt(i) == 'ü' || string.charAt(i) == 'ñ' || string.charAt(i) == 'ö'){
|
|
226
|
+ precstring = string.slice(0,i);
|
|
227
|
+ postcstring = "";
|
|
228
|
+ if(i != string.length-1){
|
|
229
|
+ postcstring = string.slice(i+1,string.length);
|
|
230
|
+ }
|
|
231
|
+ switch(string.charAt(i)){
|
|
232
|
+ case 'á':
|
|
233
|
+ string = precstring.concat('a',postcstring);
|
|
234
|
+ break;
|
|
235
|
+ case 'é':
|
|
236
|
+ string = precstring.concat('e',postcstring);
|
|
237
|
+ break;
|
|
238
|
+ case 'í':
|
|
239
|
+ string = precstring.concat('i',postcstring);
|
|
240
|
+ break;
|
|
241
|
+ case 'ó':
|
|
242
|
+ string = precstring.concat('o',postcstring);
|
|
243
|
+ break;
|
|
244
|
+ case 'ú':
|
|
245
|
+ string = precstring.concat('u',postcstring);
|
|
246
|
+ break;
|
|
247
|
+ case 'ü':
|
|
248
|
+ string = precstring.concat('u',postcstring);
|
|
249
|
+ break;
|
|
250
|
+ case 'ñ':
|
|
251
|
+ string = precstring.concat('n',postcstring);
|
|
252
|
+ break;
|
|
253
|
+ case 'ö':
|
|
254
|
+ string = precstring.concat('o',postcstring);
|
|
255
|
+ break;
|
|
256
|
+ }
|
|
257
|
+ }
|
|
258
|
+ }
|
|
259
|
+ return string;
|
|
260
|
+}
|