123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- function ViewerLoadManager(widget) {
- this.m_oWidget = widget;
- this.m_oDelayedLoadingContext = new DelayedLoadingContext();
- this.m_aQueue = [];
- this.m_fOnEmptyCallback = null;
- this.m_bPendingRequest = false;
- this.m_bViewerLoadInitiated = false;
- this.m_bCanRunReports = false;
- }
- ViewerLoadManager.prototype.viewerLoadInitiated = function() {
- this.m_bViewerLoadInitiated = true;
- };
- ViewerLoadManager.prototype.isViewerLoadInitiated = function() {
- return this.m_bViewerLoadInitiated;
- };
- ViewerLoadManager.prototype.canRunReports = function() {
- return this.m_bCanRunReports;
- };
- ViewerLoadManager.prototype.runningReport = function() {
- if(!this.m_bCanRunReports) {
- this._queue( { fCallback: dojo.hitch(this, function() {
- this.m_bCanRunReports = true;
- return false;
- })});
- }
- };
- ViewerLoadManager.prototype.isViewerReady = function() {
- if(!this.isViewerLoaded()) {
- return false;
- }
-
- if(!this._isEmpty() || this.m_fOnEmptyCallback || this.m_bPendingRequest) {
- return false;
- }
- return true;
- };
- ViewerLoadManager.prototype.isViewerLoaded = function() {
-
- var oCV = this.m_oWidget.getViewerObject();
- if(!oCV) {
- return false;
- }
- if(this.m_oWidget.isLiveReport()) {
- var sStatus = oCV.getStatus();
- return sStatus === "complete" || sStatus === "prompting" || sStatus === "fault";
- }
- return true;
- };
- ViewerLoadManager.prototype.runWhenHasViewer = function(f, sGroupId) {
- if(this.isViewerReady()) {
- this._run(f);
- return true;
- } else {
- var oCallback = {fCallback: f};
- if(sGroupId) {
- oCallback.sGroupId = sGroupId;
- }
- this._queue(oCallback);
-
- if(!this.m_bViewerLoadInitiated) {
- this.getDelayedLoadingContext().setForceRunReport(true);
- this.m_oWidget.setRunReportOption(false);
- this.m_oWidget.postReport(null);
- }
- return false;
- }
- };
- ViewerLoadManager.prototype.processQueue = function() {
-
- this.m_bPendingRequest = false;
-
-
-
- var bServerRequest = false;
- while(!bServerRequest && !this._isEmpty()) {
- var oCallback = this.m_aQueue.shift();
-
-
- while(oCallback.sGroupId && !this._isEmpty() && this.m_aQueue[0].sGroupId === oCallback.sGroupId) {
- oCallback = this.m_aQueue.shift();
- }
- bServerRequest = this._run(oCallback.fCallback);
- }
-
-
-
-
- if(this._isEmpty() && !bServerRequest && this.m_fOnEmptyCallback) {
- var fCallback = this.m_fOnEmptyCallback;
- this.m_fOnEmptyCallback = null;
- fCallback();
- }
- };
- ViewerLoadManager.prototype._run = function(f) {
- var bServerRequest = f.call();
- if(bServerRequest) {
-
-
-
- this.m_bPendingRequest = true;
- }
- return bServerRequest;
- };
- ViewerLoadManager.prototype._isEmpty = function() {
- return !this.m_aQueue.length;
- };
- ViewerLoadManager.prototype._queue = function(oEntry) {
- this.m_aQueue.push(oEntry);
- };
- ViewerLoadManager.prototype.setOnEmptyCallback = function(fCallback) {
- this.m_fOnEmptyCallback = fCallback;
- };
- ViewerLoadManager.prototype.getDelayedLoadingContext = function() {
- return this.m_oDelayedLoadingContext;
- };
|