You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/js/Grid/jsGrid.js

200 lines
6.3 KiB
JavaScript

3 years ago
function el(id){
return document.getElementById(id);
}
window.onload = function(){ //alert(abc);
el("div1").oncontextmenu = function(ev){
showMenu(ev);
return false;
};
document.onmousedown = function(){if(!over)hideMenu();};
};
var over = false;
var menu = null;
function showMenu(ev){
ev = ev || window.event;
hideMenu();
var e = ev.srcElement || ev.target;
if(e.tagName=="TH") return;
var x = ev.pageX || ev.clientX + document.documentElement.scrollLeft;
var y = ev.pageY || ev.clientY + document.documentElement.scrollTop;
menu = document.createElement("DIV");
menu.className = "menu";
menu.style.left = x+4+"px";
menu.style.top = y+"px";
document.body.appendChild(menu);
var id = e.parentNode.getElementsByTagName("td")[1].innerHTML;
e.parentNode.id = "tr_"+id;
var sname = document.location.pathname.substring(7,location.pathname.length).toString();
var s = "<a href=\"javascript:showInfo({id},'{sname}');\">详细信息</a>";
s += "<a href=\"javascript:refresh('{sname}');\">刷新</a>";
//s += "<a href='javascript:editInfo({id});'>修改用户信息</a>";
//s += "<a href='javascript:deleteInfo({id});'>删除该条记录</a>";
s = s.replace(/{id}/g, id);
s = s.replace(/{sname}/g, sname);
menu.innerHTML = s;
menu.onmouseover = function(){over=true;};
menu.onmouseout = function(){over=false;};
}
function hideMenu(){
if(menu){
document.body.removeChild(menu);
menu = null;
}
}
function refresh(sname){
var req = getReq();
req.open("GET", sname+"?refresh=1&id=", true);
/*req.onreadystatechange = function(){
if(req.readyState==4)
{
el("bod").innerHTML = req.responseText;
}
};*/
req.send(null);
}
function showInfo(id,sname){
hideMenu();
shideBody();
el("tit").innerHTML = "查看用户的详细信息";
el("bod").innerHTML = "<img src='wait.gif' alt='loading...' />";
el("bot").innerHTML = "<input type='button' value='关闭' onclick='cancelShide()' />";
var req = getReq();
req.open("GET", sname+"?getinfo=1&id="+id, true);
req.onreadystatechange = function(){
if(req.readyState==4){
el("bod").innerHTML = req.responseText;
}
};
req.send(null);
}
function editInfo(id){
hideMenu();
shideBody();
el("tit").innerHTML = "编辑用户信息";
el("bod").innerHTML = "<img src='wait.gif' alt='loading...' />";
el("bot").innerHTML = "<input type='button' value='确定' onclick='doEdit("+id+")' /> <input type='button' value='取消' onclick='cancelShide()' />";
var tds = el("tr_"+id).getElementsByTagName("td");
var boy = tds[2].innerHTML == "男";
var s = "<table>";
s += "<tr><td>姓名</td><td><input type='text' value='"+ tds[1].innerHTML +"' /></td></tr>";
s += "<tr><td>性别</td><td><input type='radio' name='rad_sex'"+ (boy?" checked":"") +" />男 <input type='radio' name='rad_sex'"+ (!boy?" checked":"") +" />女</td></tr>";
s += "<tr><td>年龄</td><td><input type='text' value='"+ tds[3].innerHTML +"' /></td></tr>";
s += "</table>";
el("bod").innerHTML = s;
}
function deleteInfo(id){
hideMenu();
if(!confirm("确定要删除该记录吗?"))return;
removeRow(el("tr_"+id));
var req = getReq();
req.open("GET", "default.aspx?delete=1&id="+id, true);
req.onreadystatechange = function(){};
req.send(null);
}
function doEdit(id){
var puts = el("bod").getElementsByTagName("input");
if(isNaN(puts[3].value)){
puts[3].select();return;
}
var tds = el("tr_"+id).getElementsByTagName("td");
tds[1].innerHTML = puts[0].value;
tds[2].innerHTML = puts[1].checked?"男":"女";
tds[3].innerHTML = puts[3].value;
var data = "name="+ escape(tds[1].innerHTML);
data += "&sex="+ escape(tds[2].innerHTML);
data += "&age="+ escape(tds[3].innerHTML);
var req = getReq();
req.open("POST", "default.aspx?edit=1&id="+id, true);
req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
req.onreadystatechange = function(){};
req.send(data);
cancelShide();
}
var shield;
function shideBody()
{
shield = document.createElement("DIV");
shield.id = "shield";
shield.style.position = "absolute";
shield.style.left = "0px";
shield.style.top = "0px";
shield.style.width = "100%";
shield.style.height = document.documentElement.scrollHeight+"px";
shield.style.background = "#333333";
shield.style.textAlign = "center";
shield.style.zIndex = "10";
shield.style.filter = "alpha(opacity=0)";
shield.style.opacity = 0;
document.body.appendChild(shield);
this.setOpacity = function(obj,opacity){
if(opacity>=1)opacity=opacity/100;
try{ obj.style.opacity=opacity; }catch(e){}
try{
if(obj.filters.length>0 && obj.filters("alpha")){
obj.filters("alpha").opacity=opacity*150;
}else{
obj.style.filter="alpha(opacity=\""+(opacity*150)+"\")";
}
}catch(e){}
}
var c = 0;
this.doAlpha = function(){
if (++c > 20){clearInterval(ad);return 0;}
setOpacity(shield,c);
}
var ad = setInterval("doAlpha()",1);
el("divh").style.display = "";
el("divh").style.marginTop = -75+document.documentElement.scrollTop + "px";
}
function cancelShide()
{
if(el("divh"))
{
el("divh").style.display = "none";
}
if(shield)
{
document.body.removeChild(shield);
shield = null;
}
}
function getReq()
{
var oHttpReq = null;
if(window.ActiveXObject)
oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
else if(window.createRequest)
oHttpReq = window.createRequest();
else
oHttpReq = new XMLHttpRequest();
return oHttpReq;
}
function removeRow(e)
{
e.style.backgroundColor = "#ff0000";
setTimeout(function(){e.style.backgroundColor = "#ffcccc";},100);
setTimeout(function(){e.style.backgroundColor = "MistyRose";},300);
setTimeout(function(){e.style.display = "none";},450);
}