comparison app/controller/FilterResult.js @ 937:6739bfdb743e

LadaPrint enabled dynamic printing of tables.
author Dustin Demuth <dustin@intevation.de>
date Wed, 30 Sep 2015 15:24:25 +0200
parents e7270963947c
children fe85a4d23370
comparison
equal deleted inserted replaced
936:e7270963947c 937:6739bfdb743e
221 var selection = grid.getView().getSelectionModel().getSelection(); 221 var selection = grid.getView().getSelectionModel().getSelection();
222 console.log(selection); 222 console.log(selection);
223 var i18n = Lada.getApplication().bundle; 223 var i18n = Lada.getApplication().bundle;
224 var me = this; 224 var me = this;
225 var columns = []; 225 var columns = [];
226 var columnNames = [];
227 var visibleColumns = {}
226 var data = []; 228 var data = [];
229
227 // Write the columns to an array 230 // Write the columns to an array
228 try { 231 try {
229 for (key in selection[0].data) { 232 for (key in selection[0].data) {
230 // Do not write owner or readonly 233 // Do not write owner or readonly or id
231 if (["owner", "readonly"].indexOf(key) == -1){ 234 if (["owner", "readonly", "id"].indexOf(key) == -1){
232 columns.push(key); 235 columns.push(key);
233 } 236 }
234 } 237 }
235 } catch (e) { 238 }
239 catch (e) {
240 console.log(e);
241 }
242
243 //Retrieve visible columns' id's and names.
244 try {
245 var grid = button.up('filterresultgrid');
246 var cman = grid.columnManager;
247 var cols = cman.getColumns();
248 for (key in cols) {
249 if (cols[key].dataIndex) {
250 visibleColumns[cols[key].dataIndex] = cols[key].text;
251 }
252 }
253 }
254 catch (e) {
236 console.log(e); 255 console.log(e);
237 } 256 }
238 257
239 258
240 // Retrieve Data from selection 259 // Retrieve Data from selection
243 var row = selection[item].data; 262 var row = selection[item].data;
244 var out = []; 263 var out = [];
245 //Lookup every column and write to data array. 264 //Lookup every column and write to data array.
246 for (key in columns){ 265 for (key in columns){
247 var attr = columns[key]; 266 var attr = columns[key];
248 if (row[attr] != null) { 267 //Only write data to output when the column is not hidden.
268 if (row[attr] != null &&
269 visibleColumns[attr] != null) {
249 out.push(row[attr].toString()); 270 out.push(row[attr].toString());
250 } 271 }
251 else { 272 else if (visibleColumns[attr] != null) {
252 out.push(''); 273 out.push('');
253 } 274 }
254 } 275 }
255 data.push(out); 276 data.push(out);
256 } 277 }
257 } catch (e){ 278 }
279 catch (e){
258 console.log(e); 280 console.log(e);
259 } 281 }
260 console.log(columns); 282
261 console.log(data); 283 //Retrieve the names of the columns.
284 try {
285 var grid = button.up('filterresultgrid');
286 var cman = grid.columnManager;
287 var cols = cman.getColumns();
288 //Iterate columns and find column names for the key...
289 // This WILL run into bad behaviour when column-keys exist twice.
290 for (key in columns){
291 for (k in cols){
292 if (cols[k].dataIndex == columns[key]){
293 columnNames.push(cols[k].text);
294 break;
295 }
296 }
297 }
298 }
299 catch (e) {
300 console.log(e);
301 }
262 302
263 var printData = { 303 var printData = {
264 'layout': 'A4 landscape', 304 'layout': 'A4 landscape',
265 'outputFormat': 'pdf', 305 'outputFormat': 'pdf',
266 'attributes': { 306 'attributes': {
267 'title': 'Auszug aus LADA', 307 'title': 'Auszug aus LADA',
268 'datasource': [{ 308 'displayName': 'Proben',
269 'displayName': 'Proben', 309 'table': {
270 'table': { 310 'columns': columnNames,
271 'columns': columns, 311 'data': data
272 'data': data 312 }
273 }
274
275 }]
276 } 313 }
277 } 314 }
278 315
279 Ext.Ajax.request({ 316 Ext.Ajax.request({
280 url: 'lada-printer/buildreport.pdf', 317 url: 'lada-printer/buildreport.pdf',

http://lada.wald.intevation.org