← Back to team overview

openerp-dev-web team mailing list archive

Update

 

1. Finally created 24-25 sprint, is a bit full compared to previous but my time estimates might be a little on the high side. We'll see.

2. I just realized I hadn't explained how the iframe removal stuff works, might be interesting so you can understand how things interact. Code is in openerp.base.js, not big (60 lines) and concepts are easy but might be a bit dense.

Let's take the two parts:
* Forms
Looks out for "onsubmit" events on form elements *unless form has a target attribute* [1], and when find one submit via xhr (using jquery-form plugin so it also works for e.g. file uploads) and load response in #appContent div. This is why to submit form via javascript after modification use jQuery(form).submit() so it triggers all events, not just `form.submit()` (alternatively, don't stop native submit event maybe)

* Links
Looks out for "onclic" on links, pretty similar to forms except ignores not just target but also if link has no `href` or if `href` starts with `#` or `javascript:` so it ignores links with only javascript handler[2]

A big difference from forms is that links call `openLink(string url, optional function afterLoad)` to do the opening. if no #appContent, openLink uses window.location.assign(), if #appContent loads content via xhr and then calls afterLoad().

If you want to open URLs in app content area from javascript, use openLink (not e.g. window.location.href = url). If you want to popup, in HTML best is link with href and right target (e.g. _blank), in javascript openobject.tools.openWindow is still available.

3. Might have noted that now when clicking on links and stuff waitbox sometimes appears (is when takes too long). On that front, expanded openerp.ui.WaitBox API a bit:
* Waitbox now available everywhere, can create one where you want/need
* If want to display waitbox only if some event takes too long (common), use method `WaitBox.showAfter(milliseconds delay)`, creates internal timer to call show(), can be called repeatedly on same waitbox (later invocation will cancel new one, so if call 3 times in a row only last will be used)
* clearTimeout to clear timeout set by showAfter, should *not* be used because
* hide() hides the waitbox if it is displayed, and cancels waitbox timer (from showAfter) if there is one

So use case is:

    var waitBox = openerp.ui.WaitBox();
    waitBox.showAfter(2000); // use named constant for clarity here, magic numbers are bad
    startOperationWhichCanTakeLongTimeAndTakesCallbackForEnd(function () {
        waitBox.hide();
    });

that way if operation is actually short never displays waitbox, otherwise erases it when operation is done. In fact is almost exactly what is done with form xhr:

    waitBox.showAfter(FORM_WAIT_NO_ACTIVITY);
    form.ajaxSubmit({
        complete: function (xhr) {
            app.html(xhr.responseText);
            waitBox.hide();
        }
    });

That should probably be in some documentation for development of web client, along with a bunch of other stuff...

Anyway if you have any question about that, or sprint, don't hesitate asking or if you have anything to say, do also.

Xavier

[1] If form has target, idea is programmer does want result in e.g. a popup, or whole page, or whatever, so don't touch/xhr it
[2] Event handers like that in HTML and links with no actual URL are not very good though, we should try to improve so people can e.g. middle-click on links to open in new tab