// JavaScript Document var Filter = function(e, c){ this.init(e, c); }; p = Filter.prototype; //PROPs p.oLayer = null; p.req = null; p.iInterval = 0; p.bStopOut = false; p.sSearched = '?&^$%#@'; p.aOptions = null; p.oSelected = null; p.onSelected = null; p.onMissed = null; p.onRespone = null;//Agregado para poder volver el bAutoSelect a true despues del foco p.sImgDir = ''; // p.bSearching = false; p.bShowEmpty = true;//Agregado para evitar que se muestre el mensaje vacion p.bAutoSelect = true;//Agregado por que cuando se agrega que directamente en el foco mueste la lista y tenia uno solo se seleccionaba automaticamente p.oEmpty = null; p.oLoader = null; p.oCurOpt = null; //METs p.init = function(ele, conf){ var e = null; if(!ele || typeof(ele) != 'object'){ return alert("Filter.ini: Elemento inexistente"); } else if(!conf || typeof(conf) != 'object'){ return alert("Filter.ini: Configuración incompleta"); } this.oEle = ele; this.oConf = conf; this.aOptions = new Array; if(!!this.oConf['sImgDir']){ this.sImgDir = this.oConf['sImgDir']; } this.oLayer = document.createElement('div'); this.oEle.parentNode.insertBefore(this.oLayer, this.oEle); this.oLayer.className = 'FiltradorLayer'; this.oEmpty = document.createElement('div'); this.oEle.parentNode.insertBefore(this.oEmpty, this.oEle); this.oEmpty.innerHTML = 'No se encontraron registros.'; this.oEmpty.className = 'FiltradorEmpty'; this.oLoader = document.createElement('div'); this.oEle.parentNode.insertBefore(this.oLoader, this.oEle); this.oLoader.innerHTML = ' Cargando...'; this.oLoader.className = 'FiltradorLoader'; if(!!this.oConf['iWidth']){ this.oLayer.style.width = this.oConf['iWidth'] + 'px'; } this.req = new Request(); this.req.listener = this.getResponse.closure(this); AddEvent(this.oEle, 'keydown', this.filter.closure(this)); AddEvent(this.oEle, 'blur', this.onBlur.closure(this)); AddEvent(this.oEle, 'dblclick', this.onDblclick.closure(this)); AddEvent(this.oEle, 'focus', this.onFocus.closure(this)); AddEvent(this.oLayer, 'focus', this.showLayer.closure(this)); AddEvent(this.oLayer, 'keydown', this.onEscape.closure(this)); AddEvent(this.oLayer, 'mousedown', this.onMouseDown.closure(this)); }; // p.getResponse = function(){ var d = this.req.respuestaXML, i = 0; this.bSearching = false; this.hideLoader(); if(!d){ return alert('Filter.getResponse: Respuesta XML inválida (' + this.req.respuestaHTML + ').'); } if(d.childNodes.length < 1){ if(this.bShowEmpty){ this.showEmpty(); } if(this.onMissed != null){ this.onMissed(); } } else{ for(i; i < d.childNodes.length; i++){ this.addOption(d.childNodes[i]); } if(i == 1 && this.bAutoSelect && this.oEle.value != ''){ this.selectOption(this.aOptions[0], true); } else{ this.showLayer(); } } if(!!this.onRespone){ this.onRespone(); } d = i = null; }; // p.filter = function(e, dbl){ if(!!e){ //enter if(e.keyCode == 13 || dbl == true){ this.search(); } //abajo o arriba y tuvimos exito en la busqueda else if((e.keyCode == 40 || e.keyCode == 38) && this.aOptions.length > 0){ this.showLayer(); this.move(e); } //escape else if(e.keyCode == 27){ this.escape(false); } } }; p.search = function(){ if(this.oEle.__msjVacio == this.oEle.value){ this.oEle.value = ''; } if(this.oEle.value != this.sSearched){ if(this.bSearching){ return false; } this.bSearching = true; this.hideLayer(); this.cleanOptions(); this.sSearched = this.oEle.value; this.hideEmpty(); this.showLoader(); this.req.pedir(this.oConf['sFile'], 'clave' + SEP_IGUAL + this.sSearched + SEP_AND); } else if(this.aOptions.length > 0){ this.showLayer(); } }; // p.showLayer = function(){ this.oLayer.style.marginTop = this.oEle.offsetHeight + 'px'; if(!this.oConf['iWidth']){ this.oLayer.style.width = this.input.offsetWidth + 'px'; } this.oLayer.style.display = 'block'; }; p.hideLayer = function(){ this.oLayer.style.display = 'none'; }; // p.onDblclick = function(e){ this.filter(e, true); }; p.onBlur = function(e){ if(this.iInterval != 0){ this.stopOut(); } this.hideEmpty(); if(this.oEle.value != '' && this.oEle.value != this.oEle.__msjVacio){ if(!this.oSelected && this.oEle.value == this.sSearched){ this.showLayer(); } else if(this.oEle.value != this.sSearched){ this.search(); } } else{ if(this.onMissed != null){ this.onMissed(); } this.iInterval = window.setTimeout(this.out.closure(this), 10); } }; p.onEscape = function(e){ if(e.keyCode == 27){ this.escape(false); } }; p.onMouseDown = function(){ this.bStopOut = true; try{ this.oEle.focus(); } catch(e){}; }; p.onFocus = function(){ this.oEle.select(); }; // p.out = function(){ if(!this.bStopOut){ this.hideLayer(); this.stopOut(); if(this.oEle.value != '' && this.oEle.value != this.sSearched){ this.unselect(); if(!!this.onMissed){ this.onMissed(); } if(this.oEle.__msjVacio != ''){ this.oEle.value = this.oEle.__msjVacio; } } } else{ this.bStopOut = false; try{ this.oEle.focus(); } catch(e){}; } }; p.stopOut = function(){ if(this.iInterval){ window.clearTimeout(this.iInterval); this.iInterval = 0; } }; p.escape = function(b){ if(!b){ try{ this.oEle.focus(); } catch(e){}; } this.hideLayer(); if(this.oCurOpt != null){ this.oCurOpt.oEle.className = 'FiltradorOpcionOff'; this.oCurOpt = null; } }; // p.addOption = function(e){ var o = new Object, i = 0; o.oEle = document.createElement('div'); this.oLayer.appendChild(o.oEle); o.oEle.className = 'FiltradorOpcionOff'; o.oEle.unselectable = true; o.oEle.innerHTML = (!!e.firstChild)? e.firstChild.data : ((!e.textContent)? e.text : e.textContent); o.oInfo = new Object; for(i; i < e.attributes.length; i++){ o.oInfo[e.attributes[i].nodeName] = e.attributes[i].nodeValue; } o.oEle.onmouseover = new Function("this.className = 'FiltradorOpcionOn'"); o.oEle.onmouseout = new Function("this.className = 'FiltradorOpcionOff'"); o.stopOut = this.stopOut.closure(this); o.selectOption = this.selectOption.closure(this, false); o.out = this.out.closure(this); o.move = this.move.closure(this); o.onBlur = this.onBlur.closure(this); AddEvent(o.oEle, "mousedown", function(){ this.stopOut(); }.closure(o)); AddEvent(o.oEle, "focus", function(){ this.stopOut(); this.oEle.className = 'FiltradorOpcionOn'; }.closure(o)); AddEvent(o.oEle, "blur", function(e){ this.oEle.className = 'FiltradorOpcionOff'; this.onBlur(e); }.closure(o)); AddEvent(o.oEle, "mouseup", function(){ this.selectOption(this, false); this.out(); }.closure(o)); AddEvent(o.oEle, "keydown", function(e){ if(e.keyCode == 13){ this.selectOption(this, false); } else if(e.keyCode == 38 || e.keyCode == 40){ this.move(e); } }.closure(o)); o.iPos = this.aOptions.length; this.aOptions.push(o); o = i = null; }; p.cleanOptions = function(){ var i = this.aOptions.length; for(i; i > 0; i--){ this.aOptions[i - 1].oEle.parentNode.removeChild(this.aOptions[i - 1].oEle); EliminarClosures(this.aOptions[i - 1]); this.aOptions.splice(this.aOptions[i - 1].iPos, 1); } this.aOptions = new Array; this.oCurOpt = null; }; p.selectOption = function(o, b){ this.oSelected = o; this.oSelected.oEle.className = 'FiltradorOpcionOff'; if(!!this.oSelected.oEle.textContent){ this.oEle.value = this.sSearched = this.oSelected.oEle.textContent; } else{ this.oEle.value = this.sSearched = this.oSelected.oEle.innerText; } this.escape(b); if(!!this.onSelected){ this.onSelected(this.oSelected.oInfo); } }; // p.showEmpty = function(){ this.oEmpty.style.marginTop = this.oEle.offsetHeight + 'px'; this.oEmpty.style.display = 'block'; }; p.hideEmpty = function(){ this.oEmpty.style.display = 'none'; }; // p.move = function(e){ var p = 0; //arriba if(e.keyCode == 38){ //si no hay if(!this.oCurOpt){ p = this.aOptions.length - 1; } else{ if(this.oCurOpt.iPos == 0){ p = -1; } else{ p = this.oCurOpt.iPos - 1; } } } //abajo else if(e.keyCode == 40){ //si no hay if(!this.oCurOpt){ p = 0; } else{ if(this.oCurOpt.iPos == this.aOptions.length - 1){ p = -1; } else{ p = this.oCurOpt.iPos + 1; } } } if(p == -1){ this.oCurOpt = null; this.oEle.focus(); } else{ this.oCurOpt = this.aOptions[p]; this.oCurOpt.oEle.focus(); } }; // p.showLoader = function(){ this.oLoader.style.marginTop = this.oEle.offsetHeight + 'px'; this.oLoader.style.display = 'block'; }; p.hideLoader = function(){ this.oLoader.style.display = 'none'; }; // p.unselect = function(){ this.oSelected = null; this.oEle.value = ''; this.sSearched = '?&^$%#@'; }; p.setOption = function(f, v){ this.req.pedir(this.oConf['sFile'], f + SEP_IGUAL + v + SEP_AND); }; // JavaScript Document var oObjsComsImg = {'iNum':0, 'sDir':'', 'aImg':new Array, 'sSesion':'', 'sImagePHP':'ImagenesMetodos.php', 'sMsjConf':'¿Esta seguro que desea eliminar la imagen?', 'sMsjCancel':'¿Esta seguro que desea cancelar la carga?', 'sMsjElim':'Eliminar imagen', 'sImgLoad':'btnCargarOff.gif'}; var Imagen = function(p, c){ this.init(p, c); }; var p = Imagen.prototype; //PROPs p.iNum = 0; p.sDir = ''; p.oEle = null; p.oConf = null; p.bReady = true; p.bLink = true; // p.onUnloadImageAcept = null; p.onCancelLoadImageAcept = null; p.onLoadImage = null; //METs p.init = function(p, c){ var e; if(!p) return alert('Imagen.init: El contenedor no existe.'); else if(typeof(c) != 'object') return alert('Imagen.init: La configuración para el objeto no fue ingresada.'+typeof(c)); this.oEle = document.createElement('div'); p.appendChild(this.oEle); this.oConf = new Object; for(e in c) this.oConf[e] = c[e]; this.iNum = oObjsComsImg.iNum; this.sDir = oObjsComsImg.sDir; oObjsComsImg.aImg.push(this); oObjsComsImg.iNum++; if(this.oConf['sClass'] != '') this.oEle.className = this.oConf['sClass']; var msjElim = ''; // alert(oToolTip.mostrar); if(!Nav.esIE)msjElim = 'onmouseover="oToolTip.mostrar(event,\''+oObjsComsImg['sMsjElim']+'\')"'; var anexTemp = ''; if(this.oConf['dirTemp'])anexTemp = '&dirTemp='+this.oConf['dirTemp'] this.oEle.innerHTML = ''+ ''+ ''+ ''+ '
'+ '
'+ '
'+ '
'; this.oConf['oPrev'] = $('ImagenImgPrev'+this.iNum); this.oConf['oElim'] = $('ImagenImgElim'+this.iNum); this.oConf['oLink'] = $('ImagenImgLink'+this.iNum); this.oConf['oIframe'] = $('ImagenIframe'+this.iNum); this.oConf['oForm'] = $('ImagenForm'+this.iNum); this.oConf['oFile'] = $('ImagenInpFile'+this.iNum); this.oConf['oLoad'] = $('ImagenDivLoad'+this.iNum); this.oConf['oCancel'] = $('ImagenACancel'+this.iNum); this.oConf['oImg'] = null; this.oConf['sLink'] = this.oConf['sAlt'] = ''; this.oConf['sTarget'] = '_blank'; if(!Nav.esIE){ AddEvent(this.oConf['oPrev'],'load',function(){ this.oConf['oElim'].style.marginLeft = (this.oConf['oPrev'].offsetWidth)+'px'; this.oConf['oElim'].style.marginTop = -(this.oConf['oPrev'].offsetHeight)+'px'; }.closure(this)); } this.onUnloadImageAcept = function(){ this.unloadImageAcept(); }.closure(this); this.onCancelLoadImageAcept = function(){ this.cancelLoadImageAcept(); }.closure(this); this.onAceptLink = function(){ this.aceptLink(); }.closure(this); if(Nav.esIE)AddEvent(this.oConf['oIframe'], 'readystatechange', function(){ this.control(); }.closure(this)); else AddEvent(this.oConf['oIframe'], 'load', function(){ this.controlResto(); }.closure(this)); AddEvent(this.oConf['oFile'], 'change', function(){ this.upload(); }.closure(this)); AddEvent(this.oConf['oElim'], 'click', function(){ this.unloadImageConfirm(); }.closure(this)); AddEvent(this.oConf['oLink'], 'click', function(){ this.addLink(); }.closure(this)); AddEvent(this.oConf['oPrev'], 'mouseover', function(){ this.showElim(); if(this.bLink){ this.showLink(); } }.closure(this)); AddEvent(this.oConf['oPrev'], 'mouseout', function(){ if(!this.oConf['elimEver'])this.hideElim(); this.hideLink(); }.closure(this)); if(this.oConf['elimEver'])this.showElim(); if(Nav.esIE)AddEvent(this.oConf['oElim'], 'mouseover', function(){ this.showElim(); if(this.bLink){ this.showLink(); } oToolTip.mostrar(oObjsComsImg['sMsjElim']); }.closure(this)); else AddEvent(this.oConf['oElim'], 'mouseover', function(){ this.showElim(); if(this.bLink){ this.showLink(); } }.closure(this)); AddEvent(this.oConf['oElim'], 'mouseout', function(){ if(!this.oConf['elimEver'])this.hideElim(); this.hideLink(); oToolTip.ocultar(); }.closure(this)); AddEvent(this.oConf['oLink'], 'mouseover', function(){ this.showLink(); this.showElim(); oToolTip.mostrar('Agregar link'); }.closure(this)); AddEvent(this.oConf['oLink'], 'mouseout', function(){ this.hideLink(); this.hideLink(); oToolTip.ocultar(); }.closure(this)); AddEvent(this.oConf['oCancel'], 'click', this.cancelLoadImageConfirm.closure(this)); this.showElim(); e = null; }; p.destroy = function(p){ EliminarClosures(this); this.oEle.parentNode.removeChild(this.oEle); this.oConf = this.oEle = this.onUnloadImageAcept = null; delete(oObjsComsImg.aImg[this.iNum]); }; // p.showElim = function(){ if(!!this.oConf['oImg'] && !this.oConf['oImg'].eli) this.oConf['oElim'].style.display = 'block'; }; p.hideElim = function(){ if(!!this.oConf['oImg'] && !this.oConf['oImg'].eli) this.oConf['oElim'].style.display = 'none'; }; // p.showLink = function(){ if(!!this.oConf['oImg'] && !this.oConf['oImg'].eli) this.oConf['oLink'].style.display = 'block'; }; p.hideLink = function(){ if(!!this.oConf['oImg'] && !this.oConf['oImg'].eli) this.oConf['oLink'].style.display = 'none'; }; // p.unloadImageConfirm = function(){ oToolTip.ocultar(); Confirmer.message = oObjsComsImg['sMsjConf']; Confirmer.onAcept = this.onUnloadImageAcept; Confirmer.onCancel = function(){ Blocker.hide(); } $('layBlocker').style.height = (document.documentElement.scrollHeight) + 'px'; $('layBlocker').style.width = (document.documentElement.scrollWidth) + 'px'; $('layConfirm').style.top = (document.documentElement.scrollTop + 150) + 'px'; Blocker.show(); Confirmer.show(); }; p.unloadImageAcept = function(){ Confirmer.hide(); Blocker.hide(); this.hideElim(); this.unloadImage(); }; // p.addLink = function(){ var l = (this.oConf['sLink'] != '')? this.oConf['sLink'] : ''; var a = (this.oConf['sAlt'] != '')? this.oConf['sAlt'] : ''; var t = (this.oConf['sTarget'] != '')? this.oConf['sTarget'] : '_blank'; Linker.setLink(l, a, t); Linker.onAcept = this.onAceptLink; Linker.onCancel = function(){ Blocker.hide(); } $('layBlocker').style.height = (document.documentElement.scrollHeight) + 'px'; $('layBlocker').style.width = (document.documentElement.scrollWidth) + 'px'; $('layLink').style.top = (document.documentElement.scrollTop + 150) + 'px'; Blocker.show(); Linker.show(); }; p.aceptLink = function(){ var s = trim($('layLinkValue').value); this.oConf['sLink'] = (!!s)? trim(s) : this.oConf['sLink']; s = trim($('layLinkAlt').value); this.oConf['sAlt'] = (!!s)? trim(s) : this.oConf['sAlt']; s = trim($('layLinkTarget').value); this.oConf['sTarget'] = (!!s)? trim(s) : this.oConf['sTarget']; Linker.hide(); Blocker.hide(); }; p.remLink = function(){ this.oConf['sLink'] = this.oConf['sAlt'] = this.oConf['sTarget'] = ''; }; // p.cancelLoadImageConfirm = function(){ oToolTip.ocultar(); Confirmer.message = oObjsComsImg['sMsjCancel']; Confirmer.onAcept = this.onCancelLoadImageAcept; Confirmer.onCancel = function(){ Blocker.hide(); } Blocker.show(); Confirmer.show(); }; p.cancelLoadImageAcept = function(){ Confirmer.hide(); Blocker.hide(); // this.oConf['oIframe'].src = this.sDir+'clasesPHP/'+oObjsComsImg.sImagePHP+'?fuente=POST&metodo=ninguno'; this.oConf['oLoad'].style.display = 'none'; this.oConf['oForm'].reset(); this.bReady = true; // this.unloadImage(); }; // p.upload = function(){ var ext = this.oConf['oFile'].value.substr(this.oConf['oFile'].value.lastIndexOf('.')).toLowerCase(); if(this.oConf['oFile'].value == '' || ext.search(/^(.jpg|.jpeg|.gif|.png)$/) == -1) return false; else if(!this.bReady) return false; this.bReady = false; this.oConf['oFile'].parentNode.parentNode.style.display = 'none'; this.oConf['oLoad'].style.display = 'block'; this.oConf['oForm'].submit(); ext = null; }; p.control = function(){ var d = null, i = 0, e = null; if(this.oConf['oIframe'].readyState == 'complete'){ // this.oConf['oLoad'].style.display = 'none'; this.oConf['oForm'].reset(); // d = this.oConf['oIframe'].contentWindow.document.body; if(d.getAttribute('res') == 'ninguno') return false; else if(d.getAttribute('res') == 'subir'){ for(i = 0; i < d.childNodes.length; i++){ // e = d.childNodes[i]; if(e.getAttribute('res') == 'error') alert('Imagen.control: ' + e.innerText); else if(e.getAttribute('res') == 'exito') this.loadImage(e, false); else alert('Imagen.control: ' + e.innerHTML + '(ERROR 2)'); } } else alert('Imagen.control: ' + d.innerHTML + '(ERROR 2)'); if(this.oConf['oImg'] == null) this.oConf['oFile'].parentNode.parentNode.style.display = 'block'; this.bReady = true; } d = i = e = null; }; p.controlResto = function(){ var d = null, i = 0, e = null; this.oConf['oLoad'].style.display = 'none'; this.oConf['oForm'].reset(); // d = this.oConf['oIframe'].contentWindow.document.body; if(d.getAttribute('res') == 'ninguno') return false; else if(d.getAttribute('res') == 'subir'){ for(i = 0; i < d.childNodes.length; i++){ // e = d.childNodes[i]; if(e.getAttribute('res') == 'error') alert('Imagen.control: ' + e.innerText); else if(e.getAttribute('res') == 'exito') this.loadImage(e, false); else alert('Imagen.control: ' + e.innerHTML + '(ERROR 2)'); } } else alert('Imagen.control: ' + d.innerHTML + '(ERROR 2)'); this.bReady = true; d = i = e = null; } p.loadImage = function(e, b){ if(!b && e.getAttribute('nom') == ''){ return false; } // this.oConf['oImg'] = new Object; this.oConf['oImg'].id = (!b)? e.getAttribute('id') : e['id']; this.oConf['oImg'].nom = (!b)? e.getAttribute('nom') : e['nom']; this.oConf['oImg'].ext = (!b)? e.getAttribute('ext') : e['ext']; this.oConf['oImg'].dir = (!b)? e.getAttribute('dir') : e['dir']; this.oConf['oImg'].eli = false; if(!b && e.firstChild){ this.oConf['sLink'] = e.firstChild.text; } else{ this.oConf['sLink'] = ''; } if(!b){ this.oConf['sTarget'] = e.getAttribute('tar'); } else{ this.oConf['sTarget'] = ''; } if(!b && e.lastChild){ this.oConf['sAlt'] = e.lastChild.text; } else{ this.oConf['sAlt'] = ''; } // this.oConf['oPrev'].src = this.sDir + this.oConf['oImg'].dir + this.oConf['oImg'].nom + 'c' + this.oConf['oImg'].ext; // this.oConf['oFile'].parentNode.parentNode.style.display = 'none'; // this.showElim(); if(typeof(this.onLoadImage) == 'function') this.onLoadImage(); }; p.unloadImage = function(){ // if(this.oConf['oImg']) this.oConf['oImg'].eli = true; this.hideElim(); this.hideLink(); this.remLink(); this.oConf['oFile'].parentNode.parentNode.style.display = 'block'; this.oConf['oPrev'].src = this.sDir + 'img/fotoDef.png'; // if(typeof(this.onUnLoadImage) == 'function') this.onUnLoadImage(); }; // p.toPOST = function(s){ var v = ''; if(!s) s = 'Img'+this.iNum; if(!!this.oConf['oImg']){ v += s + 'Id' + SEP_IGUAL + this.oConf['oImg'].id + SEP_AND; v += s + 'Nom' + SEP_IGUAL + this.oConf['oImg'].nom + SEP_AND; v += s + 'Ext' + SEP_IGUAL + this.oConf['oImg'].ext + SEP_AND; v += s + 'Dir' + SEP_IGUAL + this.oConf['oImg'].dir + SEP_AND; v += s + 'Eli' + SEP_IGUAL + ((this.oConf['oImg'].eli)? 1 : 0) + SEP_AND; v += s + 'Lin' + SEP_IGUAL + this.oConf['sLink'] + SEP_AND; v += s + 'Alt' + SEP_IGUAL + this.oConf['sAlt'] + SEP_AND; v += s + 'Tar' + SEP_IGUAL + this.oConf['sTarget'] + SEP_AND; } return v; }; p.toXML = function(){ var s = ''; if(!!this.oConf['oImg'] && !this.oConf['oImg'].eli){ s += ''+ ''; } else{ s += ''; } return s; }; // p.fromXML = function(n){ if(n.tagName.toLowerCase() != 'img') return alert("Imagen.fromXML: Nodo inválido."); else this.loadImage(n, false); };