/*******************************************************************************
* 声 明:Copyright @zhiye, 2005
* 功 能:客户端分页处理
* 描 述:将页面显示的元素信息传输到客户端后
* 借助JS对其进行动态的分页和排序
* 以提高网站的访问速度
* @作者:智野
* @时间:2005-9-25
* @版本:V1.0.1
* 历 史:
* 创建
* 修 改:无
******************************************************************************/
/**
* 封装起来的分页处理类
* @属性
* total - 总记录数
* pageSize - 每页显示记录数
* currentPage - 当前页
* totalPage - 总页数
* lastPage - 最后一页
* previousPage - 上一页
* nextPage - 下一页
* firstPage - 首页
*
* @方法
* getStartIndex() -- 获取当前页面输出的起始位置
* getEndIndex() -- 获取当前页面输出的结束位置
* setPage() -- 设置当前页面,并同步其他参数
* writeViewBar() -- 输出分页导航信息到指定容器
* setPatternObj() -- 设定用来输出内容的容器
* writeViewBar() -- 输出分页导航信息到指定容器
*
* first() -- 显示首页
* previous() -- 显示上一页
* next() -- 显示下一页
* last() -- 显示尾页
*
* @限定条件
* 需要结合pageElementObj.js中的pageElement方法使用
*
*/
function PageView(size,total){
/**
* 用来输出内容的页面容器
*/
this.patternObj = null;
/**
* 总记录数
*/
this.total = total;
/**
* 每页显示记录数
*/
this.pageSize = (size > 0) ? size : 1;
/**
* 当前页
*/
this.currentPage = 1;
/**
* 总页数
*/
this.totalPage = Math.ceil(this.total / this.pageSize);
//纠错运算
this.totalPage = (this.totalPage > 0) ? this.totalPage : 1;
this.currentPage = (this.totalPage < this.currentPage)?this.totalPage:this.currentPage;
/**
* 最后一页
*/
this.lastPage = this.totalPage;
/**
* 上一页
*/
this.previousPage = (this.currentPage > 1) ? (this.currentPage - 1) : 1;
/**
* 下一页
*/
this.nextPage = (this.currentPage + 1 < this.totalPage) ? (this.currentPage + 1) : this.totalPage;
/**
* 首页
*/
this.firstPage = 1;
/**
* 获取当前页面输出的起始位置
* @out 无
* @return 当前页面输出的起始位置
*/
this.getStartIndex = function(){
return (this.currentPage-1) * this.pageSize;
}
/**
* 获取当前页面输出的结束位置
* @out 无
* @return 当前页面输出的结束位置
*/
this.getEndIndex = function(){
return (this.currentPage >= this.totalPage)? (this.total - 1):(this.currentPage * this.pageSize -1);
}
/**
* 设置当前页面,并同步其他参数
* @out 无
* @return true - 成功
* @return false - 失败
*/
this.setPage = function(current){
this.currentPage = (current > 0) ? current : 1;
this.currentPage = (this.totalPage < this.currentPage)?this.totalPage:this.currentPage;
this.previousPage = (this.currentPage > 1) ? (this.currentPage - 1) : 1;
this.nextPage = (this.currentPage + 1 < this.totalPage) ? (this.currentPage + 1) : this.totalPage;
}
/**
* 输出分页导航信息到指定容器
* @out 分页导航条
* @return true-输出成功
* false-输出失败
*/
this.writeViewBar = function(barObj) {
try{
//若分页容器不存在,则返回
if(barObj == null){
alert("指定的显示分页导航条的对象不存在!");
return false;
}
var barString = "第"+this.currentPage+"页/共"+this.totalPage+"页 ";
barString += " <font style='cursor:hand;' οnclick='page.first();' title='首页'>首页</font>";
barString += " <font style='cursor:hand;' οnclick='page.previous();' title='上一页' >上一页</font>";
barString += " <font style='cursor:hand;' οnclick='page.next();' title='下一页' >下一页</font>";
barString += " <font style='cursor:hand;' οnclick='page.last();' title='尾页' >尾页</font>";
//输出barString到指定容器
barObj.innerHTML = barString;
return true;
}catch(e){
return false;
}
}
/**
* 设定用来输出内容的容器
* @out 当页内容
* @return true-输出成功
* false-输出失败
*/
this.setPatternObj = function(obj){
this.patternObj = obj;
}
/**
* 显示首页内容到指定容器
* @out 首页要显示的元素
* @return true-输出成功
* false-输出失败
*/
this.first = function(){
if(this.patternObj == null)return false;
this.setPage(this.firstPage);
viewPattern(this.patternObj,this.getStartIndex(),this.getEndIndex());
}
/**
* 显示上一页内容到指定容器
* @out 上一页要显示的元素
* @return true-输出成功
* false-输出失败
*/
this.previous = function(){
if(this.patternObj == null || this.currentPage == 1)return false;
this.setPage(this.currentPage - 1);
viewPattern(this.patternObj,this.getStartIndex(),this.getEndIndex());
}
/**
* 显示下一页内容到指定容器
* @out 下一页要显示的元素
* @return true-输出成功
* false-输出失败
*/
this.next = function(){
if(this.patternObj == null || this.currentPage == this.totalPage)return false;
this.setPage(this.currentPage + 1);
viewPattern(this.patternObj,this.getStartIndex(),this.getEndIndex());
}
/**
* 显示尾页内容到指定容器
* @out 尾页要显示的元素
* @return true-输出成功
* false-输出失败
*/
this.last = function(){
if(this.patternObj == null)return false;
this.setPage(this.lastPage);
viewPattern(this.patternObj,this.getStartIndex(),this.getEndIndex());
}
}