Mercurial > lada > lada-client
changeset 934:3e3e737050b7
Added Print function to talk with mapfish
author | Dustin Demuth <dustin@intevation.de> |
---|---|
date | Tue, 29 Sep 2015 17:28:01 +0200 |
parents | c8aceb9e60cc |
children | cd809e56dff6 |
files | app/controller/FilterResult.js |
diffstat | 1 files changed, 72 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/app/controller/FilterResult.js Wed Sep 23 07:39:30 2015 +0200 +++ b/app/controller/FilterResult.js Tue Sep 29 17:28:01 2015 +0200 @@ -170,7 +170,6 @@ } var me = this; Ext.Ajax.request({ - method: 'POST', url: 'lada-server/export/laf', jsonData: {'proben': proben}, success: function(response) { @@ -221,25 +220,87 @@ var grid = button.up('grid'); var selection = grid.getView().getSelectionModel().getSelection(); var i18n = Lada.getApplication().bundle; - var proben = []; - for (var i = 0; i < selection.length; i++) { - proben.push(selection[i].get('id')); + var me = this; + /*Example: { + "layout": "A4 landscape", + "outputFormat": "pdf", + "attributes": { + "title": "Auszug aus Lada", + "datasource": [ + { + "displayName": "Proben", + "table" : { + "columns": ["ProbeId", "MST", "Proben-Nr"], + "data": [ + [1, "LiLiblah", "icon_pan"], + [2, "LiLiblip", "icon_zoomin"] + ] + } + } + ] + } + }; */ + + var columns = []; + var data = []; + // Write the columns to an array + try { + for (key in selection[0].data) { + // Do not write owner or readonly + if (["owner", "readonly"].indexOf(key) == -1){ + columns.push(key); + } + } + } catch (e) { } - var me = this; + + // Retrieve Data from selection + try { + for (item in selection) { + var row = selection[item].data; + var out = []; + //Lookup every column and write to data array. + for (key in columns){ + var attr = columns[key]; + out.push(row[attr].toString()); + } + data.push(out); + } + } catch (e){ + } + + var printData = { + 'layout': 'A4 landscape', + 'outputFormat': 'pdf', + 'attributes': { + 'title': 'Auszug aus LADA', + 'datasource': [{ + 'displayName': 'Proben', + 'table': { + 'columns': columns, + 'data': data + } + + }] + } + } + Ext.Ajax.request({ - method: 'POST', - url: '127.0.0.1', // TODO - jsonData: {'proben': proben}, // TODO + url: 'lada-printer/buildreport.pdf', + //configure a proxy in apache conf! + jsonData: printData, + binary: true, success: function(response) { - console.log('success'); - var content = response.responseText; - var blob = new Blob([content],{type: 'application/pdf'}); + var content = response.responseBytes; + var filetype = response.getResponseHeader('Content-Type'); + var blob = new Blob([content],{type: filetype}); saveAs(blob, 'lada-print.pdf'); }, failure: function(response) { console.log('failure'); // Error handling // TODO + //console.log(response.responseText) if (response.responseText) { try { var json = Ext.JSON.decode(response.responseText);