001: package com.salmonllc.jsp;
002:
003: import com.salmonllc.html.HtmlPage;
004: import com.salmonllc.html.HtmlComponent;
005:
006: /**
007: * This tag creates an expandall component
008: * @author Nicolás Genta
009: */
010: public class JspExpandAll extends HtmlComponent {
011:
012: private String _expand;
013: private String _imgexp;
014: private String _imgcont;
015: private String _altexp;
016: private String _altcont;
017:
018: public JspExpandAll(String name, String expand, String imgexp,
019: String imgcont, HtmlPage p) {
020: super (name, p);
021: setTheme(null);
022: _expand = expand;
023: _imgexp = imgexp;
024: _imgcont = imgcont;
025: _altexp = null;
026: _altcont = null;
027: }
028:
029: public void generateHTML(java.io.PrintWriter p, int rowNo)
030: throws Exception {
031: if (!getVisible())
032: return;
033:
034: String nameShow = getFullName();
035: String nameHide = getFullName();
036: if (rowNo != -1) {
037: nameShow += "_" + rowNo;
038: nameHide += "_" + rowNo;
039: }
040: String srcExp = translateSiteMapURL(_imgexp);
041: String srcCont = translateSiteMapURL(_imgcont);
042: String altExp = ((_altexp == null) ? "" : _altexp);
043: String altCont = ((_altcont == null) ? "" : _altcont);
044: String onclickShow = "";
045: String onclickHide = "";
046:
047: JspController controller = (JspController) getPage();
048: HtmlComponent comp = controller.getComponent(_expand);
049: if (comp != null && comp instanceof JspExpand) {
050: JspExpand expand = (JspExpand) comp;
051: String div = expand.getDiv();
052: HtmlComponent divComp = controller.getComponent(div);
053: if (divComp != null && divComp instanceof JspDiv) {
054: onclickShow = "showAll('" + divComp.getFullName()
055: + "');";
056: onclickHide = "hideAll('" + divComp.getFullName()
057: + "');";
058: }
059: }
060:
061: StringBuffer sbOut = new StringBuffer();
062: sbOut.append("<IMG NAME=\"" + nameShow + "\"" + " SRC=\""
063: + srcExp + "\"" + " ALT=\"" + altExp + "\""
064: + " ONCLICK=\"" + onclickShow + "\"/>");
065: sbOut.append(" ");
066: sbOut.append("<IMG NAME=\"" + nameHide + "\"" + " SRC=\""
067: + srcCont + "\"" + " ALT=\"" + altCont + "\""
068: + " ONCLICK=\"" + onclickHide + "\"/>");
069: p.print(sbOut.toString());
070: addScript();
071: }
072:
073: public String getExpand() {
074: return _expand;
075: }
076:
077: public void setExpand(String expand) {
078: this ._expand = expand;
079: }
080:
081: public String getImgexp() {
082: return _imgexp;
083: }
084:
085: public void setImgexp(String imgexp) {
086: this ._imgexp = imgexp;
087: }
088:
089: public String getImgcont() {
090: return _imgcont;
091: }
092:
093: public void setImgcont(String imgcont) {
094: this ._imgcont = imgcont;
095: }
096:
097: public String getAltexp() {
098: return _altexp;
099: }
100:
101: public void setAltexp(String altexp) {
102: this ._altexp = altexp;
103: }
104:
105: public String getAltcont() {
106: return _altcont;
107: }
108:
109: public void setAltcont(String altcont) {
110: this ._altcont = altcont;
111: }
112:
113: private void addScript() {
114: if (!getPage().isScriptAdded("ExpandAllScript")) {
115: StringBuffer jsExpandAll = new StringBuffer();
116:
117: jsExpandAll
118: .append("function showAll(divId) {\n"
119: + "\tvar divs = document.getElementsByTagName(\"div\");\n"
120: + "\tfor (var i=0; i<divs.length; i++) {\n"
121: + "\t\tvar divFullName = divs[i].id;\n"
122: + "\t\tvar divName = divFullName.substring(0, divFullName.lastIndexOf(\"_\"));\n"
123: + "\t\tif (divName == divId) {\n"
124: + "\t\t\tvar row = divFullName.substring(divFullName.lastIndexOf(\"_\")+1);\n"
125: + "\t\t\tvar div = document.getElementById(divId + \"_\" + row);\n"
126: + "\t\t\tif (div.style.display == \"none\") {\n"
127: + "\t\t\t\texpand(divId, parseInt(row));\n"
128: + "\t\t\t}\n" + "\t\t}\n" + "\t}\n"
129: + "}\n\n");
130: jsExpandAll
131: .append("function hideAll(divId) {\n"
132: + "\tvar divs = document.getElementsByTagName(\"div\");\n"
133: + "\tfor (var i=0; i<divs.length; i++) {\n"
134: + "\t\tvar divFullName = divs[i].id;\n"
135: + "\t\tvar divName = divFullName.substring(0, divFullName.lastIndexOf(\"_\"));\n"
136: + "\t\tif (divName == divId) {\n"
137: + "\t\t\tvar row = divFullName.substring(divFullName.lastIndexOf(\"_\")+1);\n"
138: + "\t\t\tvar div = document.getElementById(divId + \"_\" + row);\n"
139: + "\t\t\tif (div.style.display == \"block\") {\n"
140: + "\t\t\t\texpand(divId, parseInt(row));\n"
141: + "\t\t\t}\n" + "\t\t}\n" + "\t}\n"
142: + "}\n\n");
143:
144: getPage().addScript("ExpandAllScript",
145: jsExpandAll.toString());
146: }
147: }
148: }
|