I am working on a ruby on rails project, using multiple sortable elements to arrange some data. I have everything working but when I drag between elements I get two posts to the server. Is there a way to force only one post that sends the sorted arrays of both sorted elements? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
khatibda
2007-May-24 21:44 UTC
Re: Sortable: force a single post when dragging between elements
i had a similar issue last week actually. i had two sortable containers calling the same post method onUpdate, so both containers would issue the same post data when an element was dragged from one container to the other. here''s what worked for me: - I created a .saving property in my javascript module, and I used it like a temporary flag. Let''s say it''s called Module.saving. Initially set Module.saving = false. - The post method should include something like this: Module.save = function(){ if (Module.saving = true) return; Module.saving = true; //rest of your post method //..... //OnSuccess of your ajax request:{ Module.saving = false } } Module.save() will be called twice by Sortable, but it will only actually execute the post once. The potential downside to this approach is that Module.save won''t be ready to execute another update until the first one is fully processed. In my case, I actually preferred this and it was why i chose the approach, but it''s something to keep in mind... also, i''m pretty new to programming in general so there is probably a better approach somewhere out there...but i hope this helps.... On May 24, 6:15 am, Ricky <Anderson.Andr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am working on a ruby on rails project, using multiple sortable > elements to arrange some data. > I have everything working but when I drag between elements I get two > posts to the server. > Is there a way to force only one post that sends the sorted arrays of > both sorted elements?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
khatibda
2007-May-24 21:52 UTC
Re: Sortable: force a single post when dragging between elements
oops, quick "==" typo...so it should be... Module.save = function(){ if (Module.saving == true) return; Module.saving = true; //rest of your post method //..... //OnSuccess of your ajax request:{ Module.saving = false } } On May 24, 2:44 pm, khatibda <khati...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> i had a similar issue last week actually. i had two sortable > containers calling the same post method onUpdate, so both containers > would issue the same post data when an element was dragged from one > container to the other. > > here''s what worked for me: > > - I created a .saving property in my javascript module, and I used it > like a temporary flag. Let''s say it''s called Module.saving. Initially > set Module.saving = false. > > - The post method should include something like this: > > Module.save = function(){ > if (Module.saving = true) return; > Module.saving = true; > //rest of your post method > //..... > //OnSuccess of your ajax request:{ > Module.saving = false > } > } > > Module.save() will be called twice by Sortable, but it will only > actually execute the post once. > The potential downside to this approach is that Module.save won''t be > ready to execute another update until the first one is fully > processed. In my case, I actually preferred this and it was why i > chose the approach, but it''s something to keep in mind... > > also, i''m pretty new to programming in general so there is probably a > better approach somewhere out there...but i hope this helps.... > > On May 24, 6:15 am, Ricky <Anderson.Andr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I am working on a ruby on rails project, using multiple sortable > > elements to arrange some data. > > I have everything working but when I drag between elements I get two > > posts to the server. > > Is there a way to force only one post that sends the sorted arrays of > > both sorted elements?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Ricky
2007-May-25 13:10 UTC
Re: Sortable: force a single post when dragging between elements
Thank you for the reply. I will try it out. On May 24, 5:52 pm, khatibda <khati...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> oops, quick "==" typo...so it should be... > > Module.save = function(){ > if (Module.saving == true) return; > Module.saving = true; > //rest of your post method > //..... > //OnSuccess of your ajax request:{ > Module.saving = false > } > } > > On May 24, 2:44 pm, khatibda <khati...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > i had a similar issue last week actually. i had two sortable > > containers calling the same post method onUpdate, so both containers > > would issue the same post data when an element was dragged from one > > container to the other. > > > here''s what worked for me: > > > - I created a .saving property in my javascript module, and I used it > > like a temporary flag. Let''s say it''s called Module.saving. Initially > > set Module.saving = false. > > > - The post method should include something like this: > > > Module.save = function(){ > > if (Module.saving = true) return; > > Module.saving = true; > > //rest of your post method > > //..... > > //OnSuccess of your ajax request:{ > > Module.saving = false > > } > > } > > > Module.save() will be called twice by Sortable, but it will only > > actually execute the post once. > > The potential downside to this approach is that Module.save won''t be > > ready to execute another update until the first one is fully > > processed. In my case, I actually preferred this and it was why i > > chose the approach, but it''s something to keep in mind... > > > also, i''m pretty new to programming in general so there is probably a > > better approach somewhere out there...but i hope this helps.... > > > On May 24, 6:15 am, Ricky <Anderson.Andr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I am working on a ruby on rails project, using multiple sortable > > > elements to arrange some data. > > > I have everything working but when I drag between elements I get two > > > posts to the server. > > > Is there a way to force only one post that sends the sorted arrays of > > > both sorted elements?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---