Skip to content

Commit

Permalink
[IMP] Allow preview of image files
Browse files Browse the repository at this point in the history
  • Loading branch information
lmignon committed Mar 17, 2017
1 parent e8293f1 commit 2b1ced9
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
9.0.?.?.? (?)
~~~~~~~~~~~~~

* Improvement: Allow the preview of image files.
* Fix: A name in CMIS can not ends with a dot. On the CMIS backend the
'sanitize_cmis_name' method removes this character if it's found at the
end of the string to sanitize and this case is detected by the method
Expand Down
53 changes: 45 additions & 8 deletions cmis_web/static/src/js/form_widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,21 @@
return QWeb.render("CmisContentActions", ctx);
},

get_preview_url : function(){
isImage: function(){
if (this.baseTypeId === 'cmis:folder') {
return false;
}
return this.mimetype.split('/')[0]=='image';
},

get_content_url: function(){
return this.cmis_session.getContentStreamURL(this.objectId, 'inline');
},

get_preview_url: function(){
var rendition = _.findWhere(this.renditions, {mimeType: 'application/pdf'});
if (this.mimetype === 'application/pdf') {
return this.cmis_session.getContentStreamURL(this.objectId, 'inline');
if (this.isImage() || this.mimetype === 'application/pdf') {
return this.get_content_url();
} else if (rendition) {
return this.cmis_session.getContentStreamURL(rendition['streamId']);
}
Expand Down Expand Up @@ -1029,19 +1040,45 @@ var CmisMixin = {
},

on_click_preview: function(row){
//http://localhost:8080/share/proxy/alfresco/api/node/workspace/SpacesStore/34a2e79c-9118-4d85-890c-32a720d70ad5/content/thumbnails/pdf?c=force&lastModified=pdf%3A146062
var previewer_url = this.get_previewer_url(row.data());
this.display_preview(previewer_url);
var cmisObjectWrapped = row.data();
if (cmisObjectWrapped.isImage()){
this.display_preview_image(cmisObjectWrapped);
} else {
this.display_preview_pdf(cmisObjectWrapped);
}
},

display_preview_image: function(cmisObjectWrapped){
var image_url = cmisObjectWrapped.get_content_url();
var image_viewer_el = QWeb.render("CmisImageViewer", {'url': image_url,
'object': cmisObjectWrapped});
var $document_preview = this.$el.find(".documentpreview");
$document_preview.empty();
$document_preview.append(image_viewer_el);
// Show the previewer
var $tables_wrapper = this.$el.find(".dataTables_wrapper");
$tables_wrapper.fadeOut(400, function() {
$document_preview.fadeIn(400, function() {
});
});
// Attach an event to the "Back to document" icon
$document_preview.find(".button-back-browser").on('click', function() {
$document_preview.fadeOut(400, function() {
$tables_wrapper.fadeIn();
});
});
},

display_preview: function(previewerUrl){
display_preview_pdf: function(cmisObjectWrapped){
var previewer_url = this.get_previewer_url(cmisObjectWrapped);
var width="100%";
var height = '' + this.$el.height() - 30 + 'px'; //' ' + (H - r.top) + 'px';
var $document_preview = this.$el.find(".documentpreview");
$document_preview.empty();
$document_preview.append(QWeb.render("CmisDocumentViewer", {'url': previewerUrl,
$document_preview.append(QWeb.render("CmisDocumentViewer", {'url': previewer_url,
'width': width,
'height': height,

}));

// Show the previewer
Expand Down
17 changes: 15 additions & 2 deletions cmis_web/static/src/xml/form_widgets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,28 @@

</t>

<t t-name='CmisImageViewer'>
<div class="cmis_viewer_image cmis_document_viewer">
<div class='cmis_document_viewer_toolbar pull-right'>
<button type="button" class="btn btn-primary btn-sm button-back-browser">
<span class="glyphicon glyphicon-arrow-left" aria-hidden="true"></span>&amp;nbsp;Back to documents list
</button>
</div>
<div class='cmis_image_container'>
<img t-att-src='url' width='100%' allowfullscreen='1' webkitallowfullscreen='1'></img>
</div>
</div>
</t>

<t t-name='CmisDocumentViewer'>
<div class="cmis_document_viewer">
<div class="cmis_viewer_pdf cmis_document_viewer">
<div class='cmis_document_viewer_toolbar pull-right'>
<button type="button" class="btn btn-primary btn-sm button-back-browser">
<span class="glyphicon glyphicon-arrow-left" aria-hidden="true"></span>&amp;nbsp;Back to documents list
</button>
</div>
<div class='cmis_document_viewer_iframe'>
<iframe id='viewer'
<iframe id='viewer'
t-att-src='url'
t-att-width='width'
t-att-height='height'
Expand Down

0 comments on commit 2b1ced9

Please sign in to comment.