(function(){"use strict";u8.Base.JobPoller=function(t){$.extend(this,u8.Base.JobPoller.defaults,t);if(!this.jobId){$error("The job poller needs a job id!")}this.bind();if(this.startImmediately){this.start()}};u8.Base.JobPoller.defaults={autoRefreshInterval:100};$.extend(u8.Base.JobPoller.prototype,{dispose:function(){if(this._isDisposed){return}this.stop();delete this._status;this._isDisposed=true},start:function(){if(this._isDisposed){$error("Can not start disposed poller.")}if(this._status=="Polling"){$error("Can not start poller that is already polling.")}if(this._status=="Stopped"){$error("Can not restart poller that has been stopped.")}this._getJob()},stop:function(){if(this._isDisposed){return}if(this._timer){clearTimeout(this._timer);delete this._timer}this._status="Stopped"},isPolling:function(){return this._status=="Polling"},_getJob:function(){this._status="Polling";delete this._timer;var t=this;u8.services.jobs.getJob(this.jobId,function(e,s){if(t._status!="Polling"){return undefined}if(s.error){return t.raise("Error",s)}var r=s.job;if(!r){return t.raise("Error",{error:{message:"The response was empty!"}})}t.raise("Progress",{job:r,progress:r.tasks&&r.tasks.length>0&&r.tasks.map(function(t){return $.extend({},t.data,{infoAreaId:t.name})})});if(r.status!=u8.Base.Jobs.JobStatus.queued&&r.status!=u8.Base.Jobs.JobStatus.executing){t.stop();t.raise("Done",{job:r})}else{t._timer=setTimeout(t._getJob.bind(t),t.autoRefreshInterval)}})}});u8.Base.JobPoller.makeClass({name:"JobPoller",events:["Done","Error","Progress"]})})();