text: BX.namespace("BX.Mobile.Crm.Invoice.Edit");BX.CrmActivityStorageType={undefined:0,file:1,webdav:2,disk:3};BX.Mobile.Crm.Invoice.Edit={ajaxPath:"",formActionUrl:"",formId:"",invoiceViewPath:"",mode:"",products:[],productDataFieldName:"",productsContainerNode:"",contactContainerNode:"",companyContainerNode:"",dealContainerNode:"",quoteContainerNode:"",contactInfo:"",clientInfo:"",clientPrefix:"",clientType:"",quoteInfo:"",dealInfo:"",isRestrictedMode:false,convDealId:"",convQuoteId:"",pageId:"",onDeleteClientEventName:"",onSelectClientEventName:"",onSelectContactEventName:"",onSelectQuoteEventName:"",onSelectDealEventName:"",emailEditUrl:"",emailSubject:"",statusSort:{},pageIdProductSelectorBack:"crmInvoiceEditPage",init:function(e){if(e&&typeof e==="object"){this.ajaxPath=e.ajaxPath||"";this.formActionUrl=e.formActionUrl||"";this.formId=e.formId||"";this.invoiceViewPath=e.invoiceViewPath||"";this.mode=e.mode||"";this.products=e.products||[];this.productDataFieldName=e.productDataFieldName||"";this.contactInfo=e.contactInfo||"";this.clientInfo=e.clientInfo||"";this.clientPrefix=e.clientPrefix||"";this.clientType=e.clientType||"";this.dealInfo=e.dealInfo||"";this.quoteInfo=e.quoteInfo||"";this.convDealId=e.convDealId||"";this.convQuoteId=e.convQuoteId||"";this.isRestrictedMode=e.isRestrictedMode||"";this.productsContainerNode=document.querySelector("[data-role='mobile-crm-invoice-edit-products']")||"";this.contactContainerNode=document.querySelector("[data-role='mobile-crm-invoice-edit-contact']")||"";this.clientContainerNode=document.querySelector("[data-role='mobile-crm-invoice-edit-client']")||"";this.quoteContainerNode=document.querySelector("[data-role='mobile-crm-invoice-edit-quote']")||"";this.dealContainerNode=document.querySelector("[data-role='mobile-crm-invoice-edit-deal']")||"";this.pageId=e.pageId||"";this.onDeleteClientEventName=e.onDeleteClientEventName||"";this.onSelectClientEventName=e.onSelectClientEventName||"";this.onSelectContactEventName=e.onSelectContactEventName||"";this.onSelectQuoteEventName=e.onSelectQuoteEventName||"";this.onSelectDealEventName=e.onSelectDealEventName||"";this.emailEditUrl=e.emailEditUrl||"";this.emailSubject=e.emailSubject||"";this.statusSort=e.statusSort||{};this.pageIdProductSelectorBack=e.pageIdProductSelectorBack||"crmInvoiceEditPage"}if(this.mode=="EDIT"||this.mode=="CREATE"){app.setPageID(this.pageIdProductSelectorBack)}if(this.mode=="EDIT"){BXMobileApp.addCustomEvent("onCrmInvoiceEditUpdate",BX.proxy(function(e){if(e.formId==this.formId){BXMobileApp.UI.Page.reload()}},this))}if(this.mode=="VIEW"){BXMobileApp.addCustomEvent("onCrmInvoiceViewUpdate",BX.proxy(function(e){if(e.formId==this.formId){BXMobileApp.UI.Page.reload()}},this));BX.addCustomEvent("onSubmitAjaxSuccess",BX.proxy(function(e){if(e.formId==this.formId)BXMobileApp.onCustomEvent("onCrmInvoiceEditUpdate",{formId:this.formId},true)},this))}if(this.mode=="CREATE"){BX.addCustomEvent("onCrmInvoiceCreate",BX.proxy(function(){BX.Mobile.Crm.loadPageBlank(this.invoiceViewPath)},this))}BX.addCustomEvent("onCrmInvoiceDetailDelete",function(){BXMobileApp.onCustomEvent("onCrmInvoiceListUpdate",{},true);BXMobileApp.UI.Page.close({drop:true})});var t={entityContainerNode:this.contactContainerNode,entityInfo:this.contactInfo,isRestrictedMode:this.isRestrictedMode,onSelectEventName:this.onSelectContactEventName};this.contactEditor=new BX.Mobile.Crm.EntityEditor(t);var i={entityContainerNode:this.clientContainerNode,entityInfo:this.clientInfo,isRestrictedMode:this.isRestrictedMode,onDeleteEventName:this.onDeleteClientEventName,onSelectEventName:this.onSelectClientEventName};this.clientEditor=new BX.Mobile.Crm.EntityEditor(i);var o={entityContainerNode:this.dealContainerNode,entityInfo:this.dealInfo,isRestrictedMode:this.isRestrictedMode,onSelectEventName:this.onSelectDealEventName};this.dealEditor=new BX.Mobile.Crm.EntityEditor(o);var n={entityContainerNode:this.quoteContainerNode,entityInfo:this.quoteInfo,isRestrictedMode:this.isRestrictedMode,onSelectEventName:this.onSelectQuoteEventName};this.quoteEditor=new BX.Mobile.Crm.EntityEditor(n);if(this.clientType=="CONTACT"){this.showHideContactBlock("N")}if(this.mode!=="VIEW"){BX.addCustomEvent(this.onDeleteClientEventName,BX.proxy(function(){BX.onCustomEvent("CrmEntitySelectorChangeValue",["COMPANY",0]);this.refreshPaySystemList("")},this));BX.addCustomEvent(this.onSelectClientEventName,BX.proxy(function(e){if(e.entity=="contact"){if(this.clientPrefix!=="C_")BX("bx_PAY_SYSTEM_ID").innerHTML="";this.clientPrefix="C_";this.clientType="CONTACT";BX.onCustomEvent("CrmEntitySelectorChangeValue",["COMPANY",0]);this.refreshPaySystemList("CONTACT");this.showHideContactBlock("N")}else if(e.entity=="company"){if(this.clientPrefix!=="CO_")BX("bx_PAY_SYSTEM_ID").innerHTML="";this.clientPrefix="CO_";this.clientType="COMPANY";BX.onCustomEvent("CrmEntitySelectorChangeValue",["COMPANY",e.id]);this.refreshPaySystemList("COMPANY");this.showHideContactBlock("Y")}},this));this.onCrmInvoiceEditStatusChange();var a=BX.delegate(function(e,t,i){if(e==this.formId&&i){BX.addCustomEvent(i,"onChange",BX.proxy(this.onChangeField,this))}},this);BX.addCustomEvent("onInitialized",a);var r=BX.Mobile.Grid.Form.getByFormId(this.formId);a(this.formId,"",r)}if(this.mode=="CONVERT"||this.mode=="CREATE"){var s=function(){BX.removeCustomEvent("onOpenPageAfter",s);app.closeModalDialog()};BX.addCustomEvent("onCrmInvoiceClosePage",function(){if(!(window.isCurrentPage&&window.isCurrentPage=="Y")){BX.addCustomEvent("onOpenPageAfter",s)}else{window.isCurrentPage=""}})}if(this.mode=="VIEW"){BXMobileApp.addCustomEvent("onSubmitForm",BX.proxy(function(e,t,i){if(e.formId==this.formId){if(i.checked==false||!i.hasAttribute("checked")){var o=BX.create("INPUT",{attrs:{type:"hidden",name:i.name,value:""}});i.parentNode.insertBefore(o,i)}}},this));BX.addCustomEvent("onSubmitAjaxSuccess",BX.proxy(function(e){if(e.hasOwnProperty("formId")&&e.formId==this.formId){BXMobileApp.onCustomEvent("onCrmInvoiceListUpdate",{},true)}},this))}},showHideContactBlock:function(e){if(e!="Y"&&e!="N")return;var t=document.querySelector("[data-role='mobile-crm-invoice-edit-contact']");if(t){t.parentNode.parentNode.parentNode.style.display=e=="Y"?"block":"none"}},refreshPaySystemList:function(e){BX.ajax({method:"POST",dataType:"json",url:this.ajaxPath,data:{sessid:BX.bitrix_sessid(),action:"getPaySystemItems",clientType:e},onsuccess:BX.proxy(function(e){var t=BX("bx_PAY_SYSTEM_ID");if(t)t.innerHTML="";if(BX("bx_PAY_SYSTEM_ID_select"))BX("bx_PAY_SYSTEM_ID_select").innerHTML=BX.message("M_CRM_INVOICE_SELECT");if(t&&typeof e=="object"&&e.hasOwnProperty("PAY_SYSTEMS")){var i=e.PAY_SYSTEMS;var o=true;for(var n in i){if(!i.hasOwnProperty(n))continue;var a={value:n};if(o){a["selected"]="selected";BX("bx_PAY_SYSTEM_ID_select").innerHTML=i[n];o=false}t.appendChild(BX.create("option",{html:i[n],attrs:a}))}}BX.onCustomEvent(t,"onChange")},this)})},onChangeField:function(e,t){if(typeof t!=="object")return;if(t.name&&t.name=="STATUS_ID"){this.onCrmInvoiceEditStatusChange()}},onCrmInvoiceEditStatusChange:function(){var e=this.statusSort;var t=BX(this.formId);if(t){var i=BX.findChild(t,{tag:"input",attr:{type:"text",name:"PAY_VOUCHER_NUM"}},true,false);var o=BX.findChild(t,{tag:"select",attr:{name:"STATUS_ID"}},true,false);var n=BX.findChild(t,{tag:"input",attr:{type:"hidden",name:"PAY_VOUCHER_DATE"}},true,false);var a=BX.findChild(t,{tag:"textarea",attr:{name:"REASON_MARKED_SUCCESS"}},true,false);var r=BX.findChild(t,{tag:"input",attr:{type:"hidden",name:"DATE_MARKED"}},true,false);var s=BX.findChild(t,{tag:"textarea",attr:{name:"REASON_MARKED"}},true,false);var d=null,c=false,l=false,m=null;if(o&&n&&i&&a&&r&&s){d=o.value;if(typeof d==="string"&&d.length>0){c=d==="P";if(c)l=false;else l=e[d]>=e["D"];var h=[n,i,a];var f=[r,s];for(var u in h){if(h.hasOwnProperty(u)){m=BX.findParent(h[u],{tag:"div",attr:{"class":"mobile-grid-section "}});if(m)m.style.display=c?"":"none"}}for(u in f){if(f.hasOwnProperty(u)){m=BX.findParent(f[u],{tag:"div",attr:{"class":"mobile-grid-section "}});if(m)m.style.display=l?"":"none"}}}}}},getInvoicePdfContent:function(e,t){if(!e||!t)return;data={INVOICE_ID:e,INVOICE_NUM:t,action:"savePdf",pdf:1,GET_CONTENT:"Y",sessid:BX.bitrix_sessid()};BXMobileApp.UI.Page.LoadingScreen.show();BX.ajax({data:data,method:"POST",dataType:"json",url:this.ajaxPath,onsuccess:BX.delegate(function(e){BXMobileApp.UI.Page.LoadingScreen.hide();if(e){if(!e.ERROR)this.crmInvoiceOpenEmailDialog(e);else BX.Mobile.Crm.showErrorAlert(e.ERROR)}},this),onfailure:function(){BX.debug("onfailure: getPdfContent")}})},crmInvoiceOpenEmailDialog:function(e){if(typeof e!=="object"||!e.hasOwnProperty("diskfile"))return;var t={timestamp:(new Date).getTime(),subject:this.emailSubject,storageTypeId:BX.CrmActivityStorageType.disk,storageElements:[{id:e.diskfile.ID,name:e.diskfile.NAME,url:e.diskfile.VIEW_URL}]};app.loadPageBlank({url:this.emailEditUrl,cache:false,data:t})},submit:function(){BXMobileApp.UI.Page.LoadingScreen.show();var e=BX(this.formId);if(e){var t={sessid:BX.bitrix_sessid()};if(this.convDealId||this.convQuoteId){if(this.convDealId)t["conv_deal_id"]=this.convDealId;else if(this.convQuoteId)t["conv_quote_id"]=this.convQuoteId;t["continue"]="Y"}else{t["save"]="Y"}if(BX.Mobile.Crm.ProductEditor&&BX.Mobile.Crm.ProductEditor.products){t[this.productDataFieldName]=BX.Mobile.Crm.ProductEditor.products}if(this.clientEditor&&this.clientEditor.curEntityId){t["PRIMARY_ENTITY_TYPE"]=this.clientType;t["PRIMARY_ENTITY_ID"]=this.clientEditor.curEntityId}if(this.contactEditor){t["SECONDARY_ENTITY_IDS"]=this.contactEditor.curEntityId}if(this.dealEditor){t["UF_DEAL_ID"]=this.dealEditor.curEntityId}if(this.quoteEditor){t["UF_QUOTE_ID"]=this.quoteEditor.curEntityId}BX.Mobile.Crm.Detail.collectInterfaceFormData(e,t);BX.ajax({method:"POST",dataType:"json",url:this.formActionUrl,data:t,onsuccess:BX.proxy(function(e){BXMobileApp.UI.Page.LoadingScreen.hide();if(e.error){BX.Mobile.Crm.showErrorAlert(e.error)}else{if(this.mode=="EDIT"){BXMobileApp.onCustomEvent("onCrmInvoiceListUpdate",{},true);BXMobileApp.onCustomEvent("onCrmInvoiceViewUpdate",{formId:this.formId},true);app.closeModalDialog({cache:false})}if(this.mode=="CREATE"){var t=this.invoiceViewPath.replace("#invoice_id#",e.itemId);BXMobileApp.onCustomEvent("onCrmInvoiceLoadPageBlank",{path:t},true);app.closeModalDialog({cache:false})}if(this.mode=="CONVERT"&&e.url){if(e.url.indexOf("page=edit")>0){BXMobileApp.PageManager.loadPageModal({url:e.url})}else{BXMobileApp.onCustomEvent("onCrmInvoiceLoadPageBlank",{path:e.url,type:"convert"},true)}app.closeModalDialog({cache:false})}}},this)})}}};
  //# sourceMappingURL=script.map.js