Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/ui/stepprocessing/dist/ |
Upload File : |
this.BX=this.BX||{};this.BX.UI=this.BX.UI||{};(function(t,e,s,i,n,o,r,l){"use strict";const a={progress:"PROGRESS",completed:"COMPLETED"};const h={intermediate:"INTERMEDIATE",running:"RUNNING",completed:"COMPLETED",stopped:"STOPPED",error:"ERROR",canceling:"CANCELING"};let u=t=>t,d,p,c,g,f,m,S,y;class B{constructor(t){this.obligatory=false;this.emptyMessage="";this.className="";this.disabled=false;this.value=null;this.id="id"in t?t.id:"ProcessDialogField_"+Math.random().toString().substring(2);this.name=t.name;this.type=t.type;this.title=t.title;this.obligatory=!!t.obligatory;if("value"in t){this.setValue(t.value)}if("emptyMessage"in t&&l.Type.isStringFilled(t.emptyMessage)){this.emptyMessage=t.emptyMessage}else{this.emptyMessage=l.Loc.getMessage("UI_STEP_PROCESSING_EMPTY_ERROR")||""}}setValue(t){throw new Error("BX.UI.StepProcessing: Must be implemented by a subclass")}getValue(){throw new Error("BX.UI.StepProcessing: Must be implemented by a subclass")}render(){throw new Error("BX.UI.StepProcessing: Must be implemented by a subclass")}lock(t=true){throw new Error("BX.UI.StepProcessing: Must be implemented by a subclass")}isFilled(){throw new Error("BX.UI.StepProcessing: Must be implemented by a subclass")}getInput(){return this.field?this.field:null}getContainer(){if(!this.container){this.container=l.Tag.render(d||(d=u`<div class="${0} ${0}"></div>`),Y.ProcessOptionContainer,this.className);if(this.title){this.container.appendChild(l.Tag.render(p||(p=u`<div class="${0}"></div>`),Y.ProcessOptionsTitle)).appendChild(l.Tag.render(c||(c=u`<label for="${0}_inp">${0}</label>`),this.id,this.title))}this.container.appendChild(l.Tag.render(g||(g=u`<div class="${0}"></div>`),Y.ProcessOptionsInput)).appendChild(this.render());if(this.obligatory){const t=this.id+"_alert";this.container.appendChild(l.Tag.render(f||(f=u`<div id="${0}" class="${0}" style="display:none"></div>`),t,Y.ProcessOptionsObligatory)).appendChild(l.Tag.render(m||(m=u`<span class="ui-alert-message">${0}</span>`),this.emptyMessage))}}return this.container}showWarning(t){const e=t!=null?t:this.emptyMessage;const s=this.id+"_alert";const i=this.container.querySelector("#"+s);if(i){if(l.Type.isStringFilled(e)){const t=i.querySelector(".ui-alert-message");t.innerHTML=e}i.style.display="block"}else if(l.Type.isStringFilled(e)){this.container.appendChild(l.Tag.render(S||(S=u`<div id="${0}" class="${0}"></div>`),s,Y.ProcessOptionsObligatory)).appendChild(l.Tag.render(y||(y=u`<span class="ui-alert-message">${0}</span>`),e))}return this}hideWarning(){const t=this.id+"_alert";const e=this.container.querySelector("#"+t);if(e){e.style.display="none"}return this}}let T=t=>t,E;class b extends B{constructor(t){super(t);this.type="text";this.className=Y.ProcessOptionText;this.rows=10;this.cols=50;if(t.textSize){this.cols=t.textSize}if(t.textLine){this.rows=t.textLine}}setValue(t){this.value=t;if(this.field){this.field.value=this.value}return this}getValue(){if(this.field&&this.disabled!==true){if(typeof this.field.value!=="undefined"){this.value=this.field.value}}return this.value}isFilled(){if(this.field){if(typeof this.field.value!=="undefined"){return l.Type.isStringFilled(this.field.value)}}return false}render(){if(!this.field){this.field=l.Tag.render(E||(E=T`<textarea id="${0}" name="${0}" cols="${0}" rows="${0}"></textarea>`),this.id,this.name,this.cols,this.rows)}if(this.value){this.field.value=this.value}return this.field}lock(t=true){this.disabled=t;this.field.disabled=!!t;return this}}let P=t=>t,O;class C extends B{constructor(t){if(!("emptyMessage"in t)){t.emptyMessage=l.Loc.getMessage("UI_STEP_PROCESSING_FILE_EMPTY_ERROR")}super(t);this.type="file";this.className=Y.ProcessOptionFile}setValue(t){this.value=t;if(this.field){if(t instanceof FileList){this.field.files=t}else if(t instanceof File){this.field.files[0]=t}}return this}getValue(){if(this.field&&this.disabled!==true){if(typeof this.field.files[0]!="undefined"){this.value=this.field.files[0]}}return this.value}isFilled(){if(this.field){if(typeof this.field.files[0]!="undefined"){return true}}return false}render(){if(!this.field){this.field=l.Tag.render(O||(O=P`<input type="file" id="${0}" name="${0}">`),this.id,this.name)}return this.field}lock(t=true){this.disabled=t;this.field.disabled=!!t;return this}}let w=t=>t,R,k,_,v,D,x,M;class q extends B{constructor(t){super(t);this.type="checkbox";this.list=[];this.multiple=false;this.className=Y.ProcessOptionCheckbox;if("list"in t){this.list=t.list}this.multiple=this.list.length>1;if(this.multiple){this.class=Y.ProcessOptionMultiple}}setValue(t){if(this.multiple){this.value=l.Type.isArray(t)?t:[t]}else{if(t==="Y"||t==="N"||t===null||t===undefined){t=t==="Y"}this.value=t}if(this.field){if(this.multiple){const t=this.field.querySelectorAll("input[type=checkbox]");if(t){for(let e=0;e<t.length;e++){t[e].checked=this.value.indexOf(t[e].value)!==-1}}}else{const t=this.field.querySelector("input[type=checkbox]");if(t){t.checked=l.Type.isBoolean(this.value)?this.value:t.value===this.value}}}return this}getValue(){if(this.field&&this.disabled!==true){if(this.multiple){this.value=[];const t=this.field.querySelectorAll("input[type=checkbox]");if(t){for(let e=0;e<t.length;e++){if(t[e].checked){this.value.push(t[e].value)}}}}else{const t=this.field.querySelector("input[type=checkbox]");if(t){if(t.value&&t.value!=="Y"){this.value=t.checked?t.value:""}else{this.value=t.checked}}}}return this.value}isFilled(){if(this.field){const t=this.field.querySelectorAll("input[type=checkbox]");if(t){return true}}return false}getInput(){if(this.field){if(this.multiple){const t=this.field.querySelectorAll("input[type=checkbox]");if(t){return t}}else{const t=this.field.querySelector("input[type=checkbox]");if(t){return t}}}return null}render(){if(!this.field){this.field=l.Tag.render(R||(R=w`<div id="${0}"></div>`),this.id)}if(this.multiple){Object.keys(this.list).forEach((t=>{if(this.value.indexOf(t)!==-1){this.field.appendChild(l.Tag.render(k||(k=w`<label><input type="checkbox" name="${0}[]" value="${0}" checked>${0}</label>`),this.name,t,this.list[t]))}else{this.field.appendChild(l.Tag.render(_||(_=w`<label><input type="checkbox" name="${0}[]" value="${0}">${0}</label>`),this.name,t,this.list[t]))}}))}else{if(l.Type.isBoolean(this.value)){if(this.value){this.field.appendChild(l.Tag.render(v||(v=w`<input type="checkbox" id="${0}_inp" name="${0}" value="Y" checked>`),this.id,this.name))}else{this.field.appendChild(l.Tag.render(D||(D=w`<input type="checkbox" id="${0}_inp" name="${0}" value="Y">`),this.id,this.name))}}else{if(this.value!==""){this.field.appendChild(l.Tag.render(x||(x=w`<input type="checkbox" id="${0}_inp" name="${0}" value="${0}" checked>`),this.id,this.name,this.value))}else{this.field.appendChild(l.Tag.render(M||(M=w`<input type="checkbox" id="${0}_inp" name="${0}" value="${0}>"`),this.id,this.name,this.value))}}}return this.field}lock(t=true){this.disabled=t;if(this.field){const e=this.field.querySelectorAll("input[type=checkbox]");if(e){for(let s=0;s<e.length;s++){e[s].disabled=!!t}}}return this}}let I=t=>t,A,F;class N extends B{constructor(t){super(t);this.type="select";this.multiple=false;this.list=[];this.className=Y.ProcessOptionSelect;if("multiple"in t){this.multiple=l.Type.isBoolean(t.multiple)?t.multiple===true:t.multiple==="Y"}if(this.multiple){if("size"in t){this.size=t.size}}if("list"in t){this.list=t.list}}setValue(t){if(this.multiple){this.value=l.Type.isArray(t)?t:[t]}else{this.value=t}if(this.field){if(this.multiple){for(let t=0;t<this.field.options.length;t++){this.field.options[t].selected=this.value.indexOf(this.field.options[t].value)!==-1}}else{this.field.value=this.value}}return this}getValue(){if(this.field&&this.disabled!==true){if(this.multiple){this.value=[];for(let t=0;t<this.field.options.length;t++){if(this.field.options[t].selected){this.value.push(this.field.options[t].value)}}}else{this.value=this.field.value}}return this.value}isFilled(){if(this.field){for(let t=0;t<this.field.options.length;t++){if(this.field.options[t].selected){return true}}}return false}render(){if(!this.field){this.field=l.Tag.render(A||(A=I`<select id="${0}" name="${0}"></select>`),this.id,this.name)}if(this.multiple){this.field.multiple="multiple";if(this.size){this.field.size=this.size}}Object.keys(this.list).forEach((t=>{let e;if(this.multiple===true){e=this.value.indexOf(t)!==-1}else{e=t===this.value}let s=this.field.appendChild(l.Tag.render(F||(F=I`<option value="${0}">${0}</option>`),t,this.list[t]));if(e){s.selected="selected"}}));return this.field}lock(t=true){this.disabled=t;this.field.disabled=!!t;return this}}let L=t=>t,j,X,W;class U extends B{constructor(t){super(t);this.type="radio";this.list=[];this.className=Y.ProcessOptionMultiple;if("list"in t){this.list=t.list}}setValue(t){this.value=t;if(this.field){const t=this.field.querySelectorAll("input[type=radio]");if(t){for(let e=0;e<t.length;e++){t[e].checked=t[e].value===this.value}}}return this}getValue(){if(this.field){const t=this.field.querySelectorAll("input[type=radio]");if(t){for(let e=0;e<t.length;e++){if(t[e].checked){this.value=t[e].value;break}}}}return this.value}isFilled(){if(this.field){const t=this.field.querySelectorAll("input[type=radio]");if(t){for(let e=0;e<t.length;e++){if(t[e].checked){return true}}}}return false}getInput(){if(this.field&&this.disabled!==true){const t=this.field.querySelector("input[type=radio]");if(t){return t}}return null}render(){if(!this.field){this.field=l.Tag.render(j||(j=L`<div id="${0}"></div>`),this.id)}Object.keys(this.list).forEach((t=>{if(t===this.value){this.field.appendChild(l.Tag.render(X||(X=L`<label><input type="radio" name="${0}" value="${0}" checked>${0}</label>`),this.name,t,this.list[t]))}else{this.field.appendChild(l.Tag.render(W||(W=L`<label><input type="radio" name="${0}" value="${0}">${0}</label>`),this.name,t,this.list[t]))}}));return this.field}lock(t=true){this.disabled=t;if(this.field){const e=this.field.querySelectorAll("input[type=radio]");if(e){for(let s=0;s<e.length;s++){e[s].disabled=!!t}}}return this}}let H=t=>t,$,V,G,z;const Y={ProcessWindow:"bx-stepprocessing-dialog-process",ProcessPopup:"bx-stepprocessing-dialog-process-popup",ProcessSummary:"bx-stepprocessing-dialog-process-summary",ProcessProgressbar:"bx-stepprocessing-dialog-process-progressbar",ProcessOptions:"bx-stepprocessing-dialog-process-options",ProcessOptionContainer:"bx-stepprocessing-dialog-process-option-container",ProcessOptionsTitle:"bx-stepprocessing-dialog-process-options-title",ProcessOptionsInput:"bx-stepprocessing-dialog-process-options-input",ProcessOptionsObligatory:"ui-alert ui-alert-xs ui-alert-warning",ProcessOptionText:"bx-stepprocessing-dialog-process-option-text",ProcessOptionCheckbox:"bx-stepprocessing-dialog-process-option-checkbox",ProcessOptionMultiple:"bx-stepprocessing-dialog-process-option-multiple",ProcessOptionFile:"bx-stepprocessing-dialog-process-option-file",ProcessOptionSelect:"bx-stepprocessing-dialog-process-option-select",ButtonStart:"popup-window-button-accept",ButtonStop:"popup-window-button-disable",ButtonCancel:"popup-window-button-link-cancel",ButtonDownload:"popup-window-button-link-download",ButtonRemove:"popup-window-button-link-remove"};const K={Shown:"BX.UI.StepProcessing.Dialog.Shown",Closed:"BX.UI.StepProcessing.Dialog.Closed",Start:"BX.UI.StepProcessing.Dialog.Start",Stop:"BX.UI.StepProcessing.Dialog.Stop"};class Q{constructor(t={}){this.id="";this._settings={};this.isShown=false;this.buttons={};this.fields={};this._messages={};this._handlers={};this.isAdminPanel=false;this._settings=t;this.id=this.getSetting("id","ProcessDialog_"+Math.random().toString().substring(2));this._messages=this.getSetting("messages",{});let e={};const s=this.getSetting("optionsFields");if(l.Type.isArray(s)){s.forEach((t=>{if(l.Type.isPlainObject(t)&&t.hasOwnProperty("name")&&t.hasOwnProperty("type")){e[t.name]=t}}))}else if(l.Type.isPlainObject(s)){Object.keys(s).forEach((t=>{let i=s[t];if(l.Type.isPlainObject(i)&&i.hasOwnProperty("name")&&i.hasOwnProperty("type")){e[i.name]=i}}))}this.setSetting("optionsFields",e);const i=this.getSetting("optionsFieldsValue");if(!i){this.setSetting("optionsFieldsValue",{})}const n=this.getSetting("showButtons");if(!n){this.setSetting("showButtons",{start:true,stop:true,close:true})}this._handlers=this.getSetting("handlers",{})}destroy(){if(this.popupWindow){this.popupWindow.destroy();this.popupWindow=null}}getId(){return this.id}getSetting(t,e=null){return this._settings.hasOwnProperty(t)?this._settings[t]:e}setSetting(t,e){this._settings[t]=e;return this}getMessage(t){return this._messages&&this._messages.hasOwnProperty(t)?this._messages[t]:""}setMessage(t,e){this._messages[t]=e;return this}setHandler(t,e){if(typeof e=="function"){this._handlers[t]=e}return this}callHandler(t,e){if(typeof this._handlers[t]=="function"){this._handlers[t].apply(this,e)}}start(){this.callHandler("start");i.EventEmitter.emit(K.Start,new i.BaseEvent({dialog:this}))}stop(){this.callHandler("stop");i.EventEmitter.emit(K.Stop,new i.BaseEvent({dialog:this}))}show(){if(this.isShown){return}const t=document.querySelector("#bx-admin-prefix");if(t){this.isAdminPanel=true}this.progressBar=new BX.UI.ProgressBar({statusType:BX.UI.ProgressBar.Status.COUNTER,size:this.isAdminPanel?BX.UI.ProgressBar.Size.LARGE:BX.UI.ProgressBar.Size.MEDIUM,fill:this.isAdminPanel,column:!this.isAdminPanel});this.error=new o.Alert({color:o.AlertColor.DANGER,icon:o.AlertIcon.DANGER,size:o.AlertSize.SMALL});this.warning=new o.Alert({color:o.AlertColor.WARNING,icon:o.AlertIcon.WARNING,size:o.AlertSize.SMALL});this.popupWindow=n.PopupManager.create({id:this.getId(),cacheable:false,titleBar:this.getMessage("title"),autoHide:false,closeByEsc:false,closeIcon:true,content:this._prepareDialogContent(),draggable:true,buttons:this._prepareDialogButtons(),className:Y.ProcessWindow,bindOptions:{forceBindPosition:false},events:{onClose:BX.delegate(this.onDialogClose,this)},overlay:true,resizable:true,minWidth:Number.parseInt(this.getSetting("minWidth",500)),maxWidth:Number.parseInt(this.getSetting("maxWidth",1e3)),...this._settings.popupOptions});if(!this.popupWindow.isShown()){this.popupWindow.show()}this.isShown=this.popupWindow.isShown();if(this.isShown){this.callHandler("dialogShown");i.EventEmitter.emit(K.Shown,new i.BaseEvent({dialog:this}))}return this}close(){if(!this.isShown){return}if(this.popupWindow){this.popupWindow.close()}this.isShown=false;this.callHandler("dialogClosed");i.EventEmitter.emit(K.Closed,new i.BaseEvent({dialog:this}));return this}_prepareDialogContent(){this.summaryBlock=l.Tag.render($||($=H`<div class="${0}">${0}</div>`),Y.ProcessSummary,this.getMessage("summary"));this.errorBlock=this.error.getContainer();this.warningBlock=this.warning.getContainer();this.errorBlock.style.display="none";this.warningBlock.style.display="none";if(this.progressBar){this.progressBarBlock=l.Tag.render(V||(V=H`<div class="${0}" style="display:none"></div>`),Y.ProcessProgressbar);this.progressBarBlock.appendChild(this.progressBar.getContainer())}if(!this.optionsFieldsBlock){this.optionsFieldsBlock=l.Tag.render(G||(G=H`<div class="${0}" style="display:none"></div>`),Y.ProcessOptions)}else{l.Dom.clean(this.optionsFieldsBlock)}let t=this.getSetting("optionsFields",{});let e=this.getSetting("optionsFieldsValue",{});Object.keys(t).forEach((s=>{let i=e[s]?e[s]:null;let n=this._renderOption(t[s],i);if(n instanceof HTMLElement){this.optionsFieldsBlock.appendChild(n);this.optionsFieldsBlock.style.display="block"}}));let s=l.Tag.render(z||(z=H`<div class="${0}"></div>`),Y.ProcessPopup);s.appendChild(this.summaryBlock);s.appendChild(this.warningBlock);s.appendChild(this.errorBlock);if(this.progressBarBlock){s.appendChild(this.progressBarBlock)}if(this.optionsFieldsBlock){s.appendChild(this.optionsFieldsBlock)}return s}_renderOption(t,e=null){t.id=this.id+"_opt_"+t.name;switch(t.type){case"text":this.fields[t.name]=new b(t);break;case"file":this.fields[t.name]=new C(t);break;case"checkbox":this.fields[t.name]=new q(t);break;case"select":this.fields[t.name]=new N(t);break;case"radio":this.fields[t.name]=new U(t);break}if(e!==null){this.fields[t.name].setValue(e)}const s=this.fields[t.name].getContainer();return s}onDialogClose(){if(this.popupWindow){this.popupWindow.destroy();this.popupWindow=null}this.buttons={};this.fields={};this.summaryBlock=null;this.isShown=false;this.callHandler("dialogClosed");i.EventEmitter.emit(K.Closed,new i.BaseEvent({dialog:this}))}handleStartButtonClick(){const t=this.getButton("start");if(t&&t.isDisabled()){return}this.start()}handleStopButtonClick(){const t=this.getButton("stop");if(t&&t.isDisabled()){return}this.stop()}handleCloseButtonClick(){this.popupWindow.close()}_prepareDialogButtons(){const t=this.getSetting("showButtons");let e=[];this.buttons={};if(t.start){const t=this.getMessage("startButton");this.buttons.start=new r.Button({text:t||"Start",color:r.Button.Color.SUCCESS,icon:r.Button.Icon.START,events:{click:BX.delegate(this.handleStartButtonClick,this)}});e.push(this.buttons.start)}if(t.stop){const t=this.getMessage("stopButton");this.buttons.stop=new r.Button({text:t||"Stop",color:r.Button.Color.LIGHT_BORDER,icon:r.Button.Icon.STOP,events:{click:BX.delegate(this.handleStopButtonClick,this)}});this.buttons.stop.setDisabled();e.push(this.buttons.stop)}if(t.close){const t=this.getMessage("closeButton");this.buttons.close=new r.CancelButton({text:t||"Close",color:r.Button.Color.LIGHT_BORDER,tag:r.Button.Tag.SPAN,events:{click:BX.delegate(this.handleCloseButtonClick,this)}});e.push(this.buttons.close)}return e}setDownloadButtons(t,e,s){let i=[];if(t){let s=this.getMessage("downloadButton");s=s!==""?s:"Download file";const n=new r.Button({text:s,color:r.Button.Color.SUCCESS,icon:r.Button.Icon.DOWNLOAD,className:Y.ButtonDownload,tag:r.Button.Tag.LINK,link:t,props:{download:e}});i.push(n)}if(typeof s=="function"){let t=this.getMessage("clearButton");t=t!==""?t:"Delete file";const e=new r.Button({text:t,color:r.Button.Color.LIGHT_BORDER,icon:r.Button.Icon.REMOVE,className:Y.ButtonRemove,events:{click:s}});i.push(e)}if(this.buttons.close){i.push(this.buttons.close)}if(i.length>0&&this.popupWindow){this.popupWindow.setButtons(i)}return this}resetButtons(t={start:true,stop:true,close:true}){this._prepareDialogButtons();t=t||this.getSetting("showButtons");let e=[];if(t.start){e.push(this.buttons.start)}if(t.stop){e.push(this.buttons.stop)}if(t.close){e.push(this.buttons.close)}if(e.length>0&&this.popupWindow){this.popupWindow.setButtons(e)}return this}getButton(t){var e;return(e=this.buttons[t])!=null?e:null}lockButton(t,e,s){const i=this.getButton(t);if(i){i.setDisabled(e);if(l.Type.isBoolean(s)){i.setWaiting(s)}}return this}showButton(t,e){const s=this.getButton(t);if(s){s.getContainer().style.display=!!e?"":"none"}if(t==="close"){if(this.popupWindow&&this.popupWindow.closeIcon){this.popupWindow.closeIcon.style.display=!!e?"":"none"}}return this}setSummary(t,e=false){if(this.optionsFieldsBlock){BX.clean(this.optionsFieldsBlock);this.optionsFieldsBlock.style.display="none"}if(l.Type.isStringFilled(t)){if(this.summaryBlock){if(!!e)this.summaryBlock.innerHTML=t;else this.summaryBlock.innerHTML=BX.util.htmlspecialchars(t);this.summaryBlock.style.display="block"}}else{this.summaryBlock.innerHTML="";this.summaryBlock.style.display="none"}return this}setErrors(t,e=false){t.forEach((t=>this.setError(t,e)));return this}setError(t,e){if(l.Type.isStringFilled(t)){this.setSummary("");if(this.progressBar){this.progressBar.setColor(BX.UI.ProgressBar.Color.DANGER)}if(!!e){this.error.setText(t)}else{this.error.setText(BX.util.htmlspecialchars(t))}this.errorBlock.style.display="flex"}return this}clearErrors(){if(this.error){this.error.setText("")}if(this.errorBlock){this.errorBlock.style.display="none"}return this}setWarning(t,e=false){if(l.Type.isStringFilled(t)){if(!!e){this.warning.setText(t)}else{this.warning.setText(BX.util.htmlspecialchars(t))}this.warningBlock.style.display="flex"}return this}clearWarnings(){if(this.warning){this.warning.setText("")}if(this.warningBlock){this.warningBlock.style.display="none"}return this}setProgressBar(t,e,s){if(this.progressBar){if(l.Type.isNumber(e)&&l.Type.isNumber(t)&&t>0){BX.show(this.progressBarBlock);this.progressBar.setColor(BX.UI.ProgressBar.Color.PRIMARY);this.progressBar.setMaxValue(t);s=s||"";this.progressBar.setTextBefore(s);this.progressBar.update(e)}else{this.hideProgressBar()}}return this}hideProgressBar(){if(this.progressBar){BX.hide(this.progressBarBlock)}return this}getOptionField(t){if(l.Type.isString(t)){if(this.fields[t]&&this.fields[t]instanceof B){return this.fields[t]}}return null}getOptionFieldValues(){let t={};if(this.optionsFieldsBlock){Object.keys(this.fields).forEach((e=>{let s=this.getOptionField(e);let i=s.getValue();if(s.type==="checkbox"&&l.Type.isBoolean(i)){t[e]=i?"Y":"N"}else if(l.Type.isArray(i)){if(l.Type.isArrayFilled(i)){t[e]=i}}else if(i){t[e]=i}}))}return t}checkOptionFields(){let t=true;if(this.optionsFieldsBlock){Object.keys(this.fields).forEach((e=>{let s=this.getOptionField(e);if(s.obligatory){if(!s.isFilled()){s.showWarning();t=false}else{s.hideWarning()}}}))}return t}lockOptionFields(t=true){if(this.optionsFieldsBlock){Object.keys(this.fields).forEach((e=>{let s=this.getOptionField(e);if(s){s.lock(t)}}))}return this}}const J={StateChanged:"BX.UI.StepProcessing.StateChanged",BeforeRequest:"BX.UI.StepProcessing.BeforeRequest"};const Z={StateChanged:"StateChanged",RequestStart:"RequestStart",RequestStop:"RequestStop",RequestFinalize:"RequestFinalize",StepCompleted:"StepCompleted"};const tt={AuthError:l.Loc.getMessage("UI_STEP_PROCESSING_AUTH_ERROR"),RequestError:l.Loc.getMessage("UI_STEP_PROCESSING_REQUEST_ERR"),DialogStartButton:l.Loc.getMessage("UI_STEP_PROCESSING_BTN_START"),DialogStopButton:l.Loc.getMessage("UI_STEP_PROCESSING_BTN_STOP"),DialogCloseButton:l.Loc.getMessage("UI_STEP_PROCESSING_BTN_CLOSE"),RequestCanceling:l.Loc.getMessage("UI_STEP_PROCESSING_CANCELING"),RequestCanceled:l.Loc.getMessage("UI_STEP_PROCESSING_CANCELED"),RequestCompleted:l.Loc.getMessage("UI_STEP_PROCESSING_COMPLETED"),DialogExportDownloadButton:l.Loc.getMessage("UI_STEP_PROCESSING_FILE_DOWNLOAD"),DialogExportClearButton:l.Loc.getMessage("UI_STEP_PROCESSING_FILE_DELETE"),WaitingResponse:l.Loc.getMessage("UI_STEP_PROCESSING_WAITING")};const et={Controller:"controller",Component:"component"};class st{constructor(t){this.action="";this.method="POST";this.params={};this.isRequestRunning=false;this.queue=[];this.currentStep=-1;this.state=h.intermediate;this.initialOptionValues={};this.optionsFields={};this.handlers={};this.messages=new Map;this.options=l.Type.isPlainObject(t)?t:{};this.id=this.getOption("id","");if(!l.Type.isStringFilled(this.id)){this.id="Process_"+l.Text.getRandom().toLowerCase()}const e=this.getOption("controller","");const s=this.getOption("component","");if(l.Type.isStringFilled(e)){this.controller=e;this.controllerDefault=e;this.endpointType=et.Controller}else if(l.Type.isStringFilled(s)){this.component=s;this.endpointType=et.Component;this.componentMode=this.getOption("componentMode","class")}if(!l.Type.isStringFilled(this.controller)){if(!l.Type.isStringFilled(this.component)){throw new TypeError("BX.UI.StepProcessing: There no any ajax endpoint was defined.")}}this.setQueue(this.getOption("queue",[])).setParams(this.getOption("params",{})).setOptionsFields(this.getOption("optionsFields",{})).setHandlers(this.getOption("handlers",{})).setMessages(tt).setMessages(this.getOption("messages",{}))}destroy(){if(this.dialog instanceof Q){this.dialog.close().destroy();this.dialog=null}this._closeConnection()}start(t=1){this._refreshHash();t=t||1;if(this.state===h.intermediate||this.state===h.stopped||this.state===h.completed){if(!this.getDialog().checkOptionFields()){return}this.getDialog().clearErrors().clearWarnings();this.networkErrorCount=0;if(this.getQueueLength()>0){this.currentStep=0;if(t>1){this.currentStep=t-1}if(this.endpointType===et.Controller){if(l.Type.isStringFilled(this.queue[this.currentStep].controller)){this.setController(this.queue[this.currentStep].controller)}}if(!l.Type.isStringFilled(this.queue[this.currentStep].action)){throw new Error("BX.UI.StepProcessing: Could not find controller action at the queue position.")}this.setAction(this.queue[this.currentStep].action);this.startRequest();if(this.queue[this.currentStep].title){this.getDialog().setSummary(this.queue[this.currentStep].title)}else{this.getDialog().setSummary(this.getMessage("WaitingResponse"))}}else{this.startRequest()}}return this}stop(){if(this.state===h.running){this.stopRequest();this.currentStep=-1}return this}startRequest(){if(this.isRequestRunning||this.state===h.canceling){return this.ajaxPromise}this.isRequestRunning=true;this.ajaxPromise=null;let t=new FormData;let e=(s,i)=>{if(l.Type.isPlainObject(s)){Object.keys(s).forEach((n=>{let o=n;if(i){o=i+"["+n+"]"}if(l.Type.isArray(s[n])||l.Type.isPlainObject(s[n])){e(s[n],o)}else{t.append(o,s[n])}}))}else if(l.Type.isArray(s)){s.forEach((e=>t.append(i+"[]",e)))}};e(this.params);if(this.queue[this.currentStep].params){e(this.queue[this.currentStep].params)}let s=this.getDialog().getOptionFieldValues();if(BX.type.isNotEmptyObject(s)){e(s);this.initialOptionValues=s;this.storeOptionFieldValues(s)}else{Object.keys(this.initialOptionValues).forEach((t=>{if(this.initialOptionValues[t]instanceof File){delete this.initialOptionValues[t]}}));e(this.initialOptionValues)}this.setState(h.running);if(this.hasActionHandler(Z.RequestStart)){this.callActionHandler(Z.RequestStart,[t])}else if(this.hasHandler(Z.RequestStart)){this.callHandler(Z.RequestStart,[t])}i.EventEmitter.emit(J.BeforeRequest,new i.BaseEvent({data:{process:this,actionData:t}}));let n={data:t,method:this.method,onrequeststart:this._onRequestStart.bind(this)};if(this.endpointType===et.Controller){this.ajaxPromise=BX.ajax.runAction(this.controller+"."+this.getAction(),n).then(this._onRequestSuccess.bind(this),this._onRequestFailure.bind(this))}else if(this.endpointType===et.Component){n.mode=this.componentMode;if("signedParameters"in n.data){n.signedParameters=n.data.signedParameters;delete n.data.signedParameters}this.ajaxPromise=BX.ajax.runComponentAction(this.component,this.getAction(),n).then(this._onRequestSuccess.bind(this),this._onRequestFailure.bind(this))}return this.ajaxPromise}stopRequest(){if(this.state===h.canceling){return this.ajaxPromise}this.setState(h.canceling);this._closeConnection();let t=BX.clone(this.params);t.cancelingAction=this.getAction();this.getDialog().setSummary(this.getMessage("RequestCanceling"));let e=true;if(this.hasActionHandler(Z.RequestStop)){e=false;this.callActionHandler(Z.RequestStop,[t])}else if(this.hasHandler(Z.RequestStop)){e=false;this.callHandler(Z.RequestStop,[t])}i.EventEmitter.emit(J.BeforeRequest,new i.BaseEvent({data:{process:this,actionData:t}}));this.ajaxPromise=null;if(e){let e={data:t,method:this.method,onrequeststart:this._onRequestStart.bind(this)};if(this.endpointType===et.Controller){this.setController(this.controllerDefault);this.ajaxPromise=BX.ajax.runAction(this.controller+".cancel",e).then(this._onRequestSuccess.bind(this),this._onRequestFailure.bind(this))}else if(this.endpointType===et.Component){e.mode=this.componentMode;if("signedParameters"in e.data){e.signedParameters=e.data.signedParameters;delete e.data.signedParameters}this.ajaxPromise=BX.ajax.runComponentAction(this.component,"cancel",e).then(this._onRequestSuccess.bind(this),this._onRequestFailure.bind(this))}}return this.ajaxPromise}finalizeRequest(){if(this.state===h.canceling){return this.ajaxPromise}let t=BX.clone(this.params);let e=true;if(this.hasActionHandler(Z.RequestFinalize)){e=false;this.callActionHandler(Z.RequestFinalize,[t])}else if(this.hasHandler(Z.RequestFinalize)){e=false;this.callHandler(Z.RequestFinalize,[t])}i.EventEmitter.emit(J.BeforeRequest,new i.BaseEvent({data:{process:this,actionData:t}}));this.ajaxPromise=null;if(e){let e={data:t,method:this.method,onrequeststart:this._onRequestStart.bind(this)};if(this.endpointType===et.Controller){this.setController(this.controllerDefault);this.ajaxPromise=BX.ajax.runAction(this.controller+".finalize",e)}else if(this.endpointType===et.Component){e.mode=this.componentMode;if("signedParameters"in e.data){e.signedParameters=e.data.signedParameters;delete e.data.signedParameters}this.ajaxPromise=BX.ajax.runComponentAction(this.component,"finalize",e)}}return this.ajaxPromise}_refreshHash(){this.hash=this.id+Date.now();this.setParam("PROCESS_TOKEN",this.hash);return this}_onRequestSuccess(t){this.isRequestRunning=false;this.xhr=null;this.ajaxPromise=null;if(!t){this.getDialog().setError(this.getMessage("RequestError"));this.setState(h.error);return}if(l.Type.isArrayFilled(t.errors)){const e=t.errors.slice(-10);let s=[];e.forEach((t=>s.push(t.message)));this.getDialog().setErrors(s,true);this.setState(h.error);return}this.networkErrorCount=0;const e=t.data;const s=l.Type.isStringFilled(e.STATUS)?e.STATUS:"";let i="";if(l.Type.isStringFilled(e.SUMMARY)){i=e.SUMMARY}else if(l.Type.isStringFilled(e.SUMMARY_HTML)){i=e.SUMMARY_HTML}const n=l.Type.isNumber(e.PROCESSED_ITEMS)?e.PROCESSED_ITEMS:0;const o=l.Type.isNumber(e.TOTAL_ITEMS)?e.TOTAL_ITEMS:0;let r=!!e.FINALIZE;if(this.hasActionHandler(Z.StepCompleted)){this.callActionHandler(Z.StepCompleted,[s,e])}if(l.Type.isStringFilled(e.WARNING)){this.getDialog().setWarning(e.WARNING)}if(s===a.progress||s===a.completed){if(o>0){if(this.queue[this.currentStep].progressBarTitle){this.getDialog().setProgressBar(o,n,this.queue[this.currentStep].progressBarTitle)}else{this.getDialog().setProgressBar(o,n)}}else{this.getDialog().hideProgressBar()}}if(s===a.progress){if(i!==""){this.getDialog().setSummary(i,true)}if(this.state===h.canceling){this.setState(h.stopped)}else{if(this.endpointType===et.Controller){const t=l.Type.isStringFilled(e.NEXT_CONTROLLER)?e.NEXT_CONTROLLER:"";if(t!==""){this.setController(t)}else if(l.Type.isStringFilled(this.queue[this.currentStep].controller)){this.setController(this.queue[this.currentStep].controller)}else{this.setController(this.controllerDefault)}}const t=l.Type.isStringFilled(e.NEXT_ACTION)?e.NEXT_ACTION:"";if(t!==""){this.setAction(t)}setTimeout(BX.delegate(this.startRequest,this),100)}return}if(this.state===h.canceling){this.getDialog().setSummary(this.getMessage("RequestCanceled"));this.setState(h.completed)}else if(s===a.completed){if(this.getQueueLength()>0&&this.currentStep+1<this.getQueueLength()){this.currentStep++;if(this.endpointType===et.Controller){if(l.Type.isStringFilled(this.queue[this.currentStep].controller)){this.setController(this.queue[this.currentStep].controller)}else{this.setController(this.controllerDefault)}}if(!l.Type.isStringFilled(this.queue[this.currentStep].action)){throw new Error("BX.UI.StepProcessing: Could not find controller action at the queue position.")}if("finalize"in this.queue[this.currentStep]){r=true;this.setAction(this.queue[this.currentStep].action)}else{this.setAction(this.queue[this.currentStep].action);this.getDialog().setSummary(this.queue[this.currentStep].title);setTimeout(BX.delegate(this.startRequest,this),100);return}}if(i!==""){this.getDialog().setSummary(i,true)}else{this.getDialog().setSummary(this.getMessage("RequestCompleted"))}if(l.Type.isStringFilled(e.DOWNLOAD_LINK)){if(l.Type.isStringFilled(e.DOWNLOAD_LINK_NAME)){this.getDialog().setMessage("downloadButton",e.DOWNLOAD_LINK_NAME)}if(l.Type.isStringFilled(e.CLEAR_LINK_NAME)){this.getDialog().setMessage("clearButton",e.CLEAR_LINK_NAME)}this.getDialog().setDownloadButtons(e.DOWNLOAD_LINK,e.FILE_NAME,BX.delegate((function(){this.getDialog().resetButtons({stop:true,close:true});this.callAction("clear");setTimeout(BX.delegate((function(){this.getDialog().resetButtons({close:true})}),this),1e3)}),this))}this.setState(h.completed,e);if(r){setTimeout(BX.delegate(this.finalizeRequest,this),100)}}else{this.getDialog().setSummary("").setError(this.getMessage("RequestError"));this.setState(h.error)}}_onRequestFailure(t){this.isRequestRunning=false;this.ajaxPromise=null;if(l.Type.isPlainObject(t)&&"data"in t&&l.Type.isPlainObject(t.data)&&"ajaxRejectData"in t.data&&l.Type.isPlainObject(t.data.ajaxRejectData)&&"reason"in t.data.ajaxRejectData&&t.data.ajaxRejectData.reason==="status"&&"data"in t.data.ajaxRejectData&&t.data.ajaxRejectData.data===401){this.getDialog().setError(this.getMessage("AuthError"))}else if(l.Type.isPlainObject(t)&&"errors"in t&&l.Type.isArrayFilled(t.errors)){let e=false;let s=false;t.errors.forEach((t=>{if(t.code==="NETWORK_ERROR"){if(this.state===h.canceling){e=true}else{s=true}}}));if(e){return}if(s){this.networkErrorCount++;if(this.networkErrorCount<=2){setTimeout(BX.delegate(this.startRequest,this),15e3);return}}const i=t.errors.slice(-10);let n=[];i.forEach((t=>{if(t.code==="NETWORK_ERROR"){n.push(this.getMessage("RequestError"))}else{n.push(t.message)}}));this.getDialog().setErrors(n,true)}else{this.getDialog().setError(this.getMessage("RequestError"))}this.xhr=null;this.currentStep=-1;this.setState(h.error)}_closeConnection(){if(this.xhr instanceof XMLHttpRequest){try{this.xhr.abort();this.xhr=null}catch(t){}}}_onRequestStart(t){this.xhr=t}setId(t){this.id=t;return this}getId(){return this.id}setQueue(t){t.forEach((t=>this.addQueueAction(t)));return this}addQueueAction(t){this.queue.push(t);return this}getQueueLength(){return this.queue.length}setOption(t,e){this.options[t]=e;return this}getOption(t,e=null){return this.options.hasOwnProperty(t)?this.options[t]:e}setOptionsFields(t){Object.keys(t).forEach((e=>this.addOptionsField(e,t[e])));return this}addOptionsField(t,e){this.optionsFields[t]=e;return this}storeOptionFieldValues(t){if("sessionStorage"in window){let e={};Object.keys(this.optionsFields).forEach((s=>{let i=this.optionsFields[s];switch(i.type){case"checkbox":case"select":case"radio":if(i.name in t){e[i.name]=t[i.name]}break}}));window.sessionStorage.setItem("bx."+this.getId(),JSON.stringify(e))}return this}restoreOptionFieldValues(){let t={};if("sessionStorage"in window){t=JSON.parse(window.sessionStorage.getItem("bx."+this.getId()));if(!l.Type.isPlainObject(t)){t={}}}return t}setParams(t){this.params={};Object.keys(t).forEach((e=>this.setParam(e,t[e])));return this}getParams(){return this.params}setParam(t,e){this.params[t]=e;return this}getParam(t){return this.params[t]?this.params[t]:null}setState(t,e={}){if(this.state===t){return this}this.state=t;if(t===h.intermediate||t===h.stopped){this.getDialog().lockButton("start",false).lockButton("stop",true).showButton("close",true)}else if(t===h.running){this.getDialog().lockButton("start",true,true).lockButton("stop",false).showButton("close",false)}else if(t===h.canceling){this.getDialog().lockButton("start",true).lockButton("stop",true,true).showButton("close",false).hideProgressBar()}else if(t===h.error){this.getDialog().lockButton("start",true).lockButton("stop",true).showButton("close",true)}else if(t===h.completed){this.getDialog().lockButton("start",true).lockButton("stop",true).showButton("close",true).hideProgressBar()}if(this.hasActionHandler(Z.StateChanged)){this.callActionHandler(Z.StateChanged,[t,e])}else if(this.hasHandler(Z.StateChanged)){this.callHandler(Z.StateChanged,[t,e])}i.EventEmitter.emit(J.StateChanged,new i.BaseEvent({data:{state:t,result:e}}));return this}getState(){return this.state}setController(t){this.controller=t;return this}getController(){return this.controller}setComponent(t,e="class"){this.component=t;this.componentMode=e;return this}getComponent(){return this.component}setAction(t){this.action=t;return this}getAction(){return this.action}callAction(t){this.setAction(t)._refreshHash();return this.startRequest()}setHandlers(t){Object.keys(t).forEach((e=>this.setHandler(e,t[e])));return this}setHandler(t,e){if(l.Type.isFunction(e)){this.handlers[t]=e}return this}hasHandler(t){return l.Type.isFunction(this.handlers[t])}callHandler(t,e){if(this.hasHandler(t)){this.handlers[t].apply(this,e)}}hasActionHandler(t){if(this.queue[this.currentStep]){if("handlers"in this.queue[this.currentStep]){return l.Type.isFunction(this.queue[this.currentStep].handlers[t])}}return false}callActionHandler(t,e){if(this.hasActionHandler(t)){this.queue[this.currentStep].handlers[t].apply(this,e)}}setMessages(t){Object.keys(t).forEach((e=>this.setMessage(e,t[e])));return this}setMessage(t,e){this.messages.set(t,e);return this}getMessage(t,e=null){let s=this.messages.has(t)?this.messages.get(t):"";if(l.Type.isStringFilled(s)&&l.Type.isPlainObject(e)){Object.keys(e).forEach((t=>{s=s.replace("#"+t+"#",e[t])}))}return s}getDialog(){if(!this.dialog){this.dialog=new Q({id:this.id,optionsFields:this.getOption("optionsFields",{}),minWidth:Number.parseInt(this.getOption("dialogMinWidth",500)),maxWidth:Number.parseInt(this.getOption("dialogMaxWidth",1e3)),optionsFieldsValue:this.restoreOptionFieldValues(),messages:{title:this.getMessage("DialogTitle"),summary:this.getMessage("DialogSummary"),startButton:this.getMessage("DialogStartButton"),stopButton:this.getMessage("DialogStopButton"),closeButton:this.getMessage("DialogCloseButton"),downloadButton:this.getMessage("DialogExportDownloadButton"),clearButton:this.getMessage("DialogExportClearButton")},showButtons:this.getOption("showButtons"),handlers:{start:BX.delegate(this.start,this),stop:BX.delegate(this.stop,this),dialogShown:typeof this.handlers.dialogShown=="function"?this.handlers.dialogShown:null,dialogClosed:typeof this.handlers.dialogClosed=="function"?this.handlers.dialogClosed:null},popupOptions:this.options.popupOptions})}return this.dialog}showDialog(){this.getDialog().setSetting("optionsFieldsValue",this.restoreOptionFieldValues()).resetButtons(this.getOption("optionsFields")).show();if(!this.isRequestRunning){this.setState(h.intermediate)}return this}closeDialog(){if(this.isRequestRunning){this.stop()}this.getDialog().close();return this}}class it{static create(t){if(!this.instances){this.instances=new Map}let e=new st(t);this.instances.set(e.getId(),e);return e}static get(t){if(this.instances){if(this.instances.has(t)){return this.instances.get(t)}}return null}static has(t){if(this.instances){return this.instances.has(t)}return false}static delete(t){if(this.instances){if(this.instances.has(t)){this.instances.get(t).destroy();this.instances.delete(t)}}}}t.ProcessManager=it;t.Process=st;t.ProcessState=h;t.ProcessEvent=J;t.ProcessCallback=Z;t.ProcessResultStatus=a;t.Dialog=Q;t.DialogEvent=K})(this.BX.UI.StepProcessing=this.BX.UI.StepProcessing||{},BX,BX.UI,BX.Event,BX.Main,BX.UI,BX.UI,BX); //# sourceMappingURL=stepprocessing.bundle.map.js