您的位置:首页 > Web前端 > JQuery

Jquery autocomplete

2010-01-08 13:30 344 查看
<%@ page language="java" %>
<%--
<%@ include file="../include/contentheader.jsp" %>
--%>
<%@ page import="java.util.*,
java.text.DecimalFormat,
com.eastpro.util.Constants,
com.eastpro.setupplan.dao.bean.*,
com.eastpro.common.EastproBean,
com.eastpro.common.AccessRightBean"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<jsp:useBean id="fundAllocateForm" scope="request" class="com.eastpro.setupplan.action.FundAllocateForm" />
<html:html>
<head>
<title><bean:message key="sys.application_title" /></title>

<html:base/>

<meta http-equiv="Content-Type" content="text/html; charset=<bean:message key="sys.language"/>">
<link rel="stylesheet" href="../css/global.css">
<%-- For jQuery AutoComplete --%>
<link rel="stylesheet" type="text/css" href="../css/jQuery/jquery.autocomplete.css" />
<%-- For jQuery AutoComplete --%>

<%@ include file="../include/contentlayer.jsp"%>
<script language="javascript" src="../jscript/js.js"></script>
<script language="javascript" src="../jscript/js_layer.js"></script>
<script language="javascript" src="../jscript/jquery-1.3.2.min.js"></script>
<script language="javascript" src="../jscript/json2.js"></script>
<script language="javascript" src="../jscript/Bajax.js"></script>
<script language="javascript" src="../jscript/setupplan/check.js"></script>
<script language="javascript" src="../jscript/fg.function.js"></script>
<script language="javascript" src="../jscript/common.js"></script>
<script language="javascript" src="../jscript/setupplan/validation.js"></script>

<%-- For AutoComplete --%>
<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/datasource/datasource-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/yahoo/yahoo-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/event/event-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/connection/connection-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/autocomplete/autocomplete-min.js"></script>
<%-- For AutoComplete --%>

<%-- For jQuery AutoComplete --%>
<script language="javascript" src='../jscript/jQuery/jquery.autocomplete.js'></script>
<%-- For jQuery AutoComplete --%>

<logic:notEqual name="accRightBean" scope="request" property="onlyViewRight" value="true">
<script>
$(function(){
var fundName=document.getElementById("fundName");
if(fundName!='null' && fundName!=null)
{
if(document.forms[0].fundName[0]!=null)
{
document.forms[0].fundName[0].focus();
}
else{
document.forms[0].fundName.focus();
}
}
});
</script>
</logic:notEqual>

<script type="text/javascript">

<!--
function Form_Load(){
var obj = document.forms[0].elements;
for(i=0;i<obj.length;i++){
if(obj[i].type == "select-one"||obj[i].type == "text"){
obj[i].focus();
break;
}
}
}

function calTotalPerc() {
with (document.forms[0]) {
var tot = 0;
for (var i = 0; i < 10; i++) {
if (switchToUnit[i].value != "") {
tot += parseFloat(switchToUnit[i].value);
}
}
totalPerc.value = commafy(parseFloat(tot).toFixed(0));
}
}

function dataformat(val, num){
if(val != ''){
result = uncommafy(commafy(parseFloat(val).toFixed(num)));
if(result == 'NaN')
return '';
else
return result;
}else{
return '';
}
}

function checkSave()
{
if(validation()){
document.getElementById("topSave").disabled=true;
document.getElementById("bottomSave").disabled=true;
document.forms[0].submit();
}
}

function checkGotoPre()
{
if(validation()){
document.getElementById('mainForm').action="<%=request.getContextPath() %>/sp-fundallocate.do?reqCode=saveFundAllocate&previous=Y";
document.getElementById("topSave").disabled=true;
document.getElementById("bottomSave").disabled=true;
document.forms[0].submit();
}
}

function checkGotoNext()
{
if(validation()){
document.getElementById('mainForm').action="<%=request.getContextPath() %>/sp-fundallocate.do?reqCode=saveFundAllocate&next=Y";
document.getElementById("topSave").disabled=true;
document.getElementById("bottomSave").disabled=true;
document.forms[0].submit();
}
}

function saveFundAllocate()
{
document.getElementById('mainForm').action="<%=request.getContextPath() %>/sp-fundallocate.do?reqCode=saveFundAllocate";
return false;
}

function validation(){

with (document.getElementById('mainForm')) {

for (var k = 0; k < 10; k++) {
if(fundCode[k].value != ""){
if(switchToUnit[k].value =='')
{
jsMsg = '<bean:message key="errors.required" arg0="{0}"/>';
var temp_validate = new Array('<bean:message key="label.fundAllocate.allocation" />');
jsMsg = concatMsg(jsMsg,temp_validate);
alert(jsMsg);
setfocus = eval(switchToUnit[k]);
setfocus.focus();
return false;
}
}
}

for (var k = 0; k < 10; k++) {
if(fundCode[k].value != ""){
if(switchToUnit[k].value < 10)
{
jsMsg = '<bean:message key="msg.e.74"/>';
alert(jsMsg);
switchToUnit[k].value='';
setfocus = eval(switchToUnit[k]);
setfocus.focus();
return false;
}
}
}

if(totalPerc.value == '' || totalPerc.value!=100){
jsMsg = '<bean:message key="msg.e.75"/>';
alert(jsMsg);
return false;
}

for (var i = 0; i < fundCode.length; i++) {
for (var j = 0; j < i; j++) {

if(fundCode[i].value != ""){
if(fundCode[i].value==fundCode[j].value)
{
jsMsg = "<bean:message key='msg.e.76'/>";
alert(jsMsg);
setfocus = eval(fundName[i]);
setfocus.focus();
return false;
}
}
}
}

}

return true;
}

