Message from discussion
Adding a delete confirmation
MIME-Version: 1.0
Message-ID: <57884500-5410-4878-88be-839320368457@f47g2000hsd.googlegroups.com>
Date: Fri, 25 Jan 2008 16:57:35 -0800 (PST)
Received: by 10.100.125.12 with SMTP id x12mr79500anc.23.1201309055936; Fri,
25 Jan 2008 16:57:35 -0800 (PST)
In-Reply-To: <8E511704-4426-49A8-8C34-4B1CF569E8C5@jlaine.net>
X-IP: 12.177.68.254
References: <8ced4378-7ea2-43f2-9ac8-05b4ad3ea287@x69g2000hsx.googlegroups.com>
<f58d8dcb0801241734l66d81ad2t5db054dc198bb089@mail.gmail.com>
<B8AC67E0-9EE3-4543-A8F3-E941CDB8B978@jlaine.net> <36189a9b-c116-48e2-bc48-a01bd2d24ae1@d70g2000hsb.googlegroups.com>
<80968BCD-78C8-4F54-88AB-C1261FB83545@jlaine.net> <58bb3c54-3fbf-4539-bdb2-575d605b1b45@i12g2000prf.googlegroups.com>
<8E511704-4426-49A8-8C34-4B1CF569E8C5@jlaine.net>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11)
Gecko/20071127 Firefox/2.0.0.11,gzip(gfe),gzip(gfe)
Subject: Re: Adding a delete confirmation
From: KJoyner <K...@kjoyner.com>
To: Low Pro <low-pro@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
I changed the auth code as follows but cannot figure out any way to
furthur simplify.
var AJ =
{
encode_authenticity_token:function( token )
{
return encodeURIComponent( $F(token) )
},
authenticity_token_query_parameter_for_page:function()
{
return 'authenticity_token=' + AJ.encode_authenticity_token(
$$( 'input[ name = "authenticity_token" ]' ).first() )
}
}
I also moved to event delegation instead of trying to make the reload
work. The javascript now looks as follows:
Remote.Delete = Behavior.create( Remote.Base,
{
onclick: function( event )
{
var element = Event.element( event );
if ( element.hasClassName( 'delete_link' ) )
{
if ( confirm( 'Are you sure?' ) )
{
var options =
{
url: element.href.gsub( '/delete$', '' ),
method: 'delete',
parameters:
AJ.authenticity_token_query_parameter_for_page()
};
options = Object.extend( options, this.options );
this._makeRequest( options );
}
return false;
}
return true;
}
});
Event.addBehavior(
{
'#item_list' : Remote.Delete
});
Notice, that this attaches a behavior to a div with an ID of
item_list. If the element that received the click has a classname of
delete_link, then a confirmation will be displayed and the element
deleted through the destroy method.
On 25 Jan, 00:25, Jarkko Laine <jar...@jlaine.net> wrote:
> On 25.1.2008, at 9.20, KJoyner wrote:
>
>
>
> > I have added the following that now works, except for the reload which
> > does not appear to be working as I intended. For completeness, I have
> > included my updated delete method.
>
> > var AJ =
> > {
> > encode_authenticity_token:function( token )
> > {
> > return encodeURIComponent( $(token).value )
>
> Can't answer to your reload question off the top of my head, but you
> can replace $(token).value with $F(token) (seehttp://prototypejs.org/api/utility/dollar-f)
>
> > document.body.select( 'input[ name = "authenticity_token" ]' )
> > [ 0 ] )
>
> This is also same as $$('input[name="authenticity_token']).first() (http://prototypejs.org/api/utility/dollar-dollar
> ). If you give the input field an id, it can be reduced to $
> ('authenticity_token').
>
> --