﻿function RecordListPageControl(id,pageSize)
{this.id=id;this.pageSize=pageSize;this.totalRows=-1;this.currentPage=0;this.onPageChange=new REvent();RegisterControl.statics.getInstance().add(this);this.onPageChange.addEventListener(new REventListener(this.onPageChangeListener,this));}
RecordListPageControl.prototype.attach=function(node)
{var table=document.createElement("table");table.id=RegisterControl.statics.encodeId(this);table.className='layoutTable';var tbody=document.createElement("tbody");table.appendChild(tbody);var tr=document.createElement("tr");tbody.appendChild(tr);var td=document.createElement("td");td.id=RegisterControl.statics.encodeId(this,"recordsCell");td.style.padding="0 4px 0 0";tr.appendChild(td);td=document.createElement("td");tr.appendChild(td);var button=new StyleButton(this.getId()+'_firstPage',this.getId()+'_firstPage',null,RecordListPageControl.statics.onFirstPageClick,ResourcesPlatform.FirstPage,'/timesheet/WebResource.axd?d=djLaH47sOAKNk7WaoWvCi_RRTU6pSfwL94oFXgbC5k5o2xy33KPVs4jWGqvT1h2c1wv_nRcDd2c-wwzv0iXA5yxXfLzL5E9t1oI1TsqG9S3qipl6Q2iZfn0CIWXOX3dD0&t=633894763760000000&c=1',StyleButton.statics.Size["SHORT"]);button.PlaceInDom(td,Mixin_DomInsertable.statics.INSERTMETHOD_APPENDASCHILD);button.GetDomNode().instanceId=this.getId();td=document.createElement("td");tr.appendChild(td);button=new StyleButton(this.getId()+'_previousPage',this.getId()+'_previousPage',null,RecordListPageControl.statics.onPreviousPageClick,ResourcesPlatform.PreviousPage,'/timesheet/WebResource.axd?d=djLaH47sOAKNk7WaoWvCi_RRTU6pSfwL94oFXgbC5k5o2xy33KPVs4jWGqvT1h2c1wv_nRcDd2c-wwzv0iXA5yxXfLzL5E9t1oI1TsqG9S3i1orWv8gLr3C4RAnlvmqblQaV5WwBbR9IT1MlhoVq0w2&t=633894763760000000&c=1',StyleButton.statics.Size["SHORT"]);button.PlaceInDom(td,Mixin_DomInsertable.statics.INSERTMETHOD_APPENDASCHILD);button.GetDomNode().instanceId=this.getId();td=document.createElement("td");td.id=RegisterControl.statics.encodeId(this,"pageCell");td.style.padding="0 4px 0 4px";tr.appendChild(td);td.appendChild(document.createTextNode(ResourcesPlatform.Page+" "));var pageSelect=document.createElement("select");pageSelect.instanceId=this.getId();pageSelect.id=RegisterControl.statics.encodeId(this,"pageSelect");pageSelect.onchange=RecordListPageControl.statics.onPageChange;td.appendChild(pageSelect);td.appendChild(document.createTextNode(" "+ResourcesPlatform.Of+" "));var pageTotal=document.createElement("span");pageTotal.id=RegisterControl.statics.encodeId(this,"pageTotal");td.appendChild(pageTotal);td=document.createElement("td");tr.appendChild(td);button=new StyleButton(this.getId()+'_nextPage',this.getId()+'_nextPage',null,RecordListPageControl.statics.onNextPageClick,ResourcesPlatform.NextPage,'/timesheet/WebResource.axd?d=djLaH47sOAKNk7WaoWvCi_RRTU6pSfwL94oFXgbC5k5o2xy33KPVs4jWGqvT1h2c1wv_nRcDd2c-wwzv0iXA5yxXfLzL5E9t1oI1TsqG9S31vgKeuvyGigGwVQvS3nLw0&t=633894763760000000&c=1',StyleButton.statics.Size["SHORT"]);button.PlaceInDom(td,Mixin_DomInsertable.statics.INSERTMETHOD_APPENDASCHILD);button.GetDomNode().instanceId=this.getId();td=document.createElement("td");tr.appendChild(td);button=new StyleButton(this.getId()+'_lastPage',this.getId()+'_lastPage',null,RecordListPageControl.statics.onLastPageClick,ResourcesPlatform.LastPage,'/timesheet/WebResource.axd?d=djLaH47sOAKNk7WaoWvCi_RRTU6pSfwL94oFXgbC5k5o2xy33KPVs4jWGqvT1h2c1wv_nRcDd2c-wwzv0iXA5yxXfLzL5E9t1oI1TsqG9S36EDGbg86LBUdaUdcZES110&t=633894763760000000&c=1',StyleButton.statics.Size["SHORT"]);button.PlaceInDom(td,Mixin_DomInsertable.statics.INSERTMETHOD_APPENDASCHILD);button.GetDomNode().instanceId=this.getId();node.appendChild(table);}
RecordListPageControl.prototype.setCurrentRows=function(totalRows,startIndex)
{var page=Math.floor(startIndex/this.pageSize);if(this.totalRows!=totalRows||this.currentPage!=page)
{this.totalRows=totalRows;this.currentPage=page;this.updateRecordsCell();this.updatePageCell();var totalPages=this.getTotalPages();if(this.currentPage>=totalPages)
this.setPage(totalPages-1);}}
RecordListPageControl.prototype.getStartRecord=function()
{return(this.currentPage)*this.pageSize;}
RecordListPageControl.prototype.getTotalPages=function()
{var totalPages=Math.ceil(this.totalRows/this.pageSize);if(1>totalPages)
totalPages=1;return totalPages;}
RecordListPageControl.prototype.updateRecordsCell=function()
{var recordsCell=document.getElementById(RegisterControl.statics.encodeId(this,"recordsCell"));var startRecord=this.getStartRecord()+1;var endRecord=((this.currentPage+1)*this.pageSize);if(endRecord>this.totalRows)
endRecord=this.totalRows;if(startRecord>endRecord)
startRecord=endRecord;recordsCell.innerHTML=ResourcesPlatform.Records+" <b>"+startRecord+"</b> "+ResourcesPlatform.To+" <b>"+endRecord+"</b> "+ResourcesPlatform.Of+" "+this.totalRows;}
RecordListPageControl.prototype.updatePageCell=function()
{var totalPages=this.getTotalPages();var pageSelect=document.getElementById(RegisterControl.statics.encodeId(this,"pageSelect"));pageSelect.options.length=totalPages;for(var i=1;i<=totalPages;i++)
{pageSelect.options[i-1].text=i;}
if(this.currentPage<totalPages)
pageSelect.options.selectedIndex=this.currentPage;var pageTotal=document.getElementById(RegisterControl.statics.encodeId(this,"pageTotal"));pageTotal.innerHTML=totalPages;}
RecordListPageControl.prototype.setPage=function(page)
{this.currentPage=page;var pageSelect=document.getElementById(RegisterControl.statics.encodeId(this,"pageSelect"));if(pageSelect)
this.currentPage=pageSelect.options.selectedIndex;}
RecordListPageControl.prototype.onPageChangeListener=function(recordIndex)
{this.updateRecordsCell();}
RecordListPageControl.prototype.getId=function()
{return this.id;}
RecordListPageControl.prototype.jumpPage=function()
{var pageSelect=document.getElementById(RegisterControl.statics.encodeId(this,"pageSelect"));this.currentPage=pageSelect.options.selectedIndex;this.onPageChange.trigger(this.getStartRecord());}
RecordListPageControl.prototype.setPage=function(page)
{if(this.currentPage!=page)
{this.currentPage=page;var pageSelect=document.getElementById(RegisterControl.statics.encodeId(this,"pageSelect"));if(pageSelect)
pageSelect.options.selectedIndex=this.currentPage;this.onPageChange.trigger(this.getStartRecord());}}
RecordListPageControl.prototype.firstPage=function()
{this.setPage(0);}
RecordListPageControl.prototype.lastPage=function()
{this.setPage(this.getTotalPages()-1);}
RecordListPageControl.prototype.nextPage=function()
{var page=this.currentPage+1;if(page<this.getTotalPages())
this.setPage(page);}
RecordListPageControl.prototype.previousPage=function()
{var page=this.currentPage-1;if(0<=page)
this.setPage(page);}
RecordListPageControl.statics=new Object();RecordListPageControl.statics.onPageChange=function(){RecordListPageControl.statics.callFunction(this.instanceId,"jumpPage");}
RecordListPageControl.statics.onFirstPageClick=function(){RecordListPageControl.statics.callFunction(this.instanceId,"firstPage");}
RecordListPageControl.statics.onLastPageClick=function(){RecordListPageControl.statics.callFunction(this.instanceId,"lastPage");}
RecordListPageControl.statics.onNextPageClick=function(){RecordListPageControl.statics.callFunction(this.instanceId,"nextPage");}
RecordListPageControl.statics.onPreviousPageClick=function(){RecordListPageControl.statics.callFunction(this.instanceId,"previousPage");}
RecordListPageControl.statics.callFunction=function(id,functionName)
{var params=new Array();var instance=RegisterControl.statics.decodeId(id,params);instance[functionName].apply(instance);}