i would never do that, i would just send one request. If you really have to do it, try the mootools-more Group:
http://mootools.net/docs/more/Utilities/Group -- Fábio Miranda Costa Solucione Sistemas Front-End Engineer http://meiocodigo.com On Sun, Aug 2, 2009 at 6:30 AM, Rolf <[email protected]> wrote: > > Hi Fabio, > > That's a way of doing it yes, which I use as well. However, my goals > was to use the same deleteItem method I already have. As this method > does more than just a direct ajaxRequest. > > On the other hand I could send a deleteAll ajaxRequest in the > deleteContainer method, instead of 10x the deleteItem method (= 10x > the same checks, 10x ajaxRequest). > > But OK, let's say I would like to use already created methods.. how > would you implement callback stuff or what's you way of doing things > when you have to "wait" for the return of a method you call, before > you can proceed with the rest a bigger function? > > E.g. > foreach(items as item) { > if(!this.deleteItem(item)) error = true; > } > if(!error) deleteContainer > else showMessage; > > like you can in php etc. > > Cheerio > > > On Aug 2, 3:54 am, Fábio M. Costa <[email protected]> wrote: > > What i would do: > > on deleteItem: > > make the ajaxRequest first and onSuccess remove visually the div. > > > > on deleteContainer: > > check for the items i got inside and send one request, onSuccess it will > > tell me if all the items were deleted or not (this one will depend on > what > > you want, it could tell you which ones it was able to remove) and them > > remove visually the items. > > > > The thing is, make sure it worked serverside and change things on the dom > > onSuccess of the request, or you cold have inconsistencies. > > > > -- > > Fábio Miranda Costa > > Solucione Sistemas > > Front-End Engineerhttp://meiocodigo.com > > > > On Sat, Aug 1, 2009 at 10:26 PM, Rolf -nl <[email protected]> > wrote: > > > > > Hi all, > > > > > Another one of those "I wonder how others..." questions I have. > > > > > For this case I have one or more <items> that can be placed into a > > > <container>. > > > > > I have a method called "deleteItem" and I have a method called > > > "deleteContainer" > > > > > "deleteItem" checks some stuff, prompts maybe a confirm dialog, and > > > does ajax request to actually delete the item from a database or kills > > > a file. This all results in either a succesfull delete or an error. > > > > > "deleteContainer" should destroy the whole container (e.g. it's a div > > > holding various item-divs) and my idea is to: > > > 1. Check for items inside. > > > 2. If there are any, loop through the number of items and call the > > > "deleteItem" for each item. > > > 3. Kill the container (e.g. in a database and/or on screen destroying > > > the element). > > > > > Ok, so I would like to cancel the "deleteContainer" action if there's > > > a problem with "deleteItem" for one of the items inside the container. > > > You know; perhaps the ajax request generated an error, or the user > > > pressed cancel on the confirm dialog. The process should stop and the > > > container should not be deleted. > > > > > Because JS is asynchronous, the code below a foreach loop (the foreach > > > to delete all items in container) that will destroy the container is > > > executed instantly and doesn't wait for the dialog or an ajax error > > > inside the deleteItems method. > > > > > Does this make sense? > > > > > I'm now handling this server side: detroying container runs php and > > > first deletes any elements from the database and if there's no error, > > > it will destroy the container. This will either return a complete > > > success or an error with details so that in the JS I can see what > > > happened and what I should do visually on screen. > > > > > But are there any tips, examples, best practices, ideas on how to > > > handle this within a JS class? > > > > > Cheers, > > > Rolf >
