richdocuments/js/viewer/viewer.js

116 lines
3.8 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,
2015-11-04 10:30:16 +01:00
supportedMimesReadOnly: [
],
2015-11-04 10:30:16 +01:00
supportedMimesReadWrite: [
2013-10-20 21:51:03 +03:00
'application/vnd.oasis.opendocument.text',
'application/vnd.oasis.opendocument.spreadsheet',
'application/vnd.oasis.opendocument.graphics',
'application/vnd.oasis.opendocument.presentation',
'application/vnd.lotus-wordpro',
'image/svg+xml',
'application/vnd.visio',
'application/vnd.wordperfect',
'application/msonenote',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
'application/vnd.ms-word.document.macroEnabled.12',
'application/vnd.ms-word.template.macroEnabled.12',
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
'application/vnd.ms-excel.sheet.macroEnabled.12',
'application/vnd.ms-excel.template.macroEnabled.12',
'application/vnd.ms-excel.addin.macroEnabled.12',
'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
'application/vnd.ms-powerpoint',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/vnd.openxmlformats-officedocument.presentationml.template',
'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
'application/vnd.ms-powerpoint.addin.macroEnabled.12',
'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
'application/vnd.ms-powerpoint.template.macroEnabled.12',
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12'
2013-10-20 21:51:03 +03:00
],
2014-01-31 23:12:01 +03:00
register : function(response){
var i,
2015-11-04 10:30:16 +01:00
mimeReadOnly,
mimeReadWrite;
2014-01-31 23:12:01 +03:00
if (response && response.mimes){
jQuery.each(response.mimes, function(i, mime){
2015-11-04 10:30:16 +01:00
odfViewer.supportedMimesReadOnly.push(mime);
odfViewer.supportedMimesReadWrite.push(mime);
2014-01-31 23:12:01 +03:00
});
}
2015-11-04 10:30:16 +01:00
for (i = 0; i < odfViewer.supportedMimesReadOnly.length; ++i) {
mimeReadOnly = odfViewer.supportedMimesReadOnly[i];
OCA.Files.fileActions.register(mimeReadOnly, 'View', OC.PERMISSION_READ, '', odfViewer.onView);
OCA.Files.fileActions.setDefault(mimeReadOnly, 'View');
2013-10-20 21:51:03 +03:00
}
2015-11-04 10:30:16 +01:00
for (i = 0; i < odfViewer.supportedMimesReadWrite.length; ++i) {
mimeReadWrite = odfViewer.supportedMimesReadWrite[i];
2014-06-10 16:41:04 +03:00
OCA.Files.fileActions.register(
2015-11-04 10:30:16 +01:00
mimeReadWrite,
'Edit',
OC.PERMISSION_UPDATE,
OC.imagePath('core', 'actions/rename'),
odfViewer.onEdit,
2015-12-16 17:57:44 +03:00
t('richdocuments', 'Edit')
2013-12-02 19:23:30 +03:00
);
2015-11-04 10:30:16 +01:00
OCA.Files.fileActions.setDefault(mimeReadWrite, 'Edit');
2013-12-02 16:25:45 +03:00
}
2013-10-20 21:51:03 +03:00
},
2013-10-20 21:51:03 +03:00
dispatch : function(filename){
2015-11-04 10:30:16 +01:00
if (odfViewer.supportedMimesReadWrite.indexOf(OCA.Files.fileActions.getCurrentMimeType()) !== -1
2015-06-16 20:02:05 +03:00
&& 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){
2015-08-04 14:21:30 +03:00
var fileId = context.$file.attr('data-id');
var fileDir = context.dir;
if (fileDir) {
window.location = OC.generateUrl('apps/richdocuments/index#{file_id}_{dir}', {file_id: fileId, dir: fileDir});
} else {
window.location = OC.generateUrl('apps/richdocuments/index#{file_id}', {file_id: fileId});
}
2013-10-20 21:51:03 +03:00
},
2015-10-28 21:05:13 -04:00
onView: function(filename, context) {
var attachTo = odfViewer.isDocuments ? '#documents-content' : '#controls';
FileList.setViewerMode(true);
2013-10-20 21:51:03 +03:00
},
2013-10-20 21:51:03 +03:00
onClose: function() {
FileList.setViewerMode(false);
$('#loleafletframe').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(
2015-12-16 17:57:44 +03:00
OC.filePath('richdocuments', 'ajax', 'mimes.php'),
2014-01-31 23:12:01 +03:00
{},
odfViewer.register
);
2013-10-20 21:51:03 +03:00
}
$('#odf_close').live('click', odfViewer.onClose);
});