Ext.namespace("Zarafa.plugins.filepreviewer");Zarafa.plugins.filepreviewer.ABOUT='<p>Copyright (C) 2015  Christoph Haas &lt;christoph.h@sprinternet.at&gt;</p><p>This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.</p><p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.</p><p>You should have received a copy of the GNU Affero General Public License along with this program.  If not, see <a href="http://www.gnu.org/licenses/" target="_blank">http://www.gnu.org/licenses/</a>.</p><hr /><p>The filepreviewer plugin contains the following third-party components:</p><h1>ViewerJS</h1><p>Copyright (C) 2015 viewerjs.org</p>';
Ext.namespace("Zarafa.plugins.filepreviewer");
Zarafa.plugins.filepreviewer.FileviewerPlugin=Ext.extend(Zarafa.core.Plugin,{initPlugin:function(){Zarafa.plugins.filepreviewer.FileviewerPlugin.superclass.initPlugin.apply(this,arguments);Zarafa.core.data.SharedComponentType.addProperty("filepreviewer.viewpanel")},doOpen:function(a){Zarafa.core.data.UIFactory.openLayerComponent(Zarafa.core.data.SharedComponentType["filepreviewer.viewpanel"],a,{modal:true,autoResize:true})},isSupportedDocument:function(a){return a.match(/^.*\.(pdf|od[tps]|jpg|jpeg|png|bmp|gif|mp4|mp3|ogg|webm|wav)$/i)?true:
false},bidSharedComponent:function(a,b){var c=-1;switch(a){case Zarafa.core.data.SharedComponentType["filepreviewer.viewpanel"]:c=1;break;case Zarafa.core.data.SharedComponentType["common.view"]:if(b instanceof Zarafa.core.data.IPMAttachmentRecord)if(this.isSupportedDocument(b.get("name")))c=2;break}return c},getSharedComponent:function(a){var b;switch(a){case Zarafa.core.data.SharedComponentType["common.view"]:b=this;break;case Zarafa.core.data.SharedComponentType["filepreviewer.viewpanel"]:b=Zarafa.plugins.filepreviewer.ViewerPanel;
break}return b}});Zarafa.onReady(function(){container.registerPlugin(new Zarafa.core.PluginMetaData({name:"filepreviewer",displayName:_("File previewer plugin"),about:Zarafa.plugins.filepreviewer.ABOUT,pluginConstructor:Zarafa.plugins.filepreviewer.FileviewerPlugin}))});Ext.namespace("Zarafa.plugins.filepreviewer");
Zarafa.plugins.filepreviewer.ViewerPanel=Ext.extend(Ext.Panel,{viewerjsPath:"external/ViewerJS/index.html",src:"",title:"",autoResize:false,defaultScale:0.8,constructor:function(a){a=a||{};if(Ext.isDefined(a.record)){this.title=a.record.get("name")||a.record.get("filename");var b=this.title.split(".").pop();this.src=this.getIframeURL(a.record.getInlineImageUrl(),b)}else{this.src=a.src;this.title=a.title}this.autoResize=Ext.isDefined(a.autoResize)?a.autoResize:false;this.defaultScale=Ext.isDefined(a.defaultScale)?
a.defaultScale:0.8;Ext.applyIf(a,{xtype:"filepreviewer.viewerpanel",layout:"anchor",anchor:"100%",items:[{xtype:"component",ref:"iframe",autoEl:{tag:"iframe",src:this.src,style:{width:"100%",height:"100%"},frameborder:0,allowfullscreen:true},listeners:{afterrender:this.onAfterRender}}],title:this.title,header:false,height:Ext.getBody().getViewSize().height*this.defaultScale,width:Ext.getBody().getViewSize().width*this.defaultScale});Zarafa.plugins.filepreviewer.ViewerPanel.superclass.constructor.call(this,
a)},initEvents:function(){if(this.autoResize===true)Ext.EventManager.onWindowResize(this.resizePanel,this);else if(this.autoResize!==false){this.autoResize.on("resize",this.resizePanel,this);if(Ext.isDefined(this.autoResize.autoScroll)){this.autoResize.initialAutoScrollValue=this.autoResize.autoScroll;this.autoResize.setAutoScroll(false)}}},onDestroy:function(){if(this.autoResize===true)Ext.EventManager.removeResizeListener(this.resizePanel,this);else if(this.autoResize!==false){this.autoResize.un("resize",
this.resizePanel,this);Ext.isDefined(this.autoResize.autoScroll)&&this.autoResize.setAutoScroll(this.autoResize.initialAutoScrollValue)}Zarafa.plugins.filepreviewer.ViewerPanel.superclass.onDestroy.call(this,arguments)},resizePanel:function(a,b){if(arguments.length>2){var c=arguments[0];a=c.getInnerWidth();b=c.getInnerHeight()}this.setWidth(a*this.defaultScale);this.setHeight(b*this.defaultScale);this.ownerCt instanceof Ext.Window&&this.ownerCt.center()},getIframeURL:function(a,b){var c=container.getBasePath()+
"plugins/filepreviewer/",d="";if(Ext.isDefined(b)){d+=b==="pdf"?"?zoom="+container.getSettingsModel().get("zarafa/v1/plugins/filepreviewer/config_pdf_default_zoom"):/(od[tps])$/i.test(b)?"?zoom="+container.getSettingsModel().get("zarafa/v1/plugins/filepreviewer/config_odf_default_zoom"):"?zoom=auto";d+="&type="+b}return c+this.viewerjsPath+d+"#"+a},onAfterRender:function(){var a=this.refOwner;this.getEl().on("load",a.onLoadFrame,this.getEl(),{single:true})},onLoadFrame:function(){var a=this.dom.contentDocument.getElementById("download");
a=Ext.get(a);a.on("click",function(){Zarafa.core.Util.skipRequester=true})}});Ext.reg("filepreviewer.viewerpanel",Zarafa.plugins.filepreviewer.ViewerPanel);
