1 16 17 package org.apache.jetspeed.modules.parameters; 18 19 import org.apache.ecs.html.Input; 21 import org.apache.ecs.html.IMG; 22 import org.apache.ecs.html.A; 23 import org.apache.ecs.html.Script; 24 import org.apache.ecs.ElementContainer; 25 26 import java.util.Map ; 28 import java.util.Date ; 29 import java.text.SimpleDateFormat ; 30 import java.text.MessageFormat ; 31 32 import org.apache.turbine.util.RunData; 34 35 60 public class PopupCalendar extends ParameterPresentationStyle 61 { 62 63 public static final String PARM_FORM_NAME = "formName"; 64 public static final String PARM_FORMAT = "format"; 65 66 69 public String getContent(RunData data, String name, String value, Map parms) 70 { 71 72 ElementContainer container = new ElementContainer(); 73 74 if ( value.equals("$today") ) 75 { 76 Date dt = new Date (System.currentTimeMillis()); 77 value = new SimpleDateFormat ("M/d/yyyy").format(dt); 78 } 79 80 container.addElement(new Script().setLanguage("JavaScript").setSrc("javascript/PopupCalendar.js")); 81 82 container.addElement(new Input(Input.TEXT, name, value)); 83 84 IMG img = new IMG("images/cal.gif").setAlt("Click here for popup calendar").setBorder(0); 85 A a = new A(this.getJavaScript(name), img); 86 87 container.addElement(a); 88 89 return container.toString(); 90 } 91 92 95 private String getJavaScript(String fieldName) 96 { 97 98 String formName = (String )this.getParm(PARM_FORM_NAME, "DefaultCustomizer"); 99 String format = (String )this.getParm(PARM_FORMAT, "mm/dd/yyyy"); 100 101 Object [] args = { 102 formName, 103 fieldName, 104 format 105 }; 106 107 String template = "javascript: show_calendar(''{0}.{1}'',{0}.{1}.value,''{2}'');"; 108 109 return new MessageFormat (template).format(args); 110 111 } 112 113 116 public static void main(String args[]) 117 { 118 119 PopupCalendar pc = new PopupCalendar(); 120 System.out.println(pc.getContent(null, "test", "08/01/2001", null)); 121 System.out.println(pc.getContent(null, "test", "$today", null)); 122 123 } 124 125 } 126 | Popular Tags |