function checkAllo(obj){
if(obj.value != ""){
obj.value = uncommafy(obj.value);
field='<bean:message key="label.fundAllocate.allocation" />';
if(checkNum(obj,field)&&checkLengthA(obj,field,'0')){
addFormatPoint(obj,0);
}
}
}

function checkNum(obj,field){
var n =/^/d+(/./d+)?$/ ;
if(n.test(obj.value)){
return true;
}else{
jsMsg = '<bean:message key="msg.e.40" arg0="{0}"/>';
var temp = new Array(field);
jsMsg = concatMsg(jsMsg,temp);
alert(jsMsg);
obj.focus();
obj.value="";
return false;
}
}

function checkLengthA(obj,field,point){
var num = parseFloat(obj.value)+"";
var pointNum = num.indexOf('.');
if(pointNum>0){
jsMsg = '<bean:message key="msg.e.64" arg0="{0}"/>';
var temp = new Array(point);
jsMsg = concatMsg(jsMsg,temp);
alert(jsMsg);
obj.focus();
obj.value="";
return false;
}
if(obj.value>100){
jsMsg = '<bean:message key="msg.e.5" arg0="{0}" arg1="{1}"/>';
var temp = new Array(field,'100');
jsMsg = concatMsg(jsMsg,temp);
alert(jsMsg);
obj.focus();
obj.value="";
return false;
}

return true;
}

function addFormatPoint(obj,point){
if(obj.value != ""){
value = uncommafy(obj.value);
var num = parseFloat(value)+"";
var pointNum = num.indexOf('.');
if(pointNum>0){
var num1 = num.substring(0,pointNum);
var num2 = num.substring(pointNum+1,num.length);
num = commafy(num1)+'.'+num2;

for(i=num2.length;i<point;i++){
num=num+"0";
}
obj.value=num;
}else{
num = commafy(num);
if(point>0){
num = num+".";
for(i=0;i<point;i++){
num=num+"0";
}
}
obj.value=num;

}
}
}

//-->

</script>

<%

DecimalFormat df0 = new DecimalFormat("###########0");

int tabIndex = 6;
double totalPerc = 0.0f;

int loopupCnt = 10;

FooterBean footerBean=(FooterBean)request.getAttribute("footerBean");
String app_no=footerBean.getAppNo();
String appNo=footerBean.getAppNo();
String[] fundHsName = fundAllocateForm.getFundHsName();
String[] fundCode = fundAllocateForm.getFundCode();
String[] fundName = fundAllocateForm.getFundName();
double[] switchToUnit = fundAllocateForm.getSwitchToUnit();

%>

</head>

<body class="yui-skin-sam" background="../image/common/content_back.gif" leftmargin="5" topmargin="10" onLoad="hideloadImage();Form_Load;" tabindex="-1" onkeydown="cancelBack();">

<html:form styleId="mainForm" action="/sp-fundallocate.do?reqCode=saveFundAllocate">
<html:hidden name="fundAllocateForm" property="planNo"></html:hidden>
<input id="funcCodeId" type="hidden" name="func_code" value="<bean:write name="func_code"/>"/>
<input id="field_changed" type="hidden" name="field_changed" />
<input id="pageFromId" type="hidden" name="pageFrom" value='<bean:write name="pageFrom"/>' />

<table align=center width="100%" border=0 class="outtb">

<logic:equal name="func_code" scope="request" value="FN010154">
<jsp:include flush="true" page="../include/publicHeader.jsp">
<jsp:param name="func_desc" value="label.fundAllocate"/>
</jsp:include>
</logic:equal>

</table>
<%-- HEADER --%>
<%@ include file="sp-header.jsp"%>

<tr>
<td class="buttonback">
<table width="100%" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="right" width="100%"> 

<logic:notEqual name="accRightBean" scope="request" property="onlyViewRight" value="true">
<a onClick="return false;" style="cursor: hand">
<%--
<input type="image" style="cursor: hand" onclick="javascript:if(validation()){Goto_Previous();this.form.submit();}" src=../image/list-previous.gif border="0" tabindex=<%=tabIndex++%>>
--%>
<input type="image" style="cursor: hand" onclick="return checkGotoPre();" src=../image/list-previous.gif border="0" tabindex=<%=tabIndex++%>>
</a>
<logic:equal name="accRightBean" scope="request" property="printRight" value="true">
<input type="button" class="button" name="print" value="<bean:message key="button.title.print"/>"
onclick="javascript:window.print()" style="cursor: hand" title='<bean:message key="button.title.print"/>(Alt+P)' accesskey="P" tabindex=<%=tabIndex++%>>
</logic:equal>

