0byt3m1n1
Path:
C:
/
Program Files (x86)
/
Microsoft Office
/
Office12
/
Groove
/
ToolData
/
groove.net
/
GrooveForms
/
[
Home
]
File: SUBMIT.JS
// Global variables. var g_RecordID = null; var g_Record = null; var g_SelectedID = null; var g_ModifyRecord = false; var g_ElementsEnabled = true; var g_IsPreviewLayout = false; var g_IsPreviewPane = false; var g_IsLayout = false; var g_IsSearch = false; var g_IsNewRecord = false; var g_IsResponse = false; var g_HasDesignChanged = false; var g_NoEdit = false; var g_CreateAnother = false; var g_objDispatch = getScriptDispatch(); var g_arrRichText = new Array(); var g_AttachmentsElement = null; var g_AttachmentsObject = null; var g_Initialized = false; // Capture keydown and contextmenu events for the document. document.onkeydown = keyDownEvent; document.oncontextmenu = contextMenuEvent; // === keyDownEvent() ============== // event handler for key down action function keyDownEvent() { // Return false for backspace key, otherwise do nothing. var intKeyCode = event.keyCode; var objElement = event.srcElement; var strTagName = objElement.tagName; // Only allow backspace for <input type=text>, <input type=password> and <textarea> objects. var blnNoBackspace = true; if (strTagName == "TEXTAREA" || (strTagName == "INPUT" && (objElement.type == "text" || objElement.type == "password"))) blnNoBackspace = false; // Capture Backspace, Ctrl+N, and Ctrl+P keystrokes to disable them. if (intKeyCode == 8 && blnNoBackspace || (event.ctrlKey && (intKeyCode == 78 || intKeyCode == 80))) event.returnValue = false; } // === contextMenuEvent() ============== // event handler for context menu action function contextMenuEvent() { // Right-click context menu will only appear if 'Ctrl' key is held down. if (!event.ctrlKey) event.returnValue = false; } // === GrooveField(string, string) ============ // object used to define each field in the form function GrooveField(i_Name, i_Value) { this.name = i_Name; this.value = i_Value; } // === GrooveElement(string, object) ======================= // object used to defined each object type field in the form function GrooveElement(i_Name, i_Element) { this.name = i_Name; this.element = i_Element; } // === getMultiValue(object, string) ============== // get the string value from a multiselect list box function getMultiValue(i_objForm, i_strName) { var strResult = ""; for (var i = 0; i < i_objForm.elements[i_strName].length; i++) { if (i_objForm.elements[i_strName].options[i].selected) { if (i_objForm.elements[i_strName].options[i].value != "") strResult += i_objForm.elements[i_strName].options[i].value + ","; else strResult += i_objForm.elements[i_strName].options[i].text + ","; } } return strResult.substr(0, (strResult.length) - 1); } // === initBackground() ========================================= // set the form background image from attributes on the style tag function initBackground() { var objFormTheme = document.getElementById("grooveFormTheme"); if (objFormTheme) { var strBasePath = g_objDispatch.GetBasePath(); var strImage = objFormTheme.getAttribute("IMAGE"); var strRepeat = objFormTheme.getAttribute("REPEAT"); var strAttachment = objFormTheme.getAttribute("ATTACHMENT"); var strPosition = objFormTheme.getAttribute("POSITION"); if (strImage != null) document.body.style.backgroundImage = "url(" + strBasePath + strImage + ")"; if (strRepeat != null) document.body.style.backgroundRepeat = strRepeat; if (strAttachment != null) document.body.style.backgroundAttachment = strAttachment; if (strPosition != null) document.body.style.backgroundPosition = strPosition; } } // === initSystemFields(bool) ====================== // set the values of the system fields if they exist function initSystemFields(i_blnNew) { var divAuthor = document.getElementById("_SystemAuthor"); var divCreated = document.getElementById("_SystemCreated"); var divModified = document.getElementById("_SystemModified"); if (!g_IsPreviewLayout) { if (!i_blnNew && (typeof g_Record == "string" || g_Record == null)) return; if (divAuthor) { divAuthor.style.fontWeight = "bold"; divAuthor.style.fontStyle = "italic"; if (i_blnNew) divAuthor.innerText = g_objDispatch.GetCurrentAuthorName(); else divAuthor.innerText = g_objDispatch.GetAuthorNameFromRecord(g_Record); } if (divCreated) { divCreated.style.fontWeight = "bold"; divCreated.style.fontStyle = "italic"; if (i_blnNew) divCreated.innerText = g_objDispatch.GetFormattedDate(new Date().valueOf()); else { if (g_Record.HasField("_Created")) divCreated.innerText = g_objDispatch.GetFormattedDate(g_Record.OpenField("_Created")); } } if (divModified) { divModified.style.fontWeight = "bold"; divModified.style.fontStyle = "italic"; if (i_blnNew) divModified.innerText = g_objDispatch.GetFormattedDate(new Date().valueOf()); else { if (g_Record.HasField("_Modified")) divModified.innerText = g_objDispatch.GetFormattedDate(g_Record.OpenField("_Modified")); } } } else if (g_IsSearch) { if (divAuthor) divAuthor.innerHTML = "<INPUT TYPE=\"text\" NAME=\"_CreatedBy\" />"; if (divCreated) divCreated.innerHTML = "<SPAN NAME=\"_Created\" FormatDateShortFormat=\"M/d/yyyy\"><INPUT TYPE=\"text\" NAME=\"_Created\" DataType=\"Date\" /><BUTTON ONCLICK=\"doCalendar(this)\" STYLE=\"margin-left:5px; width:100px;\" CLASS=\"button\">Calendar...</BUTTON></SPAN>"; if (divModified) divModified.innerHTML = "<SPAN NAME=\"_Modified\" FormatDateShortFormat=\"M/d/yyyy\"><INPUT TYPE=\"text\" NAME=\"_Modified\" DataType=\"Date\" /><BUTTON ONCLICK=\"doCalendar(this)\" STYLE=\"margin-left:5px; width:100px;\" CLASS=\"button\">Calendar...</BUTTON></SPAN>"; } } // === initFormPage(integer) ========== // called when page is finished loading function initFormPage(i_RecordID) { if (g_objDispatch == null) return false; // Set the background of the window according to the theme chosen. initBackground(); // Enable all of the form elements on the page. disableFormElements(false); // Get base form for use throughout the function. var DocumentForm = getDocumentForm(); // Clean up the form elements for display. if (typeof i_RecordID == "undefined") cleanUpFormElements(); if (window.location.search != "") { if (typeof i_RecordID != "undefined") { g_RecordID = i_RecordID; } else { // Get global variables from the documents querystring. getQueryStringVariables(); } // Hide the print button if professional license does not exist. if (!g_IsPreviewLayout && typeof DocumentForm.PrintButton != "undefined" && typeof DocumentForm.PrintButton.style != "undefined" && !g_objDispatch.DoesGrooveStandardLicenseExistFromAccount(g_objDispatch.g_Account)) DocumentForm.PrintButton.style.display = "none"; // Check early on to see if this is a response and if so, if it is valid to create a response if (g_IsResponse && !g_IsPreviewPane) { // First check to see if we have a record which has been highlighted and if not, error out and go back to home.... if (g_SelectedID == "-1" || g_objDispatch.GetRecordByRecordID(g_SelectedID) == null) { g_objDispatch.OKMessageBox("You must select a valid parent document in order to create a response.", "Invalid Selection"); g_objDispatch.LoadHomePage(); return; } // Will add the following to R3 of Forms based on new UI choices /* // Second, check to see if the record selected is also a response. If it is, we can put up a warning as well since in most // cases responses will not be allowed to responses. if (g_SelectedID != -1) { // get the selected record. var SelectedFormURL = g_objDispatch.GetFormUrlByRecordID(g_SelectedID); var BindableFormURL = String(window.location.href); if (BindableFormURL.indexOf("?") >= 0) BindableFormURL = BindableFormURL.substring(0, BindableFormURL.indexOf("?")); var ThisFormURL = BindableFormURL; // Normalize the urls by converting to lowercase for comparison if (SelectedFormURL.toLowerCase() == ThisFormURL.toLowerCase()) { g_objDispatch.OKMessageBox("You must select a valid parent document in order to create a response. You have a response selected.", "Invalid Selection"); g_objDispatch.LoadHomePage(); return; } } */ } // Pass out document to be used by glue code. if (g_IsPreviewPane) g_objDispatch.SetCurrentPreviewDocument(document); // Hide or show the submit buttons depending on what the user is doing. if ((g_IsPreviewLayout && !g_IsLayout) || g_IsPreviewPane) document.getElementById("SubmitBase").style.display = "none"; // Set forms glue global variable for command bar. if (!g_IsPreviewPane && !g_IsPreviewLayout) g_objDispatch.SetOnFormPage(true); if (g_IsSearch) { // Display values of system fields on form. initSystemFields(true); // If it is a search form, blank out all values. clearAllFormValues(true); } else if (g_RecordID) { // Get the record from the record id that was passed in. g_Record = g_objDispatch.GetRecordByRecordID(g_RecordID); // If it is a search form, blank out all values. clearAllFormValues(false); // Set-up the form with the values stored in the record. initFormWithRecord(g_Record, false); } else { // Display values of system fields on form. initSystemFields(true); // Create a new record if there is no record id. if (!g_IsLayout && !g_IsPreviewLayout) createNewRecord(); // Set-up the form with the values stored in the record. initFormWithRecord(g_Record, true); } } else { // Hide the print button if professional license does not exist. if (typeof DocumentForm.PrintButton != "undefined" && typeof DocumentForm.PrintButton.style != "undefined" && !g_objDispatch.DoesGrooveStandardLicenseExistFromAccount(g_objDispatch.g_Account)) DocumentForm.PrintButton.style.display = "none"; // Show the Save, Reset, and Cancel buttons. document.getElementById("SubmitBase").style.display = "block"; // Set forms glue global variable for command bar. g_objDispatch.SetOnFormPage(true); // Display values of system fields on form. initSystemFields(true); // Create a new record if there is no querystring. createNewRecord(); } // Disable the form elements if they are supposed to be. disableFormElements(true); // Set-up some specialized fields and set focus to first form element. if (!g_IsPreviewLayout) setupSpecializedFields(); if (!g_NoEdit) { // Make the 'Save and Create Another' button visible if supported. var objTdApplyButton = document.getElementById("tdApplyButton"); if (objTdApplyButton != null) objTdApplyButton.style.display = "block"; } // Make the 'Print' button visible if supported. var objTdPrintButton = document.getElementById("tdPrintButton"); if (objTdPrintButton != null) objTdPrintButton.style.display = "block"; try { CustomInitialize(); } catch (error) { } g_Initialized = true; } // === terminateFormPage() =============================== // called when the form is unloaded, for script developers function terminateFormPage() { // Set forms glue global variable for command bar. g_objDispatch.SetOnFormPage(false); try { CustomTerminate(); } catch (error) { } } // === submitData() ================================= // called when user wants to save form data as record function submitData() { if (g_IsLayout) return false; var DocumentForm = getDocumentForm(); // Blur all of the elements to check their validation. for (var i = 0 ; i < DocumentForm.length; i++) { DocumentForm.elements[i].fireEvent("onblur"); } // Check error array to see if there are still uncorrected errors. for (var i = 0; i < g_arrError.length; i++) { if (typeof g_arrError[i] != "undefined") { window.setTimeout("g_objDispatch.OKMessageBox('The form values you have entered are not valid. Please correct the error as displayed in the form.', 'Invalid Form Values')", 10); g_CreateAnother = false; return false; } } // This routine submits the form data to Groove. var FieldStringEnum = new Array(); var FieldElementEnum = new Array(); var FieldCount = 0; var lastobjname = ""; for (var i = 0; i < DocumentForm.length; i++) { var DocumentElement = DocumentForm.elements[i]; if (DocumentElement.type == "text" || DocumentElement.type == "password" || DocumentElement.type == "textarea") { var ElementValue = DocumentElement.value; var ElementName = DocumentElement.name; var strDataType = DocumentElement.getAttribute("DataType"); if (strDataType != null && strDataType == "Numeric") { ElementName = ElementName + "|~|Numeric"; if (ElementValue != "") ElementValue = getValidNumber(ElementValue); } else if (strDataType != null && strDataType == "Date") { var strParentName = DocumentElement.parentElement.getAttribute("NAME"); if (strParentName != null) ElementName = strParentName + "|~|Date"; var intDateFormat = g_objDispatch.GrooveIntlDateFormatStyle_Short; var strDateFormat = DocumentElement.parentElement.getAttribute("FormatDateShortFormat"); if (strDateFormat == null || strDateFormat == "") { strDateFormat = DocumentElement.parentElement.getAttribute("FormatDateLongFormat"); intDateFormat = g_objDispatch.GrooveIntlDateFormatStyle_Full; } if (ElementValue != "") { var ElementDate = new Date(getValidDateMillis(ElementValue, strDateFormat, intDateFormat)); if (!isNaN(ElementDate)) { if (!g_IsPreviewLayout && ElementDate.getHours() == 0 && ElementDate.getMinutes() == 0 && ElementDate.getSeconds() == 0) ElementDate.setHours(12, 0, 0); ElementValue = ElementDate.valueOf(); } else ElementValue = ""; } } else ElementName = ElementName + "|~|String"; FieldStringEnum[FieldCount] = new GrooveField(ElementName, ElementValue); FieldCount++; } else if (DocumentElement.type == "select-one") { if (DocumentElement.selectedIndex >= 0) { var objname = DocumentElement.name; var objvalue = DocumentElement.options[DocumentElement.selectedIndex].value; FieldStringEnum[FieldCount] = new GrooveField(objname, objvalue); FieldCount++; } } else if (DocumentElement.type == "select-multiple") { if (DocumentElement.selectedIndex >= 0) { var multobjname = DocumentElement.name; var multobjvalue = getMultiValue(DocumentForm, multobjname); FieldStringEnum[FieldCount] = new GrooveField(multobjname, multobjvalue); FieldCount++; } } else if (DocumentElement.type == "radio") { var radioobjname = DocumentElement.name; var selectedIndex = null; if (lastobjname != radioobjname) { var radiogroup = DocumentForm.elements[radioobjname]; for (var j = 0; j < radiogroup.length; j++) { if (radiogroup[j].checked) selectedIndex = j; } if (selectedIndex != null) { FieldStringEnum[FieldCount] = new GrooveField(radioobjname, radiogroup[selectedIndex].value); FieldCount++; } lastobjname = radioobjname; } } else if (DocumentElement.type == "checkbox") { var checkobjname = DocumentElement.name; if (DocumentForm.elements[checkobjname].checked) { // The checkbox is checked, return a value ('on' by default) if it exists. if (DocumentElement.value == "on") FieldStringEnum[FieldCount] = new GrooveField(checkobjname, "true"); else FieldStringEnum[FieldCount] = new GrooveField(checkobjname, DocumentElement.value); FieldCount++; } else { // The checkbox is not checked, return null string. FieldStringEnum[FieldCount] = new GrooveField(checkobjname, ""); FieldCount++; } } } if (g_IsResponse) { FieldStringEnum[FieldCount] = new GrooveField("_ParentID"+ "|~|Numeric", g_SelectedID); FieldCount++; } if (g_AttachmentsObject && !g_IsSearch) { var count = g_objDispatch.GetAttachmentCount(g_AttachmentsElement); FieldStringEnum[FieldCount] = new GrooveField("FileIcon" + "|~|Long", count > 0 ? 1 : 0); FieldCount++; } // Submit the values for groove objects (usually rich text) on the page. for (var i = 0; i < g_arrRichText.length; i++) { if (g_IsSearch) { // If this is a search, get the plain text out of the rich text object. var PlainText = getPlainText(g_arrRichText[i]); PlainText = PlainText.replace(/^\s*/, ""); PlainText = PlainText.replace(/\s*$/, ""); // Need to add a carriage return to the end of the string because the RTF component // adds one by default so when we search there will always be a carriage return in the // collection. if (PlainText != "") { //PlainText = PlainText + "\n"; FieldStringEnum[FieldCount] = new GrooveField(g_arrRichText[i].getAttribute("Name"), PlainText); FieldCount++; } } else { // If this is a form, get the rich text element out of the rich text object. var TempElement = g_objDispatch.GetRichTextElement(); g_arrRichText[i].CellContent.WriteContentToElement(TempElement); FieldElementEnum[i] = new GrooveElement(g_arrRichText[i].getAttribute("Name"), TempElement); } } // We can NEVER store bindable URLs. They don't work cross device // Therefore we need to get the canonical url from the bindable url. // We will need to do the reverse when we need to bind the other way. var BindableFormURL = String(window.location.href); if (BindableFormURL.indexOf("?") >= 0) BindableFormURL = BindableFormURL.substring(0, BindableFormURL.indexOf("?")); var CanonicalFormURL = g_objDispatch.GetCanonicalURL(BindableFormURL); var FormName = CanonicalFormURL; var AttachmentsFieldName = ""; if (g_AttachmentsObject) AttachmentsFieldName = g_AttachmentsObject.getAttribute("id"); // here is where you put the call to pass the array fieldstringenum back to groove if (g_IsSearch) g_objDispatch.Search(FieldStringEnum); else if (g_IsNewRecord) g_objDispatch.AddRecord(FieldStringEnum, FormName, g_Record, FieldElementEnum, AttachmentsFieldName, g_AttachmentsElement); else if (g_ModifyRecord) g_objDispatch.ModifyRecord(FieldStringEnum, FormName, g_RecordID, FieldElementEnum, AttachmentsFieldName, g_AttachmentsElement); else g_objDispatch.SubmitData(FieldStringEnum, FormName, FieldElementEnum); if (!g_IsSearch && !g_CreateAnother) { g_objDispatch.LoadHomePage(); g_objDispatch.ShowUICommands(true); } else if (g_CreateAnother) { var strHref = location.href; strHref = strHref.replace(/(.*)\?.*$/, "$1"); if (g_SelectedID != null) strHref = strHref + "?SelectedID=" + g_SelectedID; else { // Check to see if it is a response record, if the current record is not new. var strFormType = document.body.getAttribute("FormType"); if (strFormType != null && strFormType == "Response") { // If it is a response, get the parent id and pass it along. if (g_Record != null && g_Record.HasField("_ParentID")) { var strParentID = g_Record.OpenFieldAsDouble("_ParentID"); strHref += "?SelectedID=" + strParentID; } } } window.location.href = strHref; } else return true; } // === saveAndCreateAnother() ================================ // celled when user presses the save and create another button function saveAndCreateAnother() { g_CreateAnother = true; submitData(); } // === resetData() ========================= // called when user presses the reset button function resetData() { if (!g_IsPreviewLayout) location.reload(true); } // === cancelEdit()========================== // called when user presses the cancel button function cancelEdit() { if (!g_IsPreviewLayout) { g_objDispatch.LoadHomePage(); g_objDispatch.ShowUICommands(true); } } // === DoSearch() ======================================= // called from within the search window to submit a query function DoSearch() { g_IsSearch = true; return submitData(); } // === getPlainText(object) ====================== // retrieve the plain text from a rich text object function getPlainText(i_TextView) { // prepare for direct TOM access i_TextView.Freeze(true); i_TextView.HideDecorations(true); // retrieve TOM document var TextCache = i_TextView.TextCache; var Document = TextCache.Document; // retrieve plain text var Range = Document.Range(0, 1073741823); // see "tom" typelib for tomForward var PlainText = Range.Text; // we're done accessing the TOM directly i_TextView.HideDecorations(false); TextCache.Synchronize(1); i_TextView.Freeze(false); // we're done! return PlainText; } // === addDocument() ============================================ // adds document to HTMLComponentBridge for object initialization function addDocument() { if (!g_IsPreviewLayout) g_AttachmentsElement = g_objDispatch.AddHTMLDocument(document, g_Record); } // === removeDocument() =========================================== // removes document from HTMLComponentBridge for object termination function removeDocument() { if (!g_IsPreviewLayout) g_objDispatch.RemoveHTMLDocument(document); } // === addNewOption(object) ============== // add a custom option to a drop-down list function addNewOption(i_objSelect) { var intSelected = i_objSelect.selectedIndex; if (i_objSelect.options[intSelected].value == "GrooveAddOption") { window.setTimeout("int_addNewOption('" + i_objSelect.name + "')", 10); } } // === int_addNewOption(string) ============================================ // had to create internal call so object was not held in case of form reload function int_addNewOption(i_strSelect) { try { var strOption = g_objDispatch.AddOptionDialog("Enter the label for the new option:"); var objSelect = eval("getDocumentForm()." + i_strSelect); if (strOption != null && strOption != "") insertNewOption(objSelect, strOption); else objSelect.selectedIndex = 0; } catch (error) { var objError = new Error("There was an error adding the custom option to the drop-down list, most likely caused by the form reloading in response to a design change. Please try adding the custom option again."); g_objDispatch.DisplayError(objError); } } // === insertNewOption(object, string) ========================= // utility function to insert a new option into a select element function insertNewOption(i_objElement, i_strOption) { var objOptions = i_objElement.options; // Remove the "Custom..." option so the new one can be added at the end. if (objOptions.length > 1) { if (!g_IsSearch && objOptions[0].text == "" && objOptions[0].value == "") objOptions.remove(0); if (objOptions[objOptions.length - 1].value == "GrooveAddOption") objOptions.remove(objOptions.length - 1); } else if (objOptions.length == 1) { if (objOptions[0].value == "GrooveAddOption") objOptions.remove(0); } // Add the new option with the string input by the user. objOptions[objOptions.length] = new Option(i_strOption, i_strOption) // Add the "Custom..." option back in at the end of the list. objOptions[objOptions.length] = new Option("Custom...", "GrooveAddOption") // Select the new option in the list. i_objElement.selectedIndex = objOptions.length - 2; } // === addCustomOptionToElement(object) =================== // add the "Custom..." option to the end of a SELECT object function addCustomOptionToElement(i_objElement) { var objOptions = i_objElement.options; if (objOptions.length > 0) { if (objOptions[objOptions.length - 1].value != "GrooveAddOption") objOptions[objOptions.length] = new Option("Custom...", "GrooveAddOption"); } else { // Add a blank option so that a new on can be added. objOptions[objOptions.length] = new Option("", ""); objOptions[objOptions.length] = new Option("Custom...", "GrooveAddOption"); } } // === addEvent(object, string, string) =========== // utility function to add code to an objects event function addEvent(i_objInput, i_strEvent, i_strScript) { var strEvent = i_objInput.getAttribute(i_strEvent); if (strEvent == null) i_objInput.setAttribute(i_strEvent, ""); // Clean up passed in script in case it is messed up. i_strScript = i_strScript.replace(/^( )*/, ""); i_strScript = i_strScript.replace(/( )*$/, ""); if (i_strScript.charAt(i_strScript.length - 1) != ";" && i_strScript.charAt(i_strScript.length - 1) != "}") i_strScript = i_strScript + ";"; // If the event exists add to the current script, otherwise just add the new script. if (strEvent != null && strEvent != "") { var regEvent = new RegExp("\{\n(.*)\n\}", "i"); var arrEvent = regEvent.exec(strEvent); var strScript = RegExp.$1; var strFunction = i_strScript + " " + strScript; } else var strFunction = i_strScript; // Add the script to the object as an anonymous function. eval("i_objInput." + i_strEvent + " = new Function(strFunction);"); } // === eventHandlers ============================= // these functions handle events for form elements function onBlurHandler() { eventHandler("OnBlur"); } function onFocusHandler() { eventHandler("OnFocus"); } function onClickHandler() { eventHandler("OnClick"); } function onChangeHandler() { eventHandler("OnChange"); } function eventHandler(i_strEvent) { try { var objElement = event.srcElement; if (eval("typeof " + objElement.name + "_" + i_strEvent) != "undefined") eval(objElement.name + "_" + i_strEvent + "(objElement)"); } catch (error) {} } // ======================================================================== // === initFormPage break-out functions === // ======================================================================== // === initFormWithRecord(object, boolean) ================ // initialize the form with the values stored in the record function initFormWithRecord(i_Record, i_IsNew) { var DocumentForm = getDocumentForm(); if (typeof i_Record == "undefined" || i_Record == null) { if (g_IsPreviewLayout) return; else if (g_IsPreviewPane) { g_objDispatch.OKMessageBox("The record you have selected to preview has been deleted.", "Record Deleted"); var strBasePath = g_objDispatch.GetBasePath(); window.location.href = strBasePath + "FormsBlankPage.html"; } else { g_objDispatch.OKMessageBox("The record you have selected to edit has been deleted. You will be returned to the view.", "Record Deleted"); g_objDispatch.LoadHomePage(); } return; } if (!g_IsPreviewPane && !g_IsNewRecord) { // Mark the current record as read since it has been opened. g_objDispatch.MarkRecordRead(true); // Update submit and reset button labels for a current record. DocumentForm.SubmitButton.value = "Update"; DocumentForm.SubmitButton.title = "Save this updated record and show the data view"; DocumentForm.ResetButton.value = "Revert"; DocumentForm.ResetButton.title = "Revert to the previously saved field values for this record"; DocumentForm.CancelButton.title = "Close this record without saving any updates"; } // Display values of system fields on form. initSystemFields(false); if (!i_IsNew) { // Load the data from the name value enum into the form. var NameValueEnum = i_Record.OpenFieldNameValueEnum(); loadFormDataFromEnum(NameValueEnum); } if (g_NoEdit) { DocumentForm.SubmitButton.style.display = "none"; DocumentForm.ResetButton.style.display = "none"; for (var i = 0; i < DocumentForm.length; i++) { if (DocumentForm.elements[i].getAttribute("NAME") != "CancelButton" && DocumentForm.elements[i].getAttribute("NAME") != "PrintButton") DocumentForm.elements[i].disabled = true; } } // Make the attachments object read only if it is in the preview pane. if (g_AttachmentsObject) { if (g_IsPreviewPane) window.setTimeout("enableDocumentShare(true)", 10); else window.setTimeout("enableDocumentShare(false)", 10); } g_ModifyRecord = true; } // === disableFormElements(boolean) =================== // disable the form elements if they are supposed to be function disableFormElements(i_Disabled) { var DocumentForm = getDocumentForm(); for (var i = 0; i < DocumentForm.length; i++) { var DocumentElement = DocumentForm.elements[i]; // Disable the element if it is supposed to be. if (!g_ElementsEnabled) DocumentElement.disabled = i_Disabled; // Blank out combo-box so that the default value is not always selected. if (i_Disabled && !g_IsNewRecord && (DocumentElement.type == "select-one" || DocumentElement.type == "select-multiple")) { for (var j = 0; j < DocumentElement.options.length; j++) { DocumentElement.options[j].selected = false; } } } for (var i = 0; i < g_arrRichText.length; i++) { // Set the rich text fields to read only if they are supposed to be. if (!g_ElementsEnabled) g_arrRichText[i].ReadOnly = i_Disabled; } } // === loadFormDataFromEnum(object) ================= // load the data from a name/value enum into the form function loadFormDataFromEnum(i_NameValueEnum) { var DocumentForm = getDocumentForm(); var arrDates = document.getElementsByName("groove_date"); while (i_NameValueEnum.HasMore()) { var NameValuePair = i_NameValueEnum.OpenNextPair(); var strName = NameValuePair.First; var strValue = NameValuePair.Second; // Don't pass system field through as they are not used. // System field names begin with an underscore and a capital letter (i.e. "_Created"). if (strName.search(/^_[A-Z]/) == 0) continue; var arrElements = document.getElementsByName(strName); for (var i = 0; i < arrDates.length; i++) { var strParentName = arrDates[i].parentElement.getAttribute("NAME"); if (strParentName != null && strParentName == strName) { arrElements = new Array(arrDates[i]); break; } } for (var i = 0; i < arrElements.length; i++) { var DocumentElement = arrElements[i]; var ElementType = DocumentElement.type; if (ElementType == "text" || ElementType == "password" || ElementType == "textarea") { var strDataType = DocumentElement.getAttribute("DataType"); if (strDataType != null && strDataType == "Date") { if (strValue != 0) { var intDateFormat = g_objDispatch.GrooveIntlDateFormatStyle_Short; var strDateFormat = DocumentElement.parentElement.getAttribute("FormatDateShortFormat"); if (strDateFormat == null || strDateFormat == "") { strDateFormat = DocumentElement.parentElement.getAttribute("FormatDateLongFormat"); intDateFormat = g_objDispatch.GrooveIntlDateFormatStyle_Full; } DocumentElement.value = g_objDispatch.LocalFormatDate(parseInt(strValue), strDateFormat, intDateFormat); } else DocumentElement.value = ""; } else if (strDataType != null && strDataType == "Numeric") { DocumentElement.value = strValue; formatNumericFromDouble(DocumentElement); } else DocumentElement.value = strValue; // Fire the onblur event to format the value. if (g_ElementsEnabled || g_IsPreviewPane) DocumentElement.fireEvent("onblur"); } else if (ElementType == "checkbox") { if (strValue != "") DocumentElement.checked = true; else DocumentElement.checked = false; } else if (ElementType == "radio" && DocumentElement.value == strValue) { DocumentElement.checked = true; } else if (ElementType == "select-one") { var blnOptionFound = false; for (var j = 0; j < DocumentElement.options.length; j++) { if (DocumentElement.options[j].value == strValue) { DocumentElement.options[j].selected = true; blnOptionFound = true; } } var strCustom = DocumentElement.getAttribute("CUSTOM"); if (!blnOptionFound && strCustom != null && strCustom != "") insertNewOption(DocumentElement, strValue); } else if (ElementType == "select-multiple") { var MultipleArray = strValue.split(","); for (var j = 0; j < MultipleArray.length; j++) { for (var h = 0; h < DocumentElement.options.length; h++) { if (MultipleArray[j] == DocumentElement.options[h].value || (MultipleArray[j] == DocumentElement.options[h].text && DocumentElement.options[h].value == "")) DocumentElement.options[h].selected = true; } } } } } window.setTimeout("enableTextView()", 250); } // === enableTextView() ======================== // Fills in the data for the RTF fields function enableTextView() { for (var i = 0; i < g_arrRichText.length; i++) { // Preview the values for rich text objects on the page. var strName = g_arrRichText[i].getAttribute("Name"); if (strName != null && g_Record.HasField(strName)) { var RTFElement = g_Record.OpenFieldAsElement(strName); var RichTextObjectName = null; try { RichTextObjectName = g_arrRichText[i].IGrooveComponent.OpenName(); } catch (error) { } if (RichTextObjectName != null && RichTextObjectName != "") g_arrRichText[i].CellContent.ReadContentFromElement(RTFElement); else window.setTimeout("enableTextView()", 100); } } } // === enableDocumentShare() ======================== // set the read only mode for the document share view function enableDocumentShare(i_ReadOnly) { try { if (g_AttachmentsObject.Properties2.Initialized) { g_AttachmentsObject.Properties2.SetReadOnlyMode(i_ReadOnly); if (!i_ReadOnly) g_AttachmentsObject.Properties.SetIsDragDropTarget(true); } else window.setTimeout("enableDocumentShare(" + i_ReadOnly + ")", 10); } catch (error) { window.setTimeout("enableDocumentShare(" + i_ReadOnly + ")", 10); } } // === cleanUpFormElements() ====================================== // clean up and repair form elements before submitting data to them function cleanUpFormElements() { // Replace all instances of "'" with "'" in the form. if (document.body.hasChildNodes()) { var objChildren = document.body.childNodes; for (var i = 0; i < objChildren.length; i++) { var objChild = objChildren.item(i); if (objChild.outerHTML != null) { // Replace apostrophes at the beginning of the line. if (objChild.outerHTML.search(/^&apos;/) >= 0) objChild.outerHTML = objChild.outerHTML.replace(/^&apos;/g, "'"); // Replace apostrophes that are not in attribute values. if (objChild.outerHTML.search(/([^=])&apos;/) >= 0) objChild.outerHTML = objChild.outerHTML.replace(/([^=])&apos;/g, "$1'"); } } } var DocumentForm = getDocumentForm(); for (var i = 0; i < DocumentForm.length; i++) { var DocumentElement = DocumentForm.elements[i]; // Set the initial value for a date field if is valid. if (DocumentElement.getAttribute("DataType") == "Date") { var InitialValue = DocumentElement.parentElement.getAttribute("VALUE"); if (InitialValue != null) { // If the initial value should be today get the date string for today. if (InitialValue == "[today]") { var strDataType = DocumentElement.getAttribute("DataType"); if (strDataType != null && strDataType == "Date") { var intDateFormat = g_objDispatch.GrooveIntlDateFormatStyle_Short; var strDateFormat = DocumentElement.parentElement.getAttribute("FormatDateShortFormat"); if (strDateFormat == null || strDateFormat == "") { strDateFormat = DocumentElement.parentElement.getAttribute("FormatDateLongFormat"); intDateFormat = g_objDispatch.GrooveIntlDateFormatStyle_Full; } InitialValue = g_objDispatch.LocalFormatDate(new Date().valueOf(), strDateFormat, intDateFormat); } else InitialValue = new Date().toDateString(); } DocumentElement.value = InitialValue; formatDate(DocumentElement); } } // Replace all instances of ' with an apostrophe in the form's element values. if (DocumentElement.tagName == "SELECT") { for (var j = 0; j < DocumentElement.options.length; j++) { var DocumentOption = DocumentElement.options[j]; if (DocumentOption.value.search(/'/) >= 0) DocumentOption.value = DocumentOption.value.replace(/'/g, "'"); } } else if (DocumentElement.value != null && DocumentElement.value != "") { if (DocumentElement.value.search(/'/) >= 0) DocumentElement.value = DocumentElement.value.replace(/'/g, "'"); } // Add event handler function call to each element so it can be used by developers. if (DocumentElement.name != "") { DocumentElement.attachEvent('onblur', onBlurHandler); DocumentElement.attachEvent('onfocus', onFocusHandler); DocumentElement.attachEvent('onclick', onClickHandler); // OnChange is only supported by SELECT, TEXTAREA, and text INPUT. if (DocumentElement.tagName == "SELECT" || DocumentElement.tagName == "TEXTAREA" || (DocumentElement.tagName == "INPUT" && DocumentElement.type == "text")) DocumentElement.attachEvent('onchange', onChangeHandler); } } // Fix the default text of any textarea fields in the page. var arrTextArea = document.getElementsByTagName("TEXTAREA"); for (var i = 0; i < arrTextArea.length; i++) { arrTextArea[i].value = arrTextArea[i].value.replace(/^[ \n\r]*/, ""); arrTextArea[i].value = arrTextArea[i].value.replace(/[ \n\r]*$/, ""); } try { // Get an array of groove objects (usually rich text) on the page. var arrObject = document.getElementsByTagName("OBJECT"); for (var i = 0; i < arrObject.length; i++) { var strDataType = arrObject[i].getAttribute("DataType"); if (strDataType != null && strDataType == "RichText") { var strDefault = arrObject[i].getAttribute("DEFAULT"); if (strDefault != null) arrObject[i].RTFContent = strDefault; var strReadOnly = arrObject[i].getAttribute("READONLY"); if (strReadOnly != null && strReadOnly != "true") g_arrRichText[g_arrRichText.length] = arrObject[i]; else arrObject[i].ReadOnly = true; } else if (arrObject[i].getAttribute("DataType") == "Attachments") g_AttachmentsObject = arrObject[i]; } } catch (error) { g_objDispatch.ActiveXMessageBox(); return; } // Get an array of drop-down list boxes on the page. var arrSelect = document.getElementsByTagName("SELECT"); for (var i = 0; i < arrSelect.length; i++) { if (arrSelect[i].getAttribute("Members") != null && arrSelect[i].getAttribute("Members") == "true") { var MemberNameArray = g_objDispatch.GetMemberNameArray(); for (var j = 0; j < MemberNameArray.length; j++) { arrSelect[i].options[arrSelect[i].options.length] = new Option(MemberNameArray[j], MemberNameArray[j]); } } } // Make any fields invisible that need to be. var arrDiv = document.getElementsByTagName("TR"); for (var i = 0; i < arrDiv.length; i++) { var strInvisible = arrDiv[i].getAttribute("INVISIBLE"); if (strInvisible != null && strInvisible != "") arrDiv[i].style.display = "none"; } // Fix the onclick events for any script buttons. var arrButton = document.getElementsByTagName("BUTTON"); for (var i = 0; i < arrButton.length; i++) { var strOnClickEvent = arrButton[i].getAttribute("ONCLICKEVENT"); if (strOnClickEvent != null && strOnClickEvent != "") { strOnClickEvent = strOnClickEvent.replace(/'/g, "'"); strOnClickEvent = strOnClickEvent.replace(/"/g, "\""); addEvent(arrButton[i], "onclick", strOnClickEvent); } } } // === getQueryStringVariables() ====================== // get global variable values from document querystring function getQueryStringVariables() { var QueryString = String(window.location.search).substring(1); var SearchArray = QueryString.split("&"); for (var i = 0; i < SearchArray.length; i++) { var Request = SearchArray[i].split("=")[0]; if (Request == "RecordID") g_RecordID = SearchArray[i].split("=")[1]; else if (Request == "SelectedID") { g_SelectedID = SearchArray[i].split("=")[1]; var strFormType = document.body.getAttribute("FormType"); if (strFormType != null && strFormType == "Response") g_IsResponse = true; } else if (Request.indexOf("preview") >= 0 || Request.indexOf("previewlayout") >= 0 || Request.indexOf("layout") >= 0 || Request.indexOf("search") >= 0) { if (Request == "preview") g_IsPreviewPane = true; else if (Request == "layout") g_IsLayout = true; else if (Request == "search") g_IsSearch = true; // Set the elements enabled variable for preview, preview layout, and layout. if (Request == "preview" || Request == "previewlayout" || Request == "layout") g_ElementsEnabled = false; // Set variable for preview, layout, and search. if (Request == "previewlayout" || Request == "layout" || Request == "search") g_IsPreviewLayout = true; } else if (Request.indexOf("noedit") >= 0) { g_NoEdit = true; } } } // === createNewRecord() ======================= // create a new record to save the new data into function createNewRecord() { var NewRecord = g_objDispatch.CreateNewRecord(); if (typeof NewRecord != "undefined" && NewRecord != null) { g_Record = NewRecord; g_RecordID = g_Record.RecordID; g_IsNewRecord = true; g_objDispatch.GrooveDebugFunctions.OutputString("\nNew Record created. RecordID: " + g_RecordID + "\n\n"); } } // === clearAllFormValues(boolean) ==================================== // clear all values from the form, add a blank to SELECT tags if needed function clearAllFormValues(i_blnBlank) { var DocumentForm = getDocumentForm(); for (var i = 0; i < DocumentForm.length; i++) { var DocumentElement = DocumentForm.elements[i]; if (DocumentElement.type == "text" || DocumentElement.type == "password" || DocumentElement.type == "textarea") DocumentElement.value = ""; else if (DocumentElement.type == "checkbox") DocumentElement.checked = false; else if (DocumentElement.type == "radio") DocumentElement.checked = false; else if (DocumentElement.type == "select-one" || DocumentElement.type == "select-multiple") { for (var j = 0; j < DocumentElement.options.length; j++) { DocumentElement.options[j].selected = false; } // Add a blank option to the combo-box and select it. if (i_blnBlank) { var objOption = document.createElement("OPTION"); DocumentElement.options.add(objOption, 0); DocumentElement.options[0].selected = true; } } } for (var i = 0; i < g_arrRichText.length; i++) { g_arrRichText[i].RTFContent = ""; } } // === setupSpecializedFields() ===================================== // set-up some specialized fields and set focus to first form element function setupSpecializedFields() { var DocumentForm = getDocumentForm(); var blnFocusSet = false; for (var i = 0; i < DocumentForm.length; i++) { var DocumentElement = DocumentForm.elements[i]; // Set the focus to be the first non-disabled, visible form element. if (!blnFocusSet && !DocumentElement.disabled && DocumentElement.getAttribute("INVISIBLE") != "true" && DocumentElement.parentElement.getAttribute("INVISIBLE") != "true") { DocumentElement.focus(); blnFocusSet = true; } // Add the "Custom..." option to the end of the list for combo boxes. var strCustom = DocumentElement.getAttribute("CUSTOM"); if (DocumentElement.tagName == "SELECT" && strCustom != null && strCustom != "") addCustomOptionToElement(DocumentElement); // Add the red asterisk the signifys the field is required. addRequiredAsterisk(DocumentElement); } var arrSpan = document.getElementsByTagName("SPAN"); for (var i = 0; i < arrSpan.length; i++) { if (arrSpan[i].className == "Radio") addRequiredAsterisk(arrSpan[i]); } } // === addRequiredAsterisk(object) ======================== // add the red asterisk the signifies the field is required function addRequiredAsterisk(i_objElement) { if (g_ElementsEnabled && !g_IsSearch) { // Add a red asterisk after required fields. if (i_objElement.getAttribute("VldtRequired") != null && i_objElement.getAttribute("VldtRequired") != "") i_objElement.insertAdjacentHTML("afterEnd", " <font style=\"color:red\">*</font>"); else if (i_objElement.parentElement.getAttribute("VldtRequired") != null && i_objElement.parentElement.getAttribute("VldtRequired") != "" && i_objElement.tagName == "BUTTON") i_objElement.insertAdjacentHTML("afterEnd", " <font style=\"color:red\">*</font>"); } } // === designChanged() =================================== // called when design has changed, disable useless buttons function designChanged() { if (!g_Initialized) window.setTimeout("designChanged()", 250); if (!g_HasDesignChanged) { var DocumentForm = getDocumentForm(); // Disable the "Save" and "Save and Create Another" buttons. DocumentForm.SubmitButton.title += " (disabled by design change)"; DocumentForm.SubmitButton.disabled = true; DocumentForm.ApplyButton.title += " (disabled by design change)"; DocumentForm.ApplyButton.disabled = true; // Disable the reset button if the form no longer exists. var FormID = g_objDispatch.RightBack(location.pathname, "/"); if (!g_objDispatch.VerifyFormExistsForURL(FormID)) { DocumentForm.ResetButton.title += " (disabled by design change, this form has been deleted)"; DocumentForm.ResetButton.disabled = true; } // Disable the attachments buttons if they are present if (g_AttachmentsObject) { removeDocument(); for (var i = 0; i < DocumentForm.length; i++) { var DocumentElement = DocumentForm.elements[i]; if (DocumentElement.tagName == "BUTTON" && DocumentElement.parentNode.className == "AttachmentsField") DocumentElement.disabled = true; } addDocument(); if (g_AttachmentsObject.Properties2.Initialized) g_AttachmentsObject.Properties2.SetReadOnlyMode(true); } g_HasDesignChanged = true; } } // === roleChanged() =================================== // called when role has changed, disable/enable buttons appropriate to change function roleChanged() { var EnableButtons = false; if (g_IsNewRecord) EnableButtons = g_objDispatch.CanCreate(); else EnableButtons = g_objDispatch.CanEdit(g_RecordID); var DocumentForm = getDocumentForm(); // Enable or Disable the "Save" and "Save and Create Another" buttons. if (!EnableButtons) { if (DocumentForm.SubmitButton.title.indexOf(" (disabled by role change)") < 0) { DocumentForm.SubmitButton.title += " (disabled by role change)"; DocumentForm.ApplyButton.title += " (disabled by role change)"; } } else { DocumentForm.SubmitButton.title = DocumentForm.SubmitButton.title.replace(/ \(disabled by role change\)/, ""); DocumentForm.ApplyButton.title = DocumentForm.ApplyButton.title.replace(/ \(disabled by role change\)/, ""); } DocumentForm.SubmitButton.disabled = !EnableButtons; DocumentForm.ApplyButton.disabled = !EnableButtons; // Disable the attachments buttons if they are present if (g_AttachmentsObject) { removeDocument(); for (var i = 0; i < DocumentForm.length; i++) { var DocumentElement = DocumentForm.elements[i]; if (DocumentElement.tagName == "BUTTON" && DocumentElement.parentNode.className == "AttachmentsField") DocumentElement.disabled = !EnableButtons; } addDocument(); if (g_AttachmentsObject.Properties2.Initialized) g_AttachmentsObject.Properties2.SetReadOnlyMode(!EnableButtons); } } // === printForm() ============================ // print the data that is currently on the form function printForm() { window.print(); } // === getDocumentForm() ============= // return the form object that is used function getDocumentForm() { return document.GrooveFormBase; } // === getScriptDispatch() =============================== // safely get the script dispatch from the forms glue code function getScriptDispatch() { try { var objDispatch = window.external.Delegate.GetScriptDispatch(); return objDispatch; } catch (error) { alert("This web page should only be opened from within Groove. Please close the window."); return null; } }