From: Bill Erickson Date: Wed, 9 Apr 2014 14:20:52 +0000 (-0400) Subject: browser staff : inline print content X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=3e61a5fbc4c12e96494092c1815312ca8f11c51c;p=working%2FEvergreen.git browser staff : inline print content adds support for an inline print container controlled by print css for printing content from the browser when the external print engine is not available Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/templates/staff/css/print.css.tt2 b/Open-ILS/src/templates/staff/css/print.css.tt2 new file mode 100644 index 0000000000..c7feb78f72 --- /dev/null +++ b/Open-ILS/src/templates/staff/css/print.css.tt2 @@ -0,0 +1,12 @@ + +/* hide everything but the print div */ +head { display: none; } /* just to be safe */ +body div:not([id="print-div"]) { display:none } + +div { display: none } +#print-div { display: block } +#print-div div { display: block } + +[%# +vim: ft=css +%] diff --git a/Open-ILS/src/templates/staff/css/style.css.tt2 b/Open-ILS/src/templates/staff/css/style.css.tt2 index 38dc7e419b..5c19ab02fa 100644 --- a/Open-ILS/src/templates/staff/css/style.css.tt2 +++ b/Open-ILS/src/templates/staff/css/style.css.tt2 @@ -86,6 +86,8 @@ table.list tr.selected td { .pad-horiz {padding : 0px 10px 0px 10px; } .pad-vert {padding : 20px 0px 10px 0px;} +#print-div { display: none; } + /* ---------------------------------------------------------------------- * Grid diff --git a/Open-ILS/src/templates/staff/t_base.tt2 b/Open-ILS/src/templates/staff/t_base.tt2 index 6c3ac7b144..0f54e03907 100644 --- a/Open-ILS/src/templates/staff/t_base.tt2 +++ b/Open-ILS/src/templates/staff/t_base.tt2 @@ -10,6 +10,7 @@ + [% INCLUDE "staff/t_navbar.tt2" %] @@ -20,5 +21,6 @@ # App-specific JS load commands go into an APP_JS block. PROCESS APP_JS; %] + diff --git a/Open-ILS/web/js/ui/default/staff/services/grid.js b/Open-ILS/web/js/ui/default/staff/services/grid.js index 1f4b118482..7051ff438c 100644 --- a/Open-ILS/web/js/ui/default/staff/services/grid.js +++ b/Open-ILS/web/js/ui/default/staff/services/grid.js @@ -440,27 +440,29 @@ angular.module('egGridMod', // columns angular.forEach(grid.columnsProvider.columns, - function(col, idx) { - csvStr += grid.csvDatum(col.name); - if (idx < colCount -1) csvStr += ','; + function(col) { + if (!grid.columnsProvider.visible[col.name]) return; + csvStr += grid.csvDatum(col.label); + csvStr += ','; } ); - csvStr += "\n"; + csvStr = csvStr.replace(/,$/,'\n'); // items angular.forEach(grid.items, function(item) { angular.forEach(grid.columnsProvider.columns, - function(col, idx) { + function(col) { + if (!grid.columnsProvider.visible[col.name]) return; // bare value var val = grid.dataProvider.itemFieldValue(item, col); // filtered value (dates, etc.) val = $filter('egGridValueFilter')(val, col); csvStr += grid.csvDatum(val); - if (idx < colCount -1) csvStr += ','; + csvStr += ','; } ); - csvStr += "\n"; + csvStr = csvStr.replace(/,$/,'\n'); }); return csvStr; diff --git a/Open-ILS/web/js/ui/default/staff/services/printstore.js b/Open-ILS/web/js/ui/default/staff/services/printstore.js index c924f43579..c4a886d9d4 100644 --- a/Open-ILS/web/js/ui/default/staff/services/printstore.js +++ b/Open-ILS/web/js/ui/default/staff/services/printstore.js @@ -40,11 +40,11 @@ angular.module('egCoreMod') service.socket = null; service.hatchAvailable = false; angular.forEach(service.pending, function(msg) { + delete service.pending[msg.msgid]; switch(msg.action) { case 'print': return service.browserPrint(msg.mime, msg.value); } - delete service.pending[msg.msgid]; }); } @@ -66,6 +66,7 @@ angular.module('egCoreMod') } service.socket.onclose = function() { + if (service.hatchAvailable === false) return; // already registered console.debug("disconnected from Hatch"); service.socket = null; service.hatchAvailable = null; // reset @@ -101,36 +102,8 @@ angular.module('egCoreMod') } service.browserPrint = function(mime, data) { - - // TODO: cleanup / angularize - - console.log(data); - var w = window.open( - 'data:text/plain;charset=utf-8,' + encodeURIComponent(data)); - - w.addEventListener('DOMContentLoaded', function(e) { - w.print(); - $timeout( - function(){ - console.log(w.matchMedia('print')); - w.close() - }, - // TODO: - // http://stackoverflow.com/questions/18325025/how-to-detect-window-print-finish - 3000 - ); - }, false); - - return; - - switch (mime) { - case 'text/csv': - case 'text/plain': - $window.print(data); - break; - case 'text/html': - // TODO: generate the document and print it - } + // let our local print container handle printing + service.onBrowserPrint(mime, data); } service.print = function(mime, data) { @@ -149,4 +122,41 @@ angular.module('egCoreMod') } return service; -}]); +}]) + +/** + * Container for inserting print data into the browser page. + * On insert, $window.print() is called to print the data. + * The div housing eg-print-container must apply the correct + * print media CSS to ensure this content (and not the rest + * of the page) is printed. + */ +.directive('egPrintContainer', function() { + return { + restrict : 'AE', + template : '
{{printContent}}
', + controller : ['$scope', '$window', 'egPrintStore', + function($scope, $window, egPrintStore) { + egPrintStore.onBrowserPrint = function(mime, data) { + console.log('printing ' + data.length + ' of ' + mime); + switch(mime) { + case 'text/csv': + case 'text/plain': + $scope.printContent = data; + break; + case 'text/html': + console.error('print text/html not yet supported'); + break; + } + + // force the template to absorb the data before printing + $scope.$apply(); + $window.print(); + $scope.printContent = ''; + } + } + ] + } +}); + +