I have a shopping cart on a page that gathers files for download. As the user browses around the various nested folders, she can add things to the cart, remove single items from the cart, and empty the entire cart. At any time, she can also download the entire cart contents as a Zip archive. I am managing that download using a PHP script that forces the file-type, and thus all I do is link to a real file (download.php?cart=N) from my page. The last step of the download script is to empty out the cart in the database. But the list on screen remains the same until the visitor navigates to another folder, at which point it refreshes and declares itself empty. Which is kind of jarring to the user. I tried applying a periodic updater to the cart div, and that did work, but it also killed the other events I had registered inside that div (the individual files'' remove me buttons). It also issued a request every five seconds, which seems extreme. I am experimenting with just setting a delay after the click and checking the cart again, but that seems fragile, since I don''t know how long it might take for the server to respond with the files. If I check before it''s done, the cart will be the same (since the download hasn''t started yet and the script returned true) and if I wait too long, it will be jarring for the user. Any suggestions? I can''t show any code, it''s all hidden inside an HTTPS site. I could do some extractions, I guess, but I am hoping someone may have done this before and have a bright idea or two. Thanks, Walter --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On your download link, apply an onclick handler as well as a href- the onclick can clear your on-screen shopping cart. When is the on-screen list being loaded? at page load, ie: the rest of the site isn''t ajax based? Or does the cart remain onscreen at all times with no refresh. <a href="downloadlink.php" onclick="clearCart();return true;"> (inline handlers are bad) This will cause the cart to clear, then the user will navigate to downloadlink.php. If you didn''t want them to download, you could return false. If you attach the event with Event.Observe you have to use Event.Stop(e) though Hope this helps Gareth On 3/20/07, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> > > I have a shopping cart on a page that gathers files for download. As > the user browses around the various nested folders, she can add things > to the cart, remove single items from the cart, and empty the entire > cart. At any time, she can also download the entire cart contents as a > Zip archive. > > I am managing that download using a PHP script that forces the > file-type, and thus all I do is link to a real file > (download.php?cart=N) from my page. The last step of the download > script is to empty out the cart in the database. But the list on screen > remains the same until the visitor navigates to another folder, at > which point it refreshes and declares itself empty. Which is kind of > jarring to the user. > > I tried applying a periodic updater to the cart div, and that did work, > but it also killed the other events I had registered inside that div > (the individual files'' remove me buttons). It also issued a request > every five seconds, which seems extreme. > > I am experimenting with just setting a delay after the click and > checking the cart again, but that seems fragile, since I don''t know how > long it might take for the server to respond with the files. If I check > before it''s done, the cart will be the same (since the download hasn''t > started yet and the script returned true) and if I wait too long, it > will be jarring for the user. > > Any suggestions? I can''t show any code, it''s all hidden inside an HTTPS > site. I could do some extractions, I guess, but I am hoping someone may > have done this before and have a bright idea or two. > > Thanks, > > Walter > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The cart loads at page load and then is continuously updated without screen refresh. It is backed by the database, and that database is read by download.php to get its list of files to download. If download is successful in contacting the secure WEBDAV repository with all the big files in it (the database is just a proxy), downloading the actual files and mashing them into a zip -- then it clears the cart. But since I am just linking to (what appears to the browser as) a plain zip file for download, and that zip file doesn''t exist until the download script has finished its business, I don''t see how I can tell the cart to update on screen after the download has finished. It''s tricky. Walter On Mar 19, 2007, at 5:14 PM, Gareth Evans wrote:> On your download link, apply an onclick handler as well as a href- the > onclick can clear your on-screen shopping cart. > When is the on-screen list being loaded? at page load, ie: the rest of > the site isn''t ajax based? Or does the cart remain onscreen at all > times with no refresh. > > <a href="downloadlink.php" onclick="clearCart();return true;"> > (inline handlers are bad) > This will cause the cart to clear, then the user will navigate to > downloadlink.php. > If you didn''t want them to download, you could return false. > If you attach the event with Event.Observe you have to use > Event.Stop(e) though > > Hope this helps > > Gareth > > On 3/20/07, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: >> I have a shopping cart on a page that gathers files for download. As >> the user browses around the various nested folders, she can add things >> to the cart, remove single items from the cart, and empty the entire >> cart. At any time, she can also download the entire cart contents as a >> Zip archive. >> >> I am managing that download using a PHP script that forces the >> file-type, and thus all I do is link to a real file >> (download.php?cart=N) from my page. The last step of the download >> script is to empty out the cart in the database. But the list on >> screen >> remains the same until the visitor navigates to another folder, at >> which point it refreshes and declares itself empty. Which is kind of >> jarring to the user. >> >> I tried applying a periodic updater to the cart div, and that did >> work, >> but it also killed the other events I had registered inside that div >> (the individual files'' remove me buttons). It also issued a request >> every five seconds, which seems extreme. >> >> I am experimenting with just setting a delay after the click and >> checking the cart again, but that seems fragile, since I don''t know >> how >> long it might take for the server to respond with the files. If I >> check >> before it''s done, the cart will be the same (since the download hasn''t >> started yet and the script returned true) and if I wait too long, it >> will be jarring for the user. >> >> Any suggestions? I can''t show any code, it''s all hidden inside an >> HTTPS >> site. I could do some extractions, I guess, but I am hoping someone >> may >> have done this before and have a bright idea or two. >> >> Thanks, >> >> Walter >> >> >> >> > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The only thing I can think of, if you want to trap the end of the download event for the zip is to somehow write a flag in your download.php when the file has finished sending to the client- I am not sure if this is possible in php, im pretty sure it isn''t in ASP. Your javascript can check the flag to see if the download has completed, and if it has, clear the flag... Since the file is streaming to the client, unless you can hook into an event (server side or otherwise) I dont think you have much choice. You must clear the database immediately after building the zip and sending it to the client, vs after the download has completed.. so why not just clear the display at the same time? Gareth On 3/20/07, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> > > The cart loads at page load and then is continuously updated without > screen refresh. It is backed by the database, and that database is read > by download.php to get its list of files to download. If download is > successful in contacting the secure WEBDAV repository with all the big > files in it (the database is just a proxy), downloading the actual > files and mashing them into a zip -- then it clears the cart. > > But since I am just linking to (what appears to the browser as) a plain > zip file for download, and that zip file doesn''t exist until the > download script has finished its business, I don''t see how I can tell > the cart to update on screen after the download has finished. It''s > tricky. > > Walter > > On Mar 19, 2007, at 5:14 PM, Gareth Evans wrote: > > > On your download link, apply an onclick handler as well as a href- the > > onclick can clear your on-screen shopping cart. > > When is the on-screen list being loaded? at page load, ie: the rest of > > the site isn''t ajax based? Or does the cart remain onscreen at all > > times with no refresh. > > > > <a href="downloadlink.php" onclick="clearCart();return true;"> > > (inline handlers are bad) > > This will cause the cart to clear, then the user will navigate to > > downloadlink.php. > > If you didn''t want them to download, you could return false. > > If you attach the event with Event.Observe you have to use > > Event.Stop(e) though > > > > Hope this helps > > > > Gareth > > > > On 3/20/07, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: > >> I have a shopping cart on a page that gathers files for download. As > >> the user browses around the various nested folders, she can add things > >> to the cart, remove single items from the cart, and empty the entire > >> cart. At any time, she can also download the entire cart contents as a > >> Zip archive. > >> > >> I am managing that download using a PHP script that forces the > >> file-type, and thus all I do is link to a real file > >> (download.php?cart=N) from my page. The last step of the download > >> script is to empty out the cart in the database. But the list on > >> screen > >> remains the same until the visitor navigates to another folder, at > >> which point it refreshes and declares itself empty. Which is kind of > >> jarring to the user. > >> > >> I tried applying a periodic updater to the cart div, and that did > >> work, > >> but it also killed the other events I had registered inside that div > >> (the individual files'' remove me buttons). It also issued a request > >> every five seconds, which seems extreme. > >> > >> I am experimenting with just setting a delay after the click and > >> checking the cart again, but that seems fragile, since I don''t know > >> how > >> long it might take for the server to respond with the files. If I > >> check > >> before it''s done, the cart will be the same (since the download hasn''t > >> started yet and the script returned true) and if I wait too long, it > >> will be jarring for the user. > >> > >> Any suggestions? I can''t show any code, it''s all hidden inside an > >> HTTPS > >> site. I could do some extractions, I guess, but I am hoping someone > >> may > >> have done this before and have a bright idea or two. > >> > >> Thanks, > >> > >> Walter > >> > >> > >> > >> > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Did you want me to paste, or was there something there that you wanted to show me? Walter On Mar 19, 2007, at 9:59 PM, Colin Mollenhour wrote:> http://pastie.caboo.se--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks. I may just try to get the page to reload somehow. That would also show the cleared cart on screen. Walter On Mar 19, 2007, at 10:24 PM, Colin Mollenhour wrote:> If you need to show lots of code that is a good way to do it but I > think you''ll just have to experiment a bunch. I don''t know if this > will work but you could try opening the URL for your download in a > popup window and attaching an event to onunload like so (completely > untested): > > var win = window.open(''download.php?id=''+this.element.id,''_blank''); > win.onunload=function(){this.clearCart();}.bind(this); > > I don''t know when onload or onunload would be called with a file > download or if they would at all, but that has worked for me to > trigger a print action before. Let us know if this works or you find > another solution. > > Colin > > Walter Lee Davis wrote:Did you want me to paste, or was there > something there that you wanted >> to show me? >> >> Walter >> >> On Mar 19, 2007, at 9:59 PM, Colin Mollenhour wrote: >> >> >>> http://pastie.caboo.se >>> >> >> >> >> > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Same problem really- how do you know when to refresh the page? Gareth --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Good point. I may just leave the cart-emptying as an exercise for the user! At least then it remains in user control and doesn''t break the experience. Logging out also clears the cart. Walter On Mar 19, 2007, at 9:33 PM, Gareth Evans wrote:> Same problem really- how do you know when to refresh the page? > > Gareth > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
http://pastie.caboo.se Walter Lee Davis wrote:> I have a shopping cart on a page that gathers files for download. As > the user browses around the various nested folders, she can add things > to the cart, remove single items from the cart, and empty the entire > cart. At any time, she can also download the entire cart contents as a > Zip archive. > > I am managing that download using a PHP script that forces the > file-type, and thus all I do is link to a real file > (download.php?cart=N) from my page. The last step of the download > script is to empty out the cart in the database. But the list on screen > remains the same until the visitor navigates to another folder, at > which point it refreshes and declares itself empty. Which is kind of > jarring to the user. > > I tried applying a periodic updater to the cart div, and that did work, > but it also killed the other events I had registered inside that div > (the individual files'' remove me buttons). It also issued a request > every five seconds, which seems extreme. > > I am experimenting with just setting a delay after the click and > checking the cart again, but that seems fragile, since I don''t know how > long it might take for the server to respond with the files. If I check > before it''s done, the cart will be the same (since the download hasn''t > started yet and the script returned true) and if I wait too long, it > will be jarring for the user. > > Any suggestions? I can''t show any code, it''s all hidden inside an HTTPS > site. I could do some extractions, I guess, but I am hoping someone may > have done this before and have a bright idea or two. > > Thanks, > > Walter > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#ffffff" text="#000000"> Why store the cart on the server? why not locally? Maybe some sort of iframe hack would let you download the file and attach an event on completion but I''d think that clearing the cart when they click the download link would be good enough. Only disadvantage would be if they clicked cancel they''d have to refill the cart to try again, but you can only account for so much carelessness on behalf of the user :) See <a class="moz-txt-link-freetext" href="http://ecosmear.com/relay/">http://ecosmear.com/relay/</a><br> <br> Colin<br> <br> Walter Lee Davis wrote: <blockquote cite="mid:8adc2b161d9e9ec3a05f750a2590bef7-HQgmohHLjDZWk0Htik3J/w@public.gmane.org" type="cite"> <pre wrap="">The cart loads at page load and then is continuously updated without screen refresh. It is backed by the database, and that database is read by download.php to get its list of files to download. If download is successful in contacting the secure WEBDAV repository with all the big files in it (the database is just a proxy), downloading the actual files and mashing them into a zip -- then it clears the cart. But since I am just linking to (what appears to the browser as) a plain zip file for download, and that zip file doesn''t exist until the download script has finished its business, I don''t see how I can tell the cart to update on screen after the download has finished. It''s tricky. Walter On Mar 19, 2007, at 5:14 PM, Gareth Evans wrote: </pre> <blockquote type="cite"> <pre wrap="">On your download link, apply an onclick handler as well as a href- the onclick can clear your on-screen shopping cart. When is the on-screen list being loaded? at page load, ie: the rest of the site isn''t ajax based? Or does the cart remain onscreen at all times with no refresh. <a href="downloadlink.php" onclick="clearCart();return true;"> (inline handlers are bad) This will cause the cart to clear, then the user will navigate to downloadlink.php. If you didn''t want them to download, you could return false. If you attach the event with Event.Observe you have to use Event.Stop(e) though Hope this helps Gareth On 3/20/07, Walter Lee Davis <a class="moz-txt-link-rfc2396E" href="mailto:waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org"><waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org></a> wrote: </pre> <blockquote type="cite"> <pre wrap="">I have a shopping cart on a page that gathers files for download. As the user browses around the various nested folders, she can add things to the cart, remove single items from the cart, and empty the entire cart. At any time, she can also download the entire cart contents as a Zip archive. I am managing that download using a PHP script that forces the file-type, and thus all I do is link to a real file (download.php?cart=N) from my page. The last step of the download script is to empty out the cart in the database. But the list on screen remains the same until the visitor navigates to another folder, at which point it refreshes and declares itself empty. Which is kind of jarring to the user. I tried applying a periodic updater to the cart div, and that did work, but it also killed the other events I had registered inside that div (the individual files'' remove me buttons). It also issued a request every five seconds, which seems extreme. I am experimenting with just setting a delay after the click and checking the cart again, but that seems fragile, since I don''t know how long it might take for the server to respond with the files. If I check before it''s done, the cart will be the same (since the download hasn''t started yet and the script returned true) and if I wait too long, it will be jarring for the user. Any suggestions? I can''t show any code, it''s all hidden inside an HTTPS site. I could do some extractions, I guess, but I am hoping someone may have done this before and have a bright idea or two. Thanks, Walter </pre> </blockquote> <pre wrap=""> > </pre> </blockquote> <pre wrap=""><!----> </pre> </blockquote> <br> --~--~---------~--~----~------------~-------~--~----~<br> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. <br> To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en <br> -~----------~----~----~----~------~----~------~--~---<br> </body> </html> <br>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#ffffff" text="#000000"> If you need to show lots of code that is a good way to do it but I think you''ll just have to experiment a bunch. I don''t know if this will work but you could try opening the URL for your download in a popup window and attaching an event to onunload like so (completely untested):<br> <br> var win = window.open(''download.php?id=''+this.element.id,''_blank'');<br> win.onunload=function(){this.clearCart();}.bind(this);<br> <br> I don''t know when onload or onunload would be called with a file download or if they would at all, but that has worked for me to trigger a print action before. Let us know if this works or you find another solution.<br> <br> Colin<br> <br> Walter Lee Davis wrote: <blockquote cite="mid:a812cfa62e7d79c069e3e601566805e6-HQgmohHLjDZWk0Htik3J/w@public.gmane.org" type="cite"> <pre wrap="">Did you want me to paste, or was there something there that you wanted to show me? Walter On Mar 19, 2007, at 9:59 PM, Colin Mollenhour wrote: </pre> <blockquote type="cite"> <pre wrap=""><a class="moz-txt-link-freetext" href="http://pastie.caboo.se">http://pastie.caboo.se</a> </pre> </blockquote> <pre wrap=""><!----> </pre> </blockquote> <br> --~--~---------~--~----~------------~-------~--~----~<br> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. <br> To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en <br> -~----------~----~----~----~------~----~------~--~---<br> </body> </html> <br>