Created
January 22, 2014 23:07
-
-
Save jansanchez/8569305 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Modulo para cargar los tags leyendo desde la cookie "search" | |
@class generateTags | |
@main empresas | |
@author Jan Sanchez | |
*/ | |
yOSON.AppCore.addModule('generateTags', function(Sb) { | |
/** | |
Object to store the dom of this module | |
@property dom | |
@type Object | |
@default "{}" | |
*/ | |
var addNew, addObject, afterCatchDom, catchDom, collection, dom, findAnotherChilds, getCategoryName, getNamePlace, initialize, loadTags, seekFor, seekForCriteria, st, suscribeEvents, updateAll; | |
dom = {}; | |
/** | |
Array to store the objects of this module | |
@property collection | |
@type Array | |
@default "[]" | |
*/ | |
collection = []; | |
/** | |
Main settings of the module(these can be overridden) | |
@property st | |
@type Object | |
@default "{}" | |
*/ | |
st = { | |
container: '#divTagsListSearch', | |
list: 'ul', | |
"delete": 'a', | |
divOtherOptions: '#divOtherOptions', | |
btnUpdate: '#btnUpdate', | |
ulLocations: '#ulLocations', | |
tpl: '#tplTags', | |
HTMLtpl: null, | |
limit: 0, | |
flag: true, | |
places: yOSON.search.fields.ubicacion, | |
playas: yOSON.search.fields.playas, | |
arrDepartament: [], | |
arrProvince: [], | |
arrDistrito: [], | |
arrDepartament2: [], | |
arrProvince2: [], | |
arrDistrito2: [] | |
}; | |
/** | |
Function to store the DOM to start the module (only runs once) | |
@method catchDom | |
@return {null} | |
*/ | |
catchDom = function() { | |
dom.container = $(st.container); | |
dom.list = $(st.list, st.container); | |
dom.ulLocations = $(st.ulLocations); | |
dom.divOtherOptions = $(st.divOtherOptions); | |
dom.btnUpdate = $(st.btnUpdate, dom.divOtherOptions); | |
dom.tpl = $(st.tpl); | |
}; | |
/** | |
Function to store the template we will use in our module (only runs once) | |
@method afterCatchDom | |
@return {null} | |
*/ | |
afterCatchDom = function() { | |
var _ref; | |
st.HTMLtpl = (_ref = st.HTMLtpl) != null ? _ref : $.trim(dom.tpl.html()); | |
}; | |
/** | |
Función para suscribir los eventos del modulo (solo se ejecuta una vez) | |
@method suscribeEvents | |
@return {null} | |
*/ | |
suscribeEvents = function() { | |
dom.btnUpdate.on('click', updateAll); | |
}; | |
/** | |
Function para agregar un nuevo objeto a.k.a (etiqueta) | |
@method updateAll | |
@return {null} | |
*/ | |
updateAll = function(e) { | |
var $divKm, $txtDesde, $txtHasta, range; | |
range = true; | |
$divKm = $('#divKm'); | |
$txtDesde = $('#txtKmDesde', $divKm); | |
$txtHasta = $('#txtKmHasta', $divKm); | |
if ($txtDesde.val() === '' && $txtHasta.val() === '') { | |
range = false; | |
} | |
if (range === true) { | |
$txtDesde.trigger('blur'); | |
$txtHasta.trigger('blur'); | |
if (Number($txtDesde.val()) >= Number($txtHasta.val())) { | |
warn('Distancia de Lima: El rango ingresado no es correcto.'); | |
return false; | |
} | |
} | |
Sb.trigger('GenerateUrlexecute'); | |
}; | |
/** | |
Function to obtener el nombre normalizado de la categoria | |
@method getCategoryName | |
@return {String} | |
*/ | |
getCategoryName = function(category) { | |
var nameNormalized; | |
nameNormalized = ''; | |
switch (category) { | |
case yOSON.search.estado: | |
nameNormalized = 'Estado'; | |
break; | |
case yOSON.search.localizado: | |
nameNormalized = 'Localizado'; | |
break; | |
case yOSON.search.tipoInmueble: | |
nameNormalized = 'Tipo de Inmueble'; | |
break; | |
case yOSON.search.precio: | |
nameNormalized = 'Precio'; | |
break; | |
case yOSON.search.habitaciones: | |
nameNormalized = 'Habitaciones'; | |
break; | |
case yOSON.search.antiguedad: | |
nameNormalized = 'Antiguedad'; | |
break; | |
case yOSON.search.bath: | |
nameNormalized = 'Baño(s)'; | |
break; | |
case yOSON.search.cocheras: | |
nameNormalized = 'Cochera(s)'; | |
break; | |
case yOSON.search.publicacion: | |
nameNormalized = 'Publicación'; | |
break; | |
case yOSON.search.areaTotal: | |
nameNormalized = 'Área Total'; | |
break; | |
case yOSON.search.areaConstruida: | |
nameNormalized = 'Área Construida'; | |
break; | |
case yOSON.search.servicios: | |
nameNormalized = 'Servicios'; | |
break; | |
case yOSON.search.camas: | |
nameNormalized = 'Camas'; | |
break; | |
case yOSON.search.fila: | |
nameNormalized = 'Fila'; | |
break; | |
case yOSON.search.estadia: | |
nameNormalized = 'Estadía'; | |
break; | |
case yOSON.search.empresasAgentes: | |
nameNormalized = 'Empresas/Agentes'; | |
break; | |
case yOSON.search.distancia: | |
nameNormalized = 'Distancia de Lima'; | |
break; | |
case yOSON.search.fecha: | |
nameNormalized = 'Fecha'; | |
break; | |
case yOSON.search.playas: | |
nameNormalized = 'Playas'; | |
break; | |
case yOSON.search.keyword: | |
nameNormalized = 'Búsqueda libre'; | |
break; | |
case yOSON.search.projectState: | |
nameNormalized = 'Estado del Proyecto'; | |
break; | |
default: | |
nameNormalized = category; | |
} | |
return nameNormalized + ': '; | |
}; | |
/** | |
Funcion para obtener el nombre Original de la ubicacion | |
@method getNamePlace | |
@return {String} | |
*/ | |
getNamePlace = function(place) { | |
var originalName; | |
switch (place) { | |
case st.places[place]: | |
originalName = 'Departamento'; | |
break; | |
case st.places[place]: | |
originalName = 'Provincia'; | |
break; | |
case st.places[place]: | |
originalName = 'Distrito'; | |
break; | |
case st.places[place]: | |
originalName = 'Urbanización'; | |
break; | |
default: | |
originalName = 'Desconocido'; | |
} | |
return originalName; | |
}; | |
/** | |
Function to load cookies | |
@method loadTags | |
@return {null} | |
*/ | |
loadTags = function() { | |
var ancestor, ancestorName, ancestors, category, departament, distance, distanceField, district, field, haveMain, i, id, id2, indice, j, k, nombreCategoria, object, priceField, province, tipoInmueble, type, value, value2, _i, _j, _k, _l, _len, _len1, _len10, _len11, _len12, _len13, _len14, _len2, _len3, _len4, _len5, _len6, _len7, _len8, _len9, _m, _n, _o, _p, _q, _r, _ref, _ref1, _ref10, _ref11, _ref12, _ref13, _ref14, _ref15, _ref16, _ref17, _ref18, _ref19, _ref2, _ref20, _ref21, _ref22, _ref23, _ref24, _ref25, _ref26, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _s, _t, _u, _v, _w; | |
if (Cookie.read('search')) { | |
collection = []; | |
collection = $.parseJSON(Cookie.read('search')); | |
for (category in collection) { | |
id = ''; | |
value = ''; | |
type = ''; | |
switch (category) { | |
case yOSON.search.fecha: | |
if (collection[category][yOSON.search.fields.fecha.opcion1][0]) { | |
if (collection[category][yOSON.search.fields.fecha.opcion1].length > 0) { | |
id = collection[category][yOSON.search.fields.fecha.opcion1][0].id; | |
value = collection[category][yOSON.search.fields.fecha.opcion1][0].value; | |
if (!(id === '*' || id === '[*]' || id === '[* TO *]')) { | |
addNew(id, value, type, category, getCategoryName(category)); | |
} | |
} else { | |
} | |
} else { | |
} | |
break; | |
case yOSON.search.localizado: | |
case yOSON.search.antiguedad: | |
case yOSON.search.camas: | |
case yOSON.search.habitaciones: | |
case yOSON.search.fila: | |
case yOSON.search.projectState: | |
if (collection[category].length > 0) { | |
id = collection[category][0].id; | |
value = collection[category][0].value; | |
if (!(id === '*' || id === '[*]' || id === '[* TO *]')) { | |
addNew(id, value, type, category, getCategoryName(category)); | |
} | |
} | |
break; | |
case yOSON.search.cocheras: | |
case yOSON.search.bath: | |
if (collection[category].length > 0) { | |
id = collection[category][0].id; | |
value = collection[category][0].value; | |
if (!(id === '*' || id === '[*]' || id === '[* TO *]')) { | |
if (id === '1') { | |
nombreCategoria = getCategoryName(category).replace('(s)', ''); | |
} else { | |
nombreCategoria = getCategoryName(category); | |
} | |
addNew(id, value, type, category, nombreCategoria); | |
} | |
} | |
break; | |
case yOSON.search.estado: | |
if (collection[category].length > 0) { | |
id = collection[category][0].id; | |
value = collection[category][0].value; | |
if (!(id === '*' || id === '[*]' || id === '[* TO *]')) { | |
addNew(id, value, type, category, getCategoryName(category)); | |
} | |
} | |
break; | |
case yOSON.search.tipoInmueble: | |
case yOSON.search.publicacion: | |
case yOSON.search.servicios: | |
case yOSON.search.empresasAgentes: | |
case yOSON.search.areaTotal: | |
case yOSON.search.areaConstruida: | |
case yOSON.search.estadia: | |
if (collection[category].length > 0) { | |
haveMain = false; | |
_ref = collection[category]; | |
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
tipoInmueble = _ref[_i]; | |
id = tipoInmueble.id; | |
value = tipoInmueble.value; | |
if (!(id === '*' || id === '[*]' || id === '[* TO *]')) { | |
addNew(id, value, type, category, getCategoryName(category)); | |
} else { | |
haveMain = true; | |
field = tipoInmueble; | |
} | |
} | |
} | |
break; | |
case yOSON.search.ubicacion: | |
_ref1 = st.places; | |
for (j = _j = 0, _len1 = _ref1.length; _j < _len1; j = ++_j) { | |
field = _ref1[j]; | |
_ref2 = collection[category][j][field]; | |
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { | |
object = _ref2[_k]; | |
ancestorName = ''; | |
id = object.id; | |
value = (_ref3 = object.value) != null ? _ref3 : ''; | |
value = value.toLowerCase().replace(/-/gi, " "); | |
type = (_ref4 = object.type) != null ? _ref4 : ''; | |
ancestors = (_ref5 = object.ancestors) != null ? _ref5 : ''; | |
for (i = _l = 0, _len3 = ancestors.length; _l < _len3; i = ++_l) { | |
ancestor = ancestors[i]; | |
ancestor.value = ancestor.value.toLowerCase().replace(/-/gi, " "); | |
ancestorName += ancestor.value + ' - '; | |
if (i === 0) { | |
if (seekFor(ancestor.id, st.arrDepartament) === -1) { | |
st.arrDepartament.push(ancestor.id); | |
} | |
} | |
if (i === 1) { | |
if (seekFor(ancestor.id, st.arrProvince) === -1) { | |
st.arrProvince.push(ancestor.id); | |
} | |
} | |
if (i === 2) { | |
if (seekFor(ancestor.id, st.arrDistrito) === -1) { | |
st.arrDistrito.push(ancestor.id); | |
} | |
} | |
} | |
if (ancestorName === '') { | |
switch (type) { | |
case 0: | |
ancestorName = 'Departamento: '; | |
break; | |
case 1: | |
ancestorName = 'Provincia: '; | |
break; | |
default: | |
ancestorName = 'Ubicación: '; | |
} | |
} | |
addNew(id, value, type, category, ancestorName); | |
} | |
} | |
_ref6 = st.places; | |
for (k = _m = 0, _len4 = _ref6.length; _m < _len4; k = ++_m) { | |
field = _ref6[k]; | |
if (k === 0) { | |
_ref7 = collection[category][k][field]; | |
for (_n = 0, _len5 = _ref7.length; _n < _len5; _n++) { | |
departament = _ref7[_n]; | |
if (st.arrDepartament.length > 0) { | |
if (departament.type === 0) { | |
indice = seekFor(departament.id, st.arrDepartament); | |
if (indice !== -1) { | |
$('li', dom.container).each(function(i, e) { | |
if ($(e).data('type') === departament.type && $(e).data('id') === departament.id) { | |
$(e).fadeOut(); | |
$(e).remove(); | |
} | |
}); | |
$('li', dom.ulLocations).each(function(i, e) { | |
if ($(e).data('type') === departament.type && $(e).data('id') === departament.id) { | |
$(e).fadeOut(); | |
$(e).remove(); | |
} | |
}); | |
} | |
} | |
} | |
} | |
} | |
if (k === 1) { | |
_ref8 = collection[category][k][field]; | |
for (_o = 0, _len6 = _ref8.length; _o < _len6; _o++) { | |
province = _ref8[_o]; | |
if (st.arrProvince.length > 0) { | |
if (province.type === 1) { | |
indice = seekFor(province.id, st.arrProvince); | |
if (indice !== -1) { | |
$('li', dom.container).each(function(i, e) { | |
if ($(e).data('type') === province.type && $(e).data('id') === province.id) { | |
$(e).fadeOut(); | |
$(e).remove(); | |
} | |
}); | |
$('li', dom.ulLocations).each(function(i, e) { | |
if ($(e).data('type') === province.type && $(e).data('id') === province.id) { | |
$(e).fadeOut(); | |
$(e).remove(); | |
} | |
}); | |
} | |
} | |
} | |
} | |
} | |
if (k === 2) { | |
_ref9 = collection[category][k][field]; | |
for (_p = 0, _len7 = _ref9.length; _p < _len7; _p++) { | |
district = _ref9[_p]; | |
if (st.arrDistrito.length > 0) { | |
if (district.type === 2) { | |
indice = seekFor(district.id, st.arrDistrito); | |
if (indice !== -1) { | |
$('li', dom.container).each(function(i, e) { | |
if ($(e).data('type') === district.type && $(e).data('id') === district.id) { | |
$(e).fadeOut(); | |
$(e).remove(); | |
} | |
}); | |
$('li', dom.ulLocations).each(function(i, e) { | |
if ($(e).data('type') === district.type && $(e).data('id') === district.id) { | |
$(e).fadeOut(); | |
$(e).remove(); | |
} | |
}); | |
} | |
} | |
} | |
} | |
} | |
} | |
break; | |
case yOSON.search.playas: | |
_ref10 = st.playas; | |
for (j = _q = 0, _len8 = _ref10.length; _q < _len8; j = ++_q) { | |
field = _ref10[j]; | |
_ref11 = collection[category][j][field]; | |
for (_r = 0, _len9 = _ref11.length; _r < _len9; _r++) { | |
object = _ref11[_r]; | |
ancestorName = ''; | |
id = object.id; | |
value = (_ref12 = object.value) != null ? _ref12 : ''; | |
value = value.toLowerCase().replace(/-/gi, " "); | |
type = (_ref13 = object.type) != null ? _ref13 : ''; | |
ancestors = (_ref14 = object.ancestors) != null ? _ref14 : ''; | |
for (i = _s = 0, _len10 = ancestors.length; _s < _len10; i = ++_s) { | |
ancestor = ancestors[i]; | |
ancestor.value = ancestor.value.toLowerCase().replace(/-/gi, " "); | |
ancestorName += ancestor.value + ' - '; | |
if (i === 0) { | |
if (seekFor(ancestor.id, st.arrDepartament) === -1) { | |
st.arrDepartament.push(ancestor.id); | |
} | |
} | |
if (i === 1) { | |
if (seekFor(ancestor.id, st.arrProvince) === -1) { | |
st.arrProvince.push(ancestor.id); | |
} | |
} | |
if (i === 2) { | |
if (seekFor(ancestor.id, st.arrDistrito) === -1) { | |
st.arrDistrito.push(ancestor.id); | |
} | |
} | |
} | |
if (ancestorName === '') { | |
switch (type) { | |
case 0: | |
ancestorName = 'Departamento: '; | |
break; | |
case 1: | |
ancestorName = 'Provincia: '; | |
break; | |
case 2: | |
ancestorName = 'Distrito: '; | |
break; | |
default: | |
ancestorName = 'Playa: '; | |
} | |
} | |
addNew(id, value, type, category, ancestorName); | |
} | |
} | |
_ref15 = st.playas; | |
for (k = _t = 0, _len11 = _ref15.length; _t < _len11; k = ++_t) { | |
field = _ref15[k]; | |
if (k === 0) { | |
_ref16 = collection[category][k][field]; | |
for (_u = 0, _len12 = _ref16.length; _u < _len12; _u++) { | |
departament = _ref16[_u]; | |
if (st.arrDepartament.length > 0) { | |
if (departament.type === 0) { | |
indice = seekFor(departament.id, st.arrDepartament); | |
if (indice !== -1) { | |
$('li', dom.container).each(function(i, e) { | |
if ($(e).data('type') === departament.type && $(e).data('id') === departament.id) { | |
$(e).fadeOut(); | |
$(e).remove(); | |
} | |
}); | |
$('li', dom.ulLocations).each(function(i, e) { | |
if ($(e).data('type') === departament.type && $(e).data('id') === departament.id) { | |
$(e).fadeOut(); | |
$(e).remove(); | |
} | |
}); | |
} | |
} | |
} | |
} | |
} | |
if (k === 1) { | |
_ref17 = collection[category][k][field]; | |
for (_v = 0, _len13 = _ref17.length; _v < _len13; _v++) { | |
province = _ref17[_v]; | |
if (st.arrProvince.length > 0) { | |
if (province.type === 1) { | |
indice = seekFor(province.id, st.arrProvince); | |
if (indice !== -1) { | |
$('li', dom.container).each(function(i, e) { | |
if ($(e).data('type') === province.type && $(e).data('id') === province.id) { | |
$(e).fadeOut(); | |
$(e).remove(); | |
} | |
}); | |
$('li', dom.ulLocations).each(function(i, e) { | |
if ($(e).data('type') === province.type && $(e).data('id') === province.id) { | |
$(e).fadeOut(); | |
$(e).remove(); | |
} | |
}); | |
} | |
} | |
} | |
} | |
} | |
if (k === 2) { | |
_ref18 = collection[category][k][field]; | |
for (_w = 0, _len14 = _ref18.length; _w < _len14; _w++) { | |
district = _ref18[_w]; | |
if (st.arrDistrito.length > 0) { | |
if (district.type === 2) { | |
indice = seekFor(district.id, st.arrDistrito); | |
if (indice !== -1) { | |
$('li', dom.container).each(function(i, e) { | |
if ($(e).data('type') === district.type && $(e).data('id') === district.id) { | |
$(e).fadeOut(); | |
$(e).remove(); | |
} | |
}); | |
$('li', dom.ulLocations).each(function(i, e) { | |
if ($(e).data('type') === district.type && $(e).data('id') === district.id) { | |
$(e).fadeOut(); | |
$(e).remove(); | |
} | |
}); | |
} | |
} | |
} | |
} | |
} | |
} | |
break; | |
case yOSON.search.keyword: | |
id = collection[category]; | |
value = id; | |
addNew(id, value, type, category, getCategoryName(category)); | |
break; | |
} | |
if (category === yOSON.search.precio) { | |
for (priceField in collection[yOSON.search.precio]) { | |
switch (priceField) { | |
case yOSON.search.fields.precio.moneda: | |
if (collection[category][yOSON.search.fields.precio.moneda].length > 0) { | |
id = (_ref19 = collection[category][yOSON.search.fields.precio.moneda][0].id + '|') != null ? _ref19 : ''; | |
value = (_ref20 = collection[category][yOSON.search.fields.precio.moneda][0].value + ' ') != null ? _ref20 : ''; | |
} else { | |
} | |
break; | |
case yOSON.search.fields.precio.opcion1: | |
if (collection[category][yOSON.search.fields.precio.opcion1].length > 0) { | |
id += (_ref21 = collection[category][yOSON.search.fields.precio.opcion1][0].id + '|') != null ? _ref21 : ''; | |
value += (_ref22 = collection[category][yOSON.search.fields.precio.opcion1][0].value + ' ') != null ? _ref22 : ''; | |
if (collection[category][yOSON.search.fields.precio.opcion1][0].id !== '*') { | |
addNew(id, value, type, category, getCategoryName(category)); | |
} | |
} else { | |
} | |
break; | |
} | |
} | |
} | |
} | |
distance = yOSON.search.distancia; | |
id = ''; | |
id2 = ''; | |
value = ''; | |
value2 = ''; | |
for (distanceField in collection[distance]) { | |
switch (distanceField) { | |
case yOSON.search.fields.distancia.orientacion: | |
if (collection[distance][yOSON.search.fields.distancia.orientacion][0]) { | |
id = (_ref23 = collection[distance][yOSON.search.fields.distancia.orientacion][0].id + '|') != null ? _ref23 : ''; | |
value = (_ref24 = collection[distance][yOSON.search.fields.distancia.orientacion][0].value + ' ') != null ? _ref24 : ''; | |
} else { | |
} | |
break; | |
case yOSON.search.fields.distancia.opcion1: | |
if (collection[distance][yOSON.search.fields.distancia.opcion1][0]) { | |
id2 = (_ref25 = collection[distance][yOSON.search.fields.distancia.opcion1][0].id + '|') != null ? _ref25 : ''; | |
value2 = (_ref26 = collection[distance][yOSON.search.fields.distancia.opcion1][0].value + ' ') != null ? _ref26 : ''; | |
} else { | |
} | |
break; | |
} | |
if (id !== '' && id2 !== '' && value !== '' && value2 !== '') { | |
id2 = id2 + id; | |
value2 = value2 + value; | |
addNew(id2, value2, type, distance, getCategoryName(distance)); | |
} | |
} | |
return; | |
} | |
}; | |
/** | |
Funcion para buscar dentro de la cookie | |
@method seekFor | |
@return {} | |
*/ | |
seekFor = function(needle, haystack) { | |
var i, placeObject, _i, _len; | |
if (haystack === []) { | |
return -1; | |
} | |
for (i = _i = 0, _len = haystack.length; _i < _len; i = ++_i) { | |
placeObject = haystack[i]; | |
if (placeObject.toString() === needle.toString()) { | |
return i; | |
} | |
} | |
return -1; | |
}; | |
/** | |
Funcion para buscar dentro de la cookie | |
@method seekForCriteria | |
@return {} | |
*/ | |
seekForCriteria = function(needle, haystack, criteria) { | |
var i, placeObject, _i, _len; | |
if (haystack === []) { | |
return -1; | |
} | |
for (i = _i = 0, _len = haystack.length; _i < _len; i = ++_i) { | |
placeObject = haystack[i]; | |
if (placeObject[criteria.toString()].toString() === needle.toString()) { | |
return i; | |
} | |
} | |
return -1; | |
}; | |
/** | |
Funcion para buscar recursivamente en generateTags | |
@method findAnotherChilds | |
@return {} | |
*/ | |
findAnotherChilds = function(category, idChild, level, total) { | |
var cLAnId, cLId, current, currentArray, currentLocation, indice, otherChilds, places, response, upperLevel, _i, _len; | |
if (total == null) { | |
total = []; | |
} | |
otherChilds = 0; | |
collection = $.parseJSON(Cookie.read('search')); | |
places = st.places; | |
if (category !== yOSON.search.ubicacion) { | |
places = st.playas; | |
} | |
currentArray = collection[category][level][places[level]]; | |
upperLevel = level - 1; | |
indice = seekForCriteria(idChild, currentArray, 'id'); | |
if (upperLevel === -1) { | |
return false; | |
} else { | |
currentLocation = currentArray[indice]; | |
cLId = currentLocation.id; | |
cLAnId = currentLocation.ancestors[upperLevel].id; | |
for (_i = 0, _len = currentArray.length; _i < _len; _i++) { | |
current = currentArray[_i]; | |
if (current.id !== cLId && current.ancestors[upperLevel].id === cLAnId) { | |
otherChilds++; | |
} | |
} | |
response = { | |
upperLevel: upperLevel, | |
cLAnId: cLAnId, | |
otherChilds: otherChilds | |
}; | |
total.push(response); | |
if (response.upperLevel > 0 && response.otherChilds === 0) { | |
return findAnotherChilds(category, response.cLAnId, response.upperLevel, total); | |
} else { | |
return total; | |
} | |
} | |
}; | |
/** | |
Funcion para agregar un objeto al array de tipos de inmueble | |
@method addObject | |
@param {Object} newObject Objeto que contiene la data para reemplazar en la plantilla | |
@param {Boolean} validate Booleano para indicar si validaremos algunas condicionales de esta funcion | |
@return {null} | |
*/ | |
addObject = function(newObject, validate) { | |
var $current, compiled_template, html, | |
_this = this; | |
if (validate == null) { | |
validate = true; | |
} | |
compiled_template = _.template(st.HTMLtpl); | |
html = compiled_template(newObject); | |
$current = $(html); | |
$current.on('click', "a", function(e) { | |
var $el, category, field, i, index, indiceLoc, place, placeObject, r, result, tipoInmueble, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2; | |
$el = $(e.target).parent(); | |
collection = $.parseJSON(Cookie.read('search')); | |
index = -1; | |
category = $el.data('category'); | |
switch (category) { | |
case yOSON.search.localizado: | |
case yOSON.search.estado: | |
case yOSON.search.antiguedad: | |
case yOSON.search.camas: | |
case yOSON.search.cocheras: | |
case yOSON.search.habitaciones: | |
case yOSON.search.fila: | |
case yOSON.search.projectState: | |
case yOSON.search.bath: | |
collection[category] = []; | |
break; | |
case yOSON.search.tipoInmueble: | |
case yOSON.search.publicacion: | |
case yOSON.search.servicios: | |
case yOSON.search.empresasAgentes: | |
case yOSON.search.areaTotal: | |
case yOSON.search.areaConstruida: | |
case yOSON.search.estadia: | |
_ref = collection[category]; | |
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { | |
tipoInmueble = _ref[i]; | |
if (tipoInmueble.id.toString() === $el.data('id').toString()) { | |
index = i; | |
break; | |
} | |
} | |
if (index !== -1) { | |
collection[category].splice(index, 1); | |
} | |
break; | |
case yOSON.search.precio: | |
case yOSON.search.fecha: | |
case yOSON.search.distancia: | |
for (field in collection[category]) { | |
collection[category][field] = []; | |
} | |
break; | |
case yOSON.search.ubicacion: | |
place = st.places[Number($el.data('type'))]; | |
index = -1; | |
_ref1 = collection[yOSON.search.ubicacion][Number($el.data('type'))][place]; | |
for (i = _j = 0, _len1 = _ref1.length; _j < _len1; i = ++_j) { | |
placeObject = _ref1[i]; | |
if (placeObject.id.toString() === $el.data('id').toString()) { | |
index = i; | |
break; | |
} | |
} | |
if (index !== -1) { | |
result = findAnotherChilds(category, $el.data('id'), Number($el.data('type'))); | |
for (_k = 0, _len2 = result.length; _k < _len2; _k++) { | |
r = result[_k]; | |
if (r.otherChilds === 0) { | |
indiceLoc = seekForCriteria(r.cLAnId, collection[yOSON.search.ubicacion][Number(r.upperLevel)][st.places[Number(r.upperLevel)]], 'id'); | |
collection[yOSON.search.ubicacion][Number(r.upperLevel)][st.places[Number(r.upperLevel)]].splice(indiceLoc, 1); | |
} | |
} | |
collection[yOSON.search.ubicacion][Number($el.data('type'))][place].splice(index, 1); | |
} | |
break; | |
case yOSON.search.playas: | |
place = st.playas[Number($el.data('type'))]; | |
index = -1; | |
_ref2 = collection[yOSON.search.playas][Number($el.data('type'))][place]; | |
for (i = _l = 0, _len3 = _ref2.length; _l < _len3; i = ++_l) { | |
placeObject = _ref2[i]; | |
if (placeObject.id.toString() === $el.data('id').toString()) { | |
index = i; | |
break; | |
} | |
} | |
if (index !== -1) { | |
result = findAnotherChilds(category, $el.data('id'), Number($el.data('type'))); | |
for (_m = 0, _len4 = result.length; _m < _len4; _m++) { | |
r = result[_m]; | |
if (r.otherChilds === 0) { | |
indiceLoc = seekForCriteria(r.cLAnId, collection[yOSON.search.playas][Number(r.upperLevel)][st.playas[Number(r.upperLevel)]], 'id'); | |
collection[yOSON.search.playas][Number(r.upperLevel)][st.playas[Number(r.upperLevel)]].splice(indiceLoc, 1); | |
} | |
} | |
collection[yOSON.search.playas][Number($el.data('type'))][place].splice(index, 1); | |
} | |
break; | |
case yOSON.search.keyword: | |
collection[category] = ""; | |
break; | |
} | |
Cookie.create('search', JSON.stringify(collection)); | |
$el.fadeOut(); | |
Sb.trigger('GenerateUrlexecute'); | |
}); | |
if (dom.list.hasClass('slvzr-empty')) { | |
dom.list.removeClass('slvzr-empty'); | |
} | |
dom.list.append($current); | |
$current.fadeIn().css('display', 'block'); | |
}; | |
/** | |
Function para agregar un nuevo objeto a.k.a (etiqueta) | |
@method addNew | |
@return {null} | |
*/ | |
addNew = function(id, value, type, category, categoryname) { | |
var newObject; | |
if (value == null) { | |
value = ''; | |
} | |
if (type == null) { | |
type = ''; | |
} | |
if (id !== '') { | |
switch (category) { | |
case yOSON.search.estado: | |
case yOSON.search.localizado: | |
category = ''; | |
break; | |
} | |
if (browser.msie) { | |
value = value.removeAccents(); | |
value = value.removeSigns(); | |
} | |
newObject = { | |
id: id, | |
value: value, | |
type: type, | |
category: category, | |
categoryname: categoryname | |
}; | |
addObject(newObject); | |
} | |
}; | |
/** | |
Initialize the module | |
@event initialize | |
@param {Object} oP Le pasamos un objeto con los valores que reemplazaremos por st | |
@return {null} | |
*/ | |
initialize = function(oP) { | |
$(document).ready(function() { | |
$.extend(st, oP); | |
catchDom(); | |
afterCatchDom(); | |
suscribeEvents(); | |
return loadTags(); | |
}); | |
}; | |
return { | |
/** | |
Init the module | |
@event init | |
@return {null} | |
*/ | |
init: initialize | |
}; | |
}, ['backbone/libs/underscore/underscore.js']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment