Skip to content

Commit

Permalink
Merge pull request #21 from hanhsu/refix-ZKCK-12
Browse files Browse the repository at this point in the history
refix B-ZKCK-12: Calling Ckeditor.setValue() within doAfterCompose and b...
  • Loading branch information
hanhsu committed Jan 19, 2015
2 parents 079efcd + 6d0c000 commit 00bf543
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 27 deletions.
4 changes: 2 additions & 2 deletions ckez/src/archive/web/js/ckez/CKeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ ckez.CKeditor = zk.$extends(zul.Widget, {
if (editor) {
if (fromServer) {
// ZKCK-12: need to format the value from server first before set to ckeditor
editor.setData(jq(this.$n('cnt')).html(v).text());
v = jq(this.$n('cnt')).html(v).text();
editor.setData(v);
// Issue #9: update editor's previousValue if set value from server
// to prevent unexpect onChange event
editor._.previousValue = editor.dataProcessor.toHtml(v);
} else {
editor.setData(v);
}

}
}],
autoHeight: null,
Expand Down
35 changes: 26 additions & 9 deletions test/addon/ckeztest/src/archive/test2/B-ZKCK-12.zul
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,32 @@ B-ZKCK-12.zul
Copyright (C) Potix Corporation. All Rights Reserved.
-->
<!-- <zk> -->
<!-- <label multiline="true"> -->
<!-- 1. Should see some content in ckeditor. -->
<!-- 2. Click "Clear Value" button. -->
<!-- 3. Click "Set Value" button, it is bug if the new content is different from the content set in doAfterCompose. -->
<!-- </label> -->
<!-- <window border="normal" title="hello" apply="org.zkoss.zktest.test2.B_ZKCK_12_Composer"> -->
<!-- <ckeditor id="editor" /> -->
<!-- <button id="btn1" label="Clear Value" /> -->
<!-- <button id="btn2" label="Set Value" /> -->
<!-- <button id="btn3" label="Check Value" /> -->
<!-- </window> -->
<!-- </zk> -->
<zk>
<label multiline="true">
1. Should see some content in ckeditor.
2. Click "Clear Value" button.
3. Click "Set Value" button, it is bug if the new content is different from the content set in doAfterCompose.
</label>
<window border="normal" title="hello" apply="org.zkoss.zktest.test2.B_ZKCK_12_Composer">
<ckeditor id="editor" />
<button id="btn1" label="Clear Value" />
<button id="btn2" label="Set Value" />
<button id="btn0" label="Click Me to open window"
onClick="window.setVisible(true);window.doOverlapped();" />
<window id="window" visible="false" apply="org.zkoss.zktest.test2.B_ZKCK_12_Composer" position="left">
<vbox>
<button id="btn1" label="Click Me to open more windows" />
<button id="btn2" label="Click Me to set html text" />
<button id="btn3" label="Click Me to invalidate ckeditor components" />
<ckeditor id="editor" />
<window id="window2" width="600px" visible="false" border="normal" title="hello2" position="right">
<ckeditor id="editor2" />
</window>
<button id="btn4" label="Click Me to get value after invalidate ckeditor components" />
</vbox>
</window>
</zk>
106 changes: 90 additions & 16 deletions test/addon/ckeztest/src/org/zkoss/zktest/test2/B_ZKCK_12_Composer.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,101 @@
package org.zkoss.zktest.test2;

import org.zkforge.ckez.CKeditor;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.xml.XMLs;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Window;

