Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion Adding a delete confirmation
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
KJoyner  
View profile   Translate to Translated (View Original)
 More options 26 Jan 2008, 00:57
From: KJoyner <K...@kjoyner.com>
Date: Fri, 25 Jan 2008 16:57:35 -0800 (PST)
Local: Sat 26 Jan 2008 00:57
Subject: Re: Adding a delete confirmation
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').

> --
> Jarkko Lainehttp://jlaine.nethttp://dotherightthing.comhttp://www.railsecommerce....


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google