richdocuments/js/viewer/viewer.js

103 lines
3.0 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){
2015-06-16 20:02:05 +03:00
var i,
mimeRead,
mimeUpdate;
2014-01-31 23:12:01 +03:00
if (response && response.mimes){
jQuery.each(response.mimes, function(i, mime){
odfViewer.supportedMimesRead.push(mime);
odfViewer.supportedMimesUpdate.push(mime);
});
}
2015-06-16 20:02:05 +03:00
for (i = 0; i < odfViewer.supportedMimesRead.length; ++i) {
mimeRead = odfViewer.supportedMimesRead[i];
OCA.Files.fileActions.register(mimeRead, 'View', OC.PERMISSION_READ, '', odfViewer.onView);
OCA.Files.fileActions.setDefault(mimeRead, 'View');
2013-10-20 21:51:03 +03:00
}
2015-06-16 20:02:05 +03:00
for (i = 0; i < odfViewer.supportedMimesUpdate.length; ++i) {
mimeUpdate = odfViewer.supportedMimesUpdate[i];
2014-06-10 16:41:04 +03:00
OCA.Files.fileActions.register(
2015-06-16 20:02:05 +03:00
mimeUpdate,
'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
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');
2014-06-13 17:52:32 +03:00
window.location = OC.linkTo('documents', 'index.php') + '#' + 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);
// TODO replace file_path = documentsMain.url
var viewer = window.location.protocol + '//' + window.location.host + '/cloudsuite/cloudsuite.html?' +
'file_path=' + context.dir + '/' + filename +
'&host=' + 'ws://' + window.location.hostname + ':9980' +
'&edit=' + 'false' +
'&timestamp=' + '';
var frame = '<iframe id="loleafletframe" style="width:100%;height:100%;display:block;position:fixed;top:46px;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups"/>';
$(attachTo).append(frame);
$('#loleafletframe').load(function(){
var iframe = $('#loleafletframe').contents();
iframe.find('#tb_toolbar-up_item_close').click(function() {
odfViewer.onClose();
});
});
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);
});