<%--
<input type="button" class="button" name="save" value="<bean:message key="button.title.save"/>"
onclick="javascript:if(validation()){saveFundAllocate();this.form.submit();}" style="cursor: hand" title='<bean:message key="button.title.save"/>(Alt+S)' accesskey="S" tabindex=<%=tabIndex++%>>
--%>
<input type="button" id="topSave" class="button" name="save" value="<bean:message key="button.title.save"/>"
onclick="return checkSave()" style="cursor: hand" title='<bean:message key="button.title.save"/>(Alt+S)' accesskey="S" tabindex=<%=tabIndex++%>>

<input type="button" class="button" name="reset_btn" value="<bean:message key="button.title.reset"/>"
onclick="document.getElementById('mainForm').reset();" style="cursor: hand" title='<bean:message key="button.title.reset"/>(Alt+R)' accesskey="R" tabindex=<%=tabIndex++%>>
</logic:notEqual>

<input type="button" value="<bean:message key="button.title.main_page"/>" class="button" border=0 style="cursor:hand" title='<bean:message key="button.title.main_page"/>(Alt+M)' accesskey="M" tabindex=<%=tabIndex++%>
onclick="if(unsaved(parent.content,'<bean:message key="pps.message.discard_change"/>'))location.href='<%=request.getContextPath() %>/dynamic-mc-search.do?reqCode=Search&func_code=<bean:write name="func_code"/>&reqCode2=Search'">

<logic:notEqual name="accRightBean" scope="request" property="onlyViewRight" value="true">
<a onClick="return false;" style="cursor: hand">
<%--
<input type="image" style="cursor: hand" onclick="javascript:if(validation()){Goto_Next();this.form.submit();}" src=../image/list-next.gif border="0" tabindex=<%=tabIndex++%>>
--%>
<input type="image" style="cursor: hand" onclick="return checkGotoNext();" src=../image/list-next.gif border="0" tabindex=<%=tabIndex++%>>
</a>
</logic:notEqual>
</td>
</tr>
</table>
</td>
</tr>

<%-- CONTENTS --%>

<tr class="fieldsback">
<td>

<table class="stable" align="center" border="0" cellpadding="0" cellspacing="0">

<tr>
<td class="stablehead" width=20% ><bean:message key="label.fundAllocate.fundHouse"/></td>
<td class="stablehead" width=10% ><bean:message key="label.fundAllocate.fundCode"/></td>
<td class="stablehead" width=50% ><bean:message key="label.fundAllocate.fundName"/></td>
<td class="stablehead" width=20% align='center' ><bean:message key="label.fundAllocate.allocation"/></td>
</tr>

