Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion Adding a delete confirmation

View Parsed - Show only message text

Received: by 10.35.13.4 with SMTP id q4mr29632pyi.7.1201224894945;
        Thu, 24 Jan 2008 17:34:54 -0800 (PST)
Return-Path: <m...@aimonetti.net>
Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.226])
        by mx.google.com with ESMTP id a28si1781704pye.0.2008.01.24.17.34.54;
        Thu, 24 Jan 2008 17:34:54 -0800 (PST)
Received-SPF: neutral (google.com: 64.233.162.226 is neither permitted nor denied by best guess record for domain of m...@aimonetti.net) client-ip=64.233.162.226;
Authentication-Results: mx.google.com; spf=neutral (google.com: 64.233.162.226 is neither permitted nor denied by best guess record for domain of m...@aimonetti.net) smtp.mail=m...@aimonetti.net
Received: by nz-out-0506.google.com with SMTP id i28so346843nzi.5
        for <low-pro@googlegroups.com>; Thu, 24 Jan 2008 17:34:54 -0800 (PST)
Received: by 10.142.201.3 with SMTP id y3mr923530wff.1.1201224894601;
        Thu, 24 Jan 2008 17:34:54 -0800 (PST)
Received: by 10.143.19.13 with HTTP; Thu, 24 Jan 2008 17:34:54 -0800 (PST)
Message-ID: <f58d8dcb0801241734l66d81ad2t5db054dc198bb089@mail.gmail.com>
Date: Thu, 24 Jan 2008 17:34:54 -0800
From: "Matt Aimonetti" <mattaimone...@gmail.com>
Sender: m...@aimonetti.net
To: low-pro@googlegroups.com
Subject: Re: Adding a delete confirmation
In-Reply-To: <8ced4378-7ea2-43f2-9ac8-05b4ad3ea287@x69g2000hsx.googlegroups.com>
Mime-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_Part_23041_21073203.1201224894604"
References: <8ced4378-7ea2-43f2-9ac8-05b4ad3ea287@x69g2000hsx.googlegroups.com>

------=_Part_23041_21073203.1201224894604
Content-Type: text/plain; charset=ISO-8859-1

Remote.DeleteLink = Behavior.create(Remote.Base, {
  onclick : function() {
    var options = Object.extend({ url : this.element.href, method : 'delete'
}, this.options);
    if (confirm('Are you sure?')){
      return this._makeRequest(options);
    }else{
      return false;
    }
  }
});

don't change your route, a delete action should not be a GET but a DELETE.

I'm sure my code could be cleaned up by extending Remote.Link but oh well,
this was a quick hack.

-Matt


On 1/24/08, KJoyner <K...@kjoyner.com> wrote:
>
>
> I am trying to use Low Pro to add a delete confirmation. In my
> controller, I have added a delete and a destroy action. These content
> of these actions are:
>
> def delete
>   @item = Item.find( params[ :id ] )
> end
>
> def destroy
>
>   @item = Item.find( params[ :id ] )
>   item.destroy
>
>   redirect_to items_path
> end
>
> In the routes, I add a delete route to items by:
>
> map.resources :items, :member => { :delete => :get }
>
> I then have a view where I add a delete link like this (also using
> haml):
>
> = link_to "delete", delete_item_path( item ), :class => 'delete'
>
> All of this works when I have javascript disabled. Now I am trying to
> add a behavior that will do the confirmation in javascript and if
> confirmed then redirect to the destroy action. I am trying to do this
> as follows but it is not working.
>
> Remote.Delete = Behavior.create( Remote.Base, {
>   onclick: function( event ) {
>     if ( confirm( 'Are you sure?'  ) ) {
>       var destroy_url = this.element.href.gsub( '/delete$', '' );
>       options = Object.extend( { url: destroy_url, method: 'delete' },
> this.options );
>       return this._makeRequest( options )
>     }
>     return false;
>   }
> });
>
> Event.addBehavior( {
>   '.delete' : Remote.Delete
> });
>
> The onclick gets executed but it is not working correctly. Any help
> would be appriciated.
>
> Thanks,
>
> -- Ken
> >
>

------=_Part_23041_21073203.1201224894604
Content-Type: text/html; charset=ISO-8859-1

Remote.DeleteLink = Behavior.create(Remote.Base, {<br>&nbsp; onclick : function() {<br>&nbsp;&nbsp;&nbsp; var options = Object.extend({ url : this.element.href, method : &#39;delete&#39; }, this.options);<br>&nbsp;&nbsp;&nbsp; if (confirm(&#39;Are you sure?&#39;)){
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return this._makeRequest(options);<br>&nbsp;&nbsp;&nbsp; }else{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; }<br>});<br><br>don&#39;t change your route, a delete action should not be a GET but a DELETE.<br><br>I&#39;m sure my code could be cleaned up by extending 
Remote.Link but oh well, this was a quick hack.<br><br>-Matt<br><br><br><div><span class="gmail_quote">On 1/24/08, <b class="gmail_sendername">KJoyner</b> &lt;<a href="mailto:K...@kjoyner.com">K...@kjoyner.com</a>&gt; wrote:
</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>I am trying to use Low Pro to add a delete confirmation. In my<br>controller, I have added a delete and a destroy action. These content
<br>of these actions are:<br><br>def delete<br>&nbsp;&nbsp;@item = Item.find( params[ :id ] )<br>end<br><br>def destroy<br><br>&nbsp;&nbsp;@item = Item.find( params[ :id ] )<br>&nbsp;&nbsp;item.destroy<br><br>&nbsp;&nbsp;redirect_to items_path<br>end<br><br>In the routes, I add a delete route to items by:
<br><br>map.resources :items, :member =&gt; { :delete =&gt; :get }<br><br>I then have a view where I add a delete link like this (also using<br>haml):<br><br>= link_to &quot;delete&quot;, delete_item_path( item ), :class =&gt; &#39;delete&#39;
<br><br>All of this works when I have javascript disabled. Now I am trying to<br>add a behavior that will do the confirmation in javascript and if<br>confirmed then redirect to the destroy action. I am trying to do this<br>
as follows but it is not working.<br><br>Remote.Delete = Behavior.create( Remote.Base, {<br>&nbsp;&nbsp;onclick: function( event ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;if ( confirm( &#39;Are you sure?&#39;&nbsp;&nbsp;) ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var destroy_url = this.element.href.gsub
( &#39;/delete$&#39;, &#39;&#39; );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options = Object.extend( { url: destroy_url, method: &#39;delete&#39; },<br>this.options );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return this._makeRequest( options )<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;return false;<br>&nbsp;&nbsp;}<br>
});<br><br>Event.addBehavior( {<br>&nbsp;&nbsp;&#39;.delete&#39; : Remote.Delete<br>});<br><br>The onclick gets executed but it is not working correctly. Any help<br>would be appriciated.<br><br>Thanks,<br><br>-- Ken<br>
------=_Part_23041_21073203.1201224894604--


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