richdocuments/js/viewer/viewer.js

119 lines
3.5 KiB
JavaScript
Raw Normal View History

2014-06-16 22:48:04 +03:00
/* globals FileList, OCA.Files.fileActions, oc_debug */
2013-10-20 21:51:03 +03:00
var odfViewer = {
isDocuments : false,
2013-10-20 21:51:03 +03:00
supportedMimesRead: [
'application/vnd.oasis.opendocument.text',
'application/vnd.oasis.opendocument.spreadsheet',
'application/vnd.oasis.opendocument.graphics',
'application/vnd.oasis.opendocument.presentation'
],
supportedMimesUpdate: [
2013-12-02 16:25:45 +03:00
'application/vnd.oasis.opendocument.text'
2013-10-20 21:51:03 +03:00
],
2014-01-31 23:12:01 +03:00
register : function(response){
if (response && response.mimes){
jQuery.each(response.mimes, function(i, mime){
odfViewer.supportedMimesRead.push(mime);
odfViewer.supportedMimesUpdate.push(mime);
});
}
2013-10-20 21:51:03 +03:00
for (var i = 0; i < odfViewer.supportedMimesRead.length; ++i) {
var mime = odfViewer.supportedMimesRead[i];
2014-06-10 16:41:04 +03:00
OCA.Files.fileActions.register(mime, 'View', OC.PERMISSION_READ, '', odfViewer.onView);
OCA.Files.fileActions.setDefault(mime, 'View');
2013-10-20 21:51:03 +03:00
}
2013-12-02 16:25:45 +03:00
for (var i = 0; i < odfViewer.supportedMimesUpdate.length; ++i) {
var mime = odfViewer.supportedMimesUpdate[i];
2014-06-10 16:41:04 +03:00
OCA.Files.fileActions.register(
2013-12-02 19:23:30 +03:00
mime,
'Edit',
2013-12-02 19:23:30 +03:00
OC.PERMISSION_UPDATE,
OC.imagePath('core', 'actions/rename'),
odfViewer.onEdit,
t('documents', 'Edit')
2013-12-02 19:23:30 +03:00
);
2013-12-02 16:25:45 +03:00
}
2013-10-20 21:51:03 +03:00
},
dispatch : function(filename){
2014-06-16 22:48:04 +03:00
if (odfViewer.supportedMimesUpdate.indexOf(OCA.Files.fileActions.getCurrentMimeType()) !== -1
&& OCA.Files.fileActions.getCurrentPermissions() & OC.PERMISSION_UPDATE
2013-10-20 21:51:03 +03:00
){
odfViewer.onEdit(filename);
} else {
odfViewer.onView(filename);
}
},
2014-07-09 12:09:10 +02:00
onEdit : function(fileName, context){
var fileId = context.$file.attr('data-id');
2014-06-13 17:52:32 +03:00
window.location = OC.linkTo('documents', 'index.php') + '#' + fileId;
2013-10-20 21:51:03 +03:00
},
onView: function(filename) {
var attachTo = odfViewer.isDocuments ? '#documents-content' : '#controls',
attachToolbarTo = odfViewer.isDocuments ? '#content-wrapper' : '#controls';
if (odfViewer.isDocuments){
//Documents view
var location = filename;
} else {
//Public page, files app, etc
2014-01-31 23:12:01 +03:00
var dirName = $('#dir').val()!='/' ? $('#dir').val() + '/' : '/';
2014-11-19 23:40:19 +03:00
var location = OC.filePath('documents', 'ajax', 'download.php') + '?path=' + encodeURIComponent(dirName) + encodeURIComponent(filename)
2015-05-14 20:39:03 +03:00
+ '&requesttoken=' + encodeURIComponent(oc_requesttoken);
2015-06-10 19:08:40 +03:00
OC.addStyle('documents', '3rdparty/webodf/wodotexteditor');
}
2013-10-24 19:23:59 +03:00
OC.addStyle('documents', 'viewer/odfviewer');
2013-10-24 19:23:59 +03:00
OC.addScript('documents', '3rdparty/webodf/webodf-debug', function() {
FileList.setViewerMode(true);
2013-10-20 21:51:03 +03:00
// odf action toolbar
var odfToolbarHtml =
'<div id="odf-toolbar">' +
'<button id="odf_close">' + t('documents', 'Close') +
'</button></div>';
if (odfViewer.isDocuments){
$(attachToolbarTo).prepend(odfToolbarHtml);
$('#odf-toolbar').css({position:'fixed'});
} else {
$(attachToolbarTo).append(odfToolbarHtml);
}
2013-10-20 21:51:03 +03:00
var canvashtml = '<div id="odf-canvas"></div>';
$(attachTo).after(canvashtml);
// in case we are on the public sharing page we shall display the odf into the preview tag
$('#preview').html(canvashtml);
var odfelement = document.getElementById("odf-canvas");
var odfcanvas = new odf.OdfCanvas(odfelement);
odfcanvas.load(location);
2013-10-20 21:51:03 +03:00
});
},
onClose: function() {
FileList.setViewerMode(false);
$('#odf-toolbar').remove();
$('#odf-canvas').remove();
2013-10-20 21:51:03 +03:00
}
};
$(document).ready(function() {
if ( typeof OCA !== 'undefined'
&& typeof OCA.Files !== 'undefined'
&& typeof OCA.Files.fileActions !== 'undefined'
) {
$.get(
2014-01-31 23:12:01 +03:00
OC.filePath('documents', 'ajax', 'mimes.php'),
{},
odfViewer.register
);
2013-10-20 21:51:03 +03:00
}
$('#odf_close').live('click', odfViewer.onClose);
});