| 1 24 package org.riotfamily.pages.riot.chooser; 25 26 import java.io.PrintWriter ; 27 28 import org.riotfamily.common.markup.DocumentWriter; 29 import org.riotfamily.common.markup.Html; 30 import org.riotfamily.forms.DHTMLElement; 31 import org.riotfamily.forms.MessageUtils; 32 import org.riotfamily.forms.TemplateUtils; 33 import org.riotfamily.forms.element.TextField; 34 import org.riotfamily.forms.resource.FormResource; 35 import org.riotfamily.forms.resource.ResourceElement; 36 import org.riotfamily.forms.resource.Resources; 37 import org.riotfamily.forms.resource.ScriptResource; 38 import org.riotfamily.forms.resource.StylesheetResource; 39 40 public class InternalLinkField extends TextField implements ResourceElement, 41 DHTMLElement { 42 43 private static final ScriptResource RESOURCE = new ScriptResource( 44 "riot-js/window-callback.js", "WindowCallback", 45 new FormResource[] { 46 Resources.PROTOTYPE, 47 new StylesheetResource("style/internal-link-field.css") 48 } 49 ); 50 51 private String chooserUrl = "/riot/pages/chooser"; 52 53 54 public InternalLinkField() { 55 setStyleClass("text internal-link"); 56 } 57 58 public String getChooserUrl() { 59 return this.chooserUrl; 60 } 61 62 public void setChooserUrl(String chooserUrl) { 63 this.chooserUrl = chooserUrl; 64 } 65 66 public FormResource getResource() { 67 return RESOURCE; 68 } 69 70 public String getInitScript() { 71 return TemplateUtils.getInitScript(this); 72 } 73 74 public String getButtonId() { 75 return getId() + "-button"; 76 } 77 78 public void renderInternal(PrintWriter writer) { 79 DocumentWriter doc = new DocumentWriter(writer); 80 doc.start(Html.DIV).attribute(Html.COMMON_CLASS, "internal-link"); 81 doc.start(Html.DIV).attribute(Html.COMMON_CLASS, "input-wrapper"); 82 doc.body(); 83 84 super.renderInternal(writer); 85 86 doc.end(); 87 String buttonLabel = MessageUtils.getMessage(this, 88 "internalLinkField.buttonLabel", null, "Internal ..."); 89 90 doc.startEmpty(Html.INPUT) 91 .attribute(Html.INPUT_TYPE, "button") 92 .attribute(Html.INPUT_VALUE, buttonLabel) 93 .attribute(Html.COMMON_ID, getButtonId()) 94 .attribute(Html.COMMON_CLASS, "button") 95 .closeAll(); 96 } 97 98 } 99 | Popular Tags |