Skip to content

Commit

Permalink
Added a fix for btnEl undefined error
Browse files Browse the repository at this point in the history
  • Loading branch information
edspencer committed Apr 5, 2010
1 parent 74636da commit 71e60b8
Show file tree
Hide file tree
Showing 5 changed files with 1,074 additions and 1,072 deletions.
171 changes: 86 additions & 85 deletions Button.js
Original file line number Diff line number Diff line change
@@ -1,86 +1,87 @@
/**
* @class Ext.ux.Exporter.Button
* @extends Ext.Button
* @author Nige White, with modifications from Ed Spencer
* Specialised Button class that allows downloading of data via data: urls.
* Internally, this is just a link.
* Pass it either an Ext.Component subclass with a 'store' property, or just a store:
* new Ext.ux.Exporter.Button({component: someGrid});
* new Ext.ux.Exporter.Button({store: someStore});
* @cfg {Ext.Component} component The component the store is bound to
* @cfg {Ext.data.Store} store The store to export (alternatively, pass a component with a store property)
*/
Ext.ux.Exporter.Button = Ext.extend(Ext.Button, {
constructor: function(config) {
config = config || {};

Ext.applyIf(config, {
exportFunction: 'exportGrid',
disabled : true,
text : 'Download',
cls : 'download'
});

if (config.store == undefined && config.component != undefined) {
Ext.applyIf(config, {
store: config.component.store
});
} else {
Ext.applyIf(config, {
component: {
store: config.store
}
});
}

Ext.ux.Exporter.Button.superclass.constructor.call(this, config);

if (this.store && Ext.isFunction(this.store.on)) {
var setLink = function() {
this.getEl().child('a', true).href = 'data:application/vnd.ms-excel;base64,' + Ext.ux.Exporter[config.exportFunction](this.component, null, config);

this.enable();
};

if (this.el) {
setLink.call(this);
} else {
this.on('render', setLink, this);
}

this.store.on('load', setLink, this);
}
},

template: new Ext.Template(
'<table border="0" cellpadding="0" cellspacing="0" class="x-btn-wrap"><tbody><tr>',
'<td class="x-btn-left"><i> </i></td><td class="x-btn-center"><a class="x-btn-text" href="{1}" target="{2}">{0}</a></td><td class="x-btn-right"><i> </i></td>',
"</tr></tbody></table>"),

onRender: function(ct, position){
var btn, targs = [this.text || ' ', this.href, this.target || "_self"];
if (position){
btn = this.template.insertBefore(position, targs, true);
}else{
btn = this.template.append(ct, targs, true);
}
var btnEl = btn.child("a:first");
btnEl.on('focus', this.onFocus, this);
btnEl.on('blur', this.onBlur, this);

this.initButtonEl(btn, btnEl);
Ext.ButtonToggleMgr.register(this);
},

onClick : function(e){
if (e.button != 0) return;

if (!this.disabled){
this.fireEvent("click", this, e);

if (this.handler) this.handler.call(this.scope || this, this, e);
}
}
});

/**
* @class Ext.ux.Exporter.Button
* @extends Ext.Button
* @author Nige White, with modifications from Ed Spencer
* Specialised Button class that allows downloading of data via data: urls.
* Internally, this is just a link.
* Pass it either an Ext.Component subclass with a 'store' property, or just a store:
* new Ext.ux.Exporter.Button({component: someGrid});
* new Ext.ux.Exporter.Button({store: someStore});
* @cfg {Ext.Component} component The component the store is bound to
* @cfg {Ext.data.Store} store The store to export (alternatively, pass a component with a store property)
*/
Ext.ux.Exporter.Button = Ext.extend(Ext.Button, {
constructor: function(config) {
config = config || {};

Ext.applyIf(config, {
exportFunction: 'exportGrid',
disabled : true,
text : 'Download',
cls : 'download'
});

if (config.store == undefined && config.component != undefined) {
Ext.applyIf(config, {
store: config.component.store
});
} else {
Ext.applyIf(config, {
component: {
store: config.store
}
});
}

Ext.ux.Exporter.Button.superclass.constructor.call(this, config);

if (this.store && Ext.isFunction(this.store.on)) {
var setLink = function() {
this.getEl().child('a', true).href = 'data:application/vnd.ms-excel;base64,' + Ext.ux.Exporter[config.exportFunction](this.component, null, config);

this.enable();
};

if (this.el) {
setLink.call(this);
} else {
this.on('render', setLink, this);
}

this.store.on('load', setLink, this);
}
},

template: new Ext.Template(
'<table border="0" cellpadding="0" cellspacing="0" class="x-btn-wrap"><tbody><tr>',
'<td class="x-btn-left"><i> </i></td><td class="x-btn-center"><a class="x-btn-text" href="{1}" target="{2}">{0}</a></td><td class="x-btn-right"><i> </i></td>',
"</tr></tbody></table>"),

onRender: function(ct, position){
var btn, targs = [this.text || ' ', this.href, this.target || "_self"];
if (position){
btn = this.template.insertBefore(position, targs, true);
}else{
btn = this.template.append(ct, targs, true);
}
var btnEl = btn.child("a:first");
this.btnEl = btnEl;
btnEl.on('focus', this.onFocus, this);
btnEl.on('blur', this.onBlur, this);

this.initButtonEl(btn, btnEl);
Ext.ButtonToggleMgr.register(this);
},

onClick : function(e){
if (e.button != 0) return;

if (!this.disabled){
this.fireEvent("click", this, e);

if (this.handler) this.handler.call(this.scope || this, this, e);
}
}
});

Ext.reg('exportbutton', Ext.ux.Exporter.Button);
52 changes: 26 additions & 26 deletions ExcelFormatter/Cell.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
/**
* @class Ext.ux.Exporter.ExcelFormatter.Cell
* @extends Object
* Represents a single cell in a worksheet
*/
Ext.ux.Exporter.ExcelFormatter.Cell = Ext.extend(Object, {

constructor: function(config) {
Ext.applyIf(config, {
type: "String"
});

Ext.apply(this, config);

Ext.ux.Exporter.ExcelFormatter.Cell.superclass.constructor.apply(this, arguments);
},

render: function() {
return this.tpl.apply(this);
},

tpl: new Ext.XTemplate(
'<ss:Cell ss:StyleID="{style}">',
'<ss:Data ss:Type="{type}">{value}</ss:Data>',
'</ss:Cell>'
)
/**
* @class Ext.ux.Exporter.ExcelFormatter.Cell
* @extends Object
* Represents a single cell in a worksheet
*/
Ext.ux.Exporter.ExcelFormatter.Cell = Ext.extend(Object, {

constructor: function(config) {
Ext.applyIf(config, {
type: "String"
});

Ext.apply(this, config);

Ext.ux.Exporter.ExcelFormatter.Cell.superclass.constructor.apply(this, arguments);
},

render: function() {
return this.tpl.apply(this);
},

tpl: new Ext.XTemplate(
'<ss:Cell ss:StyleID="{style}">',
'<ss:Data ss:Type="{type}"><![CDATA[{value}]]></ss:Data>',
'</ss:Cell>'
)
});
Loading

0 comments on commit 71e60b8

Please sign in to comment.