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

system.verbs.builtins.mainResponder.discuss.newMessageForm

on newMessageForm (inResponseTo=0, subject="", subjectprompt=nil, buttontext=nil, redirectUrl=nil, flShowFileUpload=false, fileprompt=nil, bodyprompt=nil, actionURL="", pta=nil, flEditableSubject=true, bodyText="", flLimitSubjectLength=true) {
	<<Changes:
		<<2/3/04; 4:46:08 PM by JES
			<<Small formatting fix when the WYSIWYG editor is enabled, but the client doesn't support it.
		<<8/22/03; 12:55:26 PM by JES
			<<Slight formatting fix when not using the WYSIWYG editor.
		<<8/15/03; 3:29:16 PM by JES
			<<Added support for Mozilla's rich text editor.
		<<9/13/01; 2:07:45 PM by PBS
			<<New optional parameter flLimitSubjectLength. Default is true, previous behavior. No breakage. If false, then there's no maxLength attribute for the subject input field. Manila needed this.
		<<05/30/01; 11:20:22 PM by JES
			<<New optional parameter: bodyText, allows an app to set the default body of a new message. Manila uses this to give the user a second shot at adding a message when they forgot to enter a subject.
		<<2000:
			<<4/12/00; 1:08:45 PM by JES
				<<Localized using mainResponder.getString
			<<02/15/00; 11:15:48 AM by PBS
				<<Add the HTML Editor to the new message form if its not turned off and the user is running a compatible browser.
			<<10/02/00; 6:03:52 PM by JES
				<<Added WYSIWYG HTML editor.
			<<10/03/00; 2:38:30 PM by PBS
				<<Support a choice of editors -- none, HTML Tags, WYSIWYG.
			<<10/09/00; 6:25:39 PM by JES
				<<New optional parameter: flEditableSubject, determines whether the user gets a subject field to edit or not.
		<<1999:
			<<Wed, 20 May 1999 6:58:21 GMT by DW
				<<Added optional param, redirectUrl. If it is not nil, add a hidden field containing the URL, so the form can redirect to a more relevant place. 
			<<Thu, 20 May 1999 16:03:20 GMT by AR
				<<Added optional parameter, flShowFileUpload. It defaults to false. If true, a form element of type=file is displayed between the <textarea> and the submit button.
				<<Added optional parameter, fileprompt. It defaults to "Attach file". It's used as the label for the optional type=file form element.
			<<Fri, 21 May 1999 11:55:12 GMT by AR
				<<Added optional bodyprompt parameter, similar to subjectprompt and fileprompt.
				<<Added optional actionURL parameter to set the form action URL. If its value is the empty string (the default), we use pta^.responderattributes.urls^.discussPostMessage.
			<<5/22/99; 9:08:21 PM by DW
				<<Moved the fileUpload part after the subject, I want every new message form to begin with the subject prompt. Consistency counts!
			<<Mon, Aug 2, 1999 at 3:54:26 PM by PBS
				<<New optional pta parameter.
			<<9/23/99; 11:44:24 AM by PBS
				<<Encode quotes in the subject as " HTML entities so the value attribute in the input box doesn't terminate prematurely. In other words:
				<<The tag might look like this:
				<<<input size="40" maxlength="60" name="subject" value="Re: "Foo" bar">
				<<Now it looks like this:
				<<<input size="40" maxlength="60" name="subject" value="Re: "Foo" bar">
				<<This is safe to do because the entity will be translated back into an actual quote. You don't end up with HTML entities in the subject field of the stored dg message, you get actual quote marks, as you should.
	
	if pta == nil {
		pta = html.getPageTableAddress ()};
	
	local (flWysEditor = false, flTagEditor = true);
	bundle { //figure out which editing tool is preferred
		if defined (pta^.editingToolName) {
			if string.lower (pta^.editingToolName) == "wysiwyg" {
				flWysEditor = true;
				flTagEditor = false}}};
	
	local (htmltext = "", indentlevel = 0);
	on add (s) {
		htmltext = htmltext + string.filledString ("\t", indentlevel) + s + "\r"};
	local (enctypeAttrib = "");
	if flShowFileUpload {
		enctypeAttrib = " enctype=\"multipart/form-data\""};
	if actionURL == "" {
		actionURL = pta^.responderattributes.urls^.discussPostMessage};
	
	local (editorText = mainResponder.discuss.getHtmlEditor (bodyText, pta, fieldName:"text"));
	
	if (editorText == "") or (flTagEditor) {
		add ("<form method=\"POST\"" + enctypeAttrib + " action=\"" + actionURL + "\">"); indentlevel++}
	else { //WYSIWYG editor
		try {
			local (enctype = nil);
			if flShowFileUpload {
				enctype = "multipart/form-data"};
			add (html.editor.formStart ("text", actionURL, "editMessageForm", enctype:enctype, pta:pta))}
		else {
			add ("<form name=\"editMessageForm\" method=\"POST\"" + enctypeAttrib + " action=\"" + actionURL + "\" onsubmit=\"setMode(true);document.editMessageForm.text.value = document.frames('idEdit').document.body.innerHTML\">"); indentLevel++;
			add ("<input type=\"hidden\" name=\"text\">")}};
	add ("<input type=\"hidden\" name=\"inResponseTo\" value=\"" + inResponseTo + "\">");
	if redirectUrl != nil {
		add ("<input type=\"hidden\" name=\"redirect\" value=\"" + redirectUrl + "\">")};
	
	<<bundle // old code
		<<subject = string.replaceAll (subject, "\"", """) //PBS 9/23/99: turn quotes into HTML entities
		<<if subjectprompt == nil //4/12/00; 1:11:55 PM by JES: localize default subjectprompt
			<<subjectprompt = mainResponder.getString ("discuss.responseSubjectPrompt")
		<<add ("<b>" + subjectprompt + "</b><br><input size=\"40\" maxlength=\"60\" name=\"subject\" value=\"" + subject + "\"><p>")
	if flEditableSubject { // 10/09/00 JES
		subject = string.replaceAll (subject, "\"", """); //PBS 9/23/99: turn quotes into HTML entities
		if subjectprompt == nil { //4/12/00; 1:11:55 PM by JES: localize default subjectprompt
			subjectprompt = mainResponder.getString ("discuss.responseSubjectPrompt")};
		if flLimitSubjectLength { //PBS 09/13/01: support for no maxLength in subject field
			add ("<b>" + subjectprompt + "</b><br><input size=\"40\" maxlength=\"60\" name=\"subject\" value=\"" + subject + "\"><p>")}
		else {
			add ("<b>" + subjectprompt + "</b><br><input size=\"40\" name=\"subject\" value=\"" + subject + "\"><p>")}}
	else { // add the subject as a hidden field
		add ("<input type=\"hidden\" name=\"subject\" value=\"" + subject + "\">")};
	if flShowFileUpload {
		if fileprompt == nil { //4/12/00; 1:17:20 PM by JES: localize default fileprompt
			fileprompt = mainResponder.getString ("discuss.attachFilePrompt")};
		add ("<b>" + fileprompt + "</b><br><input type=\"file\" name=\"attachfile\"><p>")};
	
	<<PBS 02/15/00: possibly add the HTML editor buttons and menus.
	if bodyprompt == nil { //4/12/00; 1:15:56 PM by JES: localized default bodyprompt
		bodyprompt = mainResponder.getString ("discuss.messageTextPrompt")};
	if editorText == "" {
		add ("<b>" + bodyprompt + "</b><br><textarea name=\"text\" rows=\"12\" cols=\"70\" wrap=\"soft\">" + bodyText + "</textarea><p>")}
	else { //add the HTML editor.
		if flTagEditor { //classic HTML tag editor
			add ("<b>" + bodyPrompt + "</b><p>" + editorText + "<p>")} //<textarea name=\"text\" rows=\"12\" cols=\"70\" wrap=\"soft\" style=\"padding:7px\">" + bodyText + "</textarea><p>")
		else { //WYSIWYG
			add ("<b>" + bodyprompt + "</b><br>" + editorText + "<p>")}};
	
	if buttontext == nil { //4/12/00; 1:10:09 PM by JES: localized default buttontext
		buttontext = mainResponder.getString ("discuss.postResponseButtonText")};
	add ("<input type=\"submit\" value=\"" + buttontext + "\">");
	add ("</form>"); indentlevel--;
	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.