public class B_ZKCK_12_Composer extends SelectorComposer<Window> {
// @Wire
// private CKeditor editor;
// public void doAfterCompose(Window comp) throws Exception {
// super.doAfterCompose(comp);
// editor.setValue("&amp;lt;AmpTag&amp;gt;Amp tag content&amp;lt;/AmpTag&amp;gt; &lt;br/&gt; &lt;escapetag&gt;escapetag content&lt;/escapetag&gt; &lt;br/&gt; &lt; space-tag &gt; space tag content &lt; /space-tag &gt;");
// }
//
// @Listen("onClick=#btn1")
// public void onClick$btn1(Event e) {
// editor.setValue("");
// }
//
// @Listen("onClick=#btn2")
// public void onClick$btn2(Event e) {
// editor.setValue("&amp;lt;AmpTag&amp;gt;Amp tag content&amp;lt;/AmpTag&amp;gt; &lt;br/&gt; &lt;escapetag&gt;escapetag content&lt;/escapetag&gt; &lt;br/&gt; &lt; space-tag &gt; space tag content &lt; /space-tag &gt;");
// }
//
// @Listen("onClick=#btn3")
// public void onClick$btn3(Event e) {
// System.out.println(editor.getValue());
// }

@Wire
private CKeditor editor;
public void doAfterCompose(Window comp) throws Exception {
super.doAfterCompose(comp);
editor.setValue("&amp;lt;AmpTag&amp;gt;Amp tag content&amp;lt;/AmpTag&amp;gt; &lt;br/&gt; &lt;escapetag&gt;escapetag content&lt;/escapetag&gt; &lt;br/&gt; &lt; space-tag &gt; space tag content &lt; /space-tag &gt;");
}

@Listen("onClick=#btn1")
public void onClick$btn1(Event e) {
editor.setValue("");
}

@Listen("onClick=#btn2")
public void onClick$btn2(Event e) {
editor.setValue("&amp;lt;AmpTag&amp;gt;Amp tag content&amp;lt;/AmpTag&amp;gt; &lt;br/&gt; &lt;escapetag&gt;escapetag content&lt;/escapetag&gt; &lt;br/&gt; &lt; space-tag &gt; space tag content &lt; /space-tag &gt;");
}
private CKeditor editor;
private CKeditor cKeditor3;

public void doAfterCompose(Window comp) throws Exception {
super.doAfterCompose(comp);
editor.setValue(doubleEscape("<tag>value</tag>") + "<br/>" + doubleEscape("<tag2>value tag2</tag2>"));
}

private String doubleEscape(String text) {
return XMLs.escapeXML(XMLs.escapeXML(text));
}

@Listen("onClick=#btn1")
public void click1() {
Window window2 = (Window) editor.getParent().getFellow("window2");
window2.setVisible(true);
window2.doOverlapped();

cKeditor3 = new CKeditor();
Window window3 = new Window();
window3.setParent(window2.getParent());
window3.appendChild(cKeditor3);

window3.setClosable(true);

window3.setPosition("center");
window3.setTitle("Message!!!");
window3.doOverlapped();
}

@Listen("onClick=#btn2")
public void click2() {
Window window2 = (Window) editor.getParent().getFellow("window2");
CKeditor cKeditor2 = (CKeditor) window2.getFellow("editor2");

String s1 = "<html222>";
String s2 = XMLs.escapeXML(s1);
String s3 = XMLs.escapeXML(s2);
editor.setValue(s3);
cKeditor2.setValue(s3);
cKeditor3.setValue(s3);
}

@Listen("onClick=#btn3")
public void click3() {
Window window2 = (Window) editor.getParent().getFellow("window2");
CKeditor cKeditor2 = (CKeditor) window2.getFellow("editor2");

// System.out.println("Before Invalidate");
System.out.println("editor1: " + editor.getValue());
System.out.println("editor2: " + cKeditor2.getValue());
System.out.println("editor3: " + cKeditor3.getValue());
editor.invalidate();
// cKeditor3.invalidate();
// cKeditor2.invalidate();
}

@Listen("onClick=#btn4")
public void click4() {
Window window2 = (Window) editor.getParent().getFellow("window2");
CKeditor cKeditor2 = (CKeditor) window2.getFellow("editor2");

// System.out.println("After Invalidate");
System.out.println("editor1: " + editor.getValue());
System.out.println("editor2: " + cKeditor2.getValue());
System.out.println("editor3: " + cKeditor3.getValue());
}
}

0 comments on commit 00bf543

Please sign in to comment.