liftable.js前
var listTable = new Object;
listTable.query = "query";
listTable.filter = new Object;
listTable.url = location.href.lastIndexOf("?") == -1 ? location.href.substring((location.href.lastIndexOf("/")) + 1) : location.href.substring((location.href.lastIndexOf("/")) + 1, location.href.lastIndexOf("?"));
listTable.url = "list.action";
listTable.url += "?ajax=true";
/**
* 创建一个可编辑区
*/
listTable.edit = function(obj, act, id)
{
var tag = obj.firstChild.tagName;
if (typeof(tag) != "undefined" && tag.toLowerCase() == "input")
{
return;
}
/* 保存原始的内容 */
var org = obj.innerHTML;
var val = Browser.isIE ? obj.innerText : obj.textContent;
/* 创建一个输入框 */
var txt = document.createElement("INPUT");
txt.value = (val == 'N/A') ? '' : val;
txt.style.width = (obj.offsetWidth + 12) + "px" ;
/* 隐藏对象中的内容,并将输入框加入到对象中 */
obj.innerHTML = "";
obj.appendChild(txt);
txt.focus();
/* 编辑区输入事件处理函数 */
txt.onkeypress = function(e)
{
var evt = (typeof e == "undefined") ? window.event : e;
if (typeof e == "undefined") e = window.event;
var obj = document.all ? e.srcElement : e.target;
if (evt.keyCode == 13)
{
obj.blur();
return false;
}
if (evt.keyCode == 27)
{
obj.parentNode.innerHTML = org;
}
}
/* 编辑区失去焦点的处理函数 */
txt.onblur = function(e)
{
if ($.trim(txt.value).length > 0)
{
res = "";//Ajax.call(listTable.url, "act="+act+"&val=" + encodeURIComponent($.trim(txt.value)) + "&id=" +id, null, "POST", "JSON", false);
if (res.message)
{
alert(res.message);
}
if(res.id && (res.act == 'goods_auto' || res.act == 'article_auto'))
{
document.getElementById('del'+res.id).innerHTML = "<a href=\""+ thisfile +"?goods_id="+ res.id +"&act=del\" οnclick=\"return confirm('"+deleteck+"');\">"+deleteid+"</a>";
}
obj.innerHTML = (res.error == 0) ? res.content : org;
}
else
{
obj.innerHTML = org;
}
}
}
listTable.upMove = function(url){
$.getJSON(url,this.MapFilter(),this.listCallback);
}
listTable.downMove = function(url){
$.getJSON(url,this.MapFilter(),this.listCallback);
}
/**
* 切换状态
*/
listTable.toggle = function(obj,act,url)
{
var val = (obj.src.match(/tick.gif/i)) ? false : true;
var args= [];
args.push({name: act, value: val });
$.getJSON(url,args,function(res)
{
if (res.message)
{
alert(res.message);
}
if (res.error == 0)
{
obj.src = (val) ? 'Image/tick.gif' : 'Image/cross.gif';
}
}
);
}
/**
* 切换排序方式
*/
listTable.sort = function(sortName)
{
if (this.filter.sortName == sortName)
{
this.filter.sortOrder = this.filter.sortOrder == "desc" ? "asc" : "desc";
}
else
{
this.filter.sortName = sortName;
this.filter.sortOrder = "asc";
}
this.loadList();
}
listTable.isEmpty = function( val )
{
switch (typeof(val))
{
case 'string':
return $.trim(val).length == 0 ? true : false;
break;
case 'number':
return val == 0;
break;
case 'object':
return val == null;
break;
case 'array':
return val.length == 0;
break;
default:
return true;
}
}
/**
* 翻页
*/
listTable.gotoPage = function(page)
{
if (page != null) this.filter['page'] = page;
this.loadList();
}
/**
* 载入列表
*/
listTable.loadList = function()
{
//var args = "act="+this.query+"" + this.compileFilter();
// alert(this.url+" --- "+$.param(this.MapFilter()));
$.getJSON(this.url,this.MapFilter(),this.listCallback);
}
/**
* 删除列表中的一个记录
*/
listTable.remove = function(url, cfm)
{
if ((typeof(cfm) == 'undefined') || confirm(cfm))
{
$.getJSON(url,this.listCallback);
}
}
/**
*页尺寸修改
*/
listTable.changePageSize = function(pageSize)
{
if (pageSize != null) this.filter['pageSize'] = pageSize;
this.loadList();
}
/**
*页码修改
*/
listTable.changePage = function(e)
{
var evt = (typeof e == "undefined") ? window.event : e;
if (evt.keyCode == 13)
{
this.filter['page']= this.getPage(this.pageCount);
this.loadList();
return false;
};
}
listTable.changePageSyp = function()
{
var temp=$("#gotoPage").val();
this.gotoPage(temp);
}
listTable.getPage = function(pageCount)
{
var curPage = 1;
page = document.getElementById("curPage");
if (page)
{
curPage = this.isInt(page.value) ? page.value : 1;
if (curPage > this.pageCount) curPage = 1;
page.value=curPage;
}
return curPage;
}
listTable.listCallback = function(result)
{
if (result.error > 0)
{
alert(result.message);
}
else
{
try
{
document.getElementById('listDiv').innerHTML = result.content;
if (typeof result.filter == "object")
{
listTable.filter = result.filter;
}
}
catch (e)
{
alert(e.message);
}
}
}
listTable.MapFilter = function()
{
var args = [];
for (var i in this.filter)
{
if (typeof(this.filter[i]) != "function" && typeof(this.filter[i]) != "undefined")
{
if (this.filter[i] != "")
{
args.push({name: i, value: this.filter[i] });
}
}
}
return args;
}
listTable.isInt = function(val)
{
if (val == "")
{
return false;
}
var reg = /\D+/;
return !reg.test(val);
}
listTable.compileFilter = function()
{
var args = '';
for (var i in this.filter)
{
if (typeof(this.filter[i]) != "function" && typeof(this.filter[i]) != "undefined")
{
args += "&" + i + "=" + encodeURIComponent(this.filter[i]);
}
}
return args;
}
listTable.change = function(url){
$.getJSON(url,this.MapFilter(),this.selectCallback);
}
listTable.selectCallback = function(result)
{
if (result.error > 0)
{
alert(result.message);
}
else
{
try
{
document.getElementById('selectOffice').innerHTML = result.content;
}
catch (e)
{
alert(e.message);
}
}
}