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

system.verbs.builtins.radio.userInterface.categoryCheckboxes

on categoryCheckboxes (adrdata, adrpost, bgcolor=radio.data.htmlColors.cellBgColor) {
	<<Changes:
		<<2/4/02; 3:38:04 PM by JES
			<<Changed the mag-glass to a New link.
		<<12/10/01; 1:51:43 PM by JES
			<<Localized.
		<<11/7/01; 1:06:18 PM by DW
			<<Changed the Edit button to a spyglass and moved it adjacent to the word "Categories" to make its purpose more clear.
		<<10/29/01; 5:01:42 PM by JES
			<<Added optional parameter, bgcolor.
		<<10/29/01; 12:29:11 PM by DW
			<<Add an EDIT button to the category checkboxes, linked to the Categories page. 
		<<10/28/01; 9:22:20 AM by DW
			<<Change cellspacing on table to 0 to tighten up the display of categories on the "Status Center" home page.
		<<10/9/01; 5:05:32 PM by JES
			<<Add categories to posts in radio.macros.weblogPostForm, instead of here. This fixes a bug where categories could not be added for new posts.
		<<8/30/01; 4:42:33 AM by JES
			<<Adapted to work with data stored at @weblogData^, and with the weblog posting form script at radio.macros.weblogPostForm.
	local (pta = html.getPageTableAddress ());
	local (htmltext, indentlevel = 0);
	on add (s) {
		htmltext = htmltext + string.filledstring ("\t", indentlevel) + s + "\r\n"};
	<<if pta^.method == "POST"
		<<workspace.pt = pta^; edit (@workspace.pt)
		<<on addCatsTo (adrpost)
			<<local (adrarg, name, adrcats = @adrpost^.categories)
			<<if defined (adrcats^)
				<<local (adr)
				<<local (id = number (nameof (adrpost^)))
				<<for adr in @adrdata^.categories
					<<if adr^.storyList contains id
						<<adr^.storyList = adr^.storyList - {id}
						<<adr^.flDirty = true
				<<delete (adrcats)
			<<for adrarg in @pta^.radioResponder.postArgs
				<<name = nameof (adrarg^)
				<<if name beginswith "cat:"
					<<local (catname = string.nthfield (name, ":", 2))
					<<if not defined (adrcats^)
						<<new (tabletype, adrcats)
					<<adrcats^.[catname] = true
			<<bundle //see which RSS files need to be rebuilt
				<<local (adr)
				<<for adr in @adrdata^.categories
					<<local (fldirty = false)
					<<local (id = number (nameof (adrpost^)))
					<<if defined (adrcats^.[nameof (adr^)]) //it's part of the category
						<<if not (adr^.storyList contains id)
							<<adr^.storyList = adr^.storyList + {id}
							<<fldirty = true
					<<else //it's not part of the category
						<<if adr^.storyList contains id
							<<adr^.storyList = adr^.storyList - {id}
							<<fldirty = true
					<<if fldirty //don't clear it here
						<<adr^.flDirty = true
						<<system.temp.radio.flPublishCategoryRss = true
		<<if adrpost != nil
			<<addCatsTo (adrpost)
	if adrdata^.prefs.flCategoryCheckboxes {
		<<bundle //Edit/Create buttons version
			<<local (editbuttonimg = radio.images.systemImageRef ("icons/edit2", flFileUrl:pta^.radioResponder.flSameMachine))
			<<local (createbuttonimg = radio.images.systemImageRef ("icons/create", flFileUrl:pta^.radioResponder.flSameMachine))
			<<local (editbuttontext = "<a href=\"" + radio.data.systemUrls.categories + "\" title=\"" + radio.string.getlocalizedstring ("weblogPostForm.editCategoryToolTip") + "\">" + editbuttonimg + "</a>")
			<<local (createbuttontext = "<a href=\"" + radio.data.systemUrls.newCategory + "?referer=" + string.urlEncode ("http://" + pta^.host + pta^.uri) + "\" title=\"" + radio.string.getlocalizedstring ("weblogPostForm.createCategoryToolTip") + "\">" + createbuttonimg + "</a>")
			<<add ("<table style=\"padding-top:4\" cellspacing=\"0\" border=\"0\"><tr><td valign=\"middle\" class=\"small\"><b>" + radio.string.getlocalizedstring ("weblogPostForm.categoriesPrompt") + "</b></td><td>  " + editbuttontext + " " + createbuttontext + "</td></tr></table>")
		<<local (spyglassimg = radio.images.systemImageRef ("qbullet/search", flFileUrl:pta^.radioResponder.flSameMachine))
		<<local (spyglasstext = "<a href=\"" + radio.data.systemUrls.categories + "\" title=\"" + radio.string.getlocalizedstring ("weblogPostForm.categorySpyglassToolTip") + "\">" + spyglassimg + "</a>")
		local (newurl);
		bundle { //get newurl
			local (args);
			new (tabletype, @args);
			args.referer = "http://" + pta^.host + pta^.uri;
			newurl = radio.data.systemUrls.newCategory + "?" + webserver.encodeargs (@args)};
		local (newlink = "<a href=\"" + newurl + "\" title=\"" + radio.string.getlocalizedstring ("weblogPostForm.newCategoryLinkToolTip") + "\">" + radio.string.getlocalizedstring ("weblogPostForm.newCategoryLinkText") + "</a>");
		add ("<div class=\"small\"><b>" + radio.string.getlocalizedstring ("weblogPostForm.categoriesPrompt") + "</b> (" + newlink + ")<br></div>");
		add ("<table cellpadding=\"0\" cellspacing=\"5\" border=\"0\">"); indentlevel++;
		add ("<tr><td>"); indentlevel++;
		add ("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"); indentlevel++;
		add ("<tr>"); indentlevel++;
		add ("<td><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"); indentlevel++;
		add (radio.html.addCategoryCheckboxes (adrdata, adrpost, bgcolor));
		add ("</td></table>"); indentlevel--;
		<<add ("<td valign=\"bottom\"><div class=\"small\"><b>     " + spyglasstext + "</b></div></td>")
		add ("</tr>"); indentlevel--;
		add ("</table>"); indentlevel--;
		add ("</td></tr>"); indentlevel++;
		add ("</table>"); indentlevel--};
	return (htmltext)}
<<bundle //testing
	<<local (adrdata = radio.weblog.init ())
	<<local (adrpost = @adrdata^.posts.["00000008"])
	<<categoryCheckboxes (adrdata, adrpost)



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.