(function(){ var TaskRunner = this.taskrunner = new Class({ Implements: [Events,Options], options:{ stateClass:{ error:'error2', loading:'loading', complete:'complete', success:'' }, showStep:'.appNum', showAppName:'.appName', container:false, dataClass:'.tasks_ipt' }, initialize:function(tasks,options){ this.setOptions(options); this.tasks=$splat(tasks); if(!this.tasks)return; this.num=this.tasks.length||0; this.container=$(this.options.container); }, init:function(container){ if(!this.iframe) this.iframe = this.options.iframe?this.options.iframe: new Element('iframe',{src:'about:blank',name:'_TASK_IFRM_',style:'display:none;height:100%;width:100%'}); container=container||this.container; this.iframe.inject(container||document.body); this.form = this.form||new Element('form',{style:'display:none',method:'post',target:this.iframe.name}).inject(document.body); var options=this.options; if(!container)return this; this.showStep=container.getElement(options.showStep); this.appName=container.getElement(options.showAppName); this.items=container.getElements('.box'); return this; }, getText:function(){ var temp = document.createElement('div'); return this[(temp.innerText == null) ? 'textContent' : 'innerText']; }, createFormData:function(ipt){ if(!this.form)return this; this.form.empty(); var options=this.options,fdoc=document.createDocumentFragment(), data=ipt?ipt:$ES(options.dataClass); if(data&&data.length) data.each(function(ipt,k){ var n=ipt.name,v=ipt.value; fdoc.appendChild(new Element('input',{type:'hidden','name':n,value:v})); }); this.form.appendChild(fdoc); return this; }, loader:function(){ if(this.items&&this.items.length)this.items[this.prestep].addClass(this.options.stateClass.loading); if(this.showStep)this.showStep.setText(this.step); if(this.appName)this.appName.setText(this.items[this.prestep].get('appname')); return this.fireEvent('loader'); }, cancel:function(){ return this.fireEvent('cancel',this.step); }, run:function(actions){ this.extra_action=actions; this.init(this.container).fireEvent('load',[this.tasks]).createFormData(); if(actions)return this.progress(actions); return this.start(); }, start:function(step,actions){ this.step=step||1; this.prestep=this.step-1; this.actions=actions||this.tasks[this.prestep]; return this.fireEvent('start').loader().progress(this.actions); }, error:function(text){ if(text)alert(text); var stateClass=this.options.stateClass; if(this.items&&this.items.length&&this.items[this.prestep]) this.items[this.prestep].removeClass(stateClass.loading).addClass(stateClass.error); return this.fireEvent('error',text).cancel(); }, next:function(step){ var steps=(step||0)+1; return this.start(steps); }, progress:function(actions){ if(!actions)return this; var action=actions||this.actions,iframe=this.iframe,_this=this,rsp,req; req = new Request({ url : action, method : 'post', data : this.createFormData().form.toQueryString(), onComplete : function(rs){ _this.check(rs); } }).send(); return this.fireEvent('progress'); }, check:function(messageText){ this.result=/(\s*)ok\.(\s*)/.test(messageText.slice(-4)); this.fireEvent('check',messageText); var error=messageText.slice(-500); messageText.slice(-500).replace(/Error:(\s\S+)/,function(){ var arg=arguments;error=arg[1]; }); return this.result?this.complete():this.error(error); }, complete:function(){ this.fireEvent('complete'); if(this.extra_action){delete this.extra_action;return this.start(1);} var stateClass=this.options.stateClass; if(this.items&&this.items.length) this.items[this.prestep].removeClass(stateClass.loading).addClass(stateClass.complete); if(!this.step&&!this.num)return this.success(); var step=this.step||0; return this[step==this.num?'success':'next'](step); }, success:function(){ if(this.form)this.form.destroy(); return this.fireEvent('success'); } }); var cmdrunner = this.cmdrunner = new Class({ Extends:TaskRunner, options:{ title:'', singlon:true }, delayT:function(){ if(!this.iframe.contentWindow)return this; var doc=this.iframe.contentWindow.document.body; if(!doc)return this; var text=this.getText.call(doc); text.replace(/[>|\n]([^\n]+)/gi,function($1,$2){ if($2.trim().length>1) this.csolinfo.set('text',$2); }.bind(this)); return this; }, startTimer:function(){ this.timer= this.delayT.periodical(200,this); return this; }, stopTimer:function(){ if(this.timer) $clear(this.timer); return this; }, check:function(iframe){ this.stopTimer().delayT(); return this.parent(iframe); }, createTpl:function(){ var queue=this.tasks,type=queue.filter(function(el){return el.type!=='dialog';}),html=this.options.singlon?'':'
loading...
'+LANG_Cmdrunner['console']+'