On 12/05/2013 07:13 AM, Valdis Vītoliņš wrote:
I was happy enough with simple solution, which
required saving document
before adding new object:
#set($redirect=$xwiki.getRequestURL())
{{html}}<a
href="$tdoc.getURL("objectadd","classname=Space.ObjectClass&xredirect=
${redirect}")&form_token=$!services.csrf.getToken()">Add
object</a>{{/html}}
Though for "average users" it could be hard to digest. Therefore I'm
analysing Object edit mode form, where it works. I checked that link
generation in #macro(displayAddObject $class) of the editobject.vm
doesn't do the magic and I suppose it is somewhere in JavaScript.
Can you provide some hints how it is actually done?
Thanks in advance!
Valdis
In the Object editor, objects are added via AJAX, and the form is not
saved before adding. See
https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwi…
for the JavaScript code which handles this. If you wish to save the
document before adding, you could do:
document.fire('xwiki:actions:save', {'continue': true, form: theForm});
to save the document, then listen to the event fired after the document
is successfully saved and add you object:
document.observe('xwiki:actions:saved', function(event) {
// ajax call or url load
});
See also
http://platform.xwiki.org/xwiki/bin/view/DevGuide/JavaScriptAPI#HDocumentco…
--
Sergiu Dumitriu
http://purl.org/net/sergiu