0byt3m1n1
Path:
C:
/
Program Files (x86)
/
Microsoft Office
/
Office12
/
Groove
/
ToolData
/
groove.net
/
GrooveForms3
/
[
Home
]
File: SUBMIT.JS
/********************************************************************* Notice You may not modify, use, copy or distribute this file or its contents. Internal interfaces referenced in this file are nonpublic, unsupported and subject to change without notice. These interfaces may not be utilized in other software applications or components. *********************************************************************/ // These variables defined in PublicFunctions.js. g_IsNew = false; g_IsSearch = false; g_IsPreviewPane = false; g_IsReadOnly = false; g_IsResponse = false; g_IsVersioned = false; g_RecordID = -1; g_FormID = -1; g_SelectedID = -1; g_IsFormPreview = false; var g_IsFocusSet = false; var g_IsCreateAnother = false; var g_IsInitializing = false; var g_IsInitializingTextView = false; var g_IsInitializingDocumentShare = false; var g_IsPreviewPaneRefresh = false; var g_IsViewSource = false; var g_IsPrinting = false; var g_HasDesignChanged = false; var g_NewRecord; var g_SearchType; var g_RichTextObjects = new Array(); var g_DataListObjects = new Array(); var g_DigitalInkObjects = new Array(); var g_PerIdentityFields = new Array(); var g_AttachmentsObject; var g_AttachmentsElement; var IPF_InkSerializedFormat = 0; var IPF_Base64InkSerializedFormat = 1; var IPF_GIF = 2; var IPF_Base64GIF = 3; var g_IsDirty = false; // ===================================================== // === Document Event Handlers === // ===================================================== document.onkeydown = keyDownEvent; document.oncontextmenu = contextMenuEvent; function keyDownEvent() { var objElement = event.srcElement; // Only allow 'Backspace' key in writable text type fields. if (event.keyCode == 8 && ((objElement.type != "text" && objElement.type != "textarea" && objElement.type != "password") || objElement.readOnly)) event.returnValue = false; } function contextMenuEvent() { // Only allow context menu if the 'Ctrl' key is held down. if (!event.ctrlKey) event.returnValue = false; } // ===================================================== // === Form Initialization === // ===================================================== function initFormPage(i_RecordID) { if (g_IsViewSource) return; if (!g_IsFormPreview && typeof OnBeforeInitialize != "undefined" && !processCallout(OnBeforeInitialize)) return true; // Let the UIDelegate know there are no validation errors. getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").HasValidationErrors = false; // Set the dirty bit for the current form. g_IsInitializing = false; int_setIsDirty(false); g_IsInitializing = true; // We need to reset this array otherwise we'll gradually be adding more objects to it every time you // select another document and this will cause a major CPU spike g_RichTextObjects = new Array(); g_DataListObjects = new Array(); g_DigitalInkObjects = new Array(); // If a record ID is passed in then use it. if (typeof i_RecordID != "undefined") { g_IsPreviewPaneRefresh = true; g_RecordID = i_RecordID; } var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction(); try { var FormRecord; var ResponseError = false; if (!g_IsSearch && !g_IsPreviewPane && !g_IsPrinting && !g_IsFormPreview && getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").NeedToAutoCreateRecord()) { if (getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").LimitOneRecordPerMember) { FormRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CreateOrOpenMemberRecord(); getScriptHostQI("IGrooveFormsToolUIDelegateViewPrivate").SetFocusRecordID(FormRecord.ID); } else FormRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CreateRecord(""); if (!getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DoesRecordExist(FormRecord.ID)) { ResponseError = CheckValidResponseRecord(); g_IsNew = true; g_NewRecord = FormRecord; g_RecordID = FormRecord.ID; } else g_RecordID = FormRecord.ID; } else { if (g_IsSearch || g_IsFormPreview || g_IsPrinting) { if (g_IsSearch) FormRecord = getScriptHostQI("IGrooveFormsToolSearchDialogDelegatePrivate").CreateSearchRecord(""); else if (g_IsFormPreview) FormRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CreateSandboxedRecord(); else if (g_IsPrinting && g_RecordID != null && g_RecordID != -1) FormRecord = getScriptHostQI("IGrooveFormsToolPrintDialogDelegatePrivate").OpenFormRecord(g_RecordID); if (g_IsSearch || g_IsFormPreview) g_IsNew = true; else g_IsNew = false; g_NewRecord = FormRecord; g_RecordID = FormRecord.ID; } else { // Open the record if there is a record ID, otherwise create a new record. if (g_RecordID != null && g_RecordID != -1 && getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DoesRecordExist(g_RecordID)) { if (!g_IsPreviewPane) getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").MarkRecordRead(g_RecordID); FormRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").OpenRecord(g_RecordID); // Set the focus record ID as the current record ID. getScriptHostQI("IGrooveFormsToolUIDelegateViewPrivate").SetFocusRecordID(g_RecordID); } else { if (getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").LimitOneRecordPerMember) FormRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CreateOrOpenMemberRecord(); else FormRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CreateRecord(""); if (!getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DoesRecordExist(FormRecord.ID)) { ResponseError = CheckValidResponseRecord(); g_IsNew = true; g_NewRecord = FormRecord; g_RecordID = FormRecord.ID; } else g_RecordID = FormRecord.ID; } } } if (!ResponseError) { // Iterate through the form fields to properly set them up. initSystemFields(FormRecord); initFormElements(FormRecord); // If the record is new and is a response, then set the _ParentID so that HasParentID property works if (g_IsNew && g_IsResponse && g_SelectedID != -1) FormRecord.SetField("_ParentID", g_SelectedID); // Create an IGrooveFormsToolRecord global variable for scripters to use. g_FormRecord = FormRecord; } Transaction.Commit(); } catch (error) { //alert("Transaction aborted in initFormPage [" + error.description + "]"); Transaction.Abort(); } if (ResponseError) { var ResponseErrorMessage = "You must select a valid parent document in order to create a response."; getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayOKMessageBox(ResponseErrorMessage, "Invalid Selection"); window.setTimeout("getScriptHostQI('IGrooveFormsToolUIDelegatePrivate').SwitchWebState(FormsUIState_HomePage, -1)", 50); } // Update any lookups included in the form. if (!g_IsFormPreview) int_updateLookups(true, ""); // Inherit attachments field values if they should be. if (g_AttachmentsObject != null) inheritFieldValue(g_AttachmentsObject); // Enable rich text fields and inherit field values. for (var i = 0; i < g_RichTextObjects.length; i++) { inheritFieldValue(g_RichTextObjects[i]); window.setTimeout("enableTextView(" + i + ")", 10); } // Enable attachments fields. window.setTimeout("enableDocumentShare()", 10); // Add the document to HTMLComponentBridge. addDocument(); // Enable data list objects on the page. //enableDataList(); if (!g_IsSearch && !g_IsFormPreview && !g_IsPrinting) getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").SetCurrentFormDocument(document); // Tell the UIDelegate we are in the DocumentDisplay state. if (!g_IsSearch && !g_IsPreviewPane && !g_IsFormPreview && !g_IsPrinting) getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").SwitchWebState(FormsUIState_DocumentDisplay, g_RecordID, g_IsNew); g_IsPreviewPaneRefresh = false; g_IsInitializing = false; if (!g_IsFormPreview && typeof OnAfterInitialize != "undefined" && !processCallout(OnAfterInitialize)) return true; // Print the form if we should be doing it. if (g_IsPrinting) { // Display the contents of all tabs when printing. var arrDivs = document.getElementsByTagName("DIV"); for (var i = 0; i < arrDivs.length; i++) { var strObjectType = arrDivs[i].getAttribute("OBJECTTYPE"); if (strObjectType == "TabContents" && arrDivs[i].style.display == "none") { arrDivs[i].insertAdjacentHTML("beforeBegin", "<HR ID=\"" + arrDivs[i].id + "_line\" SIZE=\"1\" COLOR=\"#000000\">"); arrDivs[i].style.display = ""; } } printThroughForm(); } } function CheckValidResponseRecord() { var ResponseError = false; try { // Check to see if this is a response record, and if it is valid to create. if (g_IsResponse && !g_IsPreviewPane) { if (g_SelectedID == -1 || !getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DoesRecordExist(g_SelectedID) || !getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").IsValidRecord(g_SelectedID)) ResponseError = true; // MWATodo: update UI to add option for not allowing responses to a response. /* if (g_SelectedID != -1) { var SelectedFormURL = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DataDelegate.IGrooveFormsToolUserDataPrivate.OpenFormURLByRecordID(g_SelectedID); var ThisFormURL = String(window.location.href); if (ThisFormURL.indexOf("?") >= 0) ThisFormURL = ThisFormURL.substring(0, ThisFormURL.indexOf("?")); // Normalize the URLs by converting to lower case for comparison. if (SelectedFormURL.toLowerCase() == ThisFormURL.toLowerCase()) ResponseErrorMessage = "You must select a valid parent document in order to create a response. You have a response selected."; } */ } } catch (error) { alert("ERROR: " + error.description); } return ResponseError; } function initSystemFields(i_Record) { // There must be a valid record, unless it is new or a search. if (!g_IsNew && (typeof i_Record == "undefined" || i_Record == null)) return; var divCreatedBy = document.getElementById("_CreatedBy"); var divCreated = document.getElementById("_Created"); var divModifiedBy = document.getElementById("_ModifiedBy"); var divModified = document.getElementById("_Modified"); var divEditors = document.getElementById("_Editors"); var divReaders = document.getElementById("_Readers"); if (divCreatedBy) { if (g_IsSearch) divCreatedBy.innerHTML = "<INPUT TYPE=\"text\" CLASS=\"text\" NAME=\"_CreatedBy\">"; else if (g_IsNew) divCreatedBy.innerText = getCurrentAuthorName(); else divCreatedBy.innerText = i_Record.OpenField("_CreatedBy"); } if (divCreated) { if (g_IsSearch) divCreated.innerHTML = "<INPUT TYPE=\"text\" CLASS=\"text\" ID=\"_Created\" NAME=\"_Created\" DATATYPE=\"Date\" FORMAT=\"3\"> <BUTTON CLASS=\"dateButton\" ONCLICK=\"doCalendar('_Created');\"><IMG SRC=\"calendar.gif\" WIDTH=15 HEIGHT=13 STYLE=\"nargin 2px 2px 0px 2px;\"></BUTTON>"; else if (g_IsNew) divCreated.innerText = getScriptHostQI("IGrooveFormsToolUIDelegate").FormatDateTime(new Date().valueOf(), 3, 3); else divCreated.innerText = getScriptHostQI("IGrooveFormsToolUIDelegate").FormatDateTime(i_Record.OpenField("_Created"), 3, 3); } if (divModifiedBy) { if (g_IsSearch) divModifiedBy.innerHTML = "<INPUT TYPE=\"text\" CLASS=\"text\" NAME=\"_ModifiedBy\">"; else if (g_IsNew) divModifiedBy.innerText = getCurrentAuthorName(); else divModifiedBy.innerText = i_Record.OpenField("_ModifiedBy"); } if (divModified) { if (g_IsSearch) divModified.innerHTML = "<INPUT TYPE=\"text\" CLASS=\"text\" ID=\"_Modified\" NAME=\"_Modified\" DATATYPE=\"Date\" FORMAT=\"3\"> <BUTTON CLASS=\"dateButton\" ONCLICK=\"doCalendar('_Modified');\"><IMG SRC=\"calendar.gif\" WIDTH=15 HEIGHT=13 STYLE=\"nargin 2px 2px 0px 2px;\"></BUTTON>"; else if (g_IsNew) divModified.innerText = getScriptHostQI("IGrooveFormsToolUIDelegate").FormatDateTime(new Date().valueOf(), 3, 3); else divModified.innerText = getScriptHostQI("IGrooveFormsToolUIDelegate").FormatDateTime(i_Record.OpenField("_Modified"), 3, 3); } if (divEditors || divReaders) { var objMemberNameURLEnum = getScriptHostQI("IGrooveFormsToolUIDelegate").CreateMemberNameURLEnum(); if (divEditors) { var strEditors = ""; if (!g_IsNew && !g_IsSearch) strEditors = i_Record.OpenField("_Editors"); divEditors.innerHTML = createMemberNameURLOptions("_Editors", strEditors, objMemberNameURLEnum); } objMemberNameURLEnum.Reset(); if (divReaders) { var strReaders = ""; if (!g_IsNew && !g_IsSearch) strReaders = i_Record.OpenField("_Readers"); divReaders.innerHTML = createMemberNameURLOptions("_Readers", strReaders, objMemberNameURLEnum); } } } function getCurrentAuthorName() { if (g_IsFormPreview) return getScriptHostQI("IGrooveFormsToolUIDelegate").GetCurrentAuthorName(); else return getScriptHostQI("IGrooveFormsToolUIDelegate").CurrentAuthorName; } function getTelespaceDisplayName() { if (g_IsFormPreview) return getScriptHostQI("IGrooveFormsToolUIDelegate").GetTelespaceDisplayName(); else return getScriptHostQI("IGrooveFormsToolUIDelegate").TelespaceDisplayName; } function getToolDisplayName() { if (g_IsFormPreview) return getScriptHostQI("IGrooveFormsToolUIDelegate").GetToolDisplayName(); else return getScriptHostQI("IGrooveFormsToolUIDelegate").ToolDisplayName; } function createMemberNameURLOptions(i_strName, i_strURLs, i_objMemberNameURLEnum) { var StyleAttribute = ""; if (g_IsPreviewPane) StyleAttribute = " STYLE=\"display:none;\""; var strOptions = "<SELECT NAME=\"" + i_strName + "\" SIZE=\"4\" MULTIPLE" + StyleAttribute + ">"; while (i_objMemberNameURLEnum.HasMore()) { var objMemberNameURLPair = i_objMemberNameURLEnum.OpenNextPair(); var strMemberName = objMemberNameURLPair.First; var strMemberURL = objMemberNameURLPair.Second; var strSelected = ""; if (i_strURLs.indexOf(strMemberURL) >= 0) strSelected = " SELECTED"; strOptions += "<OPTION VALUE=\"" + strMemberURL + "\"" + strSelected + "\">" + strMemberName; } strOptions += "</SELECT>"; strOptions += "<SPAN CLASS=\"selectPreview\" ID=\"" + i_strName + "_preview\"></SPAN>"; return strOptions; } function initFormElements(i_Record) { // Iterate through elements in the form. var DocumentForm = document.GrooveFormBase; for (var i = 0; i < DocumentForm.elements.length; i++) { var DocumentElement = DocumentForm.elements[i]; if (DocumentElement.tagName == "OBJECT") { initFormObject(DocumentElement); } else { if (!g_IsNew) clearFormElement(DocumentElement); initFormElement(i_Record, DocumentElement); } if (!g_IsReadOnly && !g_IsFormPreview && !g_IsFocusSet && DocumentElement.getAttribute("ISREADONLY") == null && DocumentElement.getAttribute("ISHIDDEN") == null) { try { DocumentElement.focus(); g_IsFocusSet = true; } catch (error) { g_IsFocusSet = false; } } } } function clearFormElement(i_Element) { var ElementType = i_Element.type; var ElementDataType = i_Element.getAttribute("DATATYPE"); if (ElementType == "text" || ElementType == "textarea" || ElementType == "password") i_Element.value = ""; else if (ElementType == "checkbox" || ElementType == "radio") { if (!g_IsNew) i_Element.checked = false; } else if (ElementType.indexOf("select") == 0) { for (var i = 0; i < i_Element.options.length; i++) { i_Element.options[i].selected = false; } } } function initFormElement(i_Record, i_Element) { var ElementName = i_Element.name; var ElementType = i_Element.type; var ElementDataType = i_Element.getAttribute("DATATYPE"); var ElementPreview = null; if (g_IsReadOnly && !g_IsFormPreview) { ElementPreview = document.getElementById(ElementName + "_preview"); if (ElementPreview == null && (ElementType == "text" || ElementType == "textarea" || ElementType == "password")) return; } if (!g_IsPreviewPaneRefresh && ElementType.indexOf("select") == 0) { // Add members list to drop-down list and list box fields. var MembersAttribute = i_Element.getAttribute("MEMBERS"); if (MembersAttribute != null) { var MemberNameEnum = getScriptHostQI("IGrooveFormsToolUIDelegate").CreateMemberNameEnum(); while (MemberNameEnum.HasMore()) { var MemberName = MemberNameEnum.OpenNext(); insertNewOption(i_Element, MemberName, MemberName, false); } } if (g_IsSearch) i_Element.options.value = ""; } if (!g_IsSearch && typeof i_Record != "undefined" && i_Record != null) { // Check to see if the field exists in the record. if (i_Record.HasField(ElementName)) { var ElementValue = i_Record.OpenField(ElementName); if (g_IsNew) { // Check to see if there is a special initial value. var InitialValueTypeAttribute = i_Element.getAttribute("INITIALVALUETYPE"); var FieldTypeAttribute = i_Element.getAttribute("FIELDTYPE"); if (FieldTypeAttribute == FormObjectType_Text) { if (InitialValueTypeAttribute == GrooveFormsToolTextFieldInitialValueType_Unique) ElementValue = getUniqueID(); else if (InitialValueTypeAttribute == GrooveFormsToolTextFieldInitialValueType_UserDisplayName) ElementValue = getCurrentAuthorName(); else if (InitialValueTypeAttribute == GrooveFormsToolTextFieldInitialValueType_TelespaceDisplayName) ElementValue = getTelespaceDisplayName(); else if (InitialValueTypeAttribute == GrooveFormsToolTextFieldInitialValueType_ToolDisplayName) ElementValue = getToolDisplayName(); } else if (FieldTypeAttribute == FormObjectType_Date) { // Get the current date and set the time to noon. var CurrentDate = new Date(); CurrentDate.setHours(12); CurrentDate.setMinutes(0); CurrentDate.setSeconds(0); if (InitialValueTypeAttribute == GrooveFormsToolDateFieldInitialValueType_Today) ElementValue = CurrentDate.valueOf(); else if (InitialValueTypeAttribute == GrooveFormsToolDateFieldInitialValueType_Tomorrow) { // Add one day to the current date. CurrentDate.setMinutes(60 * 24); ElementValue = CurrentDate.valueOf(); } } else if (FieldTypeAttribute == FormObjectType_DateTime) { if (InitialValueTypeAttribute == GrooveFormsToolDateTimeFieldInitialValueType_Now) ElementValue = new Date().valueOf(); } // Get the return value from a function. if ((FieldTypeAttribute == FormObjectType_Text && InitialValueTypeAttribute == GrooveFormsToolTextFieldInitialValueType_Function) || (FieldTypeAttribute == FormObjectType_Date && InitialValueTypeAttribute == GrooveFormsToolDateFieldInitialValueType_Function) || (FieldTypeAttribute == FormObjectType_DateTime && InitialValueTypeAttribute == GrooveFormsToolDateTimeFieldInitialValueType_Function)) { var InitialValueFunctionAttribute = i_Element.getAttribute("INITIALVALUEFUNCTION"); if (InitialValueFunctionAttribute != null && InitialValueFunctionAttribute != "") { try { ElementValue = eval(InitialValueFunctionAttribute); } catch (error) { } } } } var IsValueInherited = false; // Check to see if the field value should be inherited. if (g_IsNew && g_SelectedID != -1) { var InheritAttribute = i_Element.getAttribute("INHERIT"); if (InheritAttribute != null && InheritAttribute != "") { if (getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").IsValidRecord(g_SelectedID)) { var ParentRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").OpenRecord(g_SelectedID); if (InheritAttribute == "FormsInheritSelf") InheritAttribute = ElementName; if (ParentRecord.HasField(InheritAttribute)) { ElementValue = ParentRecord.OpenField(InheritAttribute); IsValueInherited = true; // Set the inherited attribute to be used by lookup later on. i_Element.setAttribute("INHERITEDVALUE", ElementValue); } } else { displayStatusBar("The selected item in the view is not a valid record. Inheriting field values not completed.", GrooveMessageBoxIcon_Error); } } } // Set the value for each field depending on the element type. if (ElementType == "text" || ElementType == "textarea" || ElementType == "password") { if (ElementDataType == "Date") { var DateValue = ""; if (ElementValue != INVALID_DATE) { var DateFormat = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").CreateDateFormatStyleFromAttributeValue(i_Element.getAttribute("FORMAT")); var FieldTypeAttribute = i_Element.getAttribute("FIELDTYPE"); if (FieldTypeAttribute == FormObjectType_DateTime) DateValue = getScriptHostQI("IGrooveFormsToolUIDelegate").FormatDateTime(ElementValue, DateFormat, 3); else DateValue = getScriptHostQI("IGrooveFormsToolUIDelegate").FormatDate(ElementValue, DateFormat); } if (g_IsReadOnly && !g_IsFormPreview) ElementPreview.innerText = DateValue; i_Element.value = DateValue; } else if (ElementDataType == "Numeric") { if (ElementValue == 0) ElementValue = ""; if (ElementValue != "") { var FieldTypeAttribute = i_Element.getAttribute("FIELDTYPE"); if (FieldTypeAttribute == FormObjectType_Number) ElementValue = formatNumericValue(i_Element, ElementValue); else if (FieldTypeAttribute == FormObjectType_Currency) ElementValue = formatCurrencyValue(i_Element, ElementValue); } if (g_IsReadOnly && !g_IsFormPreview) ElementPreview.innerText = ElementValue; i_Element.value = ElementValue; } else { if (g_IsReadOnly && !g_IsFormPreview) { if (ElementType == "password") { var ElementValueLength = ElementValue.length; ElementValue = ""; for (var i = 0; i < ElementValueLength; i++) { ElementValue += "*"; } } ElementPreview.innerText = ElementValue; } // Check to see if the field contains a lookup. var FieldHasLookup = false; var LookupAttribute = i_Element.getAttribute("LOOKUP"); if (LookupAttribute != null) FieldHasLookup = true; if (!g_IsNew || (g_IsNew && !FieldHasLookup)) i_Element.value = ElementValue; } } else if (ElementType == "checkbox") { if (!g_IsNew || IsValueInherited) { if (ElementValue != "") i_Element.checked = true; else i_Element.checked = false; } } else if (ElementType == "radio") { if (!g_IsNew || IsValueInherited) { if (i_Element.value == ElementValue) i_Element.checked = true; else i_Element.checked = false; } } else if (ElementType == "select-one") { if (g_IsReadOnly && !g_IsFormPreview) { OptionValue = ""; for (var i = 0; i < i_Element.options.length; i++) { if (i_Element.options[i].value == ElementValue) { OptionValue = i_Element.options[i].text; break; } } if (OptionValue == "") OptionValue = ElementValue; ElementPreview.innerText = OptionValue; } if (!g_IsNew || IsValueInherited) { var IsValueFound = false; for (var i = 0; i < i_Element.options.length; i++) { if (i_Element.options[i].value == ElementValue) { i_Element.options[i].selected = true; IsValueFound = true; break; } } var CustomAttribute = i_Element.getAttribute("CUSTOM"); if (!IsValueFound && CustomAttribute != null && ElementValue != "") insertNewOption(i_Element, ElementValue, ElementValue, true); } } else if (ElementType == "select-multiple") { // Editors and Readers fields are separated with a semi-colon. var ElementValueSeparator = "\n"; if (ElementName == "_Editors" || ElementName == "_Readers") ElementValueSeparator = ";"; if (g_IsReadOnly && !g_IsFormPreview) { var ElementValueArray = ElementValue.split(ElementValueSeparator); var OptionValueArray = new Array(ElementValueArray.length); for (var i = 0; i < ElementValueArray.length; i++) { var ValueFound = false; for (var j = 0; j < i_Element.options.length; j++) { if (i_Element.options[j].value == ElementValueArray[i]) { OptionValueArray[i] = i_Element.options[j].text; ValueFound = true; break; } } if (!ValueFound) OptionValueArray[i] = ElementValueArray[i]; } for (var i = 0; i < OptionValueArray.length; i++) { if (OptionValueArray[i] == "") OptionValueArray[i] = ElementValueArray[i]; } ElementPreview.innerText = OptionValueArray.join(", "); } if (!g_IsNew || IsValueInherited) { var ElementValueArray = ElementValue.split(ElementValueSeparator); for (var i = 0; i < ElementValueArray.length; i++) { for (var j = 0; j < i_Element.options.length; j++) { if (i_Element.options[j].value == ElementValueArray[i]) { i_Element.options[j].selected = true; break; } } } } } } } else { if (g_IsPreviewPane) { getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayOKMessageBox("The record you have selected to preview has been deleted.", "Record Deleted"); location.replace("FormsBlankPage.html"); } else if (!g_IsNew && !g_IsSearch && !g_IsFormPreview && !g_IsPrinting) { getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayOKMessageBox("The record you have selected to edit has been deleted. You will be returned to the view.", "Record Deleted"); window.setTimeout("getScriptHostQI('IGrooveFormsToolUIDelegatePrivate').SwitchWebState(FormsUIState_HomePage, -1)", 50); } } if (!g_IsSearch && !g_IsPrinting) { // Add event handlers to each element in the form for script developers. i_Element.attachEvent("onblur", onBlurHandler); i_Element.attachEvent("onfocus", onFocusHandler); i_Element.attachEvent("onclick", onClickHandler); // OnChange is only supported by text INPUT, TEXTAREA, and SELECT. if (ElementType == "text" || ElementType == "textarea" || ElementType.indexOf("select") == 0) i_Element.attachEvent("onchange", onChangeHandler); // Set the disabled flag for the element. var ReadOnlyAttribute = i_Element.getAttribute("ISREADONLY"); if (ReadOnlyAttribute != null || g_IsReadOnly) { if (ElementType == "select-one") { var objCustomButton = document.getElementById(ElementName + "Button"); if (objCustomButton != null) objCustomButton.style.display = "none"; } if (ElementDataType == "Date") { var objDateButton = document.getElementById(ElementName + "Button"); if (objDateButton != null) objDateButton.disabled = true; } if (ElementType == "text" || ElementType == "textarea" || ElementType == "password") i_Element.readOnly = true; else i_Element.disabled = true; } } } function initFormObject(i_Object) { // Save the attachments elements in a global variable. var ObjectDataType = i_Object.getAttribute("DATATYPE"); if (ObjectDataType == "RichText") { var objRichText = new EmbeddedObject(); objRichText.Object = i_Object; g_RichTextObjects.push(objRichText); } else if (ObjectDataType == "Attachments") g_AttachmentsObject = i_Object; else if (ObjectDataType == "View") g_DataListObjects.push(i_Object); else if (ObjectDataType == "Ink") { var objDigitalInk = new EmbeddedObject(); objDigitalInk.Object = i_Object; g_DigitalInkObjects.push(objDigitalInk); } } function EmbeddedObject() { this.Object = null; this.Initialized = false; } // ===================================================== // === Form Termination === // ===================================================== function terminateFormPage() { if (g_IsViewSource) return; if (!g_IsFormPreview && typeof OnBeforeTerminate != "undefined" && !processCallout(OnBeforeTerminate)) return true; if (!g_IsSearch && !g_IsPreviewPane && !g_IsFormPreview && !g_IsPrinting) getScriptHostQI("IGrooveFormsToolUIDelegate").ClearStatusBarMessage(); // Remove the document from HTMLComponentBridge. removeDocument(); if (!g_IsFormPreview && typeof OnAfterTerminate != "undefined" && !processCallout(OnAfterTerminate)) return true; } function reinitAttachments() { var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction(); try { var FormRecord = openCurrentRecord(); if (FormRecord != null) { g_AttachmentsElement = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").ReinitializeAttachments(document, FormRecord); if (g_AttachmentsObject != null) g_AttachmentsObject.Commands2.Refresh(); } Transaction.Commit(); } catch (error) { //alert("Transaction aborted in reinitAttachments [" + error.description + "]"); Transaction.Abort(); } } // ===================================================== // === Add/Remove Document === // ===================================================== function addDocument() { if (!g_IsFormPreview) { var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction(); try { var FormRecord = openCurrentRecord(); if (FormRecord != null) g_AttachmentsElement = getScriptHostQI("IGrooveFormsToolUIDelegateHTMLDocumentPrivate").AddHTMLDocumentForForm(document, FormRecord, int_CreateBSTREnumFromArray(new Array())); Transaction.Commit(); } catch (error) { //alert("Transaction aborted in addDocument [" + error.description + "]"); Transaction.Abort(); } } } function removeDocument() { if (!g_IsFormPreview) getScriptHostQI("IGrooveFormsToolUIDelegateHTMLDocumentPrivate").RemoveHTMLDocument(document); } // ===================================================== // === Printing Event Handlers === // ===================================================== function beforePrint() { if (!g_IsFormPreview && typeof OnBeforePrint != "undefined" && !processCallout(OnBeforePrint)) return true; if (!g_IsPrinting) subInDivs(); } function afterPrint() { if (!g_IsFormPreview && typeof OnAfterPrint != "undefined" && !processCallout(OnAfterPrint)) return true; if (!g_IsPrinting) putBackTextAreas(); else getScriptHostQI("IGrooveFormsToolPrintDialogDelegatePrivate").PrintingComplete(); } // ===================================================== // === Dirty Bit Handling === // ===================================================== function setIsDirty() { // No need to check if it is already marked as dirty. if (g_IsDirty) return; // Rich text control does not send an event, so verify that it is valid. if (window.event != null) { var KeyCode = window.event.keyCode; var bShift = window.event.shiftKey; if ((KeyCode >= 112 && KeyCode <= 123) || (KeyCode >= 33 && KeyCode <= 40) || (KeyCode >= 16 && KeyCode <= 20) || (KeyCode == 45 && !bShift) || KeyCode == 145 || KeyCode == 27 || KeyCode == 9) return; } // Set the dirty bit to true. int_setIsDirty(true); } function int_setIsDirty(i_IsDirty) { if (g_IsSearch || g_IsPreviewPane || g_IsFormPreview || g_IsReadOnly || g_IsPrinting) return; if (i_IsDirty && (g_IsInitializing || g_IsInitializingTextView || g_IsInitializingDocumentShare)) return; if (!i_IsDirty || (i_IsDirty && g_IsDirty != i_IsDirty)) { getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").SetFormRecordIsDirty(i_IsDirty); g_IsDirty = i_IsDirty; } } // ===================================================== // === Object Initialization === // ===================================================== function enableTextView(i_Index) { g_IsInitializingTextView = true; var RichTextObject = g_RichTextObjects[i_Index].Object; var RichTextName = RichTextObject.name; // Disable all command bar buttons. if (g_IsSearch || g_IsFormPreview || g_IsReadOnly || g_IsPrinting) { setCommandDisabledState(RichTextName + "Bold", true); setCommandDisabledState(RichTextName + "Italic", true); setCommandDisabledState(RichTextName + "Underline", true); setCommandDisabledState(RichTextName + "ChooseFont", true); setCommandDisabledState(RichTextName + "ChooseColor", true); setCommandDisabledState(RichTextName + "Bold", true); setCommandDisabledState(RichTextName + "AlignLeft", true); setCommandDisabledState(RichTextName + "Center", true); setCommandDisabledState(RichTextName + "AlignRight", true); setCommandDisabledState(RichTextName + "Justify", true); setCommandDisabledState(RichTextName + "Bullets", true); setCommandDisabledState(RichTextName + "IncreaseIndent", true); setCommandDisabledState(RichTextName + "DecreaseIndent", true); } if (!g_IsFormPreview) { var RichTextObjectName = null; try { RichTextObjectName = RichTextObject.IGrooveComponent.OpenName(); } catch (error) { } if (RichTextObjectName != null && RichTextObjectName != "") { var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction(); try { var FormRecord = openCurrentRecord(); if (FormRecord != null && FormRecord.HasField(RichTextName)) { var RTFElement = FormRecord.OpenField(RichTextName); RichTextObject.CellContent.ReadContentFromElement(RTFElement); } Transaction.Commit(); } catch (error) { //alert("Transaction aborted in enableTextView(" + i_Index + ") [" + error.description + "]"); Transaction.Abort(); } if (g_IsFormPreview || !g_IsReadOnly || (g_IsReadOnly && !g_IsPreviewPane)) { // Don't allow objects to be dropped in a search dialog. if (g_IsSearch) RichTextObject.IGrooveTextImportControl.AcceptObjects = false; // Set the ReadOnly, BorderHidden, and BackColor properties. var IsReadOnly = false; var ReadOnlyAttribute = RichTextObject.getAttribute("ISREADONLY"); var IsSearchableAttribute = RichTextObject.getAttribute("ISSEARCHABLE"); if (ReadOnlyAttribute != null || g_IsReadOnly || (g_IsSearch && IsSearchableAttribute == null)) IsReadOnly = true; setCommandDisabledState(RichTextName + "Bold", IsReadOnly); setCommandDisabledState(RichTextName + "Italic", IsReadOnly); setCommandDisabledState(RichTextName + "Underline", IsReadOnly); setCommandDisabledState(RichTextName + "ChooseFont", IsReadOnly); setCommandDisabledState(RichTextName + "ChooseColor", IsReadOnly); setCommandDisabledState(RichTextName + "AlignLeft", IsReadOnly); setCommandDisabledState(RichTextName + "Center", IsReadOnly); setCommandDisabledState(RichTextName + "AlignRight", IsReadOnly); setCommandDisabledState(RichTextName + "Justify", IsReadOnly); setCommandDisabledState(RichTextName + "Bullets", IsReadOnly); setCommandDisabledState(RichTextName + "IncreaseIndent", IsReadOnly); setCommandDisabledState(RichTextName + "DecreaseIndent", IsReadOnly); RichTextObject.ReadOnly = IsReadOnly; var BorderHiddenAttribute = RichTextObject.getAttribute("ISBORDERHIDDEN"); if (BorderHiddenAttribute != null) RichTextObject.BorderVisible = false; var BackgroundColorAttribute = RichTextObject.getAttribute("BACKGROUNDCOLOR"); if (BackgroundColorAttribute != null && BackgroundColorAttribute != "") { if (BackgroundColorAttribute == "Transparent") { RichTextObject.BackStyle = 1; } else if (BackgroundColorAttribute.indexOf("#") == 0 && BackgroundColorAttribute.length == 7) { // Reverse red and blue as text view needs BGR, not RGB. var Red = BackgroundColorAttribute.substring(1, 3); var Green = BackgroundColorAttribute.substring(3, 5); var Blue = BackgroundColorAttribute.substring(5, 7); // Convert the HTML color into a long for the text view control. var BackgroundColor = "0x" + Blue + Green + Red; RichTextObject.BackColor = parseInt(BackgroundColor); } } else RichTextObject.BackColor = 0xFFFFFF; } else { var RichTextPreview = document.getElementById(RichTextName + "_preview"); if (RichTextPreview != null) { var RTFContent = getScriptHostQI("IGrooveFormsToolUIDelegatePrintFormPrivate").OpenRTFContent(RichTextObject); if (RTFContent != null) RichTextPreview.innerHTML = RTFContent; else RichTextPreview.innerText = ""; } } } else { window.setTimeout("enableTextView(" + i_Index + ")", 250); } } g_IsInitializingTextView = false; } function enableDocumentShare() { if (g_AttachmentsObject == null) return; if (g_IsSearch || g_IsFormPreview || g_IsPrinting) { setCommandDisabledState(g_AttachmentsObject.name + "Add", true); setCommandDisabledState(g_AttachmentsObject.name + "Launch", true); setCommandDisabledState(g_AttachmentsObject.name + "Save", true); setCommandDisabledState(g_AttachmentsObject.name + "Delete", true); } g_IsInitializingDocumentShare = true; if (!g_IsFormPreview) { try { if (g_AttachmentsObject.Properties2.Initialized) { var IsReadOnly = false; var ReadOnlyAttribute = g_AttachmentsObject.getAttribute("ISREADONLY"); if (ReadOnlyAttribute != null || g_IsReadOnly || g_IsSearch) IsReadOnly = true; setCommandDisabledState(g_AttachmentsObject.name + "Add", IsReadOnly); setCommandDisabledState(g_AttachmentsObject.name + "Delete", IsReadOnly); g_AttachmentsObject.Properties.SetIsDragDropTarget(!IsReadOnly); g_AttachmentsObject.Properties2.SetReadOnlyMode(IsReadOnly); var IsHiddenAttribute = g_AttachmentsObject.getAttribute("ISHIDDEN"); if (IsHiddenAttribute == null) { // Hide the attachments field if it is read-only, or // in the preview pane, and there are no attachments. var AttachmentCount = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").GetAttachmentCount(g_AttachmentsElement); var DisplayStyle = "" if (!g_IsNew && g_IsReadOnly && AttachmentCount == 0) DisplayStyle = "none"; var objAttachmentLabel = document.getElementById(g_AttachmentsObject.name + "_label"); if (objAttachmentLabel != null) objAttachmentLabel.style.display = DisplayStyle; var objAttachmentField = document.getElementById(g_AttachmentsObject.name + "_field"); if (objAttachmentField != null) objAttachmentField.style.display = DisplayStyle; } getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").SetCurrentDocumentShareView(g_AttachmentsObject.object, g_AttachmentsObject.name); } else window.setTimeout("enableDocumentShare()", 250); } catch (error) { window.setTimeout("enableDocumentShare()", 250); } } g_IsInitializingDocumentShare = false; } function setCommandDisabledState(i_Name, i_IsReadOnly) { var objCommand = document.getElementById(i_Name); if (objCommand != null) { objCommand.setAttribute("COMMANDDISABLED", i_IsReadOnly); if (i_IsReadOnly) objCommand.className = "commandDisabled"; else objCommand.className = "command"; } } function setCommandPressedState(i_Name, i_IsPressed) { var objCommand = document.getElementById(i_Name); if (objCommand != null) { if (i_IsPressed && !objCommand.getAttribute("COMMANDPRESSED")) { with (objCommand.style) { backgroundImage = "url(rtf_pressed.gif)"; borderTopColor = "buttonshadow"; borderRightColor = "buttonhighlight"; borderBottomColor = "buttonhighlight"; borderLeftColor = "buttonshadow"; } } else if (!i_IsPressed && objCommand.getAttribute("COMMANDPRESSED")) { with (objCommand.style) { backgroundImage = ""; border = "1px solid buttonface"; } } objCommand.setAttribute("COMMANDPRESSED", i_IsPressed); } } function commandMouseOver(i_Command) { if (!i_Command.getAttribute("COMMANDDISABLED") && !i_Command.getAttribute("COMMANDPRESSED")) i_Command.className = "commandHover"; } function commandMouseOut(i_Command) { if (!i_Command.getAttribute("COMMANDDISABLED") && !i_Command.getAttribute("COMMANDPRESSED")) i_Command.className = "command"; } function commandMouseDown(i_Command) { if (!i_Command.getAttribute("COMMANDDISABLED") && !i_Command.getAttribute("COMMANDPRESSED")) i_Command.className = "commandDown"; } function commandMouseUp(i_Command) { if (!i_Command.getAttribute("COMMANDDISABLED") && !i_Command.getAttribute("COMMANDPRESSED")) i_Command.className = "commandHover"; } // ===================================================== // === Inherit Utility === // ===================================================== function inheritFieldValue(i_Object) { if (i_Object != null & !g_IsSearch && !g_IsFormPreview && !g_IsPrinting && g_IsNew && getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").IsValidRecord(g_SelectedID)) { var objControl = i_Object; if (typeof i_Object.Object != "undefined") objControl = i_Object.Object; var InheritAttribute = objControl.getAttribute("INHERIT"); if (InheritAttribute != null && InheritAttribute != "") { var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction(); try { var ObjectName = objControl.name; if (InheritAttribute == "FormsInheritSelf") InheritAttribute = ObjectName; var ParentRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").OpenRecord(g_SelectedID); if (ParentRecord.HasField(InheritAttribute)) { var FormRecord = openCurrentRecord(); if (FormRecord != null) FormRecord.SetField(ObjectName, ParentRecord.OpenField(InheritAttribute)); } Transaction.Commit(); } catch (error) { //alert("Transaction aborted in inheritFieldValue [" + error.description + "]"); Transaction.Abort(); } } } } // ===================================================== // === Option Utility === // ===================================================== function addNewOption(i_Name) { try { var DocumentElement = document.getElementById(i_Name); if (DocumentElement != null) { var AddOptionResult = getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayTextInputDialog("Enter text:", "Add Custom Entry"); if (AddOptionResult.Result == GrooveDialogBoxResultCode_OK) { insertNewOption(DocumentElement, AddOptionResult.Data, AddOptionResult.Data, true); DocumentElement.fireEvent("onchange"); } } } catch (error) { var OptionError = "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."; getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayError(OptionError); } } function insertNewOption(i_Element, i_Value, i_Text, i_IsSelected) { var NewOption = document.createElement("OPTION"); NewOption.value = i_Value; NewOption.text = i_Text; i_Element.options.add(NewOption); if (i_IsSelected) i_Element.value = i_Value; } // ===================================================== // === Data Submission === // ===================================================== function submitData() { if (!g_IsFormPreview && typeof OnBeforeSubmitData != "undefined" && !processCallout(OnBeforeSubmitData)) return true; // Only continue if data saved with no errors. if (submitDataNoNavigate()) { if (!g_IsFormPreview && typeof OnAfterSubmitData != "undefined" && !processCallout(OnAfterSubmitData)) return true; // MWATodo: we have to do these timeouts to avoid a deadlock for now. if (g_IsCreateAnother) { var strHref = window.location.href; strHref = strHref.replace(/(.*)\?.*$/, "$1"); var strQuery = ""; if (g_SelectedID != -1 && getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").IsValidRecord(g_SelectedID)) { var strSelectedID = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").ConvertDesignObjectIDToString(g_SelectedID); strQuery = "?SelectedID=" + strSelectedID; } else if (g_IsResponse) { var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction(); try { // If it is a response, get the parent id and pass it along. var FormRecord = openCurrentRecord(); if (FormRecord != null && FormRecord.HasField("_ParentID")) strQuery = "?SelectedID=" + FormRecord.OpenField("_ParentID"); Transaction.Commit(); } catch (error) { //alert("Transaction aborted in submitData [" + error.description + "]"); Transaction.Abort(); } } var strFormID = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").ConvertDesignObjectIDToString(g_FormID); if (strQuery != "") strQuery += "&FormID=" + strFormID; else strQuery = "?FormID=" + strFormID; window.setTimeout("window.location.href = '" + strHref + strQuery + "'", 50); } else if (g_IsSearch) { var UIDelegate = getScriptHostQI("IGrooveFormsToolSearchDialogDelegatePrivate").GetUIDelegate(); UIDelegate.IGrooveFormsToolUIDelegatePrivate.DoSearch(); return true; } else { window.setTimeout("getScriptHostQI('IGrooveFormsToolUIDelegatePrivate').SwitchWebState(FormsUIState_HomePage, -1)", 50); } } } function submitDataNoNavigate() { // Fire the onblur event for all elements in the form. var DocumentForm = document.GrooveFormBase; for (var i = 0; i < DocumentForm.elements.length; i++) { var DocumentElement = DocumentForm.elements[i]; DocumentElement.fireEvent("onblur"); } // Check error array to see if there are still uncorrected errors. for (var i = 0; i < g_arrErrors.length; i++) { if (typeof g_arrErrors[i] != "undefined") { getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayOKMessageBox("The form values you have entered are not valid. Please correct the error(s) as displayed in the form.", "Invalid Form Values"); getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").HasValidationErrors = true; g_IsCreateAnother = false; return false; } } getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").HasValidationErrors = false; var ParentIDHasBeenReset = false; if (g_IsNew && g_IsResponse && !getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DoesRecordExist(g_SelectedID)) { var ResponseErrorMessage = "The selected parent record has been deleted. Do you want to to save this response as a main document? If you click 'No', this response will not be saved and all data will be lost."; if (getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayYesNoMessageBox(ResponseErrorMessage, "Invalid Selection")) { var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction(); try { var FormRecord = openCurrentRecord(); FormRecord.SetField("_ParentID", -1); ParentIDHasBeenReset = true; Transaction.Commit(); } catch (error) { Transaction.Abort(); } } else { window.setTimeout("getScriptHostQI('IGrooveFormsToolUIDelegatePrivate').SwitchWebState(FormsUIState_HomePage, -1)", 50); return; } } if (!g_IsFormPreview && !g_IsSearch && typeof OnBeforePropagateUpdates != "undefined" && !processCallout(OnBeforePropagateUpdates)) return true; var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction(); try { var FormRecord; if (!g_IsSearch) { FormRecord = openCurrentRecord(); if (FormRecord != null) { // If the record is versioned, save a copy as a child. if (!g_IsNew && g_IsVersioned) getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").CreateVersionedRecord(FormRecord, g_RecordID); // Save the parent ID if this is a response record. if (g_IsNew && g_IsResponse && !ParentIDHasBeenReset) { var ParentID = -1; if (FormRecord.HasField("_ParentID")) ParentID = FormRecord.OpenField("_ParentID"); if (!getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").IsValidRecord(ParentID)) FormRecord.SetField("_ParentID", g_SelectedID); } // Save the form ID, for later use. var FormID = FormRecord.OpenField("Forms_Tool_grooveFormID"); if (FormID != g_FormID) FormRecord.SetField("Forms_Tool_grooveFormID", g_FormID); // Save the record ID for script use. g_RecordID = FormRecord.ID; } } else { // Start the search query on the UI delegate. var UIDelegate = getScriptHostQI("IGrooveFormsToolSearchDialogDelegatePrivate").GetUIDelegate(); UIDelegate.IGrooveFormsToolUIDelegatePrivate.StartSearchQuery(g_SearchType); } // Reset the per-identity fields array. g_PerIdentityFields = new Array(); // Iterate through form elements to set values in the record. var DocumentForm = document.GrooveFormBase; for (var i = 0; i < DocumentForm.elements.length; i++) { var DocumentElement = DocumentForm.elements[i]; setFormElementValue(DocumentElement, FormRecord); } // Add the record to the database if it is new. if (g_IsNew && !g_IsSearch) { if (FormRecord != null) { getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").AddRecord(FormRecord); getScriptHostQI("IGrooveFormsToolUIDelegateViewPrivate").SetFocusRecordID(FormRecord.ID); // Set all of the per-identity fields after the record has been added. for (var i = 0; i < g_PerIdentityFields.length; i++) { var PerIdentityField = g_PerIdentityFields[i]; switch (PerIdentityField.Type) { case "String": FormRecord.SetField(PerIdentityField.Name, PerIdentityField.Value); break; case "R8": FormRecord.SetField(PerIdentityField.Name, PerIdentityField.Value); break; case "Date": FormRecord.SetField(PerIdentityField.Name, PerIdentityField.Value); break; case "Element": FormRecord.SetField(PerIdentityField.Name, PerIdentityField.Value); break; case "Ink": FormRecord.SetField(PerIdentityField.Name, PerIdentityField.Value); break; } } } // Make sure the UIDelegate knows that the auto-create record has been created. if (getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").NeedToAutoCreateRecord()) getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").AutoCreateRecordCreated(); } // Reset the per-identity fields array to clear out old values. g_PerIdentityFields = new Array(); // Set the dirty bit to false. int_setIsDirty(false); Transaction.Commit(); if (!g_IsFormPreview && !g_IsSearch && typeof OnAfterPropagateUpdates != "undefined" && !processCallout(OnAfterPropagateUpdates)) return true; return true; } catch (error) { //alert("Transaction aborted in submitDataNoNavigate [" + error.description + "]"); Transaction.Abort(); return false; } } function PerIdentityField(i_Name, i_Value, i_Type) { this.Name = i_Name; this.Value = i_Value; this.Type = i_Type; } function setFormElementValue(i_Element, i_Record) { var ElementName = i_Element.name; var ElementType = i_Element.type; var ElementDataType = i_Element.getAttribute("DATATYPE"); var IsPerIdentity = false; var IsPerIdentityAttribute = i_Element.getAttribute("ISPERIDENTITY"); if (IsPerIdentityAttribute != null) IsPerIdentity = true; if (g_IsSearch || (typeof i_Record != "undefined" && i_Record != null)) { // Check to see if the field exists in the record. if (g_IsSearch || i_Record.HasField(ElementName)) { // Set the value for each field depending on the element type. if (ElementType == "text" || ElementType == "textarea" || ElementType == "password") { var ElementValue = i_Element.value; if (ElementDataType == "Numeric") { if (typeof ElementValue != "undefined" && ElementValue != null && ElementValue != "") { ElementValue = getValidNumber(i_Element); if (g_IsSearch) addToCurrentSearch(ElementName, ElementValue.toString()); } else ElementValue = 0; if (!g_IsSearch) { var RecordValue = i_Record.OpenField(ElementName); if (RecordValue != ElementValue) { if (g_IsNew && IsPerIdentity) g_PerIdentityFields.push(new PerIdentityField(ElementName, ElementValue, "R8")); else i_Record.SetField(ElementName, ElementValue); } } } else if (ElementDataType == "Date") { if (ElementValue != "") { var DateFormat = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").CreateDateFormatStyleFromAttributeValue(i_Element.getAttribute("FORMAT")); ElementValue = getValidDateMillis(ElementValue, DateFormat, i_Element); } else ElementValue = INVALID_DATE; // If this is a search add the field to the query. if (g_IsSearch) { if (ElementValue != INVALID_DATE) addToCurrentSearch(ElementName, ElementValue.toString()); } else { var RecordValue = i_Record.OpenField(ElementName); if (RecordValue != ElementValue) { if (g_IsNew && IsPerIdentity) g_PerIdentityFields.push(new PerIdentityField(ElementName, ElementValue, "Date")); else i_Record.SetField(ElementName, ElementValue); } } } else { // If this is a search add the field to the query. if (g_IsSearch) addToCurrentSearch(ElementName, ElementValue); else { var RecordValue = i_Record.OpenField(ElementName); if (RecordValue != ElementValue) { if (g_IsNew && IsPerIdentity) g_PerIdentityFields.push(new PerIdentityField(ElementName, ElementValue, "String")); else i_Record.SetField(ElementName, ElementValue); } } } } else if (ElementType == "checkbox") { var ElementValue = ""; if (i_Element.checked) { ElementValue = i_Element.value; if (ElementValue == "on" || ElementValue == "") ElementValue = "true"; } // If this is a search add the field to the query. if (g_IsSearch) addToCurrentSearch(ElementName, ElementValue); else { var RecordValue = i_Record.OpenField(ElementName); if (RecordValue != ElementValue) { if (g_IsNew && IsPerIdentity) g_PerIdentityFields.push(new PerIdentityField(ElementName, ElementValue, "String")); else i_Record.SetField(ElementName, ElementValue); } } } else if (ElementType == "radio") { if (i_Element.checked) { var ElementValue = i_Element.value; // If this is a search add the field to the query. if (g_IsSearch) addToCurrentSearch(ElementName, ElementValue); else { var RecordValue = i_Record.OpenField(ElementName); if (RecordValue != ElementValue) { if (g_IsNew && IsPerIdentity) g_PerIdentityFields.push(new PerIdentityField(ElementName, ElementValue, "String")); else i_Record.SetField(ElementName, ElementValue); } } } } if (ElementType == "select-one") { var ElementValue = ""; var SelectedIndex = i_Element.selectedIndex; if (SelectedIndex >= 0) ElementValue = i_Element.options[SelectedIndex].value; // If this is a search add the field to the query. if (g_IsSearch) addToCurrentSearch(ElementName, ElementValue); else { var RecordValue = i_Record.OpenField(ElementName); if (RecordValue != ElementValue) { if (g_IsNew && IsPerIdentity) g_PerIdentityFields.push(new PerIdentityField(ElementName, ElementValue, "String")); else i_Record.SetField(ElementName, ElementValue); } } } else if (ElementType == "select-multiple") { var ElementValue = ""; // Editors and Readers fields are separated with a semi-colon. var ElementValueSeparator = "\n"; if (ElementName == "_Editors" || ElementName == "_Readers") ElementValueSeparator = ";"; for (var i = 0; i < i_Element.options.length; i++) { if (i_Element.options[i].selected) { var TempValue = i_Element.options[i].value; if (TempValue == "") TempValue = i_Element.options[i].text; if (ElementValue != "") ElementValue += ElementValueSeparator + TempValue; else ElementValue += TempValue; } } // If this is a search add the field to the query. if (g_IsSearch) addToCurrentSearch(ElementName, ElementValue); else { var RecordValue = i_Record.OpenField(ElementName); if (RecordValue != ElementValue) { if (g_IsNew && IsPerIdentity) g_PerIdentityFields.push(new PerIdentityField(ElementName, ElementValue, "String")); else i_Record.SetField(ElementName, ElementValue); } } } else if (ElementDataType == "RichText") { if (g_IsSearch) { // Get the plain text out of the rich text object. var PlainText = i_Element.TextContent.PlainText; if (PlainText != "") addToCurrentSearch(ElementName, PlainText.replace(/^[\n\r]*/, "").replace(/[\n\r]*$/, "")); } else { var RichTextElement = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").CreateRichTextElement(); i_Element.CellContent.WriteContentToElement(RichTextElement); var RecordElement = i_Record.OpenField(ElementName); if (!RecordElement.Equals(RichTextElement)) { if (g_IsNew && IsPerIdentity) g_PerIdentityFields.push(new PerIdentityField(ElementName, RichTextElement, "Element")); else i_Record.SetField(ElementName, RichTextElement); } } } else if (ElementDataType == "Attachments") { if (!g_IsSearch) { var AttachmentCount = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").GetAttachmentCount(g_AttachmentsElement); // Set the file icon field if there is at least one attachment. i_Record.SetField("FileIcon", AttachmentCount > 0 ? 1 : 0); // Set the attachment element if it has changed. var RecordElement = i_Record.OpenField(ElementName); if (!RecordElement.Equals(g_AttachmentsElement)) { if (g_IsNew && IsPerIdentity) g_PerIdentityFields.push(new PerIdentityField(ElementName, g_AttachmentsElement, "Element")); else i_Record.SetField(ElementName, g_AttachmentsElement); } } } else if (ElementDataType == "Ink") { if (!g_IsSearch) { var DigitalInkBinary = i_Element.Ink.Save(IPF_GIF); if (g_IsNew && IsPerIdentity) g_PerIdentityFields.push(new PerIdentityField(ElementName, DigitalInkBinary, "Ink")); else i_Record.SetField(ElementName, DigitalInkBinary); } } } } } function addToCurrentSearch(i_Name, i_Value) { if (typeof i_Value != "undefined" && i_Value != null && i_Value.toString() != "") getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").AddToSearchQuery(i_Name, i_Value); } // ===================================================== // === Button Event Handlers === // ===================================================== function saveAndCreateAnother() { g_IsCreateAnother = true; submitData(); } function resetData() { if (!g_IsSearch) window.location.reload(true); } function cancelEdit() { if (!g_IsSearch) { getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").HasValidationErrors = false; window.setTimeout("getScriptHostQI('IGrooveFormsToolUIDelegatePrivate').SwitchWebState(FormsUIState_HomePage, -1)", 50); } } function printForm() { try { // Have to call directly to the script dispatch when in the dialog. if (!g_IsPrinting) getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").PrintForm(); else getScriptHostQI("IGrooveFormsToolPrintDialogDelegatePrivate").PrintForm(); } catch (error) { } } function printThroughForm() { var blnContinue = true; for (var i = 0; i < g_RichTextObjects.length; i++) { if (!g_RichTextObjects[i].Initialized) { blnContinue = false; break; } } if (!blnContinue) { window.setTimeout("printThroughForm()", 250); return; } // If all objects are done initializing then we should print. printForm(); } function updateLookups() { var SourceElement = window.event.srcElement; int_updateLookups(false, SourceElement.name); } function int_updateLookups(i_IsInitial, i_SourceElementName) { // Iterate through elements in the form to perform lookups. var DocumentForm = document.GrooveFormBase; if (DocumentForm != null && DocumentForm.elements != null) { for (var i = 0; i < DocumentForm.elements.length; i++) { var DocumentElement = DocumentForm.elements[i]; if (DocumentElement.name != i_SourceElementName) { var LookupAttribute = DocumentElement.getAttribute("LOOKUP"); if (LookupAttribute != null) updateLookup(DocumentElement, i_IsInitial, i_SourceElementName); } } } // Iterate through DIV tags to perform lookups on static text fields. var DivArray = document.getElementsByTagName("DIV"); for (var i = 0; i < DivArray.length; i++) { var DocumentDiv = DivArray[i]; var LookupAttribute = DocumentDiv.getAttribute("LOOKUP"); if (LookupAttribute != null) updateLookup(DocumentDiv, i_IsInitial, i_SourceElementName); } } function doSearch(i_Type) { g_IsSearch = true; g_SearchType = i_Type; return submitData(); } // ===================================================== // === Field Value Lookup === // ===================================================== function updateLookup(i_Element, i_IsInitial, i_SourceElementName) { // Don't redo any lookups with just switching records. if (g_IsPreviewPaneRefresh && i_Element.tagName == "SELECT") return; var FieldName = i_Element.id; var LookupString = int_GetLookupStringForObject(FieldName); if (LookupString != null && LookupString != "") { // Get all of the values from the lookup string. var TelespaceDisplayName = convertFromXMLName(getValueFromQueryString("TelespaceName", LookupString)); var TelespaceURL = convertFromXMLName(getValueFromQueryString("TelespaceURL", LookupString)); var ToolDisplayName = convertFromXMLName(getValueFromQueryString("ToolDisplayName", LookupString)); var ToolName = convertFromXMLName(getValueFromQueryString("ToolName", LookupString)); var ViewName = convertFromXMLName(getValueFromQueryString("ViewName", LookupString)); var ViewID = convertFromXMLName(getValueFromQueryString("ViewID", LookupString)); var KeyColumn = convertFromXMLName(getValueFromQueryString("KeyColumn", LookupString)); var KeyValue = convertFromXMLName(getValueFromQueryString("KeyValue", LookupString)); var LookupColumn = convertFromXMLName(getValueFromQueryString("LookupColumn", LookupString)); var ReturnUnique = getValueFromQueryString("ReturnUnique", LookupString); var NoCache = getValueFromQueryString("NoCache", LookupString); var KeyValueIsFieldName = getValueFromQueryString("KeyValueIsFieldName", LookupString); // Convert the boolean values from strings. var bReturnUnique = false; if (ReturnUnique == "true") bReturnUnique = true; var bNoCache = false; if (NoCache == "true") bNoCache = true; // Get the true key value from a field if it is a field name. if (KeyValueIsFieldName == "true") { // Make sure to only update any lookups that rely on the source field. if (typeof i_SourceElementName != "undefined" && i_SourceElementName != null && i_SourceElementName != "" && i_SourceElementName != KeyValue) return; var KeyValueElement = document.getElementById(KeyValue); if (KeyValueElement != null) { var KeyValueElementType = KeyValueElement.type; if (KeyValueElementType == "text" || KeyValueElementType == "textarea") KeyValue = KeyValueElement.value; else if (KeyValueElementType.indexOf("select") == 0 && KeyValueElement.selectedIndex >= 0) KeyValue = KeyValueElement.options[KeyValueElement.selectedIndex].value; else KeyValue = ""; if (i_IsInitial) { if (KeyValueElementType == "text" || KeyValueElementType == "textarea" || KeyValueElementType.indexOf("select") == 0) KeyValueElement.attachEvent("onchange", updateLookups); else if (KeyValueElementType == "password") KeyValueElement.attachEvent("onblur", updateLookups); else if (KeyValueElementType == "checkbox" || KeyValueElementType == "radio") KeyValueElement.attachEvent("onclick", updateLookups); } } else { displayStatusBar("The field '" + KeyValue + "' does not exist on the form, so the lookup for the field '" + FieldName + "' was not performed.", GrooveMessageBoxIcon_Error); return; } } else if (typeof i_SourceElementName != "undefined" && i_SourceElementName != null && i_SourceElementName != "") return; var ElementType = i_Element.type; var ElementTagName = i_Element.tagName.toUpperCase(); if (ElementTagName == "DIV") ElementType = "static"; // Reset the value of the field. var PreviousDropDownValue = ""; var PreviousListBoxArray = new Array(); if (ElementTagName == "DIV") { if (!i_IsInitial) i_Element.innerText = ""; } else if (ElementType.indexOf("select") == 0) { var ElementOptionsLength = i_Element.options.length; if (ElementType == "select-one") PreviousDropDownValue = i_Element.value; else if (ElementType == "select-multiple") { for (var i = 0; i < ElementOptionsLength; i++) { if (i_Element.options[i].selected) PreviousListBoxArray.push(i_Element.options[i].value); } } // Remove any non-original values from the control. var RemoveCount = 0; for (var i = 0; i < ElementOptionsLength; i++) { var OriginalAttribute = i_Element.options[RemoveCount].getAttribute("ORIGINAL"); if (OriginalAttribute != null) RemoveCount++; else i_Element.options.remove(RemoveCount); } // Put the member names back if they should be there. var MembersAttribute = i_Element.getAttribute("MEMBERS"); if (MembersAttribute != null) { var MemberNameEnum = getScriptHostQI("IGrooveFormsToolUIDelegate").CreateMemberNameEnum(); while (MemberNameEnum.HasMore()) { var MemberName = MemberNameEnum.OpenNext(); insertNewOption(i_Element, MemberName, MemberName, false); } } } else { if (!i_IsInitial) i_Element.value = ""; } // Put the value returned from the lookup into the element. var strValueText = ""; // Specify the string separator to use for text fields. var strValueSep = ", "; if (ElementType == "textarea") strValueSep = "\n"; var ValueEnum = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").LookupValues(TelespaceURL, ToolName, Number(ViewID), KeyColumn, KeyValue, LookupColumn, bReturnUnique, bNoCache); while (ValueEnum != null && ValueEnum.HasMore()) { var strValue = ValueEnum.OpenNext(); if (ElementType.indexOf("select") == 0) { // Don't include blank entries if the lookup is unique and a blank is already included. if (bReturnUnique && strValue == "" && i_Element.getAttribute("BLANK") != null) continue; insertNewOption(i_Element, strValue, strValue, false); } else if (strValueText != "") strValueText += strValueSep + strValue; else strValueText += strValue; } // Set the value if it is a text based field. if (!g_IsSearch) { if (ElementTagName == "DIV") i_Element.innerText = strValueText; else if (ElementType == "text" || ElementType == "textarea") i_Element.value = strValueText; } // If this is the initial lookup, insert the record value. if (i_IsInitial) { var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction(); try { var FormRecord = openCurrentRecord(); if (FormRecord != null && FormRecord.HasField(FieldName)) { if (ElementType == "select-one") PreviousDropDownValue = FormRecord.OpenField(FieldName); else if (ElementType == "select-multiple") { var FieldValue = FormRecord.OpenField(FieldName); PreviousListBoxArray = FieldValue.split("\n"); } } Transaction.Commit(); } catch (error) { Transaction.Abort(); } } // If the value should be inherited, set it. var InheritedValue = i_Element.getAttribute("INHERITEDVALUE"); if (i_IsInitial && InheritedValue != null && InheritedValue != "") { if (ElementType == "select-one") PreviousDropDownValue = InheritedValue; else if (ElementType == "select-multiple") PreviousListBoxArray = InheritedValue.split("\n"); } // Make sure the value that was previously selected is still selected. if (ElementType == "select-one" && PreviousDropDownValue != "") { for (var i = 0; i < i_Element.options.length; i++) { if (i_Element.options[i].value == PreviousDropDownValue) { i_Element.options[i].selected = true; break; } } } // List boxes can have multiple items selected so check the previous array. if (ElementType == "select-multiple" && PreviousListBoxArray.length > 0) { for (var i = 0; i < PreviousListBoxArray.length; i++) { for (var j = 0; j < i_Element.options.length; j++) { if (i_Element.options[j].value == PreviousListBoxArray[i]) { i_Element.options[j].selected = true; break; } } } } } } function convertFromXMLName(i_XMLName) { var Value = i_XMLName; if (i_XMLName != "") Value = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").ConvertFromXMLName(i_XMLName); return Value; } // ===================================================== // === Design/Role Event Handlers === // ===================================================== function designChanged() { // We only need to call this method once. if (!g_HasDesignChanged) { // Disable the attachments buttons if they are present if (g_AttachmentsObject != null) { removeDocument(); setCommandDisabledState(g_AttachmentsObject.name + "Add", true); setCommandDisabledState(g_AttachmentsObject.name + "Delete", true); addDocument(); if (g_AttachmentsObject.Properties2.Initialized) g_AttachmentsObject.Properties2.SetReadOnlyMode(true); } // Since the document can no longer be saved, it is not dirty. int_setIsDirty(false); g_HasDesignChanged = true; } } function roleChanged() { var EnableButtons = false; if (g_IsNew) EnableButtons = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CanCreateRecords(); else EnableButtons = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CanEditRecord(g_RecordID); // Disable the attachments buttons if they are present if (g_AttachmentsObject != null && EnableButtons == false) { removeDocument(); setCommandDisabledState(g_AttachmentsObject.name + "Add", !EnableButtons); setCommandDisabledState(g_AttachmentsObject.name + "Delete", !EnableButtons); addDocument(); if (g_AttachmentsObject.Properties2.Initialized) g_AttachmentsObject.Properties2.SetReadOnlyMode(!EnableButtons); } } // ===================================================== // === QueryString Utility === // ===================================================== function getQueryStringVariables() { var strSearch = String(window.location.search).substring(1); var arrSearch = strSearch.split("&"); for (var i = 0; i < arrSearch.length; i++) { // Set up global variables depending on querystring values. var arrSubSearch = arrSearch[i].split("="); switch (arrSubSearch[0]) { case "Search": g_IsSearch = true; break; case "PreviewPane": g_IsPreviewPane = true; break; case "FormPreview": g_IsFormPreview = true; break; case "ViewSource": g_IsViewSource = true; break; case "Printing": g_IsPrinting = true; g_IsReadOnly = true; break; case "Printing": g_IsPrinting = true; g_IsReadOnly = true; break; case "RecordID": g_RecordID = Number(arrSubSearch[1]); break; case "SelectedID": g_SelectedID = Number(arrSubSearch[1]); break; case "FormID": g_FormID = Number(arrSubSearch[1]); break; } } if (!isNaN(g_FormID) && g_FormID != -1) { if (!g_IsSearch) { if (!g_IsFormPreview && !g_IsPrinting) { // If there is a valid FormID, check if records should be versioned g_IsVersioned = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").GetFormRecordsAreVersioned(g_FormID); // If there is a valid FormID, check if it is a response form. g_IsResponse = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").GetFormIsResponse(g_FormID); if (g_RecordID != -1 && !getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DoesRecordExist(g_RecordID)) g_RecordID = -1; if (g_SelectedID != -1 && !getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DoesRecordExist(g_SelectedID)) g_SelectedID = -1; // Check to see if the record should be read-only. if (getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DoesRecordExist(g_RecordID)) g_IsReadOnly = !getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CanEditRecord(g_RecordID); } // The record should always be read-only in the preview pane or form preview. if (g_IsPreviewPane || g_IsFormPreview) g_IsReadOnly = true; } } else { if (!g_IsSearch) window.setTimeout("getScriptHostQI('IGrooveFormsToolUIDelegatePrivate').SwitchWebState(FormsUIState_HomePage, -1)", 50); } } // ===================================================== // === Record Utility === // ===================================================== function openCurrentRecord() { if (g_IsNew) return g_NewRecord; else { if (g_IsPrinting) { return getScriptHostQI("IGrooveFormsToolPrintDialogDelegatePrivate").OpenFormRecord(g_RecordID); } else { if (getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DoesRecordExist(g_RecordID)) return getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").OpenRecord(g_RecordID); else return null; } } }