Monday, November 08, 2010 at 12:06 AM.

system.verbs.builtins.webserver.standardMacros.chooseFolder

on chooseFolder (argTableAdr, openURL, selectURL, cancelURL, rootPath = "", fieldname = "PATH", border = 2, color = nil) {
	local (htmltext = "",  i, pathChar = ':');
	if defined (argTableAdr^.[fieldname]) {
		basePath = argTableAdr^.[fieldname]}
	else {
		basePath = rootPath};
	on add (s) {
		htmltext = htmltext + s + cr};
	if (color != nil) {
		add ("<TABLE BORDER=" + border + " BGCOLOR=\"" + color + "\"><TR><TD>")}
	else {
		add ("<TABLE BORDER=" + border + "><TR><TD>")};
	add ("<FORM METHOD=POST ACTION=\"" + openURL + "\">");
	add ("<TABLE BORDER=0>");
	add ("<TR><TD ALIGN=LEFT COLSPAN=2>");
	if (basePath != "") {
		bundle { << show folder name
			add ((file.fileFromPath (basePath) - pathChar) + "<BR>")}}
		<<bundle << show full path
			<<add ("<FONT SIZE=-1>" + basePath + "</FONT><BR>")
		<<bundle << as pop-up list
			<<add ("<SELECT SIZE=1>")
			<<for i = 1 to string.countFields (basePath, pathChar)
				<<if (i == string.countFields (basePath, pathChar))
					<<add ("<OPTION SELECTED>" + string.nthField (basePath, pathChar, i))
				<<else
					<<add ("<OPTION>" + string.nthField (basePath, pathChar, i))
			<<add ("</SELECT><BR>")
		<<bundle << show as hierarchy
			<<add ("<FONT SIZE=-1>")
			<<for i = 1 to string.countFields (basePath, pathChar)
				<<add (string.filledString (" ", 2* (i - 1)) + string.nthField (basePath, pathChar, i) + "<BR>")
			<<add ("</FONT>")
	else {
		add ("Select a volume<BR>")};
	add ("</TD></TR>");
	add ("<TR><TD VALIGN=TOP ALIGN=CENTER>");
	add ("<SELECT NAME=\"" + fieldname + "\" SIZE=7>");
	if (basePath != rootPath) {
		add ("<OPTION VALUE=\"" + file.folderFromPath (basePath) + "\">[up a level]")};
	fileloop (fname in basePath) {
		if !file.isVisible (fname) {
			continue};
		if file.isFolder (fname) {
			add ("<OPTION VALUE=\"" + fname +"\">" +  (file.fileFromPath (fname) - ":"))}};
	add ("</SELECT>");
	add ("</TD>");
	add ("<TD VALIGN=TOP ALIGN=CENTER>");
	if (basePath != "") {
		add ("<B>" + (file.volumeFromPath (basePath) - pathChar) +  "</B><BR>");
		add ("<HR SIZE=1>")};
	add ("<INPUT TYPE=BUTTON VALUE=\"Cancel\" onClick=\"location='" +  cancelURL + "';\"><BR>");
	add ("<INPUT TYPE=SUBMIT VALUE=\"Open\">");
	add ("</TD></TR>");
	add ("</TABLE>");
	add ("</FORM>");
	if (basePath != "") {
		add ("<TR><TD COLSPAN=2 ALIGN=CENTER>");
		add ("<FORM METHOD=POST ACTION=\"" + selectURL + "\">");
		add ("<INPUT TYPE=HIDDEN NAME=\"" + fieldname + "\" VALUE=\"" + basePath + "\">");
		add ("<INPUT TYPE=SUBMIT VALUE=\"Select " + (file.fileFromPath (basePath) - pathChar) + "\">");
		add ("</FORM>");
		add ("</TD></TR>")};
	add ("</TD></TR></TABLE>");
	return (htmltext)}



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.