Your IP : 18.227.134.162


Current Path : /home/bitrix/ext_www/crm.klimatlend.ua/bitrix/js/documentgenerator/
Upload File :
Current File : /home/bitrix/ext_www/crm.klimatlend.ua/bitrix/js/documentgenerator/documentpreview.min.js

(function(){"use strict";BX.namespace("BX.DocumentGenerator");if(typeof BX.DocumentGenerator.DocumentPreview!=="undefined"){return}var e=false;BX.DocumentGenerator.DocumentPreview=function(e){this.loader=null;this.documentId=null;this.pullTag=null;this.startImageUrl=null;this.imageUrl=null;this.imageContainer=null;this.imageNode=null;this.printUrl=null;this.pdfUrl=null;this.hash=e.hash?e.hash:"";this.isPublicMode=e.isPublicMode?e.isPublicMode:false;this.isTransformationError=false;this.transformationErrorNode=null;this.transformationErrorMessage="";this.transformationErrorCode=0;this.previewNode=null;this.onReady=BX.DoNothing;this.applyOptions(e);this.initPushEvent();this.start()};BX.DocumentGenerator.DocumentPreview.prototype={};BX.DocumentGenerator.DocumentPreview.prototype.isPullConnected=function(){if(top.BX.PULL){if(BX.type.isFunction(top.BX.PULL.isConnected)){return top.BX.PULL.isConnected()}else{var e=top.BX.PULL.getDebugInfoArray();return e.connected}}return false};BX.DocumentGenerator.DocumentPreview.prototype.initPushEvent=function(){if(!e){if(this.isPullConnected()){e=true;top.BX.addCustomEvent("onPullEvent-documentgenerator",BX.proxy(this.showImage,this))}else if(this.documentId>0&&!this.imageUrl){var t="documentgenerator.api.document.get";var i={id:this.documentId};if(this.isPublicMode&&BX.type.isString(this.hash)&&this.hash.length>10){t="documentgenerator.api.publicdocument.get";i.hash=this.hash}e=true;setTimeout(BX.proxy(function(){BX.ajax.runAction(t,{data:i}).then(BX.proxy(function(t){e=false;if(t.data.document.imageUrl){this.showImage("showImage",t.data.document)}else{this.initPushEvent()}},this),function(){e=false})},this),5e3)}}};BX.DocumentGenerator.DocumentPreview.prototype.applyOptions=function(e){if(e.id){this.documentId=e.id}if(e.pullTag){this.pullTag=e.pullTag}if(e.imageUrl){this.imageUrl=e.imageUrl}if(e.startImageUrl){this.startImageUrl=e.startImageUrl}if(e.printUrl){this.printUrl=e.printUrl}if(e.pdfUrl){this.pdfUrl=e.pdfUrl}if(e.emailDiskFile){this.emailDiskFile=e.emailDiskFile}if(BX.type.isDomNode(e.imageContainer)){this.imageContainer=e.imageContainer}if(BX.type.isDomNode(e.previewNode)){this.previewNode=e.previewNode}if(BX.type.isDomNode(e.transformationErrorNode)){this.transformationErrorNode=e.transformationErrorNode}if(BX.type.isBoolean(e.isTransformationError)){this.isTransformationError=e.isTransformationError}if(BX.type.isString(e.transformationErrorMessage)){this.transformationErrorMessage=e.transformationErrorMessage}else{this.transformationErrorMessage=""}if(BX.type.isNumber(e.transformationErrorCode)){this.transformationErrorCode=e.transformationErrorCode}else{this.transformationErrorCode=0}if(BX.type.isFunction(e.onReady)){this.onReady=e.onReady}this.initPushEvent()};BX.DocumentGenerator.DocumentPreview.prototype.getLoader=function(){if(!this.loader){this.loader=new BX.Loader({size:100,offset:{left:"-8%",top:"6%"}})}return this.loader};BX.DocumentGenerator.DocumentPreview.prototype.showLoader=function(){if(this.imageContainer){if(!this.getLoader().isShown()){this.getLoader().show(this.imageContainer)}}if(BX.type.isDomNode(this.imageNode)){this.imageNode.style.opacity=.5}};BX.DocumentGenerator.DocumentPreview.prototype.hideLoader=function(){if(this.getLoader().isShown()){this.getLoader().hide()}if(BX.type.isDomNode(this.imageNode)){this.imageNode.style.opacity=1}};BX.DocumentGenerator.DocumentPreview.prototype.isValidPullTag=function(e,t){return e==="showImage"&&t["pullTag"]===this.pullTag};BX.DocumentGenerator.DocumentPreview.prototype.showImage=function(e,t){if(this.isValidPullTag(e,t)){this.applyOptions(t);if(BX.type.isDomNode(this.previewNode)){BX.hide(this.previewNode)}if(BX.type.isDomNode(this.transformationErrorNode)){if(this.isTransformationError){BX.show(this.transformationErrorNode)}else{BX.hide(this.transformationErrorNode)}}this.showImageNode();this.onReady(t);this.hideLoader()}};BX.DocumentGenerator.DocumentPreview.prototype.start=function(){if(this.imageUrl){this.showImageNode()}else if(this.startImageUrl){this.imageUrl=this.startImageUrl;this.startImageUrl=null;this.showImageNode();if(BX.type.isDomNode(this.imageNode)){this.imageNode.style.opacity=.2}if(this.pullTag){this.showLoader()}}else if(!this.isTransformationError&&!this.previewNode){this.showLoader()}};BX.DocumentGenerator.DocumentPreview.prototype.showImageNode=function(){if(!BX.type.isDomNode(this.imageContainer)){return}if(!BX.type.isDomNode(this.imageNode)){this.imageNode=BX.create("img",{style:{opacity:.1,display:"none"}});BX.append(this.imageNode,this.imageContainer)}if(this.imageUrl){this.imageNode.src=this.imageUrl;BX.show(this.imageNode);this.imageNode.style.opacity=1}};BX.DocumentGenerator.Document={isProcessing:false};BX.DocumentGenerator.Document.askAboutUsingPreviousDocumentNumber=function(e,t,i,o,n){if(BX.type.isString(e)&&parseInt(t)>0&&BX.type.isFunction(o)){if(BX.DocumentGenerator.Document.isProcessing===true){return}try{e=e.replace(/\\/g,"\\\\");BX.DocumentGenerator.Document.isProcessing=true;BX.ajax.runAction("documentgenerator.api.document.list",{data:{select:["id","number"],filter:{provider:e,templateId:t,value:i},order:{id:"desc"}},navigation:{size:1}}).then(function(e){BX.DocumentGenerator.Document.isProcessing=false;if(e.data.documents.length>0){var t=e.data.documents[0].number;BX.DocumentGenerator.showMessage(BX.message("DOCGEN_POPUP_DO_USE_OLD_NUMBER"),[new BX.PopupWindowButton({text:BX.message("DOCGEN_POPUP_NEW_BUTTON"),className:"ui-btn ui-btn-md ui-btn-primary",events:{click:function(){o();this.popupWindow.destroy()}}}),new BX.PopupWindowButton({text:BX.message("DOCGEN_POPUP_OLD_BUTTON"),className:"ui-btn ui-btn-md ui-btn-primary",events:{click:function(){o(t);this.popupWindow.destroy()}}})],BX.message("DOCGEN_POPUP_NUMBER_TITLE"),n)}else{o()}}).catch(function(){BX.DocumentGenerator.Document.isProcessing=false;if(BX.type.isFunction(n)){n()}})}catch(e){BX.DocumentGenerator.Document.isProcessing=false;if(BX.type.isFunction(n)){n()}}}};BX.DocumentGenerator.Document.onBeforeCreate=function(e,t,i){var o=BX.DocumentGenerator.parseUrl(e,"params");if(!o.hasOwnProperty("documentId")){var n=decodeURIComponent(o.providerClassName).toLowerCase();var s=o.templateId;var r=o.value;BX.DocumentGenerator.Document.askAboutUsingPreviousDocumentNumber(n,s,r,function(t){if(t){e=BX.util.add_url_param(e,{number:t})}BX.DocumentGenerator.openUrl(e,i)})}else{BX.DocumentGenerator.openUrl(e,i)}};BX.DocumentGenerator.Feedback={open:function(e,t,i){var o="/bitrix/components/bitrix/documentgenerator.feedback/slider.php";o=BX.util.add_url_param(o,{provider:e||"",templateName:t||"",templateCode:i||""});if(BX.SidePanel){BX.SidePanel.Instance.open(o,{width:735})}else{location.href=o}}};BX.DocumentGenerator.parseUrl=function(e,t){var i=document.createElement("a"),o={},n,s,r;i.href=e;n=i.search.replace(/^\?/,"").split("&");for(r=0;r<n.length;r++){s=n[r].split("=");o[s[0]]=s[1]}var a={protocol:i.protocol,host:i.host,hostname:i.hostname,port:i.port,pathname:i.pathname,search:i.search,params:o,hash:i.hash};if(t&&a.hasOwnProperty(t)){return a[t]}return a};BX.DocumentGenerator.openUrl=function(e,t,i){if(BX.SidePanel){if(!BX.type.isNumber(i)){i=980}BX.SidePanel.Instance.open(e,{width:i,cacheable:false,loader:t});var o=BX.PopupMenu.getCurrentMenu();if(o&&o.popupWindow){o.popupWindow.close()}}else{location.href=e}};BX.DocumentGenerator.showMessage=function(e,t,i,o){i=i||"";if(typeof t==="undefined"||typeof t==="object"&&t.length<=0){t=[new BX.PopupWindowButton({text:BX.message("DOCGEN_POPUP_CLOSE_BUTTON"),className:"ui-btn ui-btn-md ui-btn-default",events:{click:function(e){this.popupWindow.close();BX.PreventDefault(e)}}})]}if(this.popupConfirm!=null){this.popupConfirm.destroy()}if(!BX.type.isDomNode(e)){var n=document.createElement("div");n.innerHTML=e;e=n}if(!BX.type.isArray(e)){e=[e]}this.popupConfirm=new BX.PopupWindow("bx-popup-documentgenerator-popup",null,{zIndex:200,autoHide:true,closeByEsc:true,buttons:t,closeIcon:true,overlay:true,events:{onPopupClose:function(){if(BX.type.isFunction(o)){o()}this.destroy()},onPopupDestroy:BX.delegate(function(){this.popupConfirm=null},this)},content:BX.create("span",{attrs:{className:"bx-popup-documentgenerator-popup-content-text"},children:e}),titleBar:i,contentColor:"white",className:"bx-popup-documentgenerator-popup",maxWidth:470});this.popupConfirm.show()};BX.DocumentGenerator.Button=function(e,t){this.progress=false;this.links={};this.linksLoaded=false;this.intranetExtensions=null;this.id=e;this.text="Document";this.className="";this.menuClassName=null;this.provider=null;this.value=null;this.loaderPath=null;this.documentUrl=null;this.templateListUrl=null;this.moduleId=null;this.templatesText="Templates";this.documentsText="Documents";this.fillParameters(t)};BX.DocumentGenerator.Button.prototype.fillParameters=function(e){if(e.links&&BX.type.isNotEmptyObject(e.links)){this.links=e.links;if(this.links.length>0){this.linksLoaded=true}}if(e.menuClassName&&BX.type.isString(e.menuClassName)){this.menuClassName=e.menuClassName}if(e.className&&BX.type.isString(e.className)){this.className=e.className}if(e.moduleId&&BX.type.isString(e.moduleId)){this.moduleId=e.moduleId}if(e.text&&BX.type.isString(e.text)){this.text=e.text}if(e.templatesText&&BX.type.isString(e.templatesText)){this.templatesText=e.templatesText}if(e.documentsText&&BX.type.isString(e.documentsText)){this.documentsText=e.documentsText}this.value=e.value||null;this.provider=e.provider||null;this.loaderPath=e.loaderPath||null;this.templateListUrl=e.templateListUrl||null;this.documentUrl=e.documentUrl||null};BX.DocumentGenerator.Button.prototype.getElement=function(){return BX(this.id)};BX.DocumentGenerator.Button.prototype.createElement=function(){var e=this.getElement();if(e){return e}if(!this.id){return null}var t="button";var i="ui-btn ui-btn-md ui-btn-light-border ui-btn-dropdown ui-btn-themes";if(this.className){i+=" "+this.className}var o={id:this.id,className:i};e=BX.create(t,{attrs:o,text:this.text});return e};BX.DocumentGenerator.Button.prototype.init=function(){BX.bind(this.getElement(),"click",BX.proxy(function(){if(this.linksLoaded){this.showPopup()}else{if(this.progress){return}this.progress=true;this.showLoader();BX.ajax.runAction("documentgenerator.api.document.getButtonTemplates",{data:{moduleId:this.moduleId,provider:this.provider,value:this.value}}).then(BX.proxy(function(e){this.fillLinksFromResponse(e);this.hideLoader();this.progress=false;setTimeout(BX.proxy(this.showPopup,this),10)},this)).catch(BX.proxy(function(e){this.hideLoader();this.progress=false;alert(e.errors.pop().message)},this))}},this));BX.addCustomEvent("onPullEvent-documentgenerator",BX.proxy(function(e,t){if(e==="updateTemplate"){this.linksLoaded=false;this.links={};BX.PopupMenu.destroy(this.getPopupMenuId())}},this))};BX.DocumentGenerator.Button.prototype.fillLinksFromResponse=function(e){this.linksLoaded=true;this.links={};if(this.documentUrl&&e.data.templates&&BX.type.isArray(e.data.templates)){this.links.templates=[];var t,i=e.data.templates.length,o;for(t=0;t<i;t++){o=BX.util.add_url_param(this.documentUrl,{templateId:parseInt(e.data.templates[t]["id"]),providerClassName:this.provider.replace(/\\/g,"\\\\"),value:this.value,analyticsLabel:"generateDocument",templateCode:e.data.templates[t]["code"]});this.links.templates[t]={text:BX.util.htmlspecialchars(e.data.templates[t]["name"]),onclick:"BX.DocumentGenerator.Document.onBeforeCreate('"+o+"', {}, '"+this.loaderPath+"')"}}}if(e.data.documentList&&this.documentUrl){this.links.documentList=BX.util.add_url_param(e.data.documentList,{provider:this.provider.replace(/\\/g,"\\\\"),module:this.moduleId,value:this.value,viewUrl:this.documentUrl,loaderPath:this.loaderPath})}if(e.data.canEditTemplate&&this.templateListUrl){this.links.templateList=this.templateListUrl}if(e.data.intranetExtensions){this.intranetExtensions=e.data.intranetExtensions}};BX.DocumentGenerator.Button.prototype.prepareLinksForPopup=function(){var e=[],t=false;if(!this.linksLoaded){return e}if(this.links.templates&&BX.type.isArray(this.links.templates)){e=this.links.templates;t=true}if(this.links.documentList){if(t){e[e.length]={delimiter:true};t=false}e[e.length]={text:this.documentsText,onclick:"BX.DocumentGenerator.openUrl('"+this.links.documentList+"', null, 930)"}}if(this.links.templateList){if(t){e[e.length]={delimiter:true}}e[e.length]={text:this.templatesText,onclick:"BX.DocumentGenerator.openUrl('"+this.links.templateList+"', null, 930)"}}if(this.intranetExtensions){e.push({delimiter:true});e.push(this.intranetExtensions)}return e};BX.DocumentGenerator.Button.prototype.showPopup=function(){BX.PopupMenu.show(this.getPopupMenuId(),this.getElement(),this.prepareLinksForPopup(),{offsetLeft:0,offsetTop:0,closeByEsc:true,className:"document-toolbar-menu"})};BX.DocumentGenerator.Button.prototype.getPopupMenuId=function(){return this.id+"_menu"};BX.DocumentGenerator.Button.prototype.getLoader=function(){if(!this.loader){this.loader=new BX.Loader({size:50})}return this.loader};BX.DocumentGenerator.Button.prototype.showLoader=function(){if(this.getElement()&&!this.getLoader().isShown()){this.getLoader().show(this.getElement())}};BX.DocumentGenerator.Button.prototype.hideLoader=function(){if(this.getLoader().isShown()){this.getLoader().hide()}}})(window);
//# sourceMappingURL=documentpreview.map.js