1
|
|
|
/* globals FileList, OCA.Files.fileActions, oc_debug */ |
2
|
|
|
var odfViewer = { |
3
|
|
|
isDocuments : false, |
4
|
|
|
supportedMimesRead: [ |
5
|
|
|
'application/vnd.oasis.opendocument.text', |
6
|
|
|
'application/vnd.oasis.opendocument.spreadsheet', |
7
|
|
|
'application/vnd.oasis.opendocument.graphics', |
8
|
|
|
'application/vnd.oasis.opendocument.presentation' |
9
|
|
|
], |
10
|
|
|
|
11
|
|
|
supportedMimesUpdate: [ |
12
|
|
|
'application/vnd.oasis.opendocument.text' |
13
|
|
|
], |
14
|
|
|
|
15
|
|
|
register : function(response){ |
16
|
|
|
var i, |
17
|
|
|
mimeRead, |
18
|
|
|
mimeUpdate; |
19
|
|
|
|
20
|
|
|
if (response && response.mimes){ |
21
|
|
|
jQuery.each(response.mimes, function(i, mime){ |
22
|
|
|
odfViewer.supportedMimesRead.push(mime); |
23
|
|
|
odfViewer.supportedMimesUpdate.push(mime); |
24
|
|
|
}); |
25
|
|
|
} |
26
|
|
|
for (i = 0; i < odfViewer.supportedMimesRead.length; ++i) { |
27
|
|
|
mimeRead = odfViewer.supportedMimesRead[i]; |
28
|
|
|
OCA.Files.fileActions.register(mimeRead, 'View', OC.PERMISSION_READ, '', odfViewer.onView); |
29
|
|
|
OCA.Files.fileActions.setDefault(mimeRead, 'View'); |
30
|
|
|
} |
31
|
|
|
for (i = 0; i < odfViewer.supportedMimesUpdate.length; ++i) { |
32
|
|
|
mimeUpdate = odfViewer.supportedMimesUpdate[i]; |
33
|
|
|
OCA.Files.fileActions.register( |
34
|
|
|
mimeUpdate, |
35
|
|
|
'Edit', |
36
|
|
|
OC.PERMISSION_UPDATE, |
37
|
|
|
OC.imagePath('core', 'actions/rename'), |
38
|
|
|
odfViewer.onEdit, |
39
|
|
|
t('documents', 'Edit') |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
}, |
43
|
|
|
|
44
|
|
|
dispatch : function(filename){ |
45
|
|
|
if (odfViewer.supportedMimesUpdate.indexOf(OCA.Files.fileActions.getCurrentMimeType()) !== -1 |
46
|
|
|
&& OCA.Files.fileActions.getCurrentPermissions() & OC.PERMISSION_UPDATE |
|
|
|
|
47
|
|
|
){ |
48
|
|
|
odfViewer.onEdit(filename); |
49
|
|
|
} else { |
50
|
|
|
odfViewer.onView(filename); |
51
|
|
|
} |
52
|
|
|
}, |
53
|
|
|
|
54
|
|
|
onEdit : function(fileName, context){ |
55
|
|
|
var fileId = context.$file.attr('data-id'); |
56
|
|
|
window.location = OC.generateUrl('apps/documents/index') + '#' + fileId; |
57
|
|
|
}, |
58
|
|
|
|
59
|
|
|
onView: function(filename) { |
60
|
|
|
var fileloc, |
61
|
|
|
attachTo = odfViewer.isDocuments ? '#documents-content' : '#controls', |
62
|
|
|
attachToolbarTo = odfViewer.isDocuments ? '#content-wrapper' : '#controls'; |
63
|
|
|
|
64
|
|
|
if (odfViewer.isDocuments){ |
65
|
|
|
//Documents view |
66
|
|
|
fileloc = filename; |
67
|
|
|
} else { |
68
|
|
|
//Public page, files app, etc |
69
|
|
|
var dirName = $('#dir').val()!='/' ? $('#dir').val() + '/' : '/'; |
70
|
|
|
fileloc = OC.filePath('documents', 'ajax', 'download.php') + '?path=' |
71
|
|
|
+ encodeURIComponent(dirName) + encodeURIComponent(filename) |
|
|
|
|
72
|
|
|
+ '&requesttoken=' + encodeURIComponent(oc_requesttoken); |
|
|
|
|
73
|
|
|
OC.addStyle('documents', '3rdparty/webodf/wodotexteditor'); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
OC.addStyle('documents', 'viewer/odfviewer'); |
77
|
|
|
|
78
|
|
|
OC.addScript('documents', '3rdparty/webodf/webodf-debug', function() { |
79
|
|
|
FileList.setViewerMode(true); |
80
|
|
|
|
81
|
|
|
// odf action toolbar |
82
|
|
|
var odfToolbarHtml = |
83
|
|
|
'<div id="odf-toolbar">' + |
84
|
|
|
'<button id="odf_close">' + t('documents', 'Close') + |
85
|
|
|
'</button></div>'; |
86
|
|
|
if (odfViewer.isDocuments){ |
87
|
|
|
$(attachToolbarTo).prepend(odfToolbarHtml); |
88
|
|
|
$('#odf-toolbar').css({position:'fixed'}); |
89
|
|
|
} else { |
90
|
|
|
$(attachToolbarTo).append(odfToolbarHtml); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
var canvashtml = '<div id="odf-canvas"></div>'; |
94
|
|
|
$(attachTo).after(canvashtml); |
95
|
|
|
// in case we are on the public sharing page we shall display the odf into the preview tag |
96
|
|
|
$('#preview').html(canvashtml); |
97
|
|
|
|
98
|
|
|
var odfelement = document.getElementById("odf-canvas"); |
99
|
|
|
var odfcanvas = new odf.OdfCanvas(odfelement); |
100
|
|
|
odfcanvas.load(fileloc); |
101
|
|
|
}); |
102
|
|
|
}, |
103
|
|
|
|
104
|
|
|
onClose: function() { |
105
|
|
|
FileList.setViewerMode(false); |
106
|
|
|
$('#odf-toolbar').remove(); |
107
|
|
|
$('#odf-canvas').remove(); |
108
|
|
|
} |
109
|
|
|
}; |
110
|
|
|
|
111
|
|
|
$(document).ready(function() { |
112
|
|
|
if ( typeof OCA !== 'undefined' |
113
|
|
|
&& typeof OCA.Files !== 'undefined' |
|
|
|
|
114
|
|
|
&& typeof OCA.Files.fileActions !== 'undefined' |
|
|
|
|
115
|
|
|
) { |
116
|
|
|
$.get( |
117
|
|
|
OC.filePath('documents', 'ajax', 'mimes.php'), |
118
|
|
|
{}, |
119
|
|
|
odfViewer.register |
120
|
|
|
); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
$('#odf_close').live('click', odfViewer.onClose); |
124
|
|
|
}); |
125
|
|
|
|