cubicweb #1624745 Auto-reload ajax form [open]

Sometimes you want to submit an edition form and stay on the page without reloading it, the form still being displayed (see ui props for instance). The form needs to be reloaded in such a case, which is made easy using the following class, which I would suggest to be integrated in CubicWeb:

class InPlaceEditionFormView(EditionFormView):
    __regid__ = 'in_place_edition'

    def render_form(self, entity):
        loadurl = self._cw.build_url('json', vid=self.__regid__, fname='view',
                                     rql=uilib.rql_for_eid(entity.eid))
        self.w(u'<div class="in_place" cubicweb:loadurl="%s">'
               % xml_escape(loadurl))
        super(InPlaceEditionFormView, self).render_form(entity)
        self.w(u'</div>')

    def init_form(self, form, entity):
        form.action = self._cw.build_url(
            'validateform', __onsuccess='window.parent.reload_in_place_form',
            __cbargs=json_dumps(self.submited_message()))

Corresponding javascript code would look like:

function reload_in_place_form(result, formid, msg) {
  unfreezeFormButtons(formid);
  updateMessage(msg);
  var $div = cw.jqNode(formid).closest('.in_place');
  $div.loadxhtml($div.attr('cubicweb:loadurl'), {'pageid': pageid});
};

What do you think of it?

prioritynormal
typeenhancement
done in<not specified>
closed by<not specified>