PDA

View Full Version : how to get a delete message box working



fellfresse
4 Feb 2008, 10:47 AM
Hy Community,

this is my first Post, cause this is my first day with extjs.
I tried to use prototype, but ext fits more my needs for a project.

I have done a little skript in prototype that i want to transform into ext.

I have a delete link like this:

<a href="project/company/delete/id/{$val_COMPANY.ID}" class="app_del" title="'{$val_COMPANY.Company}' __delete__">

Now i want an event manager that displays a messagebox after clicking that link. If the user really want to delete the record than the link should be done, otherwise it should be interrupted.
My Problem now is to get a selection for this link by the css selektor.
what i tried is:


Ext.onReady(function() {

Ext.select('a.app_del').on('click', function(){
Ext.Msg.show({
title:'Delete?',
msg: 'Really???',
buttons: Ext.Msg.YESNOCANCEL
});
});


});

but this dont work, i dont get a messagebox.
i think its the css selektor.

i need this funktionality for every delete-link on this page.

thanks for your help.

Rocketman
4 Feb 2008, 11:04 AM
You need to use a callback function with your msgbox

fellfresse
4 Feb 2008, 11:42 PM
ok, and where can i read how its made? in the api under Class Ext.MessageBox i cant find something useful...

by the way, where is a good tutorial to start with ext?
i have done this (http://extjs.com/learn/Tutorial:Introduction_to_Ext_2.0) tutorial. this was great but definitely not enough.

thank you

Condor
4 Feb 2008, 11:49 PM
1. You need to stop the event (otherwise the href on the anchor tag will be followed)
2. You need to specify a handler.

Try:


Ext.onReady(function() {
Ext.select('a.app_del').on('click', function(el){
Ext.Msg.show({
title:'Delete?',
msg: 'Really???',
buttons: Ext.Msg.YESNO,
handler: function(btn) {
if (btn == 'yes') {
window.location.href = el.dom.href;
}
}
});
}, {stopEvent: true});
});

fellfresse
5 Feb 2008, 12:01 AM
unfortunately that not the full solution for this problem.
i shortly see 4 buttons on my screen OK,Yes,No,Cancel. but for the full rendering of the form is not enough time. shortly after i see the buttons the redirect happens and the record is deleted. without any interaction of myself?????


what can i do?

Condor
5 Feb 2008, 12:05 AM
Even if you specify {stopEvent:true} ?

fellfresse
5 Feb 2008, 12:42 AM
yes, i did copy and paste with your code...

i was able to take a screenshot...
http://pixxal-internetmarketing.de/images/Bildschirmfoto.png

Condor
5 Feb 2008, 12:56 AM
Oops... I made an error in the order of the parameters.

Try:


Ext.select('a.app_del').each(function(el) {
el.on('click', function(e){
Ext.Msg.show({
title:'Delete?',
msg: 'Really???',
buttons: Ext.Msg.YESNO,
handler: function(btn) {
if (btn == 'yes') {
window.location.href = el.dom.href;
}
}
});
}, el, {stopEvent: true});
});

fellfresse
5 Feb 2008, 1:08 AM
ok, this looks a little bit better.

now i see a message box and can click on the buttons. but when i click a button, the messagebox disappears and thats it...
and the message box still looks like that i posted???

is it possible that this is a problem cause i use firefox under ubuntu-linux?

fellfresse
5 Feb 2008, 1:29 AM
ok, now i added the resources/css/ext-all.css and now i got the correct messagebox.
but nothing get deleted whenn i click on yes.

Condor
5 Feb 2008, 1:40 AM
OK, I should really start testing my code before I post it...

Use:


Ext.select('a.app_del').each(function(el) {
el.on('click', function(e){
Ext.Msg.show({
title:'Delete?',
msg: 'Really???',
buttons: Ext.Msg.YESNO,
fn: function(btn) {
if (btn == 'yes') {
window.location.href = el.dom.href;
}
}
});
}, el, {stopEvent: true});
});

fellfresse
5 Feb 2008, 2:11 AM
now we got it.
thank you for your support.

greetings from germany