(function(){"use strict";u8.Base.Widgets.JobManager=function(e,t){this.Widget(e,$.extend({},u8.Base.Widgets.JobManager.defaults,t));this.commandBindings={Refresh:this._onCommandRefresh.bind(this),Dequeue:this._onCommandDequeue.bind(this)};u8.using({texts:["net_jobmanager_texts"],templates:[{name:"u8-jobmanager",url:"~/base/jobmanager.utml.htm"}]},this._create.bind(this))};u8.Base.Widgets.JobManager.makeClass({name:"JobManager",deriveFrom:u8.Base.Widgets.Widget});u8.Base.Widgets.JobManager.defaults={theme:{css:{root:"u8-panels",content:"u8-padding",gridPanel:"u8-panel u8-margin-top",statusPanel:"u8-panel u8-margin-top-l"}}};$.extend(u8.Base.Widgets.JobManager.prototype,{update:function(){this._update()},dispose:function(){if(this._isDisposed){return}this.Widget_dispose()},_create:function(){this._createModel();this._createView(this._update.bind(this))},_createModel:function(){var t=($t("TXT_net_jobmanager_texts_2")||"#Id,Name,Status,Started,Ended,Duration,% Complete").split(",");var a=[{dataKey:"executionId"},{dataKey:"name"},{dataKey:"status"},{dataKey:"dateStarted",cellFormatter:e},{dataKey:"dateEnded",cellFormatter:e},{dataKey:"durationSeconds"},{dataKey:"percentComplete"}];a.each(function(e,a){e.label=t[a]});this._gridModel=u8.create("GridModel",{rowActionCount:1,columns:a,selectionMode:"single",onSelectionChange:this._onGridSelectionChange.bind(this)})},_createView:function(e){var t={emptyGridText:$t("TXT_net_jobmanager_texts_3")||"No jobs are currently available.",model:this._gridModel,allowColumnReordering:false,allowColumnResizing:false,header:null};var a={headerName:"Special",headerGroupName:"JobManager",isDefault:this.isDefault};this.$(this.element).empty().addClass(this.theme.css.root).utml({name:"u8-jobmanager",itemOptions:{parent:this},data:{id:this.id,css:this.theme.css,gridOptions:t,headerOptions:a}},e)},_update:function(){this._updateJobList(this._updateJobStatus.bind(this))},_updateJobList:function(e){var t=this._gridModel;u8.services.jobs.getJobs(function(a,s){if(s.error||!s.jobs){return}function i(e){var t=s.jobs[e];if(t.status!==u8.Base.Jobs.JobStatus.queued){return{}}return{actions:[{image:"u8-img-delete-s",tooltip:$t("TXT_net_jobmanager_texts_6")||"Dequeue Job",command:"Dequeue",commandArguments:{executionId:t.executionId}}]}}t.setData(s.jobs,{createRows:true,rowFn:i});t.update({from:0,to:t.getRowCount()-1});if(e){e()}})},_updateJobStatus:function(){var e=this.$("#"+this.id+"_statusPanel");var t=this._gridModel.getSelectedRow();var a=t&&this._gridModel.getRowData(t);var s=a&&a.status;if(t===null||s===u8.Base.Jobs.JobStatus.failed||s===u8.Base.Jobs.JobStatus.complete){e.hide();if(this._jobStatus){this._jobStatus.dispose();delete this._jobStatus}}else{e.show();var i=a.executionId;if(this._jobStatus){this._jobStatus.setExecutionId(i)}else{var o=this.$("#"+this.id+"_status").empty();this._jobStatus=u8.widget("JobStatus",o,{executionId:i,parent:this})}}},_dequeueJob:function(e){var t=this;u8.services.jobs.dequeueJob(e,function(e,a){if(a.error||!a.job){return}t._update()})},_onGridSelectionChange:function(e,t){this._updateJobStatus()},_onCommandRefresh:function(e,t){this._update()},_onCommandDequeue:function(e,t,a){if(t!=="Dequeue"){return}this._dequeueJob(a.executionId)}});function e(e){return u8.services.typeConverter.dateToString(e,"Date Time")}})();