Skip to content

Commit

Permalink
ENHANCEMENT: SSF-168 refactoring print button so that it opens print …
Browse files Browse the repository at this point in the history
…view in a new window. This is useful for debugging and also useful for when someone wants to use the print view not for printing, but for viewing a clean version of a gridfield without the surrounding CMS, using the view for copying and pasting into another app, for example.
  • Loading branch information
Julian Seidenberg committed Apr 5, 2012
1 parent 206c61f commit 14c3fd7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
13 changes: 3 additions & 10 deletions javascript/GridField.js
Expand Up @@ -119,15 +119,7 @@
this.setUUID(new Date().getTime());
},
onclick: function(e){
var self = this, iframeID = 'gridfield-print-iframe' + this.getUUID();
var printIframe = $('#' + iframeID);

if(!printIframe.length){
printIframe = $('<IFRAME id="'+iframeID+'" class="ss-gridfield-print-iframe">');
$(document.body).append(printIframe);
}

var self = this, btn = this.closest(':button'), grid = this.getGridField(),
var btn = this.closest(':button'), grid = this.getGridField(),
form = this.closest('form'), data = form.find(':input').serialize();

// Add current button
Expand All @@ -138,7 +130,8 @@
if(window.location.search) data = window.location.search.replace(/^\?/, '') + '&' + data;

var url = $.path.makeUrlAbsolute(grid.data('url') + '?' + data, $('base').attr('href'));
printIframe.attr('src', url);
var newWindow = window.open(url);

return false;
}
});
Expand Down
5 changes: 3 additions & 2 deletions templates/Includes/GridField_print.ss
@@ -1,9 +1,9 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

<% if $Title %><title>$Title</title><% end_if %>
</head>
<body>
<body onload="window.print();">
<% if $Title %><h3>$Title</h3><% end_if %>
<table>
<thead>
Expand All @@ -21,4 +21,5 @@
<% _t('GridField.PRINTEDBY', 'Printed by') %> $Member.Name
</p>
</body>

</html>

0 comments on commit 14c3fd7

Please sign in to comment.