Hi, I''m using prototype within ruby on rails. One limitation I''d like to overcome is the restriction of beeing able to update just one html elements content using from_remote_tag or link_to_remote. AFAICS this is just a restriction of the form_remote_tag/link_to_remote implementation and it''s underlying Ajax.Updater class. Right? In theorie there should be no problem, to return some markup consisting of a list of (x)html snippets where each snippet updates some element of the current page. Of course the ids of the elements to be modified would have to be declared in the list somewhere. I''m thinking of something like <response> <snippet update="id1"> This text replaces id1''s content </snippet> <snippet update="id2"> <p>this list will appear in id2-section</p> <ul><li>some text</li><li>other text</li></ul> </snippet> </response> Are there any general problems with such an approch, that I''m missing? Has anyone done that before? Morus
On Oct 17, 2005, at 12:09 AM, Morus Walter wrote:> > In theorie there should be no problem, to return some markup > consisting > of a list of (x)html snippets where each snippet updates some > element of > the current page. Of course the ids of the elements to be modified > would > have to be declared in the list somewhere. ><snip>> > Are there any general problems with such an approch, that I''m missing? > Has anyone done that before? >Yeah, people have applied that approach to Seaside''s Prototype-like support with some success, extending the code I posted about here (in "the days before AJAX was called AJAX"): http://www.cincomsmalltalk.com/userblogs/avi/blogView? showComments=true&entry=3268075684 . I can try to dig up the mailing list traffic about those extensions if you like. As well as allowing multiple elements to be updated, they also allowed individual attributes to be updated without changing the innerHTML. I''d love to see that capability added to Prototype, since I''ve personally switched to using Prototype/Script.aculo.us for the client side of my Seaside work, but if I''m going to sell that to the Seaside community in general it would be great not to be taking a step backwards there. One note is that since you''re presumably now treating the response as an XML DOM rather than as raw HTML text, to keep using innerHTML you''re going to need to output the contents of your <snippet>s as CDATA. But that shouldn''t be a huge deal. Cheers, Avi
Morus Walter wrote:> Hi, > > I''m using prototype within ruby on rails. > One limitation I''d like to overcome is the restriction of beeing able to > update just one html elements content using from_remote_tag or > link_to_remote. > > AFAICS this is just a restriction of the form_remote_tag/link_to_remote > implementation and it''s underlying Ajax.Updater class. Right? > > In theorie there should be no problem, to return some markup consisting > of a list of (x)html snippets where each snippet updates some element of > the current page. Of course the ids of the elements to be modified would > have to be declared in the list somewhere. > I''m thinking of something like > <response> > <snippet update="id1"> > This text replaces id1''s content > </snippet> > <snippet update="id2"> > <p>this list will appear in id2-section</p> > <ul><li>some text</li><li>other text</li></ul> > </snippet> > </response> > > Are there any general problems with such an approch, that I''m missing? > Has anyone done that before? >That''s exactly how we do it in Apache Cocoon, as the page update is driven by the server. The Ajax response is a set of "browser update" elements, each containing an element to be replaced in the page. We use "destElt.innerHTML = sourceElt.xml" on IE, and a specific "importNode" function on other browsers, that recursively copies the xhtml fragment. Sylvain -- Sylvain Wallez Anyware Technologies http://people.apache.org/~sylvain http://www.anyware-tech.com Apache Software Foundation Member Research & Technology Director
I''d recommend generating JavaScript on the server, returning a JavaScript snippet and have the snippet executed on the client (onComplete callback of Ajax.Request). That gives you the power to do anything you want, including but not limited to multiple updates. Note that escaping JavaScript strings is quite easy. Rails has helpers[1] for this, so you might want to use them. Thomas [1] http://api.rubyonrails.org/classes/ActionView/Helpers/ JavaScriptHelper.html#M000399 Am 17.10.2005 um 09:09 schrieb Morus Walter:> Hi, > > I''m using prototype within ruby on rails. > One limitation I''d like to overcome is the restriction of beeing > able to > update just one html elements content using from_remote_tag or > link_to_remote. > > AFAICS this is just a restriction of the form_remote_tag/ > link_to_remote > implementation and it''s underlying Ajax.Updater class. Right? > > In theorie there should be no problem, to return some markup > consisting > of a list of (x)html snippets where each snippet updates some > element of > the current page. Of course the ids of the elements to be modified > would > have to be declared in the list somewhere. > I''m thinking of something like > <response> > <snippet update="id1"> > This text replaces id1''s content > </snippet> > <snippet update="id2"> > <p>this list will appear in id2-section</p> > <ul><li>some text</li><li>other text</li></ul> > </snippet> > </response> > > Are there any general problems with such an approch, that I''m missing? > Has anyone done that before? > > Morus > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
Morus Walter <morus.walter.ml-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> writes:> Hi, > > I''m using prototype within ruby on rails. > One limitation I''d like to overcome is the restriction of beeing able to > update just one html elements content using from_remote_tag or > link_to_remote. > > AFAICS this is just a restriction of the form_remote_tag/link_to_remote > implementation and it''s underlying Ajax.Updater class. Right? > > In theorie there should be no problem, to return some markup consisting > of a list of (x)html snippets where each snippet updates some element of > the current page. Of course the ids of the elements to be modified would > have to be declared in the list somewhere. > I''m thinking of something like > <response> > <snippet update="id1"> > This text replaces id1''s content > </snippet> > <snippet update="id2"> > <p>this list will appear in id2-section</p> > <ul><li>some text</li><li>other text</li></ul> > </snippet> > </response> > > Are there any general problems with such an approch, that I''m missing? > Has anyone done that before? > > MorusI use JSON. In the controller: divs = { :id1 => render_to_string(:partial => ''hit_controls''), :id2 => render_to_string(:partial => ''page_controls'') } render :text => divs.to_json In the view: link_to_remote(''<<'', :tooltip => ''Previous'', :complete => ''update_divs(request)'', :url => {:action => ''turn_page'', :page => 1}) And update_divs is just: function update_divs(request) { var divs = eval(''('' + request.responseText + '')''); for (var div_id in divs) { if ($(div_id)) { $(div_id).innerHTML = divs[div_id]; } } } You might want to use a JSON parser instead of eval(). Steve
On Mon, 2005-10-17 at 12:20 -0700, Steven Lumos wrote:> > I use JSON. > > In the controller: > > divs = { > :id1 => render_to_string(:partial => ''hit_controls''), > :id2 => render_to_string(:partial => ''page_controls'') > } > render :text => divs.to_json > > In the view: > > link_to_remote(''<<'', :tooltip => ''Previous'', > :complete => ''update_divs(request)'', > :url => {:action => ''turn_page'', :page => 1}) > > And update_divs is just: > > function update_divs(request) { > var divs = eval(''('' + request.responseText + '')''); > for (var div_id in divs) { > if ($(div_id)) { > $(div_id).innerHTML = divs[div_id]; > } > } > } >great. I tried Thomas Fuchs suggestion using JS and it works well, but your suggestion seems even better. Thanks for your suggestion, thanks also to Thomas, Avi and Syvain. Morus
Has anybody created publicly available controls inherited from Prototype and Scriptaculous libraries? For example, a rich dropdown control would be helpful, and it will reuse a lot of the same code as the autocompleter dropdown. No reason to reinvent. There''s a lot of controls on the Wish List, and I''m sure there''s developers out there creating their own controls which may or may not eventually be merged into the source base. Maybe there should be a page on the wiki for 3rd party implementations and enhancements? BTW, http://ajaxpatterns.org is a great resource for what these controls should/could do. -- Dylan Greene http://www.DylanGreene.com
Please go ahead and create a wiki page for that, sound like a great idea! I''ve some controls lying around here I want to eventually open-source after I get to clean them up; and they''re more specialized so they shouldn''t be in the basic script.aculo.us codebase. Controls that live up to some yet-to-be-defined standards could get own .js files in an "add-ons" folder that could be part of the scriptaculous distribution. Cheers, Thomas Am 22.11.2005 um 21:20 schrieb Dylan Greene:> Has anybody created publicly available controls inherited from > Prototype and > Scriptaculous libraries? > > For example, a rich dropdown control would be helpful, and it will > reuse a > lot of the same code as the autocompleter dropdown. No reason to > reinvent. > There''s a lot of controls on the Wish List, and I''m sure there''s > developers > out there creating their own controls which may or may not > eventually be > merged into the source base. > > Maybe there should be a page on the wiki for 3rd party > implementations and > enhancements? > > BTW, http://ajaxpatterns.org is a great resource for what these > controls > should/could do. > > -- > Dylan Greene > http://www.DylanGreene.com > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs