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.ControlImpl; 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 import info.magnolia.cms.util.AlertUtil; 24 25 import java.io.IOException ; 26 import java.io.Writer ; 27 import java.util.ArrayList ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 31 import org.apache.commons.lang.StringUtils; 32 33 34 38 public class Dialog extends DialogControlImpl { 39 40 public static final String DIALOGSIZE_NORMAL_WIDTH = "800"; 42 public static final String DIALOGSIZE_NORMAL_HEIGHT = "650"; 44 public static final String DIALOGSIZE_SLIM_WIDTH = "500"; 46 public static final String DIALOGSIZE_SLIM_HEIGHT = "600"; 48 private String callbackJavascript = "opener.document.location.reload();window.close();"; 50 private List javascriptSources = new ArrayList (); 51 52 private List cssSources = new ArrayList (); 53 54 private String action; 55 56 59 protected Dialog() { 60 } 61 62 public void setCallbackJavascript(String s) { 63 this.callbackJavascript = s; 64 } 65 66 public String getCallbackJavascript() { 67 return this.callbackJavascript; 68 } 69 70 public void setAction(String s) { 71 this.action = s; 72 } 73 74 public String getAction() { 75 if (this.action == null) { 76 return this.getRequest().getRequestURI(); 77 } 78 79 return this.action; 80 } 81 82 public void setJavascriptSources(String s) { 83 this.getJavascriptSources().add(s); 84 } 85 86 public List getJavascriptSources() { 87 return this.javascriptSources; 88 } 89 90 public void drawJavascriptSources(Writer out) throws IOException { 91 Iterator it = this.getJavascriptSources().iterator(); 92 while (it.hasNext()) { 93 out.write("<script type=\"text/javascript\" SRC=\"" + it.next() + "\"></script>"); } 95 } 96 97 public void setCssSources(String s) { 98 this.getCssSources().add(s); 99 } 100 101 public List getCssSources() { 102 return this.cssSources; 103 } 104 105 public void drawCssSources(Writer out) throws IOException { 106 Iterator it = this.getCssSources().iterator(); 107 while (it.hasNext()) { 108 out.write("<link rel=\"stylesheet\" type=\"text/css\" HREF=\"" + it.next() + "\"/>"); } 110 } 111 112 public DialogTab addTab() { 113 return this.addTab(StringUtils.EMPTY); 114 } 115 116 public DialogTab addTab(String label) { 117 DialogTab tab = new DialogTab(); 118 tab.setLabel(label); 119 this.getSubs().add(tab); 120 return tab; 121 } 122 123 public DialogTab getTab(int i) { 124 return (DialogTab) this.getSubs().get(i); 125 } 126 127 public void drawHtmlPreSubs(Writer out) throws IOException { 128 129 133 out.write("<html>"); out.write("<head>"); this.drawHtmlPreSubsHead(out); 136 if (AlertUtil.isMessageSet()) { 138 out.write("<script>mgnl.util.DHTMLUtil.addOnLoad(function(){alert('" 139 + AlertUtil.getMessage() 140 + "');})</script>"); 141 } 142 out.write("<script>mgnl.util.DHTMLUtil.addOnLoad(mgnlDialogInit);</script>"); 143 144 out.write("</head>\n"); out.write("<body class=\"mgnlDialogBody\">\n"); this.drawHtmlPreSubsForm(out); 147 this.drawHtmlPreSubsTabSet(out); 148 } 149 150 protected void drawHtmlPreSubsHead(Writer out) throws IOException { 151 out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n"); out.write("<title>" + this.getMessage(this.getConfigValue("label", MessagesManager.get("dialog.editTitle"))) + "</title>\n"); out.write(new Sources(this.getRequest().getContextPath()).getHtmlJs()); 157 out.write(new Sources(this.getRequest().getContextPath()).getHtmlCss()); 158 out.write(getHtmlKupuEditor(this.getRequest().getContextPath())); 159 out.write("<script type=\"text/javascript\">\n"); out.write("var mgnlRichEditors=new Array();\n"); out.write("var kupu = null;\n"); out.write("var kupuui = null;\n"); 164 out.write("window.onresize = eventHandlerOnResize;\n"); out.write("window.resizeTo(" + this.getConfigValue("width", DIALOGSIZE_NORMAL_WIDTH) + "," + this.getConfigValue("height", DIALOGSIZE_NORMAL_HEIGHT) + ");\n"); out.write("</script>\n"); 172 this.drawJavascriptSources(out); 173 this.drawCssSources(out); 174 } 175 176 public String getHtmlKupuEditor(String contextPath) { 177 StringBuffer html = new StringBuffer (); 178 html.append("<link rel=\"stylesheet\" type=\"text/css\" HREF=\""); html.append(contextPath); 180 html.append("/.resources/kupu/kupustyles.css\" />\n"); html.append("<link rel=\"stylesheet\" type=\"text/css\" HREF=\""); html.append(contextPath); 183 html.append("/.resources/kupu/kupucustom.css\" />\n"); html.append("<script type=\"text/javascript\" SRC=\""); html.append(contextPath); 186 html.append("/.resources/kupu/sarissa.js\"> </script>\n"); html.append("<script type=\"text/javascript\" SRC=\""); html.append(contextPath); 189 html.append("/.resources/kupu/kupuhelpers.js\"> </script>\n"); html.append("<script type=\"text/javascript\" SRC=\""); html.append(contextPath); 192 html.append("/.resources/kupu/kupueditor.js\"> </script>\n"); html.append("<script type=\"text/javascript\" SRC=\""); html.append(contextPath); 195 html.append("/.resources/kupu/kupubasetools.js\"> </script>\n"); html.append("<script type=\"text/javascript\" SRC=\""); html.append(contextPath); 198 html.append("/.resources/kupu/kupuloggers.js\"> </script>\n"); html.append("<script type=\"text/javascript\" SRC=\""); html.append(contextPath); 201 html.append("/.resources/kupu/kupucontentfilters.js\"> </script>\n"); html.append("<script type=\"text/javascript\" SRC=\""); html.append(contextPath); 204 html.append("/.resources/kupu/kupuinit.js\"> </script>\n"); return html.toString(); 206 } 207 208 protected void drawHtmlPreSubsForm(Writer out) throws IOException { 209 out.write("<form action=\"" + this.getAction() 211 + "\" name=\"mgnlFormMain\" method=\"post\" enctype=\"multipart/form-data\">\n"); 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()); } } 224 225 protected void drawHtmlPreSubsTabSet(Writer out) throws IOException { 226 String id = this.getId(); 227 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>\n"); } 233 234 public void drawHtmlPostSubs(Writer out) throws IOException { 235 this.drawHtmlPostSubsTabSet(out); 236 this.drawHtmlPostSubsButtons(out); 237 238 out.write("</form></body></html>"); } 240 241 protected void drawHtmlPostSubsTabSet(Writer out) throws IOException { 242 String id = this.getId(); 244 out.write("<div class=\"" + CssConstants.CSSCLASS_TABSETBUTTONBAR + "\">\n"); out.write("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\"><tr><td class=\"" + CssConstants.CSSCLASS_TABSETBUTTONBAR 247 + "\">"); if (this.getOptions().size() != 0) { 249 ButtonSet control = new ButtonSet(); 250 ((Button) this.getOptions().get(0)).setState(ControlImpl.BUTTONSTATE_PUSHED); 251 control.setButtons(this.getOptions()); 252 control.setName(this.getId()); 253 control.setSaveInfo(false); 254 control.setButtonType(ControlImpl.BUTTONTYPE_PUSHBUTTON); 255 out.write(control.getHtml()); 256 } 257 out.write("</td></tr></table>\n</div>\n"); out.write("<script type=\"text/javascript\">"); out.write("mgnlDialogResizeTabs('" + id + "');"); out.write("mgnlDialogShiftTab('" + id + "',false,0)"); out.write("</script>\n"); } 264 265 protected void drawHtmlPostSubsButtons(Writer out) throws IOException { 266 Messages msgs = MessagesManager.getMessages(); 267 268 out.write("<div class=\"" + CssConstants.CSSCLASS_TABSETSAVEBAR + "\">\n"); 270 Button save = new Button(); 271 String saveOnclick = this.getConfigValue("saveOnclick", "mgnlDialogFormSubmit();"); 272 String saveLabel = this.getConfigValue("saveLabel", msgs.get("buttons.save")); 273 if (StringUtils.isNotEmpty(saveOnclick) && StringUtils.isNotEmpty("saveLabel")) { 274 save.setOnclick(saveOnclick); 275 save.setLabel(saveLabel); 276 out.write(save.getHtml()); 277 } 278 Button cancel = new Button(); 279 cancel.setOnclick(this.getConfigValue("cancelOnclick", "window.close();")); cancel.setLabel(this.getConfigValue("cancelLabel", msgs.get("buttons.cancel"))); out.write(cancel.getHtml()); 282 283 out.write("</div>\n"); } 285 } 286 | Popular Tags |