Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #586 (closed enhancement: fixed)

Opened 13 years ago

Last modified 12 years ago

New AJAX Widgets: RemoteForm and LinkRemoteFunction

Reported by: anonymous Owned by: anonymous
Priority: normal Milestone: 0.9
Component: TG Widgets Version:
Severity: normal Keywords:
Cc:

Description

On this patch there are 2 new widgets: RemoteForm is a TableForm? that supports async submiting and loading the resulting HTML into any DOM object you specify LinkRemoteFunction? is a link that POSTs data and also loads the returned HTML into any object

On both widgets you can specify an action url at creation or display time. LinkRemoteFunction? also lets you specify the data to be posted at display() time.

Both widgets support some javascript callbacks and options on display time:

RemoteForm example:

On the controller (just like a tableform):

item_searchform = widgets.RemoteForm(

name="ItemSearch?", fields=SearchFormFields?(), submit_text="Search")

On the template:

<span py:replace="item_searchform.display(action='/buscarArticulo',

target_dom='items', before='getElement(\'loading\').innerHTML=\'Searching...\';', on_complete='getElement(\'loading\').innerHTML=\'Done!\';', confirm='Are you sure you want to submit this request?'

)"></span>

<div name="loading"></div> <div name="items"></div>

LinkRemoteFunctionExample?:

On the controller:

# action and data are optional and overrideable

search_modem = widgets.LinkRemoteFunction?(

action=turbogears.url('/buscarArticulo'), data=dict(searchString='modem')

)

On the template:

<!-- Standard use, action url and data specified on controller, both are overrideable --> <span py:replace="search_modem.insert('Find *modem*', update='items')"></span><br/>

<!-- You can override the default data to be posted and action url with the parameters data and action --> <span py:replace="search_modem.insert('Find *hard disk*', action=std.url('/buscarArticulo'), update='items', data=dict(searchString='hard disk'))"></span><br/>

<div name="items"></div>

Attachments

ajax.widgets.diff Download (7.4 KB) - added by anonymous 13 years ago.
updated some minor stuff
widget_tests.py Download (1.3 KB) - added by anonymous 13 years ago.
ajax.widgets.patch Download (10.1 KB) - added by anonymous 13 years ago.
Alberto Valverde rearranged the code and added WidgetDescriptors? (for toolbox tests). I fixed some stuff
ajax.widgets.2.patch Download (9.9 KB) - added by alberto 13 years ago.
patch by Claudio Martinez
mochi.patch Download (1.7 KB) - added by anonymous 13 years ago.
mochi.2.patch Download (1.6 KB) - added by alberto 13 years ago.
i'm such an idiot! i've replaced doSimpleXMLHttpRequest, this patch is the good one

Change History

Changed 13 years ago by anonymous

updated some minor stuff

Changed 13 years ago by anonymous

comment:1 Changed 13 years ago by anonymous

There's an error in one of the template examples, Were it says target_dom= it's update= I mistyped it since that variable is used internally by the widgets.

Changed 13 years ago by anonymous

Alberto Valverde rearranged the code and added WidgetDescriptors? (for toolbox tests). I fixed some stuff

Changed 13 years ago by alberto

patch by Claudio Martinez

comment:2 Changed 13 years ago by anonymous

  • Summary changed from New AJAX Widgets: RemoteForm and LinkRemoteFunction to [PATCH] New AJAX Widgets: RemoteForm and LinkRemoteFunction

comment:3 Changed 13 years ago by kevin

Nice widgets with tests and all! Thanks for the work!

The one thing that I think could be better is the functionality of ajax.js should really be submitted as a patch in some form to MochiKit?. Bob Ippolito has expressed that he'd be fine adding Ajax POST support to MochiKit?, but no one has stepped up with an API they'd like to use. Since there's an actual use case being met here, perhaps an API could be proposed.

comment:4 Changed 13 years ago by alberto

  • Status changed from new to assigned
  • Milestone set to 0.9
  • Component changed from TurboGears to Widgets
  • Summary changed from [PATCH] New AJAX Widgets: RemoteForm and LinkRemoteFunction to New AJAX Widgets: RemoteForm and LinkRemoteFunction

committed at r792. I'm leaving open until some issues regarding the update parameter not being able to be set at the constructror and the Mochi stuff gets sorted Thanks!

comment:5 Changed 13 years ago by alberto

Hi,

I'm attaching a patch for mochi to handle POST requests. I'm a total newbie on javascript so this solution will probably suck. I know that this isn't the place to post this but I would like someone more knowledgeable to look at it and improve before embarrasing myself at the mochi Trac ;)

Basically I've copied loadJSONDoc and doSimpleXMLHttpRequest into loadJSONDocPOST and doSimpleXMLHttpPOSTRequest with some tweaks inspired from ajax.js to do it the POST way.

I've minimally tested it at the mochi interactive interpreter and seems to be working as expected.

It would be nice to adapt ajax.js to use mochikit as I find it inconsistent with the rest of the TG-AJAX stuff, that is, loading JSON and manipulating at the browser side via the DOM API, with innerHtml. And mochi's error handling seems better.

comments?

Changed 13 years ago by anonymous

Changed 13 years ago by alberto

i'm such an idiot! i've replaced doSimpleXMLHttpRequest, this patch is the good one

comment:6 Changed 13 years ago by kevin

  • Status changed from assigned to closed
  • Resolution set to fixed

These have been committed already. I'm closing this ticket.

Note: See TracTickets for help on using tickets.