[daisy] Saving Hook for a Part Editor

Bruno Dumon bruno at outerthought.org
Wed Apr 30 21:48:07 CEST 2008


Hi,

On Wed, 2008-04-30 at 17:40 +0200, Michael Hänni wrote:
> Hello
> 
> I have implemented a part editor for the Part Type "SvgData" of the 
> document type "SVG document". This editor is an applet running inside a 
> browser.
> For the ease of use it should be possible for the user to click on the 
> "Save" or "Cancle editing (clears lock)" buttons to save or discharge 
> the edited part of the document. This is how it is done with the 
> document type "Simple Document".
> To meet this requirement I currently take the data from the applet and 
> write it to a hidden field of the document. This hidden field then gets 
> stored on the server side.
> 
> What could be a good presave hook for writing the changes of the applet 
> in the "SVG document"?
> Currently I'm doing this at the end of the function preSubmitChecks() of 
> the file DaisyHome\daisywiki\webapp\daisy\resources\xml\documenteditor.xml.
> This works fine, but is more a hack than a solution, as the code is 
> executed for every document type, not just for a document containing a 
> "SvgData" part.
> 
> Has anyone an idea?

The HTML editor and the navigation tree editor are in the same position:
before the form is submitted, their internal data-structures need to be
serialized and set as a field value.

For the navigation tree editor, the relevant code is in treeview.js,
function installTreeEditorOnSubmitHandler. This gets called via the
initNavTree() call in parteditor_navigation_template.xml.

The approach is basically to execute some code like the following when
loading your form (just put it in a <script> tag in your template):

var plainTextField = dojo.byId("plaintext:input");
var htmlAreaSubmitHandler = new Object();
htmlAreaSubmitHandler.forms_onsubmit = function() {
   plainTextField.value = editorApplet.getData();
   return true;
}
cocoon.forms.addOnSubmitHandler(plainTextField.form,
htmlAreaSubmitHandler);

BTW, what applet are you using? Looking forward to see the results!

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought                            http://www.daisycms.org/
bruno at outerthought.org              http://www.kauriproject.org/



More information about the daisy mailing list