1 13 package info.magnolia.cms.gui.dialog; 14 15 import info.magnolia.cms.gui.control.Button; 16 import info.magnolia.cms.gui.control.ButtonSet; 17 import info.magnolia.cms.gui.control.ControlSuper; 18 import info.magnolia.cms.gui.control.Hidden; 19 import info.magnolia.cms.gui.misc.CssConstants; 20 import info.magnolia.cms.gui.misc.Sources; 21 import info.magnolia.cms.i18n.Messages; 22 import info.magnolia.cms.i18n.MessagesManager; 23 24 import java.io.IOException ; 25 import java.io.Writer ; 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 30 import org.apache.commons.lang.StringUtils; 31 32 33 37 public class DialogDialog extends DialogSuper { 38 39 public static final String DIALOGSIZE_NORMAL_WIDTH = "800"; 41 public static final String DIALOGSIZE_NORMAL_HEIGHT = "650"; 43 public static final String DIALOGSIZE_SLIM_WIDTH = "500"; 45 public static final String DIALOGSIZE_SLIM_HEIGHT = "600"; 47 private String callbackJavascript = "opener.document.location.reload();window.close();"; 49 private List javascriptSources = new ArrayList (); 50 51 private List cssSources = new ArrayList (); 52 53 private String action; 54 55 58 protected DialogDialog() { 59 } 60 61 public void setCallbackJavascript(String s) { 62 this.callbackJavascript = s; 63 } 64 65 public String getCallbackJavascript() { 66 return this.callbackJavascript; 67 } 68 69 public void setAction(String s) { 70 this.action = s; 71 } 72 73 public String getAction() { 74 if (this.action == null) { 75 return this.getRequest().getRequestURI(); 76 } 77 78 return this.action; 79 } 80 81 public void setJavascriptSources(String s) { 82 this.getJavascriptSources().add(s); 83 } 84 85 public List getJavascriptSources() { 86 return this.javascriptSources; 87 } 88 89 public void drawJavascriptSources(Writer out) throws IOException { 90 Iterator it = this.getJavascriptSources().iterator(); 91 while (it.hasNext()) { 92 out.write("<script type=\"text/javascript\" SRC=\"" + it.next() + "\"></script>"); } 94 } 95 96 public void setCssSources(String s) { 97 this.getCssSources().add(s); 98 } 99 100 public List getCssSources() { 101 return this.cssSources; 102 } 103 104 public void drawCssSources(Writer out) throws IOException { 105 Iterator it = this.getCssSources().iterator(); 106 while (it.hasNext()) { 107 out.write("<link rel=\"stylesheet\" type=\"text/css\" HREF=\"" + it.next() + "\">"); } 109 } 110 111 public DialogTab addTab() { 112 return this.addTab(StringUtils.EMPTY); 113 } 114 115 public DialogTab addTab(String label) { 116 DialogTab tab = new DialogTab(); 117 tab.setLabel(label); 118 this.getSubs().add(tab); 119 return tab; 120 } 121 122 public DialogTab getTab(int i) { 123 return (DialogTab) this.getSubs().get(i); 124 } 125 126 public void drawHtmlPreSubs(Writer out) throws IOException { 127 128 132 out.write("<html>"); this.drawHtmlPreSubsHead(out); 134 out.write("<body class=\"mgnlDialogBody\" onload=\"mgnlDialogInit();\">"); this.drawHtmlPreSubsForm(out); 136 this.drawHtmlPreSubsTabSet(out); 137 } 138 139 protected void drawHtmlPreSubsHead(Writer out) throws IOException { 140 out.write("<head>"); out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>"); out.write("<script type=\"text/javascript\">"); out.write("window.resizeTo(" + this.getConfigValue("width", DIALOGSIZE_NORMAL_WIDTH) + "," + this.getConfigValue("height", DIALOGSIZE_NORMAL_HEIGHT) + ");"); out.write("</script>"); out.write("<title>" + this.getConfigValue("label", MessagesManager.get(getRequest(), "dialog.editTitle")) + "</title>"); out.write(new Sources(this.getRequest().getContextPath()).getHtmlJs()); 153 out.write(new Sources(this.getRequest().getContextPath()).getHtmlCss()); 154 out.write(new Sources(this.getRequest().getContextPath()).getHtmlRichEdit()); 155 out.write("<script type=\"text/javascript\">"); out.write("var mgnlRichEditors=new Array();"); out.write("var kupu = null;"); out.write("var kupuui = null;"); out.write("</script>"); this.drawJavascriptSources(out); 161 this.drawCssSources(out); 162 out.write("</head>"); } 164 165 protected void drawHtmlPreSubsForm(Writer out) throws IOException { 166 out.write("<form action=\"" + this.getAction() + "\" name=\"mgnlFormMain\" method=\"post\" enctype=\"multipart/form-data\">"); out.write(new Hidden("mgnlDialog", this.getConfigValue("dialog"), false).getHtml()); out.write(new Hidden("mgnlRepository", this.getConfigValue("repository"), false).getHtml()); out.write(new Hidden("mgnlPath", this.getConfigValue("path"), false).getHtml()); out.write(new Hidden("mgnlNodeCollection", this.getConfigValue("nodeCollection"), false).getHtml()); out.write(new Hidden("mgnlNode", this.getConfigValue("node"), false).getHtml()); out.write(new Hidden("mgnlJsCallback", this.getCallbackJavascript(), false).getHtml()); out.write(new Hidden("mgnlRichE", this.getConfigValue("richE"), false).getHtml()); out.write(new Hidden("mgnlRichEPaste", this.getConfigValue("richEPaste"), false).getHtml()); if (this.getConfigValue("paragraph").indexOf(",") == -1) { out.write(new Hidden("mgnlParagraph", this.getConfigValue("paragraph"), false).getHtml()); } } 180 181 protected void drawHtmlPreSubsTabSet(Writer out) throws IOException { 182 String id = this.getId(); 183 out.write("<script type=\"text/javascript\">"); out.write("mgnlControlSets['" + id + "']=new Object();"); out.write("mgnlControlSets['" + id + "'].items=new Array();"); out.write("mgnlControlSets['" + id + "'].resize=true;"); out.write("</script>"); } 189 190 public void drawHtmlPostSubs(Writer out) throws IOException { 191 this.drawHtmlPostSubsTabSet(out); 192 this.drawHtmlPostSubsButtons(out); 193 194 out.write("</form></body></html>"); } 196 197 protected void drawHtmlPostSubsTabSet(Writer out) throws IOException { 198 String id = this.getId(); 200 out.write("<div class=\"" + CssConstants.CSSCLASS_TABSETBUTTONBAR + "\">"); out.write("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\"><tr><td class=\"" + CssConstants.CSSCLASS_TABSETBUTTONBAR + "\">"); if (this.getOptions().size() != 0) { 204 ButtonSet control = new ButtonSet(); 205 ((Button) this.getOptions().get(0)).setState(ControlSuper.BUTTONSTATE_PUSHED); 206 control.setButtons(this.getOptions()); 207 control.setName(this.getId()); 208 control.setSaveInfo(false); 209 control.setButtonType(ControlSuper.BUTTONTYPE_PUSHBUTTON); 210 out.write(control.getHtml()); 211 } 212 out.write("</td></tr></table></div>"); out.write("<script type=\"text/javascript\">"); out.write("mgnlDialogResizeTabs('" + id + "');"); out.write("mgnlDialogShiftTab('" + id + "',false,0)"); out.write("</script>"); } 219 220 protected void drawHtmlPostSubsButtons(Writer out) throws IOException { 221 Messages msgs = MessagesManager.getMessages(getRequest()); 222 223 out.write("<div class=\"" + CssConstants.CSSCLASS_TABSETSAVEBAR + "\">"); 225 Button save = new Button(); 226 save.setOnclick(this.getConfigValue("saveOnclick", "mgnlDialogFormSubmit();")); save.setLabel(this.getConfigValue("saveLabel", msgs.get("buttons.save"))); out.write(save.getHtml()); 229 Button cancel = new Button(); 230 cancel.setOnclick(this.getConfigValue("cancelOnclick", "window.close();")); cancel.setLabel(this.getConfigValue("cancelLabel", msgs.get("buttons.cancel"))); out.write(cancel.getHtml()); 233 234 out.write("</div>"); } 236 } 237 | Popular Tags |