From ff009cb17cc33478fad93eafe4c6f4fbade00dcc Mon Sep 17 00:00:00 2001 From: Elgar Storm Date: Fri, 12 Oct 2012 16:14:31 +1300 Subject: [PATCH] Tidied code, removed unneccessary config stuff --- Exporter.js | 52 +++++++++++--------------------- csvFormatter/CsvFormatter.js | 11 ++++--- excelFormatter/Cell.js | 2 +- excelFormatter/ExcelFormatter.js | 1 - excelFormatter/Style.js | 10 +++--- 5 files changed, 29 insertions(+), 47 deletions(-) diff --git a/Exporter.js b/Exporter.js index 9f141d4..97d1b95 100644 --- a/Exporter.js +++ b/Exporter.js @@ -6,13 +6,12 @@ Ext.define("Ext.ux.exporter.Exporter", { uses: [ "Ext.ux.exporter.Base64", - "Ext.ux.exporter.Button", "Ext.ux.exporter.csvFormatter.CsvFormatter", "Ext.ux.exporter.excelFormatter.ExcelFormatter" ], statics: { - exportAny: function(component, formatter, config) { + exportAny: function(component, formatter, title) { var func = "export"; if(!component.is) { func = func + "Store"; @@ -25,51 +24,36 @@ Ext.define("Ext.ux.exporter.Exporter", { component = component.getStore(); } - return this[func](component, this.getFormatterByName(formatter), config); + return this[func](component, formatter, title); }, - /** - * Exports a grid, using the .xls formatter by default - * @param {Ext.grid.GridPanel} grid The grid to export from - * @param {Object} config Optional config settings for the formatter - */ - exportGrid: function(grid, formatter, config) { - config = config || {}; + exportGrid: function(grid, formatter, title) { formatter = this.getFormatterByName(formatter); - var columns = Ext.Array.filter(grid.columns, function(col) { - return !col.hidden; // && (!col.xtype || col.xtype != "actioncolumn"); - }); - - Ext.applyIf(config, { - title : grid.title, - columns: columns + return !col.hidden && (!col.xtype || col.xtype != "actioncolumn"); }); - + var config = { + title: grid.title ? grid.title : title, + columns: columns + }; return formatter.format(grid.store, config); }, - exportStore: function(store, formatter, config) { - config = config || {}; + exportStore: function(store, formatter, title) { formatter = this.getFormatterByName(formatter); - - Ext.applyIf(config, { - columns: store.fields ? store.fields.items : store.model.prototype.fields.items - }); - + var config = { + title: title, + columns: store.fields ? store.fields.items : store.model.prototype.fields.items + } return formatter.format(store, config); }, - exportTree: function(tree, formatter, config) { - config = config || {}; + exportTree: function(tree, formatter, title) { formatter = this.getFormatterByName(formatter); - - var store = tree.store || config.store; - - Ext.applyIf(config, { - title: tree.title - }); - + var store = tree.store; + var config = { + title: tree.title ? tree.title : title + } return formatter.format(store, config); }, diff --git a/csvFormatter/CsvFormatter.js b/csvFormatter/CsvFormatter.js index 5e1a085..4450073 100644 --- a/csvFormatter/CsvFormatter.js +++ b/csvFormatter/CsvFormatter.js @@ -6,14 +6,14 @@ Ext.define("Ext.ux.exporter.csvFormatter.CsvFormatter", { extend: "Ext.ux.exporter.Formatter", contentType: 'data:text/csv;base64,', - separator: ";", + separator: ",", extension: "csv", format: function(store, config) { this.columns = config.columns || (store.fields ? store.fields.items : store.model.prototype.fields.items); return this.getHeaders() + "\n" + this.getRows(store); }, - getHeaders: function(store) { + getHeaders: function() { var columns = [], title; Ext.each(this.columns, function(col) { var title; @@ -37,15 +37,16 @@ Ext.define("Ext.ux.exporter.csvFormatter.CsvFormatter", { return rows.join("\n"); }, - geCell: function(record, index) { + geCell: function(record) { var cells = []; Ext.each(this.columns, function(col) { var name = col.name || col.dataIndex; if(name) { + var value; if (Ext.isFunction(col.renderer)) { - var value = col.renderer(record.get(name), null, record); + value = col.renderer(record.get(name), null, record); } else { - var value = record.get(name); + value = record.get(name); } cells.push(value); } diff --git a/excelFormatter/Cell.js b/excelFormatter/Cell.js index 65143d9..28128a7 100644 --- a/excelFormatter/Cell.js +++ b/excelFormatter/Cell.js @@ -21,7 +21,7 @@ Ext.define("Ext.ux.exporter.excelFormatter.Cell", { tpl: new Ext.XTemplate( '', - '', + '{value}', '' ) }); \ No newline at end of file diff --git a/excelFormatter/ExcelFormatter.js b/excelFormatter/ExcelFormatter.js index 39c2ea4..343fd98 100644 --- a/excelFormatter/ExcelFormatter.js +++ b/excelFormatter/ExcelFormatter.js @@ -17,7 +17,6 @@ Ext.define("Ext.ux.exporter.excelFormatter.ExcelFormatter", { format: function(store, config) { var workbook = new Ext.ux.exporter.excelFormatter.Workbook(config); workbook.addWorksheet(store, config || {}); - return workbook.render(); } }); \ No newline at end of file diff --git a/excelFormatter/Style.js b/excelFormatter/Style.js index 24b6dce..b4e6881 100644 --- a/excelFormatter/Style.js +++ b/excelFormatter/Style.js @@ -80,20 +80,18 @@ Ext.define("Ext.ux.exporter.excelFormatter.Style", { tpl: new Ext.XTemplate( '', '', - '', - '', + '', '', '', '', - '', - '', - '', - '', + '', '', '', '', '', '', + '', + '', '', '', ''