carpetfrog-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2007-Feb-01 10:54 UTC
Creating a progress indicator for my mass mailer.
Hi all, this is my first post, so I''m wearing my flame-proof jacket. I am new to Ajax, and I am trying to devise a progress indicator for my application. Its written using the Codeigniter framework, ( should I mention that here? ), and the php just loops through an array of email addresses & names, sending a personalised email for each subscriber. Its a simple newsletter application for an even simpler CMS that I''m building. I want to display a progress indicator whilst the email is being sent. Ideally showing the precentage so far, but most likely due to my limited ajax know-how, it will be a simple animated gif. I''m looking at doing it using script.aculo.us, but I was hoping someone may be able to help, in any way possible, on my steep learning curve. I found this on the scriptaculous wiki, but I''m still trying to understand it. <style type="text/css" media="screen"> .inplaceeditor-saving { background: url(/images/wait.gif) bottom right no-repeat; } </style> <p id="editme3">Click me, click me!</p> <script type="text/javascript"> new Ajax.InPlaceEditor(''editme3'', ''/demoajaxreturn.html''); </script> What does the demoajaxreturn.html actually do? Thanks --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Colin Mollenhour
2007-Feb-01 14:37 UTC
Re: Creating a progress indicator for my mass mailer.
In the InPlaceEditor, demoajaxreturn.html is just a regular html file, nothing special about it. The InPlaceEditor expects the server to return the updated contents, so in most cases if the user types something and hits ok, the class is changed to ".inplaceeditor-saving", the Ajax.Request sends the new name to the server, the server does something and returns (by simply printing/echoing) whatever value is appropriate. The server''s response triggers the onComplete for the Ajax.Request which changes the CSS class back to ".inplaceeditor" or whatever it is. However, in your case I''m not so sure you need IPE. Here is a simple example that doesn''t use IPE: <div id="indicator" style="display: none;"><img src="indicator.gif" alt="" /></div> <form id="mailer_form"> <input type="text" name="subject" /> <textarea name="body"></textarea> <input type="submit" value="Submit" /> </form> <script type="text/javascript"> Event.observe(''mailer_form'',''submit'',function(event){ Event.stop(event); //prevents the form from being submitted as a normal HTML form which would cause a page reload if( !/* is form valid? */){ return; } $(''indicator'').show(); //make your indicator visible new Ajax.Request(''yourmailerhandlingpage.php'',{ parameters: Form.serialize(this), //"this" is the form''s DOM element onComplete: function(){ $(''indicator'').hide(); } }); }); </script> In ''yourmailhandlingpage.php'', $_POST == Array(subject => '''', body => '''') Your PHP page doesn''t have to do anything special, just use the POST values given to process the mass mailing and when it is done, exit normally. You could return info like the number of emails sent or whatnot rather easily (I''d suggest using JSON encoding) and then use the onComplete function to present that data to the user. A progress bar would be more complicated, maybe someone else can help you out with that but I assume you would have to update the progress value via a file, session variable, database entry or something (that can be accessed from a separate php thread) inside the loop and then poll it periodically. Prototype has handy classes for this as well, just check out the documentation on prototypejs.org/api but since you''re new to Ajax, see if you can swallow the above example before trying the progress bar. Colin carpetfrog-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org wrote:> Hi all, this is my first post, so I''m wearing my flame-proof jacket. > > I am new to Ajax, and I am trying to devise a progress indicator for > my application. Its written using the Codeigniter framework, ( should > I mention that here? ), and the php just loops through an array of > email addresses & names, sending a personalised email for each > subscriber. Its a simple newsletter application for an even simpler > CMS that I''m building. > > I want to display a progress indicator whilst the email is being sent. > Ideally showing the precentage so far, but most likely due to my > limited ajax know-how, it will be a simple animated gif. > > I''m looking at doing it using script.aculo.us, but I was hoping > someone may be able to help, in any way possible, on my steep learning > curve. > > I found this on the scriptaculous wiki, but I''m still trying to > understand it. > > <style type="text/css" media="screen"> > .inplaceeditor-saving { background: url(/images/wait.gif) bottom > right no-repeat; } > </style> > > <p id="editme3">Click me, click me!</p> > <script type="text/javascript"> > new Ajax.InPlaceEditor(''editme3'', ''/demoajaxreturn.html''); > </script> > > What does the demoajaxreturn.html actually do? > > Thanks > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
carpetfrog-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2007-Feb-01 23:20 UTC
Re: Creating a progress indicator for my mass mailer.
Thanks very much Colin, this is a great start, I''ve just spent a couple of hours looking at the prototype documentation, and its slowly starting to make sense. Its just so different to the old way of doing things, it takes some getting used to. I appreciate the helping hand, and I think its time to get my hands dirty with a few examples, this one being the first. ;) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > Its just so different to the old way of doing > things, it takes some getting used to.We''ve all been there, and it''s fun! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Carpetfrog, There''s a great article by a chap called Sergio Periera which is actually about "advanced-ish" javaScript which you might find very useful if you''re just starting out with prototype. It was written (afaik) as an offshoot to his documentation of prototype ( which is also great and worth a read ) and explains some important things like JSON. Thing is, prototype is written in a very json way which personally made it look like a nightmare the first time I looked at it... *however* I recon if you get your head round the json way of writing javascript not only does prototype make a _lot_ more sense but IMHO prototype ( and all your .js for that matter ) becomes much slicker, tidier & easier to read as a result :-) . . . anyhoo... hope it helps! http://www.sergiopereira.com/articles/advjs.html ... and Sergio''s prototype docs, + examples: http://www.sergiopereira.com/articles/prototype.js.html . . . Cheers, Jimbo On Feb 2, 1:50 am, "Ryan Gahl" <ryan.g...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Its just so different to the old way of doing > > things, it takes some getting used to. > > We''ve all been there, and it''s fun!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---