<% if (true) {
int skipped = 0;

for (int i = 0; i < loopupCnt; i++) {
if ((i-skipped)%2 == 0) {
%>
<tr class='sblueback'>
<% } else {
%>
<tr>
<% }
%>

<%-- @@#Start --%>
<%-- Fund Code and Fund Name -S--%>

<td >

<logic:notEqual name="accRightBean" scope="request" property="onlyViewRight" value="true">

<div id='fh<%=i%>'>
<%if (fundHsName[i] != null){out.println(fundHsName[i]);}%>

</div>
<input id='fhHidden<%=i%>' type="hidden" name="fundHsName" value='<%=fundHsName[i]%>'/>
</logic:notEqual>
<logic:equal name="accRightBean" scope="request" property="onlyViewRight" value="true">
<%
out.println(fundHsName[i]);
out.println("<input type='hidden' value='"+fundHsName[i]+"' id='fundHsName' name='fundHsName'>");
%>
</logic:equal>
</td>

<td >
<logic:notEqual name="accRightBean" scope="request" property="onlyViewRight" value="true">
<div id='fc<%=i%>'>
<%if (fundCode[i] != null){out.println(fundCode[i]);}%>
</div>
<input id='fcHidden<%=i%>' type="hidden" name="fundCode" value='<%=fundCode[i]%>'/>
</logic:notEqual>
<logic:equal name="accRightBean" scope="request" property="onlyViewRight" value="true">
<%
out.println(fundCode[i]);
out.println("<input type='hidden' value='"+fundCode[i]+"' id='fundCode' name='fundCode'>");
%>
</logic:equal>
</td>

<td>
<logic:notEqual name="accRightBean" scope="request" property="onlyViewRight" value="true">
<table class='sblueback' cellPadding='0' cellSpacing='0' border='0'>
<tr>
<td>
<div id="autoComplete<%=i%>">
<input name="fundName" onchange='fieldChange();' id="fundNameInput<%=i%>" type="text"
<%
if (fundName != null && fundName[i] != null){
out.println("value = '"+fundName[i]+"'");
}
%>
<%--
class="fieldbox" size="100" maxlength="100" tabindex=<%=tabIndex++%> onfocus="chgOnFocusBgColor(this)" onblur="chgOnBlurBgColor(this);clearFundCode('<%=i%>', this.value);">
--%>
class="fieldbox" size="100" maxlength="100" tabindex=<%=tabIndex++%> onfocus="chgOnFocusBgColor(this)" onblur="chgOnBlurBgColor(this);clearFundCode('<%=i%>', this);">
<div id="fundNameResult<%=i%>"></div>
</div>
</td>

<td>
<%--
<a onclick="javascript:popupDisplay('<%=request.getContextPath()%>/dynamic-mc-search.do?reqCode=Search&func_code=FN120110&isPopUp=Y&PopUpType=PPS_INS_OCC&pop_ret_val=document.forms[0].fundName[<%=i%>]&pop_val_col=1&pop_desc_col=1&start=0&app_no=<%=app_no%>&reqCode2=Search&pop_filter=app_no=/'<%=app_no%>/' and dealing_channel=/'<%=Constants.DEALING_CHANNEL%>/'','600','800');" style="cursor:hand" >
--%>
<a onclick="javascript:popupDisplay('<%=request.getContextPath()%>/dynamic-mc-search.do?reqCode=Search&func_code=FN120110&isPopUp=Y&PopUpType=PPS_INS_OCC&pop_ret_val=document.forms[0].fundName[<%=i%>]&pop_val_col=1&pop_desc_col=1&pop_ret_val3=document.forms[0].fundCode[<%=i%>]&pop_val_col3=0&pop_desc_col3=0&pop_ret_val4=document.forms[0].fundHsName[<%=i%>]&pop_val_col4=4&pop_desc_col4=4&start=0&app_no=<%=app_no%>&reqCode2=Search&pop_filter=app_no=/'<%=app_no%>/' and dealing_channel=/'<%=Constants.DEALING_CHANNEL%>/'','600','800');" style="cursor:hand" >
<img src="../image/icon/icon_mglass.gif" style="cursor:hand" title="Alpha Search">
</a>
</td>

</tr>
</table>
</logic:notEqual>
<logic:equal name="accRightBean" scope="request" property="onlyViewRight" value="true">
<%
if (fundName != null && fundName[i] != null)
{
out.println(fundName[i]);
}
%>
</logic:equal>
</td>

<%-- Fund Code and Fund Name -E--%>

<td align='center'>
<logic:notEqual name="accRightBean" scope="request" property="onlyViewRight" value="true">

<input name="switchToUnit" id="switchToUnit<%=i%>" onkeyup="" value="<% if (switchToUnit[i] > 0) { totalPerc += switchToUnit[i]; out.println(df0.format(switchToUnit[i])); } %>" type="text" class="fieldbox" size="10" maxlength="10" tabindex=<%=tabIndex++%> onfocus="chgOnFocusBgColor(this)" onblur="chgOnBlurBgColor(this); checkAllo(this);" onchange="fieldChange();calTotalPerc();">%
<%--
<input name="switchToUnit" id="switchToUnit<%=i%>" onkeyup="" value="<% if (switchToUnit[i] > 0) { totalPerc += switchToUnit[i]; out.println(df0.format(switchToUnit[i])); } %>" type="text" class="fieldbox" size="10" maxlength="10" tabindex=<%=tabIndex++%> onfocus="chgOnFocusBgColor(this)" onblur="chgOnBlurBgColor(this); this.value = dataformat(this.value, 0);" onchange="fieldChange();calTotalPerc();">%
--%>
</logic:notEqual>
<logic:equal name="accRightBean" scope="request" property="onlyViewRight" value="true">
<% if (switchToUnit[i] > 0)
{
totalPerc += switchToUnit[i]; out.println(df0.format(switchToUnit[i])+"%");
}
%>
</logic:equal>
</td>

</tr>

<% } %>

<tr>
<td colspan="3"></td>
<td align='center'>
<logic:notEqual name="accRightBean" scope="request" property="onlyViewRight" value="true">
<input id="totalPerc" name="totalPerc" type="text" class="fieldbox" value="<%=df0.format(totalPerc)%>" size="10" readonly="readonly" disabled="true">%
</logic:notEqual>
<logic:equal name="accRightBean" scope="request" property="onlyViewRight" value="true">
<%=df0.format(totalPerc)%>%
</logic:equal>
</td>
</tr>

<% } %>

<%--
</table>
</td>
</tr>
--%>

</table>

</td>
</tr>

<tr>
<td class="buttonback">
<table width="100%" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="right" width="100%"> 
<logic:notEqual name="accRightBean" scope="request" property="onlyViewRight" value="true">
<a onClick="return false;" style="cursor: hand">
<%--
<input type="image" style="cursor: hand" onclick="javascript:if(validation()){Goto_Previous();this.form.submit();}" src=../image/list-previous.gif border="0" tabindex=<%=tabIndex++%>>
--%>
<input type="image" style="cursor: hand" onclick="return checkGotoPre();" src=../image/list-previous.gif border="0" tabindex=<%=tabIndex++%>>
</a>
<logic:equal name="accRightBean" scope="request" property="printRight" value="true">
<input type="button" class="button" name="print" value="<bean:message key="button.title.print"/>"
onclick="javascript:window.print()" style="cursor: hand" title='<bean:message key="button.title.print"/>(Alt+P)' accesskey="P" tabindex=<%=tabIndex++%>>
</logic:equal>
<%--
<input type="button" class="button" name="save" value="<bean:message key="button.title.save"/>"
onclick="javascript:if(validation()){saveFundAllocate();this.form.submit();}" style="cursor: hand" title='<bean:message key="button.title.save"/>(Alt+S)' accesskey="S" tabindex=<%=tabIndex++%>>
--%>
<input type="button" id="bottomSave" class="button" name="save" value="<bean:message key="button.title.save"/>"
onclick="return checkSave()" style="cursor: hand" title='<bean:message key="button.title.save"/>(Alt+S)' accesskey="S" tabindex=<%=tabIndex++%>>
<input type="button"
class="button" name="reset_btn" value="<bean:message key="button.title.reset"/>"
onclick="document.getElementById('mainForm').reset();" style="cursor: hand" title='<bean:message key="button.title.reset"/>(Alt+R)' accesskey="R" tabindex=<%=tabIndex++%>>
</logic:notEqual>

