Skip to content

Commit

Permalink
Tidied code, removed unneccessary config stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
stormtek committed Oct 12, 2012
1 parent 9afc962 commit ff009cb
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 47 deletions.
52 changes: 18 additions & 34 deletions Exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);
},

Expand Down
11 changes: 6 additions & 5 deletions csvFormatter/CsvFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion excelFormatter/Cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Ext.define("Ext.ux.exporter.excelFormatter.Cell", {

tpl: new Ext.XTemplate(
'<ss:Cell ss:StyleID="{style}">',
'<ss:Data ss:Type="{type}"><![CDATA[{value}]]></ss:Data>',
'<ss:Data ss:Type="{type}">{value}</ss:Data>',
'</ss:Cell>'
)
});
1 change: 0 additions & 1 deletion excelFormatter/ExcelFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
10 changes: 4 additions & 6 deletions excelFormatter/Style.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,18 @@ Ext.define("Ext.ux.exporter.excelFormatter.Style", {
tpl: new Ext.XTemplate(
'<tpl if="parentStyle.length == 0">',
'<ss:Style ss:ID="{id}">',
'</tpl>',
'<tpl if="parentStyle.length != 0">',
'<tpl else>',
'<ss:Style ss:ID="{id}" ss:Parent="{parentStyle}">',
'</tpl>',
'<tpl for="attributes">',
'<tpl if="children.length == 0">',
'<ss:{name} {propertiesString} />',
'</tpl>',
'<tpl if="children.length > 0">',
'<tpl if="children.length &gt; 0">',
'<ss:{name} {propertiesString}>',
'<tpl for="children">',
'<ss:{name} {propertiesString} />',
'</tpl>',
'</ss:{name}>',
'<tpl else>',
'<ss:{name} {propertiesString} />',
'</tpl>',
'</tpl>',
'</ss:Style>'
Expand Down

0 comments on commit ff009cb

Please sign in to comment.