Robin Haswell
2006-Mar-07 15:47 UTC
[PATCH] Allow Ajax.InPlaceCollectionEditor to load collection externally
Attached is a patch to allow Ajax.InPlaceCollectionEditor to load the collection using AJAX. It adds a new option, loadOptionsURL, which is the URL used to load the values over the interweb. It expects the server to return <option></option> values. If one of them has a selected="selected" attribute, it will probably be pre-selected. Not tested that though. Also only tested in FF, however the only actual new code is a line of Element.update(), so I don''t foresee any X-Browser problems. As usual, development site, can''t show the example to the world. Yet another patch that will never know what CVS is. Enjoy people. -Rob _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Andrew Kaspick
2006-Mar-07 15:53 UTC
Re: [PATCH] Allow Ajax.InPlaceCollectionEditor to load collection externally
Patches can be submitted at http://dev.rubyonrails.org/ for scriptaculous if you want a better shot at getting it into the main trunk. Just mentioning for those who may not know. On 3/7/06, Robin Haswell <rob-gyMb1R/nBgNh8AIihN9Rc9BPR1lH4CV8@public.gmane.org> wrote:> Attached is a patch to allow Ajax.InPlaceCollectionEditor to load the > collection using AJAX. > > It adds a new option, loadOptionsURL, which is the URL used to load the > values over the interweb. It expects the server to return > <option></option> values. If one of them has a selected="selected" > attribute, it will probably be pre-selected. Not tested that though. > > Also only tested in FF, however the only actual new code is a line of > Element.update(), so I don''t foresee any X-Browser problems. > > As usual, development site, can''t show the example to the world. > > Yet another patch that will never know what CVS is. Enjoy people. > > -Rob > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > >
info-F3mW5S/pqWZeoWH0uzbU5w@public.gmane.org
2006-Mar-07 15:55 UTC
Re: [PATCH] Allow Ajax.InPlaceCollectionEditor to load collection externally
Hi,> Attached is a patch to allow Ajax.InPlaceCollectionEditor to load the > collection using AJAX. > > It adds a new option, loadOptionsURL, which is the URL used to load the > values over the interweb. It expects the server to return > <option></option> values. If one of them has a selected="selected" > attribute, it will probably be pre-selected. Not tested that though. > > Also only tested in FF, however the only actual new code is a line of > Element.update(), so I don''t foresee any X-Browser problems. > > As usual, development site, can''t show the example to the world. > > Yet another patch that will never know what CVS is. Enjoy people.can you can send an example on like using this function? On the wiki there isn''t code about InPlaceCollectionEditor Antonello> > -Rob > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
Robin Haswell
2006-Mar-07 16:04 UTC
Re: [PATCH] Allow Ajax.InPlaceCollectionEditor to load collection externally
Thanks. I might do that. Andrew Kaspick wrote:> Patches can be submitted at http://dev.rubyonrails.org/ for > scriptaculous if you want a better shot at getting it into the main > trunk. > > Just mentioning for those who may not know. > > On 3/7/06, Robin Haswell <rob-gyMb1R/nBgNh8AIihN9Rc9BPR1lH4CV8@public.gmane.org> wrote: > >>Attached is a patch to allow Ajax.InPlaceCollectionEditor to load the >>collection using AJAX. >> >>It adds a new option, loadOptionsURL, which is the URL used to load the >>values over the interweb. It expects the server to return >><option></option> values. If one of them has a selected="selected" >>attribute, it will probably be pre-selected. Not tested that though. >> >>Also only tested in FF, however the only actual new code is a line of >>Element.update(), so I don''t foresee any X-Browser problems. >> >>As usual, development site, can''t show the example to the world. >> >>Yet another patch that will never know what CVS is. Enjoy people. >> >>-Rob >> >> >>_______________________________________________ >>Rails-spinoffs mailing list >>Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >> >> >> >> > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Robin Haswell
2006-Mar-07 16:10 UTC
Re: [PATCH] Allow Ajax.InPlaceCollectionEditor to load collection externally
Sorry, I get paid to write code, not to document it. I can paste what I''m using though: new Ajax.InPlaceCollectionEditor(el, "___relations.saveRelation.ajax", { okText:"Save", cancelText:"Cancel", externalControl:control, externalControlOnly:true, loadOptionsURL:"___relation.getOptions"+relationid+".ajax" }); My version works almost exactly the same as InPlaceEditor. I couldn''t be arsed to work out how to use it as intended - I think you set an array as one of the options. It was pretty obvious to me that it wasn''t going to pull in the options externally so I wrote this patch to correct that. It seems like loadTextURL option is used to load the default value from the collection. Doesn''t make a lot of sense to me. PS. externalControlOnly is an option I submitted a patch for a long time ago. It allows you to active and InPlaceEditor (and transparently, this collections thing too), by only clicking the externalControl (ie. not by clicking the element itself, which isn''t very intuitive). -Rob info-F3mW5S/pqWZeoWH0uzbU5w@public.gmane.org wrote:> Hi, > >>Attached is a patch to allow Ajax.InPlaceCollectionEditor to load the >>collection using AJAX. >> >>It adds a new option, loadOptionsURL, which is the URL used to load the >>values over the interweb. It expects the server to return >><option></option> values. If one of them has a selected="selected" >>attribute, it will probably be pre-selected. Not tested that though. >> >>Also only tested in FF, however the only actual new code is a line of >>Element.update(), so I don''t foresee any X-Browser problems. >> >>As usual, development site, can''t show the example to the world. >> >>Yet another patch that will never know what CVS is. Enjoy people. > > > can you can send an example on like using this function? On the wiki > there isn''t code about InPlaceCollectionEditor > > Antonello > >>-Rob >>_______________________________________________ >>Rails-spinoffs mailing list >>Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >> > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Robin Haswell
2006-Mar-07 16:23 UTC
Re: [PATCH] Allow Ajax.InPlaceCollectionEditor to load collection externally
One more small correction. Allow custom callbacks. Did someone just not think this collection thing through or something? --- js/controls.js.orig 2006-03-07 15:35:45.000000000 +0000 +++ js/controls.js 2006-03-07 16:19:50.000000000 +0000 @@ -784,10 +784,27 @@ this.editField = this.cached_selectTag; if(this.options.loadTextURL) this.loadExternalText(); this.form.appendChild(this.editField); - this.options.callback = function(form, value) { + if (!this.options.callback) this.options.callback = function(form, value) { return "value=" + encodeURIComponent(value); } -Rob Robin Haswell wrote:> Attached is a patch to allow Ajax.InPlaceCollectionEditor to load the > collection using AJAX. > > It adds a new option, loadOptionsURL, which is the URL used to load the > values over the interweb. It expects the server to return > <option></option> values. If one of them has a selected="selected" > attribute, it will probably be pre-selected. Not tested that though. > > Also only tested in FF, however the only actual new code is a line of > Element.update(), so I don''t foresee any X-Browser problems. > > As usual, development site, can''t show the example to the world. > > Yet another patch that will never know what CVS is. Enjoy people. > > -Rob > > > ------------------------------------------------------------------------ > > --- js/controls.js.orig 2006-03-07 15:35:45.000000000 +0000 > +++ js/controls.js 2006-03-07 15:35:49.000000000 +0000 > @@ -784,10 +784,27 @@ > > this.editField = this.cached_selectTag; > if(this.options.loadTextURL) this.loadExternalText(); > + if(this.options.loadOptionsURL) this.loadExternalOptions(); > this.form.appendChild(this.editField); > this.options.callback = function(form, value) { > return "value=" + encodeURIComponent(value); > } > + }, > + loadExternalOptions: function() { > + Element.addClassName(this.form, this.options.loadingClassName); > + this.editField.disabled = true; > + new Ajax.Request( > + this.options.loadOptionsURL, > + Object.extend({ > + asynchronous: true, > + onComplete: this.onLoadedExternalOptions.bind(this) > + }, this.options.ajaxOptions) > + ); > + }, > + onLoadedExternalOptions: function(transport) { > + Element.removeClassName(this.form, this.options.loadingClassName); > + Element.update(this.editField, transport.responseText); > + this.editField.disabled = false; > } > }); > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Robin Haswell wrote:> One more small correction. Allow custom callbacks.Thanks Robin, you made my hours of mucking around with InPlaceCollectionEditor worthwhile. Somebody get this patch into the trunk, please! I still have one problem, though. externalControl doesn''t seem to be working for me. Can you paste some code on how you are using it? TIA, Vamsee. -- Posted via http://www.ruby-forum.com/.