<input type="button" value="<bean:message key="button.title.main_page"/>" class="button" border=0 style="cursor:hand" title='<bean:message key="button.title.main_page"/>(Alt+M)' accesskey="M" tabindex=<%=tabIndex++%>
onclick="if(unsaved(parent.content,'<bean:message key="pps.message.discard_change"/>'))location.href='<%=request.getContextPath() %>/dynamic-mc-search.do?reqCode=Search&func_code=<bean:write name="func_code"/>&reqCode2=Search'">
<logic:notEqual name="accRightBean" scope="request" property="onlyViewRight" value="true">
<a onClick="return false;" style="cursor: hand">
<%--
<input type="image" style="cursor: hand" onclick="javascript:if(validation()){Goto_Next();this.form.submit();}" src=../image/list-next.gif border="0" tabindex=<%=tabIndex++%>>
--%>
<input type="image" style="cursor: hand" onclick="return checkGotoNext();" src=../image/list-next.gif border="0" tabindex=<%=tabIndex++%>>
</a>
</logic:notEqual>
</td>
</tr>
</table>
</td>
</tr>

<%-- FOOTER --%>
<%@ include file="sp-footer.jsp"%>

</table>

</html:form>

<logic:notEqual name="accRightBean" scope="request" property="onlyViewRight" value="true">

<%--Handling the autoComplete box-S--%>
<%--
<script type="text/javascript">
var callback =
{
success: function(o) {
var xmlDoc = o.responseXML.documentElement;
var rowNum = xmlDoc.getElementsByTagName("rowNum")[0].childNodes[0].nodeValue;
var fundCode = xmlDoc.getElementsByTagName("fundCode")[0].childNodes[0].nodeValue;
var fundHsName = xmlDoc.getElementsByTagName("fundHsName")[0].childNodes[0].nodeValue;

var fcDiv = document.getElementById('fc'+rowNum);
fcDiv.innerHTML = fundCode;

var fcHidden = document.getElementById('fcHidden'+rowNum);
fcHidden.value = fundCode;

var fhDiv = document.getElementById('fh'+rowNum);
fhDiv.innerHTML = fundHsName;

var fhHidden = document.getElementById('fhHidden'+rowNum);
fhHidden.value = fundHsName;
},
failure: function(o) {
alert('failure');
}
}

var ds = new YAHOO.util.XHRDataSource("<%=request.getContextPath()%>/sp-fundallocate.do?reqCode=getFundName&appNo=<%=appNo%>");
ds.responseType = YAHOO.util.XHRDataSource.TYPE_TEXT;
ds.responseSchema = {
recordDelim: "/n",
fieldDelim: "/t"
};

var itemSelectHandler = function(sType, aArgs) {
var oMyAcInstance = aArgs[0];
var elListItem = aArgs[1];
var oData = aArgs[2];

var rowNum = oMyAcInstance.getInputEl().id.replace('fundNameInput', '');
var fundName = oMyAcInstance.getInputEl().value;

var transaction = YAHOO.util.Connect.asyncRequest('POST', '<%=request.getContextPath()%>/sp-fundallocate.do?reqCode=getFundInfo'
, callback, 'fundName='+fundName+'&rowNum='+rowNum);

};

var oACList = new Array();
for (var i = 0; i < <%=loopupCnt%>; i++) {
oACList[i] = new YAHOO.widget.AutoComplete("fundNameInput"+i, "fundNameResult"+i, ds);
oACList[i].animVert = false;
oACList[i].animHoriz = false;
oACList[i].applyLocalFilter = true;
oACList[i].queryMatchCase = false;
oACList[i].queryMatchContains = true;
oACList[i].itemSelectEvent.subscribe(itemSelectHandler);
oACList[i].generateRequest = function(sQuery) {
return "";
};

var autoComplete = document.getElementById("autoComplete"+i);
autoComplete.style.zIndex = <%=loopupCnt%> - i;
autoComplete.style.width = "25em";
autoComplete.style.paddingBottom = "1.5em";
}

function clearFundCode(seq, value){
if(value == ""){
var fcHidden = document.getElementById('fcHidden'+seq);
fcHidden.value = "";
var fcDiv = document.getElementById('fc'+seq);
fcDiv.innerHTML = "";

var fhHidden = document.getElementById('fhHidden'+seq);
fhHidden.value = "";
var fhDiv = document.getElementById('fh'+seq);
fhDiv.innerHTML = "";

var allocation = document.getElementById('switchToUnit'+seq);
allocation.value = "";
}else{
var fcDiv = document.getElementById('fc'+seq);
var fhDiv = document.getElementById('fh'+seq);

YAHOO.util.Connect.asyncRequest('POST', '<%=request.getContextPath()%>/sp-fundallocate.do?reqCode=getFundInfo'
, callback2, 'fundName='+value+'&rowNum='+seq);

}
}

var callback2 =
{
success: function(o) {
var xmlDoc = o.responseXML.documentElement;
var rowNum = xmlDoc.getElementsByTagName("rowNum")[0].childNodes[0].nodeValue;
var fundCode = xmlDoc.getElementsByTagName("fundCode")[0].childNodes[0].nodeValue;
var fundHsName = xmlDoc.getElementsByTagName("fundHsName")[0].childNodes[0].nodeValue;

if(fundCode == "null"){
return;
}

var fcDiv = document.getElementById('fc'+rowNum);
fcDiv.innerHTML = fundCode;

var fcHidden = document.getElementById('fcHidden'+rowNum);
fcHidden.value = fundCode;

var fhDiv = document.getElementById('fh'+rowNum);
fhDiv.innerHTML = fundHsName;

var fhHidden = document.getElementById('fhHidden'+rowNum);
fhHidden.value = fundHsName;

},
failure: function(o) {
alert('failure');
}
}
</script>
--%>

<%--Handling the autoComplete box-E--%>

<%-- For jQuery AutoComplete --%>

<script>

$(document).ready(function() {
$("input[name]='fundName'").each(function(i){
autocpl($('#fundNameInput'+i),i);
})
});

function autocpl(obj,j) {
$(obj).autocomplete('<%=request.getContextPath() %>/sp-fundallocate.do?reqCode=getFundInfos&appNo=<%=appNo%>', {
minChars: 1,
width:310,
max:10,
//delay:10,
autoFill: false,
mustMatch: false,
matchContains: false,
//selectFirst: true,
//cacheLength: 10,
//matchSubset: true,
//matchCase: false,
//multiple: false,
multipleSeparator: '',
//scroll: true,
//scrollHeight: 180,
dataType: 'json',
//onItemSelect: selectItemForFundName,
parse: function(data) {
return $.map(eval(data), function(row) {
return {
data: row,
value: row.fundCode,
result: row.fundName
}
});
},

formatItem: function(row, i, max) {
return row.fundCode + " - " + row.fundName;
}
,
formatMatch: function(row, i, max) {
return row.fundName;
}
,
formatResult: function(row) {
$("#fhHidden"+j).val(row.fundHsName);
$("#fh"+j).val(row.fundHsName);
$("#fh"+j).text(row.fundHsName);
$("#fcHidden"+j).val(row.fundCode);
$("#fc"+j).val(row.fundCode);
$("#fc"+j).text(row.fundCode);

return row.fundName;
}
});

$(obj).result(function(event, row, formatted) {
$("#fhHidden"+j).val(row.fundHsName);
$("#fh"+j).val(row.fundHsName);
$("#fh"+j).text(row.fundHsName);
$("#fcHidden"+j).val(row.fundCode);
$("#fc"+j).val(row.fundCode);
$("#fc"+j).text(row.fundCode);

$(obj).val(row.fundName);
});
}

function clearFundCode(seq, obj){
if(obj.value == ""){
var fcHidden = document.getElementById('fcHidden'+seq);
fcHidden.value = "";
var fcDiv = document.getElementById('fc'+seq);
fcDiv.innerHTML = "";

var fhHidden = document.getElementById('fhHidden'+seq);
fhHidden.value = "";
var fhDiv = document.getElementById('fh'+seq);
fhDiv.innerHTML = "";

var allocation = document.getElementById('switchToUnit'+seq);

var totalPerc=document.getElementById('totalPerc');
totalPerc.value=totalPerc.value-allocation.value;

allocation.value = "";

}else{
//autocpl($('#fundNameInput'+seq),seq);

var fhDiv = document.getElementById('fhHidden'+seq).value;
var fcDiv = document.getElementById('fcHidden'+seq).value;

$("#fhHidden"+seq).val(fhDiv);
$("#fh"+seq).val(fhDiv);
$("#fh"+seq).text(fhDiv);
$("#fcHidden"+seq).val(fcDiv);
$("#fc"+seq).val(fcDiv);
$("#fc"+seq).text(fcDiv);

<%--
//auto touch off js event
var fireOnThis = document.getElementById('fundNameInput'+seq);
if(document.createEvent)
{
var evObj = document.createEvent('UIEevents');
evObj.initEvent( 'keyup', true, false );
fireOnThis.dispatchEvent(evObj);
}
else if(document.createEventObject)
{
fireOnThis.fireEvent('keyup');
}
--%>
}
}

</script>
<%-- For jQuery AutoComplete --%>

</logic:notEqual>

</body>
</html:html>

<logic:equal name="func_code" scope="request" value="FN010154">
<logic:notEqual name="isLocked" scope="request" value="">
<script>
alert('<bean:write name="isLocked"/>');
</script>
</logic:notEqual>
</logic:equal>
<%@ include file="../include/contentheader.jsp" %>





