PDA

View Full Version : Question about override for MessageBox



gnosis
30 Aug 2007, 9:24 AM
Hello all,
I'd like to make all confirm dialogs non-closable so that the user must use the yes/no buttons and doesn't have the upper-right x as an option. There must be something that I don't understand about how override works, because the following code bombs my app with an error "p has no properties". All I've done is copy the confirm function verbatim from the source and plopped it into an override with the closable param added to the config. What's wrong here?

Thanks,
G

Ext.override(Ext.MessageBox, {
confirm : function(title, msg, fn, scope){
this.show({
title : title,
msg : msg,
buttons: this.YESNO,
fn: fn,
scope : scope,
closable : false
});
return this;
}
});

mystix
30 Aug 2007, 11:01 AM
Ext.override() works on an object's prototype, while Ext.MessageBox is a singleton (i.e. there's only ever 1 instance of it in the window scope).

if you need to override something in the MessageBox, you'll have to copy+paste the entire code chunk and make your amendments in the copy.

Help forum regulars, correct me if i'm wrong.

[edit]
or use Ext.apply() as hendricd has pointed out below :">

hendricd
30 Aug 2007, 11:08 AM
As Ext.MessageBox [alias: Ext.Msg ] are both singletons,



var myMsgBox= //for your own flavor
or Ext.MessageBox = Ext.apply(Ext.MessageBox, {
confirm : function(title, msg, fn, scope){
this.show({
title : title,
msg : msg,
buttons: this.YESNO,
fn: fn,
scope : scope,
closable : false
});
return this;
}
}); would work well instead.

gnosis
30 Aug 2007, 11:16 AM
Nice. I tried copying the entire MessageBox code into a file, with mods; and also hendricd's apply() solution. Both worked great.

I've stuck with hendricd's, just because it's smaller. Is there any advantage to overwriting the entire source? Or is it generally ok to use apply() as a sort of override for singletons?

Thanks,
G

mystix
30 Aug 2007, 11:29 AM
stick with Ext.apply().

less code = less bloat = less problems. ;)

devnull
30 Aug 2007, 12:19 PM
it also makes core code upgrades easier, since you are only overriding the actual code that pertains to your customization.
Imagine the fun you would have if one of the other functions was modified in an upgrade and you were overriding it with an old version. those kind of issues usually cause hair to be pulled out ;)