mirror of
https://gitee.com/ShopeX/OMS
synced 2026-04-05 06:45:32 +08:00
3 lines
6.8 KiB
JavaScript
3 lines
6.8 KiB
JavaScript
|
|
|
|
!function(){var t=this.taskrunner=new Class({Implements:[Events,Options],options:{stateClass:{error:"error2",loading:"loading",complete:"complete",success:""},showStep:".appNum",showAppName:".appName",container:!1,dataClass:".tasks_ipt"},initialize:function(t,e){this.setOptions(e),this.tasks=$splat(t),this.tasks&&(this.num=this.tasks.length||0,this.container=$(this.options.container))},init:function(t){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%"})),t=t||this.container,this.iframe.inject(t||document.body),this.form=this.form||new Element("form",{style:"display:none",method:"post",target:this.iframe.name}).inject(document.body);var e=this.options;return t&&(this.showStep=t.getElement(e.showStep),this.appName=t.getElement(e.showAppName),this.items=t.getElements(".box")),this},getText:function(){return this[null==document.createElement("div").innerText?"textContent":"innerText"]},createFormData:function(t){if(!this.form)return this;this.form.empty();var e=this.options,n=document.createDocumentFragment(),s=t||$ES(e.dataClass);return s&&s.length&&s.each(function(t,e){var s=t.name,i=t.value;n.appendChild(new Element("input",{type:"hidden",name:s,value:i}))}),this.form.appendChild(n),this},loader:function(){return this.items&&this.items.length&&this.items[this.prestep].addClass(this.options.stateClass.loading),this.showStep&&this.showStep.setText(this.step),this.appName&&this.appName.setText(this.items[this.prestep].get("appname")),this.fireEvent("loader")},cancel:function(){return this.fireEvent("cancel",this.step)},run:function(t){return this.extra_action=t,this.init(this.container).fireEvent("load",[this.tasks]).createFormData(),t?this.progress(t):this.start()},start:function(t,e){return this.step=t||1,this.prestep=this.step-1,this.actions=e||this.tasks[this.prestep],this.fireEvent("start").loader().progress(this.actions)},error:function(t){t&&alert(t);var e=this.options.stateClass;return this.items&&this.items.length&&this.items[this.prestep]&&this.items[this.prestep].removeClass(e.loading).addClass(e.error),this.fireEvent("error",t).cancel()},next:function(t){var e=(t||0)+1;return this.start(e)},progress:function(t){if(!t)return this;var e=t||this.actions,s=(this.iframe,this);new Request({url:e,method:"post",data:this.createFormData().form.toQueryString(),onComplete:function(t){s.check(t)}}).send();return this.fireEvent("progress")},check:function(t){this.result=/(\s*)ok\.(\s*)/.test(t.slice(-4)),this.fireEvent("check",t);var e=t.slice(-500);return t.slice(-500).replace(/Error:(\s\S+)/,function(){e=arguments[1]}),this.result?this.complete():this.error(e)},complete:function(){if(this.fireEvent("complete"),this.extra_action)return delete this.extra_action,this.start(1);var t=this.options.stateClass;if(this.items&&this.items.length&&this.items[this.prestep].removeClass(t.loading).addClass(t.complete),!this.step&&!this.num)return this.success();var e=this.step||0;return this[e==this.num?"success":"next"](e)},success:function(){return this.form&&this.form.destroy(),this.fireEvent("success")}}),s=this.cmdrunner=new Class({Extends:t,options:{title:"",singlon:!0},delayT:function(){if(!this.iframe.contentWindow)return this;var t=this.iframe.contentWindow.document.body;return t&&this.getText.call(t).replace(/[>|\n]([^\n]+)/gi,function(t,e){1<e.trim().length&&this.csolinfo.set("text",e)}.bind(this)),this},startTimer:function(){return this.timer=this.delayT.periodical(200,this),this},stopTimer:function(){return this.timer&&$clear(this.timer),this},check:function(t){return this.stopTimer().delayT(),this.parent(t)},createTpl:function(){var t=this.tasks,e=t.filter(function(t){return"dialog"!==t.type}),i=this.options.singlon?"":"<h5>"+LANG_Cmdrunner.title+"</h5>";i+='<ul class="division apptip">',e.length&&e.each(function(t,e){var s=t.name||this.options.title;i+='<li class="box" appname="'+s+'">'+s+"</li>"},this);var s=t.filter(function(t){return"dialog"!=t.type}).length;i+="</ul>",this.theme=this.options.singlon?i:i+'<div class="division loader"><em class="appNum">0</em>/<em>'+s+'</em><span class="appName"></span></div>';var n='<div class="console"><p class="csolinfo">loading...</p><span class="lnk csol" onClick="_open(\'index.php?app=desktop&ctl=appmgr&act=app_console\')">'+LANG_Cmdrunner.console+"</span></div>";return this.container.innerHTML=this.theme+n,this.csolinfo=$E(".csolinfo",this.container),this},close:function(t){var e=t||this.dialog;return e&&e.close.delay(800,e),this},adddialog:function(t){return new Dialog(t,{title:this.options.title,height:200,width:600,modal:!0,resizeable:!1,onClose:function(){this.stopTimer()}.bind(this)})},progress:function(t){var e;switch(t.type){case"command":e="index.php?app=desktop&ctl=appmgr&act=command&command_id="+t.command_id+"&data="+encodeURIComponent(t.data),this.startTimer().parent(e);break;case"dialog":e="index.php?app=desktop&ctl=appmgr&act="+t.action+"&data="+encodeURIComponent(t.data),this.tasks.splice(this.prestep,1),this.num=this.tasks.length,this.stopTimer(),new Request.HTML({url:e,append:this.appinfo,onComplete:function(){var t=this.appinfo.getElement(".appbtn");t?(this.container.hide(),t.addEvent("click",function(){this.container.show(),this.appinfo.hide(),this.start(this.step)}.bind(this))):this.start(this.step)}.bind(this)}).get();break;default:this.startTimer().parent(t)}},init:function(){return this.container=this.container||new Element("div",{"class":"appbox",html:this.theme||""}),this.dialog=this.adddialog.call(this,this.container),this.appinfo=new Element("div",{"class":"appinfo"}).inject(this.container,"before"),this.createTpl().parent(this.container),this},success:function(){this.parent(),this.options.singlon&&this.close(),MessageBox.success(LANG_Cmdrunner.success)}});this.appmgr=function(t){return new e(t,{onSuccess:function(){if(finderGroup)for(var t in finderGroup)finderGroup[t]&&finderGroup[t].refresh()}})};var e=new Class({Extends:t,type:{install:LANG_Cmdrunner.install,uninstall:LANG_Cmdrunner.uninstall,update:LANG_Cmdrunner.update,pause:LANG_Cmdrunner.stop,active:LANG_Cmdrunner.start,download:LANG_Cmdrunner.download},run:function(t){this.app_id=t,this.parent()},init:function(){return this},progress:function(t){new Request.JSON({url:"index.php?app=desktop&ctl=appmgr&act=prepare&action="+t,onSuccess:this.prepare.bind(this)}).post({action:t,app_id:this.app_id})},prepare:function(t){if(!t)return this.error();switch(t.status){case"confirm":if(!window.confirm(t.message))return this.dialog&&this.dialog.close(),this;break;case"alert":return void alert(t.message)}var e=this.type;return this.queue=t.queue,this.dialog&&this.dialog.close(),this.runner=new s(this.queue,{title:e[this.tasks[this.prestep]]+":"+this.app_id,singlon:!1,onSuccess:this.complete.bind(this)}),this.runner.run(),this.dialog=this.runner.dialog},success:function(){this.parent().runner.close(this.dialog)}})}(); |