/**
* getFundName
*/
public ActionForward getFundName(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException, SQLException, UserException {
log.debug("---com.eastpro.setupplan.action.FundAllocateAction.getFundName---begin---");

response.setContentType("text/plain");
PrintWriter out = response.getWriter();

String appNo = request.getParameter("appNo");

String[] columnName = { "fund_name" };
String[] columnType = { "STRING" };

DataFactory dataFactory = new DataFactory("dataFactory", columnName, columnType);

Collection result = dataFactory.select("select fund_name from v_cov_fund_mapping where app_no='"+appNo+"' and dealing_channel='"+Constants.DEALING_CHANNEL+"'");

if (result != null) {
for (Iterator it = result.iterator(); it.hasNext();) {
Data data = (Data) it.next();
out.print(data.getVcharProperty("fund_name") + "/n");
}
}

out.flush();
log.debug("---com.eastpro.setupplan.action.FundAllocateAction.getFundName---end---");
return null;
}


/**
* getFundInfo
*/
public ActionForward getFundInfo(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException, SQLException, UserException {
log.debug("---com.eastpro.setupplan.action.FundAllocateAction.getFundInfo---begin---");

Connection conn = (new ConnectionManager()).getConnection();
String langCode=(Constants.ENGLISH_VERSION.equals(LoginUserMgr.getCurrentVersion(request))? "E": "O");
try {
String[] columnName = { "fund_code", "ccy","fund_house_id","fund_house_name","fund_house_name_oth" };
String[] columnType = { "STRING","STRING", "STRING" , "STRING" , "STRING"};
DataFactory dataFactory = new DataFactory("dataFactory", columnName, columnType);

response.setContentType("text/xml");
PrintWriter out = response.getWriter();

//Get rowNum
String rowNum = request.getParameter("rowNum");

String fundCode = "";
String fundCcy = "";
String fundHsId = "";
String fundHsName = "";
//Collection result = dataFactory.select("select fund_code, ccy from prod_fund_mst where fund_name = '" + request.getParameter("fundName") + "'", conn);
Collection result = dataFactory.select("select f.fund_code,f.ccy,h.fund_house_id,h.fund_house_name,h.fund_house_name_oth from prod_fund_mst f,prod_fund_hse_mst h where f.comp_code=h.comp_code and f.fund_house_id=h.fund_house_id and f.fund_name = " + FormatMan.toSQLStr(request.getParameter("fundName")) , conn);
if (result != null) {
for (Iterator it = result.iterator(); it.hasNext();) {
Data data = (Data) it.next();
fundCode = data.getVcharProperty("fund_code");
fundCcy = data.getVcharProperty("ccy");
fundHsId = data.getVcharProperty("fund_house_id");
if(langCode!=null && "E".equals(langCode))
{
fundHsName = data.getVcharProperty("fund_house_name");
}
else
{
fundHsName = data.getVcharProperty("fund_house_name_oth");
}
}
}else{
fundCode = "null";
fundHsName = "null";
}
if(result.size() == 0){
fundCode = "null";
fundHsName = "null";
}

out.println("<xml>");
out.println("<rowNum>" + rowNum + "</rowNum>");
out.println("<fundCode>" + fundCode + "</fundCode>");
out.println("<fundCcy>" + fundCcy + "</fundCcy>");
out.println("<fundHsId>" + fundHsId + "</fundHsId>");
out.println("<fundHsName>" + fundHsName + "</fundHsName>");
out.println("</xml>");

out.flush();
} catch (Exception e) {
log.debug("Error: com.eastpro.setupplan.action.FundAllocateAction.getFundInfo()");
e.printStackTrace();
}finally{
ConnectionManager.releaseConnection(conn);
}
log.debug("---com.eastpro.setupplan.action.FundAllocateAction.getFundInfo---end---");
return null;
}


/**
* getFundName
*/
public void getFundInfos(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException, SQLException, UserException {
log.debug("---com.eastpro.setupplan.action.FundAllocateAction.getFundInfos---begin---");

response.setContentType("text/html;charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
PrintWriter out = response.getWriter();

Connection conn = (new ConnectionManager()).getConnection();
String langCode=(Constants.ENGLISH_VERSION.equals(LoginUserMgr.getCurrentVersion(request))? "E": "O");
FundMasterBean fundBean=null;
try {
String[] columnName = { "fund_code", "ccy","fund_house_id","fund_name","fund_house_name" };
String[] columnType = { "STRING","STRING", "STRING" , "STRING" , "STRING"};
DataFactory dataFactory = new DataFactory("dataFactory", columnName, columnType);

String appNo = request.getParameter("appNo");
String fundName = request.getParameter("q");
System.err.println("===request.getParameter(q)==="+request.getParameter("q")+"===");
fundName=fundName.toUpperCase();
fundName=fundName.trim();
if(fundName==null || "".equals(fundName))
{
fundName="''";
}
else
{
fundName=FormatMan.toSQLStr2(fundName);
}
System.err.println("===fundName==="+fundName+"===");
String fundCode = "";
String fundCcy = "";
String fundHsId = "";
String fundHsName = "";
StringBuffer strBuff=new StringBuffer(1000);
strBuff.append("select f.fund_code,f.ccy,h.fund_house_id, ");
if(langCode!=null && "O".equals(langCode))
{
strBuff.append("f.FUND_NAME_OTH as FUND_NAME,h.fund_house_id || ' - ' || h.fund_house_name_oth as fund_house_name ");
}
else
{
strBuff.append("f.FUND_NAME as FUND_NAME,h.fund_house_id || ' - ' || h.fund_house_name as fund_house_name ");
}
strBuff.append(" from v_cov_fund_mapping m, prod_fund_mst f,prod_fund_hse_mst h ");
strBuff.append(" where f.comp_code=h.comp_code and f.fund_house_id=h.fund_house_id ");
strBuff.append(" and m.fund_code=f.fund_code and m.comp_code=f.comp_code and m.fund_house_id=h.fund_house_id ");
strBuff.append(" and m.comp_code=h.comp_code and m.app_no='"+appNo+"' and m.dealing_channel='"+Constants.DEALING_CHANNEL+"' ");
if(langCode!=null && "O".equals(langCode))
{
/*
if(fundName.indexOf(" ")>0)
{
strBuff.append(" and (UPPER(f.FUND_NAME_OTH) LIKE UPPER("+fundName+"||'%') or UPPER(f.FUND_NAME_OTH) LIKE UPPER('%'|| "+fundName+"||'%') ");
}
else
{
//strBuff.append(" and (UPPER(f.FUND_NAME_OTH) LIKE UPPER("+fundName+"||'%') or UPPER(f.FUND_NAME_OTH) LIKE UPPER('%'|| "+fundName+") ");
//strBuff.append(" and (UPPER(f.FUND_NAME_OTH) LIKE UPPER("+fundName+"||'%') or UPPER(f.FUND_NAME_OTH) LIKE UPPER('%'||' '||"+fundName+"||'%') ");
}
*/
strBuff.append(" and (UPPER(f.FUND_NAME_OTH) LIKE '"+fundName+"%' or UPPER(f.FUND_NAME_OTH) LIKE '% "+fundName+"%' ");
}
else
{
/*
if(fundName.indexOf(" ")>0)
{
strBuff.append(" AND(UPPER(f.FUND_NAME) LIKE UPPER("+fundName+"||'%') or UPPER(f.FUND_NAME) LIKE UPPER('%'|| "+fundName+"||'%') ");
}
else
{
//strBuff.append(" AND(UPPER(f.FUND_NAME) LIKE UPPER("+fundName+"||'%') or UPPER(f.FUND_NAME) LIKE UPPER('%'|| "+fundName+") ");
//strBuff.append(" AND(UPPER(f.FUND_NAME) LIKE UPPER("+fundName+"||'%') or UPPER(f.FUND_NAME) LIKE UPPER('%'||' '||"+fundName+"||'%') ");
}
*/
strBuff.append(" AND(UPPER(f.FUND_NAME) LIKE '"+fundName+"%' or UPPER(f.FUND_NAME) LIKE '% "+fundName+"%' ");
}
/*
if(fundName.indexOf(" ")>0)
{
strBuff.append(" or UPPER(f.fund_code) LIKE UPPER("+fundName+"||'%') or UPPER(f.fund_code) LIKE UPPER('%'|| "+fundName+"||'%'))");
}
else
{
//strBuff.append(" or UPPER(f.fund_code) LIKE UPPER("+fundName+"||'%') or UPPER(f.fund_code) LIKE UPPER('%'|| "+fundName+"))");
//strBuff.append(" or UPPER(f.fund_code) LIKE UPPER("+fundName+"||'%') or UPPER(f.fund_code) LIKE UPPER('%'||' '||"+fundName+"||'%'))");
}
*/
strBuff.append(" or UPPER(f.fund_code) LIKE '"+fundName+"%' or UPPER(f.fund_code) LIKE '% "+fundName+"%')");
strBuff.append(" order by f.fund_code");
Collection result = dataFactory.select(strBuff.toString() , conn);
//List list = (List)dataFactory.select(strBuff.toString() , conn);
List list = new ArrayList();
if (result != null && result.size()>0) {
for (Iterator it = result.iterator(); it.hasNext();) {
Data data = (Data) it.next();
fundBean=new FundMasterBean();
fundCode = data.getVcharProperty("fund_code");
fundName = data.getVcharProperty("fund_name");
fundCcy = data.getVcharProperty("ccy");
fundHsId = data.getVcharProperty("fund_house_id");
fundHsName = data.getVcharProperty("fund_house_name");

fundBean.setFundCode(fundCode);
fundBean.setFundName(fundName);
fundBean.setFundCcy(fundCcy);
fundBean.setFundHsId(fundHsId);
fundBean.setFundHsName(fundHsName);
list.add(fundBean);
}
}
JSONObject json = new JSONObject();
json.accumulate("root", list);
String resultStr =json.toString();
resultStr = resultStr.substring(8, resultStr.length()-1);
out.write(resultStr);

out.flush();
} catch (Exception e) {
log.debug("Error: com.eastpro.setupplan.action.FundAllocateAction.getFundInfos()");
e.printStackTrace();
}finally{
try{
out.flush();
out.close();
out=null;
ConnectionManager.releaseConnection(conn);
}catch(Exception e){
e.printStackTrace();
}
}
log.debug("---com.eastpro.setupplan.action.FundAllocateAction.getFundInfos---end---");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: