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.

159 lines
4.9 KiB
JavaScript

10 months ago
function $(id){
return document.getElementById(id);
}
//根据不通用屏幕分辨率设定Grid高度 LWP 2012-10-13
function initDialog(){
var winScreenHeight = 0;
var winScreenWidth = 0;
if(window.screen.height){
winScreenHeight = window.screen.height;
}
if(window.screen.width){
winScreenWidth = window.screen.width;
}
if(winScreenWidth >= 1440 && winScreenWidth >= 900){
document.getElementById("mygrid").style.height = "420px";
}else if(winScreenWidth >= 1366 && winScreenWidth >= 768){
document.getElementById("mygrid").style.height = "340px";
}else if(winScreenWidth >= 1024 && winScreenWidth >= 768){
document.getElementById("mygrid").style.height = "300px";
}
}
function newGuid()
{
var guid = "";
for (var i = 1; i <= 32; i++){
var n = Math.floor(Math.random()*16.0).toString(16);
guid += n;
if((i==8)||(i==12)||(i==16)||(i==20))
guid += "-";
}
return guid.toUpperCase();
}
//转换函数(将数组转为字符串) LWP 2012-10-13
function dotransition(paraobj)
{
var tem_str = "";
for(var i=0;i<paraobj.length;i++)
{
tem_str += paraobj[i] + ",";
}
tem_str = tem_str.substring(0,tem_str.length-1);
return tem_str;
}
function PagerView(id){
var self = this;
this.id = id;
this.container = null;
this.index = 1; // 当前页码, 从1开始
this.size = page_count; // 每页显示记录数
this.maxButtons = 9; // 显示的分页按钮数量
this.itemCount = 0; // 记录总数
this.pageCount = 0; // 总页数
/**
* 控件使用者重写本方法, 获取翻页事件, 可用来向服务器端发起AJAX请求.
* @param index: 被点击的页码.
*/
this.onclick = function(index){
};
/**
* 内部方法.
*/
this._onclick = function(index){
self.index = index;
self.onclick(index);
self.render();
};
/**
* 在显示之前计算各种页码变量的值.
*/
this.calculate = function(){
self.pageCount = parseInt(Math.ceil(self.itemCount / self.size));
self.index = parseInt(self.index);
if(self.index > self.pageCount){
self.index = self.pageCount;
}
};
/**
* 渲染分页控件.
*/
this.render = function(){
if(self.id != undefined){
var div = document.getElementById(self.id);
div.view = self;
self.container = div;
}
self.calculate();
var start, end;
start = Math.max(1, self.index - parseInt(self.maxButtons/2));
end = Math.min(self.pageCount, start + self.maxButtons - 1);
start = Math.max(1, end - self.maxButtons + 1);
var str = "";
str += "<div class=\"PagerView\">\n";
if(self.pageCount > 1){
if(self.index != 1){
str += '<a href="javascript://1"><span>|&lt;</span></a>';
str += '<a href="javascript://' + (self.index-1) + '"><span>&lt;&lt;</span></a>';
}else{
str += '<span>|&lt;</span>';
str += '<span>&lt;&lt;</span>';
}
}
for(var i=start; i<=end; i++){
if(i == this.index){
str += '<span class="on">' + i + "</span>";
}else{
str += '<a href="javascript://' + i + '"><span>' + i + "</span></a>";
}
}
if(self.pageCount > 1){
if(self.index != self.pageCount){
str += '<a href="javascript://' + (self.index+1) + '"><span>&gt;&gt;</span></a>';
str += '<a href="javascript://' + self.pageCount + '"><span>&gt;|</span></a>';
}else{
str += '<span>&gt;&gt;</span>';
str += '<span>&gt;|</span>';
}
}
str += ' 一共' + self.pageCount + '页, ' + self.itemCount + '条记录 '+'&nbsp;&nbsp;&nbsp;每页显示:&nbsp;'+"<select id=\"cusShowCount\" style=\"width:70px;\" onchange=\"changeShowCount('cusShowCount')\">"+getPageOption()+"</select>";
str += "</div><!-- /.pagerView -->\n";
self.container.innerHTML = str;
var a_list = self.container.getElementsByTagName('a');
for(var i=0; i<a_list.length; i++){
a_list[i].onclick = function(){
var index = this.getAttribute('href');
if(index != undefined && index != ''){
index = parseInt(index.replace('javascript://', ''));
self._onclick(index)
}
return false;
};
}
};
}
function getPageOption(){
var pageCountArg = new Array();
pageCountArg.push(15);
pageCountArg.push(30);
pageCountArg.push(50);
pageCountArg.push(100);
pageCountArg.push(200);
var optionStr = "";
for(var i = 0;i<pageCountArg.length;i++){
if(page_count == parseInt(pageCountArg[i])){
optionStr += "<option value=\""+pageCountArg[i]+"\" selected=\"1\">"+pageCountArg[i]+"</option>";
}else{
optionStr += "<option value=\""+pageCountArg[i]+"\">"+pageCountArg[i]+"</option>";
}
}
return optionStr;
;
}