Saving the contents of TinyMCE text field automatically

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Saving the contents of TinyMCE text field automatically

nigelss
Hi all,

I'm having some trouble getting a TinyMCE component to update the server without using a normal form submission. Is there anyone who has linked up the AutoSave plugin functionality of TinyMCE?

I have been able to use the TinyMceAjaxSubmitLink class to create a clickable link for the user to save the contents. This calls Form.onSubmit() each time the user submits the link.

However, what I am looking for is a way to hook up the "Save" button (from the SavePlugin), and also the "AutoSave" plugin functionality.

TorSaveBehavior.onSave( ) gets called successfully the first time you hit the save button, but not the subsequent times, even after more edits are made.

Also the "AutoSave" warning does not appear at all when the user moves away from the page.

Any ideas or suggestions?

Thanks in advance,

Nigel



-----------------------------------------------------------------------------------------------------------------------

public class TorSaveBehavior extends InPlaceSaveBehavior {

        @Override
        protected String onSave(AjaxRequestTarget target, String newContent) {
                System.out.println ("TorSaveBehaviour.respond");
                return newContent;
        }
}

-----------------------------------------------------------------------------------------------------------------------

public class EditableUserRichText extends InPlaceEditComponent {

        @Override
        protected InPlaceSaveBehavior createSaveBehavior()
        {
                return new TorSaveBehavior();
        }


-----------------------------------------------------------------------------------------------------------------------

public class About extends CollectorPage
{
        public About(PageParameters pp) {

               ...
 
       if (editMode) {

                        TinyMCESettings settings = new TinyMCESettings(Theme.advanced);
                        settings.setToolbarLocation(Location.top);
                        SavePlugin savePlugin = new SavePlugin();
                        AutoSavePlugin autosavePlugin = new AutoSavePlugin();
                        settings.add((wicket.contrib.tinymce.settings.Button) savePlugin.getSaveButton(),
                                                TinyMCESettings.Toolbar.first, TinyMCESettings.Position.before);
                        settings.register(autosavePlugin);
                       
                        EditableUserRichText descriptionField = new EditableUserRichText("description", new PropertyModel<String> (owner, "description"), deck, owner);
               
                        Form form1 = new Form("form1") {
                                @Override
                                protected void onSubmit() {
                                        System.out.println("Submit!");
                                }
                        };
                        add(form1);
                       
                        form1.add (new TinyMceAjaxSubmitLink ("tinymce_submit") {
                        });
        } else {

               ...

        }        

}