Initial commit. FileViewer plugin v1.0
This commit is contained in:
31
js/ABOUT.js
Normal file
31
js/ABOUT.js
Normal file
@@ -0,0 +1,31 @@
|
||||
Ext.namespace('Zarafa.plugins.fileviewer');
|
||||
|
||||
/**
|
||||
* @class Zarafa.plugins.fileviewer.ABOUT
|
||||
* @extends String
|
||||
*
|
||||
* The copyright string holding the copyright notice for the Zarafa Webapp FileViewer Plugin.
|
||||
*/
|
||||
Zarafa.plugins.fileviewer.ABOUT = ""
|
||||
+ "<p>Copyright (C) 2015 Christoph Haas <christoph.h@sprinternet.at></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 fileviewer plugin contains the following third-party components:</p>"
|
||||
|
||||
+ "<h1>ViewerJS</h1>"
|
||||
|
||||
+ "<p>Copyright (C) 2015 viewerjs.org</p>";
|
104
js/FileviewerPlugin.js
Normal file
104
js/FileviewerPlugin.js
Normal file
@@ -0,0 +1,104 @@
|
||||
Ext.namespace('Zarafa.plugins.fileviewer');
|
||||
|
||||
/**
|
||||
* @class Zarafa.plugins.fileviewer.FileviewerPlugin
|
||||
* @extends Zarafa.core.Plugin
|
||||
*/
|
||||
Zarafa.plugins.fileviewer.FileviewerPlugin = Ext.extend(Zarafa.core.Plugin, {
|
||||
|
||||
/**
|
||||
* This method is called by the parent and will initialize all insertion points
|
||||
* and shared components.
|
||||
*/
|
||||
initPlugin: function () {
|
||||
Zarafa.plugins.fileviewer.FileviewerPlugin.superclass.initPlugin.apply(this, arguments);
|
||||
|
||||
Zarafa.core.data.SharedComponentType.addProperty('fileviewer.viewpanel');
|
||||
},
|
||||
|
||||
/**
|
||||
* Fired when the user doubleclicked on a box
|
||||
* @param {Zarafa.common.ui.BoxField} boxField Parent of the box
|
||||
* @param {Zarafa.common.ui.Box} box The box that has been doubleclicked
|
||||
* @param {Ext.data.Record} record The record that belongs to the box
|
||||
*/
|
||||
doOpen: function (record) {
|
||||
var componentType = Zarafa.core.data.SharedComponentType['fileviewer.viewpanel'];
|
||||
|
||||
var config = {
|
||||
modal : true,
|
||||
autoResize: true
|
||||
};
|
||||
|
||||
Zarafa.core.data.UIFactory.openLayerComponent(componentType, record, config);
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if the given file is either a PDF file or a ODF file.
|
||||
*
|
||||
* @param path
|
||||
* @returns {boolean}
|
||||
* @private
|
||||
*/
|
||||
isSupportedDocument: function (path) {
|
||||
return path.match(/^.*\.(pdf|od[tps])$/i) ? true : false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Bid for the type of shared component and the given record.
|
||||
* This will bid on a common.create or common.view for a
|
||||
* record with a message class set to IPM or IPM.Note.
|
||||
* @param {Zarafa.core.data.SharedComponentType} type Type of component a context can bid for.
|
||||
* @param {Ext.data.Record} record Optionally passed record.
|
||||
* @return {Number} The bid for the shared component
|
||||
*/
|
||||
bidSharedComponent: function (type, record) {
|
||||
var bid = -1;
|
||||
switch (type) {
|
||||
case Zarafa.core.data.SharedComponentType['fileviewer.viewpanel']:
|
||||
bid = 1;
|
||||
break;
|
||||
case Zarafa.core.data.SharedComponentType['common.view']:
|
||||
{
|
||||
if (record instanceof Zarafa.core.data.IPMAttachmentRecord) {
|
||||
var filename = record.get('name');
|
||||
if (this.isSupportedDocument(filename)) {
|
||||
bid = 2; // bit higher then the other plugins to make sure that this plugin is used
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return bid;
|
||||
},
|
||||
|
||||
/**
|
||||
* Will return the reference to the shared component.
|
||||
* Based on the type of component requested a component is returned.
|
||||
* @param {Zarafa.core.data.SharedComponentType} type Type of component a context can bid for.
|
||||
* @param {Ext.data.Record} record Optionally passed record.
|
||||
* @return {Ext.Component} Component
|
||||
*/
|
||||
getSharedComponent: function (type, record) {
|
||||
var component;
|
||||
switch (type) {
|
||||
case Zarafa.core.data.SharedComponentType['common.view']:
|
||||
component = this;
|
||||
break;
|
||||
case Zarafa.core.data.SharedComponentType['fileviewer.viewpanel']:
|
||||
component = Zarafa.plugins.fileviewer.ViewerPanel;
|
||||
break;
|
||||
}
|
||||
return component;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Zarafa.onReady(function () {
|
||||
container.registerPlugin(new Zarafa.core.PluginMetaData({
|
||||
name : 'fileviewer',
|
||||
displayName : _('PDF/ODF Preview Plugin'),
|
||||
about : Zarafa.plugins.fileviewer.ABOUT,
|
||||
pluginConstructor: Zarafa.plugins.fileviewer.FileviewerPlugin
|
||||
}));
|
||||
});
|
138
js/ViewerPanel.js
Normal file
138
js/ViewerPanel.js
Normal file
@@ -0,0 +1,138 @@
|
||||
Ext.namespace('Zarafa.plugins.fileviewer');
|
||||
|
||||
/**
|
||||
* @class Zarafa.plugins.fileviewer.ViewerPanel
|
||||
* @extends Ext.Panel
|
||||
* @xtype fileviewer.viewerpanel
|
||||
*
|
||||
* The main panel which contains the iframe to display a PDF or ODF document.
|
||||
*/
|
||||
Zarafa.plugins.fileviewer.ViewerPanel = Ext.extend(Ext.Panel, {
|
||||
/**
|
||||
* @cfg {String} viewerjsPath Path to the ViewerJS installation.
|
||||
* This is a relative path starting from the plugin root.
|
||||
*/
|
||||
viewerjsPath: 'external/ViewerJS/index.html#',
|
||||
|
||||
/**
|
||||
* @cfg {String} src The Iframe source. This will be applied if no record is set.
|
||||
* If a records was passed to this panel, the return value of the "getInlineImageUrl" function
|
||||
* will be used.
|
||||
*/
|
||||
src: '',
|
||||
|
||||
/**
|
||||
* @cfg {String} title The panel title. This will be applied if no record is set.
|
||||
* If a records was passed to this panel, the "name" or "filename" property of the record
|
||||
* will be used.
|
||||
*/
|
||||
title: '',
|
||||
|
||||
/**
|
||||
* @cfg {Boolean} autoResize This flag specifies if the panel gets automatically resized if the window size has changed.
|
||||
* Defaults to false.
|
||||
*/
|
||||
autoResize: false,
|
||||
|
||||
/**
|
||||
* @cfg {Number} defaultScale The default scaling of the panel.
|
||||
* Defaults to 0.8 meaning 80% of the browser width.
|
||||
*/
|
||||
defaultScale: 0.8,
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param config
|
||||
*/
|
||||
constructor: function (config) {
|
||||
config = config || {};
|
||||
|
||||
if (Ext.isDefined(config.record)) {
|
||||
this.src = this.getIframeURL(config.record.getInlineImageUrl());
|
||||
this.title = config.record.get('name') || config.record.get('filename');
|
||||
} else {
|
||||
this.src = config.src;
|
||||
this.title = config.title;
|
||||
}
|
||||
|
||||
if (Ext.isDefined(config.autoResize)) {
|
||||
this.autoResize = config.autoResize;
|
||||
}
|
||||
|
||||
Ext.applyIf(config, {
|
||||
xtype : 'fileviewer.viewerpanel',
|
||||
layout: 'anchor',
|
||||
anchor: '100%',
|
||||
items : [{
|
||||
xtype : 'component',
|
||||
autoEl: {
|
||||
tag : 'iframe',
|
||||
src : this.src,
|
||||
style : {
|
||||
width : '100%',
|
||||
height: '100%'
|
||||
},
|
||||
frameborder : 0,
|
||||
allowfullscreen: true
|
||||
}
|
||||
}],
|
||||
title : this.title,
|
||||
header: false,
|
||||
height: Ext.getBody().getViewSize().height * this.defaultScale,
|
||||
width : Ext.getBody().getViewSize().width * this.defaultScale
|
||||
});
|
||||
|
||||
Zarafa.plugins.fileviewer.ViewerPanel.superclass.constructor.call(this, config);
|
||||
},
|
||||
|
||||
/**
|
||||
* Initializes the events. This function is called during rendering of the panel.
|
||||
* @private
|
||||
*/
|
||||
initEvents: function () {
|
||||
if (this.autoResize) {
|
||||
Ext.EventManager.onWindowResize(this.resizePanel, this);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes the resize event listener. This function is called when the panel gets destroyed.
|
||||
* @private
|
||||
*/
|
||||
onDestroy: function () {
|
||||
if (this.autoResize) {
|
||||
Ext.EventManager.removeResizeListener(this.resizePanel, this);
|
||||
}
|
||||
Zarafa.plugins.fileviewer.ViewerPanel.superclass.onDestroy.call(this, arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Number} width The window width.
|
||||
* @param {Number} height The window height.
|
||||
* @private
|
||||
*/
|
||||
resizePanel: function (width, height) {
|
||||
this.setWidth(width * this.defaultScale);
|
||||
this.setHeight(height * this.defaultScale);
|
||||
|
||||
// center the panel
|
||||
if (this.ownerCt instanceof Ext.Window) {
|
||||
this.ownerCt.center();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Generate the complete Iframe URL including the ViewerJS path.
|
||||
*
|
||||
* @param {String} url The inline url of the attachment to view.
|
||||
* @returns {string}
|
||||
*/
|
||||
getIframeURL: function (url) {
|
||||
var pluginRoot = container.getBasePath() + 'plugins/fileviewer/';
|
||||
|
||||
return pluginRoot + this.viewerjsPath + url;
|
||||
}
|
||||
});
|
||||
|
||||
Ext.reg('fileviewer.viewerpanel', Zarafa.plugins.fileviewer.ViewerPanel);
|
Reference in New Issue
Block a user