I'm using the following custom tinymce javascript initialization (I
don't use the default which comes with wicket-tinymce, but put this
together manually). I override the image button of tinymce so the
callback can change the whole panel and display a selector one. The
user can use the selector panel to upload new pictures as well, but
that's handled by wicket at that point.


public class FormTinyMceRow extends FormTextAreaRow {

    private static final long serialVersionUID = 1L;

    public static final ResourceReference REFERENCE_MIN = new
CompressedResourceReference(
                        InPlaceEditBehavior.class, "tiny_mce/tiny_mce.js");

    public FormTinyMceRow(String id, String selector) {
        super(id, selector);
        get("component").setOutputMarkupId(true);
        add(JavascriptPackageResource.getHeaderContribution(REFERENCE_MIN));
        final AjaxFormSubmitBehaviorImpl b = new
AjaxFormSubmitBehaviorImpl("onNever");
        add(b);
        add(new Label("script", new Model<String>() {

            @Override
            public String getObject() {
                String siteCss =
CmsConfig.getSiteById(((CmsSession)getSession()).getSiteId()).getCss();
                return " tinyMCE.init({ " +
                        "mode : \"exact\", " +
                        "elements : \"" +
FormTinyMceRow.this.get("component").getMarkupId() + " \"," +
                        "language : \"hu\", " +
                        "theme : \"advanced\", " +
                        "plugins : \"paste, searchreplace, preview,
table, emotions\", " +
                        "theme_advanced_buttons1 :
\"bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect\","
+
                        "theme_advanced_buttons2 :
\"cut,copy,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,preview,|,forecolor\","
+
                        "theme_advanced_buttons3 :
\"tablecontrols,|,blockquote,removeformat,visualaid,|,sub,sup,|,charmap,emotions,hr,advhr,fullscreen\",
" +
                        "theme_advanced_buttons4 : '', " +
                        "theme_advanced_toolbar_location : \"top\"," +
                        "theme_advanced_statusbar_location : \"bottom\"," +
                        "theme_advanced_toolbar_align : \"left\"," +
                        "theme_advanced_resizing : true," +
                        "entity_encoding : \"raw\"," +
                        "content_css : \"" + siteCss + "\"," +
                        "verify_css_classes : true," +
                        "verify_html : true," +
                        "setup : function(ed) {" +
                        "ed.addButton('image', {" +
                        " onclick : function() {\n" +
                        "   tinyMCE.execCommand('mceInsertContent',
false, '%%IMAGE%%'); \n"+
                        "   tinyMCE.triggerSave(true,true);\n" +
                        "   " + b.getEventHandler() +
                        "\n  }" +
                        "});" +
                        "} });";
            }
        }).setEscapeModelStrings(false));
    }


Unfotunately I couldn't get the javascript functions to insert the
image at the right position, so I'm using a string substitution
pattern to do it. My base pages can handle pushing (to display a new
dialog) and popping (to get back to previous content) components into
the main area of my layout:

  private class AjaxFormSubmitBehaviorImpl extends AjaxFormSubmitBehavior {

        public AjaxFormSubmitBehaviorImpl(String event) {
            super(event);
        }

        @Override
        public void onSubmit(AjaxRequestTarget target) {
            CmsPage page = (CmsPage) getPage();
            ContentSelector selector = new
ContentSelector(page.getMainId(), new Model(), Photo.class) {

                @Override
                public void close(AjaxRequestTarget target) {

                    Photo photo = (Photo) getDefaultModelObject();
                    String replacement = "";
                    if (photo != null) {
                        Image image = photo.getThumbnail();
                        if (image != null) {
                            replacement =

ImageView.contentImageUrl(image.getId(), 1, null,
photo.getTitle()).toString();
                        }
                    }
                    IModel model =
FormTinyMceRow.this.get("component").getDefaultModel();

model.setObject(model.getObject().toString().replaceAll("%%IMAGE%%",
replacement));
                    ((CmsPage) getPage()).popMainContent(target);
                }
            };
            page.pushMainContent(selector, target);
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
        }

        // have to make it public
        @Override
        public CharSequence getEventHandler() {
            return super.getEventHandler();
        }

        @Override
        protected CharSequence getPreconditionScript() {
            return "return true;";
        }
    }


On Fri, Jun 5, 2009 at 8:19 AM, rolandpeng<rolandp...@cht.com.tw> wrote:
>
> I meet this requirement,too.
> anyone have solutions?
> or any comments will be welcome. thanks.
>
>
> Nino.Martinez wrote:
>>
>> Add a upload field to the page.. And reference that from tinymce?
>>
>> Mead wrote:
>>> Hello All,
>>>    Could TinyMCE upload pictures or files?
>>> I run the example of TinyMCE(from wicket stuff), and find the demo there
>>> could not upload any files or images, but only insert the URL of picture
>>>
>>> Best regards,
>>>
>>> Mead
>>> xb...@126.com
>>> 2008-01-28
>>>
>>
>
> --
> View this message in context: 
> http://www.nabble.com/Could-TinyMCE-Upload-pictures-or-files-tp15132568p23881231.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to