<!-- TODO: remote hosted CSS should be hosted locally instead -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="[% ctx.base_path %]/staff/css/style.css" />
+ <link rel="stylesheet" href="[% ctx.base_path %]/staff/css/print.css" type="text/css" media="print" />
</head>
<body>
[% INCLUDE "staff/t_navbar.tt2" %]
# App-specific JS load commands go into an APP_JS block.
PROCESS APP_JS;
%]
+ <div id="print-div" eg-print-container></div>
</body>
</html>
// 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;
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];
});
}
}
service.socket.onclose = function() {
+ if (service.hatchAvailable === false) return; // already registered
console.debug("disconnected from Hatch");
service.socket = null;
service.hatchAvailable = null; // reset
}
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) {
}
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 : '<div>{{printContent}}</div>',
+ 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 = '';
+ }
+ }
+ ]
+ }
+});
+
+