%PDF- %PDF-
Direktori : /home/bitrix/www/bitrix/js/bizproc/ |
Current File : /home/bitrix/www/bitrix/js/bizproc/starter.min.js |
(function(){"use strict";BX.namespace("BX.Bizproc");if(BX.Bizproc.Starter){return}var t=0;var e=function(){window.alert(BX.message("BIZPROC_JS_BP_STARTER_REQUEST_FAILURE"))};var i={instances:[],put:function(t){this.instances.push(t);return this},findSimilar:function(t){var e=[t];for(var i=0;i<this.instances.length;++i){var n=this.instances[i];if(n!==t&&n.moduleId===t.moduleId&&n.entity===t.entity&&n.documentType===t.documentType){e.push(n)}}return e},fireEvent:function(t,e,i){var n=this.findSimilar(t);for(var o=0;o<n.length;++o){BX.onCustomEvent(n[o],e,i)}}};var n=function(e){this.id=++t;this.templates=e.templates||null;this.moduleId=e.moduleId;this.entity=e.entity;this.documentType=e.documentType;this.documentId=e.documentId;this.ajaxUrl=e.ajaxUrl||"/bitrix/components/bitrix/bizproc.workflow.start/ajax.php";i.put(this)};n.singleStart=function(t,e){var i=new n(t);if(BX.type.isFunction(e)){BX.addCustomEvent(i,"onAfterStartWorkflow",e)}if(t.hasParameters){i.showParametersPopup(t.templateId,{title:t.templateName})}else{i.startWorkflow(t.templateId)}};n.prototype={showTemplatesMenu:function(t){if(this.templates===null){this.loadTemplates(this.showTemplatesPopupMenu.bind(this,t))}else{this.showTemplatesPopupMenu(t)}},showTemplatesPopupMenu:function(t){var e=this,i,n,o,s=[];var a=function(t,i){this.popupWindow.close();t.preventDefault();e.onTemplateMenuItemClick(i.template)};for(i=0;i<this.templates.length;++i){n=this.templates[i];o={text:n["name"],template:n,title:n["description"],onclick:a};s.push(o)}if(!s.length){this.showEmptyTemplatesHint(t)}else{BX.PopupMenu.show("bp-starter-tpl-menu-"+this.id,t,s,{closeByEsc:true,zIndex:200,autoHide:true})}},showEmptyTemplatesHint:function(t){var e=BX.message("BIZPROC_JS_BP_STARTER_NO_TEMPLATES");var i=new BX.PopupWindow("bp-starter-tpl-empty"+this.id,t,{lightShadow:true,autoHide:true,darkMode:true,offsetLeft:40,angle:{position:"top",offset:40},bindOptions:{position:"bottom"},zIndex:1100,events:{onPopupClose:function(){this.destroy()}},content:BX.create("div",{attrs:{style:"padding-right: 5px; width: 200px;"},text:e})});i.show()},loadTemplates:function(t){var e=this;this.callAction("get_templates",{},function(i){e.templates=i.templates;t(i)})},onTemplateMenuItemClick:function(t){if(!t.hasParameters){this.startWorkflow(t["id"])}else{this.showParametersPopup(t["id"],{title:t["name"]})}},startWorkflow:function(t){var e=this;this.callAction("start_workflow",{template_id:t},function(t){i.fireEvent(e,"onAfterStartWorkflow",t)})},showParametersPopup:function(t,e){var n=this;if(!BX.type.isPlainObject(e)){e={}}this.loadParametersHtml({template_id:t},function(o){var s,a=BX.create("div",{html:o});var r=a.querySelector('[data-role="bizproc-start-form"]');n.prepareParametersForm(r,t);var u=r.querySelector('[data-role="bizproc-form-buttons"]');if(u){BX.remove(u)}var p=new BX.PopupWindowButton({text:BX.message("BIZPROC_JS_BP_STARTER_START"),className:"popup-window-button-accept",events:{click:function(t){BX.fireEvent(r,"submit")}}});s=new BX.PopupWindow("bp-starter-parameters-popup-"+n.id,null,{content:a,width:600,closeIcon:true,titleBar:e.title||"",closeByEsc:true,draggable:{restrict:false},events:{onPopupClose:function(t){t.destroy()}},buttons:[p,new BX.PopupWindowButtonLink({text:BX.message("BIZPROC_JS_BP_STARTER_CANCEL"),className:"popup-window-button-link-cancel",events:{click:function(t){s.close()}}})]});BX.bind(r,"submit",function(t){t.preventDefault();p.addClassName("popup-window-button-wait");n.submitParametersForm(r,function(t){p.removeClassName("popup-window-button-wait");if(t.success){s.close();i.fireEvent(n,"onAfterStartWorkflow",t.data)}})});s.show()})},showAutoStartParametersPopup:function(t,e){var i=this;if(!BX.type.isPlainObject(e)){e={}}var n=function(t){var n;if(BX.type.isDomNode(t)){n=t.firstChild}else{n=BX.create("div",{html:t})}var o=n.querySelector('[data-role="bizproc-start-form"]');i.prepareParametersForm(o,null,"check_parameters");var s=new BX.PopupWindowButton({text:BX.message("BIZPROC_JS_BP_STARTER_SAVE"),className:"popup-window-button-accept",events:{click:function(t){BX.fireEvent(o,"submit")}}});var a=new BX.PopupWindow("bp-starter-parameters-popup-"+i.id,null,{content:n,width:600,closeIcon:true,titleBar:e.title||BX.message("BIZPROC_JS_BP_STARTER_AUTOSTART"),closeByEsc:true,draggable:{restrict:false},events:{onPopupClose:function(t){t.destroy()}},buttons:[s,new BX.PopupWindowButtonLink({text:BX.message("BIZPROC_JS_BP_STARTER_CANCEL"),className:"popup-window-button-link-cancel",events:{click:function(t){a.close()}}})]});BX.bind(o,"submit",function(t){t.preventDefault();s.addClassName("popup-window-button-wait");i.submitParametersForm(o,function(t){s.removeClassName("popup-window-button-wait");if(t.success){a.close();if(e.callback){e.callback(t.data)}}})});a.show()};if(e.contentNode){n(e.contentNode)}else{this.loadParametersHtml({auto_execute_type:t},n.bind(this))}},loadParametersHtml:function(t,i){t["sessid"]=BX.bitrix_sessid();t["site_id"]=BX.message("SITE_ID");t["module_id"]=this.moduleId;t["entity"]=this.entity;t["document_type"]=this.documentType;if(this.documentId){t["document_id"]=this.documentId}BX.ajax({method:"POST",dataType:"html",url:"/bitrix/components/bitrix/bizproc.workflow.start/popup.php",data:t,onsuccess:function(t){i(t)},onfailure:e})},prepareParametersForm:function(t,e,i){if(e){t.appendChild(BX.create("input",{attrs:{type:"hidden",name:"template_id",value:e}}))}t.appendChild(BX.create("input",{attrs:{type:"hidden",name:"module_id",value:this.moduleId}}));t.appendChild(BX.create("input",{attrs:{type:"hidden",name:"entity",value:this.entity}}));t.appendChild(BX.create("input",{attrs:{type:"hidden",name:"ajax_action",value:i?i:"start_workflow"}}));t.action=this.ajaxUrl},submitParametersForm:function(t,i){if(t.__requestInProgress){return}t.__requestInProgress=true;var n=new FormData(t);BX.ajax({method:"POST",dataType:"json",url:this.ajaxUrl,data:n,preparePost:false,onsuccess:function(e){delete t.__requestInProgress;if(!e.success){window.alert(e.errors.join("\n"))}if(i){i(e)}},onfailure:e})},callAction:function(t,i,n){i["sessid"]=BX.bitrix_sessid();i["site"]=BX.message("SITE_ID");i["ajax_action"]=t;i["module_id"]=this.moduleId;i["entity"]=this.entity;i["document_type"]=this.documentType;i["document_id"]=this.documentId;BX.ajax({method:"POST",dataType:"json",url:this.ajaxUrl,data:i,onsuccess:function(t){if(t.success){n(t.data,t)}else{window.alert(t.errors.join("\n"))}},onfailure:e})}};BX.Bizproc.Starter=n})(); //# sourceMappingURL=starter.map.js