== Popups for Form reference data == When adding items, the opened window should be a popup, Submit should close that window & pre-populate the main form with the result. !ToDo: * Make work for nested popups (currently all share the name 'popupWin') * Don't lose existing populated fields in main form (Read into JS & re-populate?) We use Progressive Enhancement to allow non-Javascript browsers to access via a new tab (with manual refresh of parent window & then manual selection of new item). Model should include a comment like this: {{{ db.table.field.comment = DIV(A(T('Add Contact'),_class='popup',_href=URL(r=request, c='pr', f='person', args='create', vars=dict(format='plain')), _target='top'), A(SPAN("[Help]"), _class="tooltip", _title=T("Contact|The Person to contact for this."))) }}} We use jQuery to catch the click for the class=popup (in {{{static/scripts/S3.js}}}): {{{ $('a.popup').click(function(){ var url=$(this).attr('href'); var caller=$(this).parents('tr').attr('id').replace(/__row/,''); openPopup(url.replace(/format=plain/,'format=popup')+'&caller='+caller); return false; }); }}} This triggers the popup defined in the same file: {{{ var popupWin = null; function openPopup(url) { if ( !popupWin || popupWin.closed ) { popupWin = window.open( url, "popupWin", "width=640,height=480" ); } else popupWin.focus(); } }}} There is a special format=popup added to the RESTlike CRUD controller in {{{00_db.py}}}: {{{ elif representation == "popup": form = crud.create(table, onvalidation=onvalidation) response.view = 'popup.html' return dict(module_name=module_name, form=form, module=module, resource=resource, main=main, caller=request.vars.caller) }}} This uses it's own view: {{{views/popup.html}}}: {{{ {{if session.s3.debug:}} {{include 'sahana_scripts_debug.html'}} {{include 'sahana_styles_debug.html'}} {{else:}} {{include 'sahana_scripts_min.html'}} {{pass}} }}} ---- DeveloperGuidelines