quicksearch.js

来自「SugarCRM5.1 开源PHP客户关系管理系统」· JavaScript 代码 · 共 960 行 · 第 1/3 页

JS
960
字号
/** WICK: Web Input Completion Kit* http://wick.sourceforge.net/* Copyright (c) 2004, Christopher T. Holland* All rights reserved.** Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:** Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.* Neither the name of the Christopher T. Holland, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.** Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.*//* start dhtml building blocks */function freezeEvent(e) {	if (e.preventDefault) e.preventDefault();	e.returnValue = false;	e.cancelBubble = true;	if (e.stopPropagation) e.stopPropagation();	return false;}//freezeEventfunction isWithinNode(e,i,c,t,obj) {	answer = false;	te = e;	while(te && !answer) {		if((te.id && (te.id == i)) || (te.className && (te.className == i+"Class"))				|| (!t && c && te.className && (te.className == c))				|| (!t && c && te.className && (te.className.indexOf(c) != -1))				|| (t && te.tagName && (te.tagName.toLowerCase() == t))				|| (obj && (te == obj))			) {			answer = te;		} else {			te = te.parentNode;		}	}	return te;}//isWithinNodefunction getEvent(event) {	return (event ? event : window.event);}//getEvent()function getEventElement(e) {	return (e.srcElement ? e.srcElement: (e.target ? e.target : e.currentTarget));}//getEventElement()function findElementPosX(obj) {	curleft = 0;	if (obj.offsetParent) {		while (obj.offsetParent) {			curleft += obj.offsetLeft;			obj = obj.offsetParent;		}	}//if offsetParent exists	else if (obj.x)		curleft += obj.x	return curleft;}//findElementPosXfunction findElementPosY(obj) {	curtop = 0;	if (obj.offsetParent) {		while (obj.offsetParent) {			curtop += obj.offsetTop;			obj = obj.offsetParent;		}	}//if offsetParent exists	else if (obj.y)		curtop += obj.y	return curtop;}//findElementPosY/* end dhtml building blocks */function handleKeyPress(event) {	e = getEvent(event);	eL = getEventElement(e);	sqs_tab_action = false;	upEl = isWithinNode(eL,null,"sqsEnabled",null,null);	sqs_id = eL["id"];	kc = e["keyCode"];	if(kc == 13 || kc == 9){		if(sqs_lookup_active)return;		sqs_tab_action = true;	}	if (siw && ((kc == 13) || (kc == 9))) {		siw.selectingSomething = true;		if (siw.isSafari) inputBox.blur();   //hack to "wake up" safari		try { siw.inputBox.focus(); }		catch(e) { return; }//		siw.inputBox.value = siw.inputBox.value;//.replace(/[ \r\n\t\f\s]+$/gi,' ');		hideSmartInputFloater(true);	} else if (upEl && (kc != 38) && (kc != 40) && (kc != 37) && (kc != 39) && (kc != 13) && (kc != 27)) {		if (!siw || (siw && !siw.selectingSomething)) {			handleInput(event);		}	} else if (siw && siw.inputBox) {		siw.internalCall = true;		siw.inputBox.focus(); //kinda part of the hack.	}}//handleKeyPress()// handle any actual user action that will result in displaying resultsfunction handleInput(event) {	e = getEvent(event);	eL = getEventElement(e);	upEl = isWithinNode(eL,null,"sqsEnabled",null,null);	if(siw && upEl.value == ''){		hideSmartInputFloater(false);	}	sqs_id = eL["id"];	if(sqs_id != 'debug' && sqs_id != 'left' && sqs_id != '' && typeof(sqs_objects) != 'undefined') {		if(typeof(sqs_objects[sqs_id]['disable']) != 'undefined' && sqs_objects[sqs_id]['disable'] == true) return; // if sqs is disabled		if(typeof(sqs_old_values) && typeof(sqs_old_values[sqs_id]) == 'undefined') {			sqs_old_values[sqs_id] = '';		}		makeRPCCall(upEl, sqs_id, rpc_timeout);	}}function handleOnPropertyChange(event) {	if(!from_popup_return) handleInput(event);}function doCall( sqs_id, sqs_query, value){    if (floaterWait == null || typeof(floaterWait) == 'undefined') {        quicksearchInit();    }	if(value != upEl.value || value == '')return;	if (typeof(window['callDelay']) != "undefined" ) window.clearTimeout(callDelay);				// wait gif				x = findElementPosX(upEl) - 19;				y = findElementPosY(upEl);				floaterWait.style.left = x;				floaterWait.style.top = y;				floaterWait.style.display="block";				floaterWait.style.visibility="visible";				for(var i = 0; i < sqs_objects[sqs_id]['conditions'].length; i++) {					if(typeof(sqs_objects[sqs_id]['conditions'][i]['source']) != 'undefined'){						src_elem = document.getElementById(sqs_objects[sqs_id]['conditions'][i]['source']);						if (typeof(src_elem)!='undefined' && src_elem.value != ''){							sqs_objects[sqs_id]['conditions'][i]['value'] = JSON.stringifyNoSecurity(src_elem.value);						}					}else{						sqs_objects[sqs_id]['conditions'][i]['value'] = JSON.stringifyNoSecurity(sqs_query);					}				}				postData = 'data=' + JSON.stringifyNoSecurity(sqs_objects[sqs_id]) + '&module=Home&action=quicksearchQuery&to_pdf=1';				sqs_request_id++;				sqs_last_query = sqs_query;				//hideSmartInputFloater(false);				sqs_query = sqs_last_query;				sqs_lookup_active = true;				YAHOO.util.Connect.asyncRequest('POST', 'index.php', {success: SugarQuickSearchObject.display, failure: SugarQuickSearchObject.fail, argument:{id: sqs_request_id, query: sqs_query}}, postData);}function makeRPCCall(upEl, sqs_id, delay) {	if(sqs_tab_action)return;	if(typeof(sqs_objects[sqs_id]) != 'undefined') {		if(sqs_objects[sqs_id]['multi'])			sqs_query = getUserInputToMatch(document.getElementById(sqs_id).value);		else			sqs_query = document.getElementById(sqs_id).value;		if(typeof(siw) != 'undefined' && sqs_query == '') hideSmartInputFloater(false);		sqs_query = sqs_query.replace(/\\/gi,'').replace(/\[/gi,'').replace(/\(/gi,'').replace(/\./gi,'\.').replace(/\?/gi,'');		sqs_query = sqs_query.replace(/[()]+/g,'');		if (sqs_query.length > 0) {			if(sqs_query.length > sqs_last_query.length &&  sqs_old_values[sqs_id].length > 0 && sqs_query.indexOf(sqs_old_values[sqs_id]) == 0							&& typeof(collection) != 'undefined' && collection.length > 0 && collection.length < sqs_objects[sqs_id]['limit']) { // don't make an RPC call, use cache				processSmartInput(upEl, sqs_id);			}			else{				hideSmartInputFloater(false);				clearSQSLookupData(false);				clearPopulateList(upEl.id, sqs_id);				if (typeof(window['callDelay']) != "undefined" ) window.clearTimeout(callDelay);				callDelay = window.setTimeout('doCall(sqs_id, sqs_query,upEl.value)', delay);			}		}		sqs_old_values[sqs_id] = sqs_query;		sqs_object_id = sqs_id;	}}// SugarCRMfunction handleKeyDown(event) {	e = getEvent(event);	eL = getEventElement(e);	sqs_tab_action = false;	if (siw && (kc = e["keyCode"])) {		if (kc == 40) { // down arrow			siw.selectingSomething = true;			freezeEvent(e);			if (siw.isGecko) siw.inputBox.blur(); /* Gecko hack */			selectNextSmartInputMatchItem();		} else if (kc == 38) { // up arrow			siw.selectingSomething = true;			freezeEvent(e);			if (siw.isGecko) siw.inputBox.blur();			selectPreviousSmartInputMatchItem();		} else if ((kc == 13) || (kc == 9)) { // tab or enter			siw.selectingSomething = true;		    sqs_tab_action = true;			activateCurrentSmartInputMatch();			freezeEvent(e);		} else if (kc == 27)  {			hideSmartInputFloater(false);			freezeEvent(e);		} else { // everything else			siw.selectingSomething = false;		}		try{siw.internalCall = true; siw.inputBox.focus();} catch(e) {return;} // top scrolling in firefox for down/up keys	}}//handleKeyDown()function handleFocus(event) {	if(siw && siw.internalCall) {		siw.internalCall = false;		return;	}	sqs_tab_action=true;	from_popup_return = false;	e = getEvent(event);	eL = getEventElement(e);	sqs_id = eL["id"];	if (focEl = isWithinNode(eL,null,"sqsEnabled",null,null)) {		if (typeof(siw) != 'undefined' && (!siw || (siw && !siw.selectingSomething))) {			sqs_old_values[sqs_id] = ''			sqs_original_value = eL.value;			handleInput(event);		}	}}//handleFocus()function handleBlur(event) {	e = getEvent(event);	eL = getEventElement(e);	if (blurEl = isWithinNode(eL,null,"sqsEnabled",null,null)) {		sqs_original_value = '';		toggleMultis(eL['id'], false);		id = eL['id'];		if(sqs_must_match && eL.value != '' && sqs_id != '' && (!siw || (siw.selectingSomething && sqs_tab_action || !siw.selectingSomething))) {			failBlur = !sqsFilledOut(sqs_id);			if(failBlur){				window.setTimeout('handleUnBlur(id)', 10);			}else{					clearSQSLookupData(true);			}		}		else{			if (typeof(window['callDelay']) != "undefined" ) window.clearTimeout(callDelay);		}			}}//handleBlur()function sqsFilledOut(sqs_id){	if(typeof sqs_objects[sqs_id] != 'undefined'            && typeof collection_extended[document.getElementById(sqs_id).value] != 'undefined' ){        for(i in sqs_objects[sqs_id]['populate_list']){            if (i > -1) {                j =sqs_objects[sqs_id]['populate_list'][i];                k =sqs_objects[sqs_id]['field_list'][i];                if(document.getElementById(j).value != String(collection_extended[document.getElementById(sqs_id).value][k]).replace(/&amp;/gi,'&').replace(/&lt;/gi,'<').replace(/&gt;/gi,'>').replace(/&#039;/gi,'\'').replace(/&quot;/gi,'"')){                    return false;                }            }        }	}	return true;}function handleUnBlur(id){	document.getElementById(id).focus();	sqs_tab_action = false;	if (typeof(window['callDelay']) != "undefined"  && sqs_query != '' && sqs_query != sqs_last_query ){			doCall(sqs_id, sqs_query, upEl.value);	}}function clearSQSLookupData(full){	if(full){		sqs_last_query = '';		sqs_query = '';	}	if(siw){		siw.matchCollection = new Array();	}	sqs_original_value = '';	collection = new Array();

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?