/**
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates.
 * The Universal Permissive License (UPL), Version 1.0
 */
"use strict";
define(["ojs/ojcore","jquery","ojs/ojpagingtabledatasource"],function(a){a.Bl=function(a,b){this.gN=a;this.wr=b};o_("PagingCellSet",a.Bl,a);a.Bl.prototype.getData=function(a){return this.gN.getData({column:a.column,row:a.row+this.wr})};a.b.g("PagingCellSet.prototype.getData",{getData:a.Bl.prototype.getData});a.Bl.prototype.getMetadata=function(a){return this.gN.getMetadata({column:a.column,row:a.row+this.wr})};a.b.g("PagingCellSet.prototype.getMetadata",{getMetadata:a.Bl.prototype.getMetadata});a.Bl.prototype.getCount=
function(a){return this.gN.getCount(a)};a.b.g("PagingCellSet.prototype.getCount",{getCount:a.Bl.prototype.getCount});a.Bl.prototype.Hfa=function(){return this.gN};a.b.g("PagingCellSet.prototype.getCellSet",{Hfa:a.Bl.prototype.Hfa});a.Bl.prototype.sF=function(){return this.wr};a.b.g("PagingCellSet.prototype.getStartIndex",{sF:a.Bl.prototype.sF});a.qb=function(g){if(!(g instanceof a.Pr))throw new a.ia("Not a datagridatasource","Not a datagridatasource",a.ia.Yc.ERROR);this.Od=g;this.pa=0;this.Init()};
o_("PagingDataGridDataSource",a.qb,a);a.b.sa(a.qb,a.Pr,"oj.PagingDataGridDataSource");a.qb.prototype.Init=function(){a.qb.u.Init.call(this);this.qE()};a.b.g("PagingDataGridDataSource.prototype.Init",{Init:a.qb.prototype.Init});a.qb.prototype.qE=function(){this.Od.on("change",this.Qva.bind(this))};a.qb.prototype.getPage=function(){return this.ie};a.b.g("PagingDataGridDataSource.prototype.getPage",{getPage:a.qb.prototype.getPage});a.qb.prototype.setPage=function(g,b){b=b||{};g=parseInt(g,10);try{a.qb.u.handleEvent.call(this,
a.bd.O.BEFOREPAGE,{page:g,previousPage:this.ie})}catch(c){return Promise.reject(null)}this.yb=null!=b.pageSize?b.pageSize:this.yb;b.startIndex=g*this.yb;var d=this.ie;this.ie=g;this.pa=b.startIndex;var e=this;return new Promise(function(a,c){e.Hg(b).then(function(){a(null)},function(){e.ie=d;e.pa=e.ie*e.yb;c(null)})})};a.b.g("PagingDataGridDataSource.prototype.setPage",{setPage:a.qb.prototype.setPage});a.qb.prototype.Hg=function(a){this.Dq=!0;this.pa=a.startIndex;var b=this;return new Promise(function(a){b.handleEvent("change",
{operation:"sync",pageSize:b.yb});a(void 0)})};a.qb.prototype.fetch=function(a){this.yb=a.pageSize+a.startIndex;a.startIndex=0;return this.Hg(a)};a.b.g("PagingDataGridDataSource.prototype.fetch",{fetch:a.qb.prototype.fetch});a.qb.prototype.getStartItemIndex=function(){return this.pa};a.b.g("PagingDataGridDataSource.prototype.getStartItemIndex",{getStartItemIndex:a.qb.prototype.getStartItemIndex});a.qb.prototype.getEndItemIndex=function(){return this.Rk};a.b.g("PagingDataGridDataSource.prototype.getEndItemIndex",
{getEndItemIndex:a.qb.prototype.getEndItemIndex});a.qb.prototype.getPageCount=function(){var a=this.totalSize();return-1==a?-1:Math.ceil(a/this.yb)};a.b.g("PagingDataGridDataSource.prototype.getPageCount",{getPageCount:a.qb.prototype.getPageCount});a.qb.prototype.Qva=function(g){switch(g.operation){case "refresh":this.pa=0;this.handleEvent("change",{operation:"sync",pageSize:this.yb});this.handleEvent(a.Ba.O.REFRESH,null);break;case "reset":this.handleEvent(a.Ba.O.RESET,null);break;case "insert":this.handleEvent(a.Ba.O.ADD,
{index:g.indexes.row});break;case "delete":this.handleEvent(a.Ba.O.REMOVE,null);break;case "update":g.indexes.row=0<=g.indexes.row-this.pa?g.indexes.row-this.pa:-1;this.handleEvent("change",g);break;default:this.handleEvent("change",g),this.handleEvent(a.Ba.O.SYNC,null)}};a.qb.prototype.getCount=function(a){var b=this.Od.getCount(a);return"row"===a&&0<=b?this.pa+this.yb<b?this.yb:b-this.pa:b};a.b.g("PagingDataGridDataSource.prototype.getCount",{getCount:a.qb.prototype.getCount});a.qb.prototype.getCountPrecision=
function(a){return this.Od.getCountPrecision(a)};a.b.g("PagingDataGridDataSource.prototype.getCountPrecision",{getCountPrecision:a.qb.prototype.getCountPrecision});a.qb.prototype.fetchHeaders=function(a,b,c){null==this.Dq?null!=b&&b.success&&b.success.call(c.success,null,a,null):"row"===a.axis?(a.start+=this.pa,a.start+a.count>this.pa+this.yb&&(a.count=this.yb-a.start),this.bw={headerRange:a,callbacks:b,callbackObjects:c},this.Od.fetchHeaders(a,{success:this.nU.bind(this),error:this.uxa.bind(this)},
c)):this.Od.fetchHeaders(a,b,c)};a.b.g("PagingDataGridDataSource.prototype.fetchHeaders",{fetchHeaders:a.qb.prototype.fetchHeaders});a.qb.prototype.nU=function(g,b,c){var d,e;this.bw.headerRange==b&&(b.start-=this.pa,b.count+=1,null!=g&&(d=new a.Wf(g,this.pa)),null!=c&&(e=new a.Wf(c,this.pa)),g=this.bw.callbacks.success,c=this.bw.callbackObjects.success,this.bw=null,g.call(c,d,b,e))};a.qb.prototype.uxa=function(a){var b,c;b=this.bw.callbacks.error;c=this.bw.callbackObjects.error;this.bw=null;b.call(c,
a)};a.qb.prototype.fetchCells=function(a,b,c){var d;if(null==this.Dq)d={getData:function(){return null},getMetaData:function(){return null},getStart:function(){return 0},getCount:function(){return 0},getLevelCount:function(){return 0},getExtent:function(){return 0},getDepth:function(){return 1}},null!=b&&b.success&&b.success.call(c.success,d,a);else{for(d=0;d<a.length;d+=1)"row"===a[d].axis&&(a[d].start+=this.pa,a[d].start+a[d].count>this.pa+this.yb&&(a[d].count=this.yb-a[d].start));this.aw={cellRanges:a,
callbacks:b,callbackObjects:c};this.Od.fetchCells(a,{success:this.Pva.bind(this),error:this.Ova.bind(this)},c)}};a.b.g("PagingDataGridDataSource.prototype.fetchCells",{fetchCells:a.qb.prototype.fetchCells});a.qb.prototype.Pva=function(g,b){var c,d,e;if(!this.aw.cellRanges!=b){for(c=0;c<b.length;c+=1)"row"===b[c].axis&&(b[c].start-=this.pa,b[c].count+=1);c=new a.Bl(g,this.pa);d=this.aw.callbacks.success;e=this.aw.callbackObjects.success;this.aw=null;this.Rk=this.pa+g.getCount("row")-1;this.handleEvent("sync",
{data:Array(g.getCount("row")),startIndex:this.pa});d.call(e,c,b)}};a.qb.prototype.Ova=function(a){var b,c;b=this.aw.callbacks.error;c=this.aw.callbackObjects.error;this.aw=null;b.call(c,a)};a.qb.prototype.keys=function(a){return this.Od.keys({column:a.column,row:a.row+this.pa})};a.b.g("PagingDataGridDataSource.prototype.keys",{keys:a.qb.prototype.keys});a.qb.prototype.indexes=function(a){a=this.Od.indexes(a);-1!=a.row&&(a.row-=this.pa);return a};a.b.g("PagingDataGridDataSource.prototype.indexes",
{indexes:a.qb.prototype.indexes});a.qb.prototype.getCapability=function(a){return this.Od.getCapability(a)};a.b.g("PagingDataGridDataSource.prototype.getCapability",{getCapability:a.qb.prototype.getCapability});a.qb.prototype.size=function(){var a;if(null==this.Dq)return-1;a=this.Od.getCount("row");return this.Od.getCount("row")>this.yb?this.yb:a};a.b.g("PagingDataGridDataSource.prototype.size",{size:a.qb.prototype.size});a.qb.prototype.sort=function(a,b,c){this.Od.sort(a,b,c)};a.b.g("PagingDataGridDataSource.prototype.sort",
{sort:a.qb.prototype.sort});a.qb.prototype.totalSize=function(){return null==this.Dq?-1:this.Od.getCount("row")};a.b.g("PagingDataGridDataSource.prototype.totalSize",{totalSize:a.qb.prototype.totalSize});a.qb.prototype.totalSizeConfidence=function(){return"actual"};a.b.g("PagingDataGridDataSource.prototype.totalSizeConfidence",{totalSizeConfidence:a.qb.prototype.totalSizeConfidence});a.qb.prototype.moveOK=function(a,b,c){return this.Od.moveOK(a,b,c)};a.b.g("PagingDataGridDataSource.prototype.moveOK",
{moveOK:a.qb.prototype.moveOK});a.qb.prototype.move=function(a,b,c,d,e){this.Od.move(a,b,c,d,e)};a.b.g("PagingDataGridDataSource.prototype.move",{move:a.qb.prototype.move});a.Wf=function(a,b){this.Uw=a;this.wr=b};o_("PagingHeaderSet",a.Wf,a);a.Wf.prototype.getData=function(a,b){return this.Uw.getData(a+this.wr,b)};a.b.g("PagingHeaderSet.prototype.getData",{getData:a.Wf.prototype.getData});a.Wf.prototype.getMetadata=function(a,b){return this.Uw.getMetadata(a+this.wr,b)};a.b.g("PagingHeaderSet.prototype.getMetadata",
{getMetadata:a.Wf.prototype.getMetadata});a.Wf.prototype.getCount=function(){return this.Uw.getCount()};a.b.g("PagingHeaderSet.prototype.getCount",{getCount:a.Wf.prototype.getCount});a.Wf.prototype.getLevelCount=function(){return this.Uw.getLevelCount()};a.b.g("PagingHeaderSet.prototype.getLevelCount",{getLevelCount:a.Wf.prototype.getLevelCount});a.Wf.prototype.getExtent=function(a,b){return this.Uw.getExtent(a+this.wr,b)};a.b.g("PagingHeaderSet.prototype.getExtent",{getExtent:a.Wf.prototype.getExtent});
a.Wf.prototype.getDepth=function(a,b){return this.Uw.getDepth(a+this.wr,b)};a.b.g("PagingHeaderSet.prototype.getDepth",{getDepth:a.Wf.prototype.getDepth});a.Wf.prototype.Yfa=function(){return this.Uw};a.b.g("PagingHeaderSet.prototype.getHeaderSet",{Yfa:a.Wf.prototype.Yfa});a.Wf.prototype.sF=function(){return this.wr};a.b.g("PagingHeaderSet.prototype.getStartIndex",{sF:a.Wf.prototype.sF})});