0byt3m1n1
Path:
C:
/
Program Files (x86)
/
Microsoft Office
/
Office12
/
Groove
/
ToolData
/
groove.net
/
GrooveForms5
/
[
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. var g_IsNew = false; var g_IsSearch = false; var g_IsPreviewPane = false; var g_IsReadOnly = false; var g_IsResponse = false; var g_IsVersioned = false; var g_RecordID = -1; var g_FormID = -1; var g_SelectedID = -1; var 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_InitializedDocumentShare = false; var g_IsPreviewPaneRefresh = false; var g_IsViewSource = false; var g_IsPrinting = false; var g_HasDesignChanged = false; var g_BypassEventCallouts = false; var g_NewRecord; var g_SearchType; var g_RichTextObjects = new Array(); var g_DataListObjects = new Array(); var g_ContactFields = new Array(); var g_RegisteredContactFields = new Array(); var g_AttachmentsObject; var g_AttachmentsElement; var g_EnableTextViewCount = 0; var g_EnableDocumentShareCount = 0; var g_EnableDataListCount = 0; var g_IsDirty = false; var g_SaveAsMain = false; // ===================================================== // === Document Event Handlers === // ===================================================== document.onkeydown = keyDownEvent; document.oncontextmenu = contextMenuEvent; function keyDownEvent() { var objElement = event.srcElement; if (event.keyCode == 27) { if (!g_IsSearch && !g_IsPreviewPane && !g_IsPrinting && !g_IsFormPreview) { // Cancel the ESC key, but prompt for changes if we should. event.returnValue = false; getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").RunEscapeHandler(); // Return focus back to the original control. if (objElement != null) objElement.focus(); } } else { // 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) { var TagName = event.srcElement.tagName; var ClassName = event.srcElement.className; var bTextSelected = (document.selection.type.toLowerCase() == "text"); var bTagSelected = (TagName == "A"); bTagSelected |= (TagName == "INPUT" && ClassName != "radio" && ClassName != "checkbox"); bTagSelected |= (TagName == "SELECT"); bTagSelected |= (TagName == "TEXTAREA"); if (bTextSelected || bTagSelected) { event.returnValue = true; event.cancelBubble = true; } else event.returnValue = false; } } // ===================================================== // === Form Initialization === // ===================================================== function initFormPage(i_RecordID) { if (g_IsViewSource) return; if (!g_IsSearch && !g_IsPreviewPane && !g_IsFormPreview && !g_IsPrinting) getScriptHostQI("IGrooveFormsToolUIDelegate").ClearStatusBarMessage(); if (!g_IsFormPreview && typeof OnBeforeInitialize != "undefined" && !processCallout(OnBeforeInitialize)) return true; // Let the UIDelegate know there are no validation errors. getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").HasValidationErrors = false; // ReEnable the Save And Create Another command if (!g_IsFormPreview) getScriptHostQI('IGrooveFormsToolUIDelegateFormPrivate').ReEnableCommand(); // 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_ContactFields = new Array(); g_RegisteredContactFields = 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 UIDelegatePrivate = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate"); var RecordType = UIDelegatePrivate.GetRecordTypeFromFormID(g_FormID); if (!g_IsSearch && !g_IsPreviewPane && !g_IsPrinting && !g_IsFormPreview && getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").NeedToAutoCreateRecord()) { if (getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").LimitOneRecordPerMember) { FormRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CreateOrOpenMemberRecord(RecordType); getScriptHostQI("IGrooveFormsToolUIDelegateViewPrivate").SetFocusRecordID(FormRecord.ID); } else FormRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CreateRecord(RecordType); if (!getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DoesRecordExist(FormRecord.ID)) { 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(RecordType); else if (g_IsFormPreview) FormRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CreateSandboxedRecord(RecordType); else if (g_IsPrinting && g_RecordID != null && g_RecordID != -1) FormRecord = getScriptHostQI("IGrooveFormsToolPrintDialogDelegatePrivate").OpenFormRecord(); 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) { // Mark the record read if it is opened full-screen. getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").MarkRecordRead(g_RecordID); // Set the focus record ID as the current record ID. getScriptHostQI("IGrooveFormsToolUIDelegateViewPrivate").SetFocusRecordID(g_RecordID); } FormRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").OpenRecord(g_RecordID); } else { if (getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").LimitOneRecordPerMember) FormRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CreateOrOpenMemberRecord(RecordType); else FormRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").CreateRecord(RecordType); if (!getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DoesRecordExist(FormRecord.ID)) { g_IsNew = true; g_NewRecord = FormRecord; g_RecordID = FormRecord.ID; } else g_RecordID = FormRecord.ID; } } } // 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(); } // Update any lookups included in the form. if (!g_IsFormPreview) int_updateLookups(true, ""); // Add the document to HTMLComponentBridge. addDocument(); // 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 embedded view fields. for (var i = 0; i < g_DataListObjects.length; i++) { window.setTimeout("enableDataList(" + i + ")", 10); } // Enable attachments fields. window.setTimeout("enableDocumentShare()", 10); if (!g_IsSearch && !g_IsFormPreview && !g_IsPrinting) getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").SetCurrentFormDocument(document); // Enable all contact fields. for (var i = 0; i < g_ContactFields.length; i++) { inheritFieldValue(g_ContactFields[i]); } enableContactFields(); if (!g_IsPrinting) registerContactFields(); // 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_IsPreviewPane) getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").OnPreviewPaneLoadingComplete(); 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 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\" TABINDEX=\"1\" 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\" TABINDEX=\"1\" CLASS=\"text\" ID=\"_CreatedSearch\" NAME=\"_CreatedSearch\" DATATYPE=\"Date\" FORMAT=\"3\"><BUTTON CLASS=\"dateButton\" NAME=\"_CreatedButton\" ID=\"_CreatedButton\" TABINDEX=\"1\" ONCLICK=\"doCalendar('_CreatedSearch');\"><IMG SRC=\"calendar.gif\" WIDTH=15 HEIGHT=13></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\" TABINDEX=\"1\" 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\" TABINDEX=\"1\" CLASS=\"text\" ID=\"_ModifiedSearch\" NAME=\"_ModifiedSearch\" DATATYPE=\"Date\" FORMAT=\"3\"><BUTTON CLASS=\"dateButton\" NAME=\"_ModifiedButton\" ID=\"_ModifiedButton\" TABINDEX=\"1\" ONCLICK=\"doCalendar('_ModifiedSearch');\"><IMG SRC=\"calendar.gif\" WIDTH=15 HEIGHT=13></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; } } } var DocumentSpans = document.getElementsByTagName("SPAN"); for (var i = 0; i < DocumentSpans.length; i++) { if (DocumentSpans[i].getAttribute("DATATYPE") == "Contact") initFormObject(DocumentSpans[i]); } } function clearFormElement(i_Element) { var ElementName = i_Element.id; if (ElementName == "") ElementName = i_Element.name; var ElementType = i_Element.type; var ElementDataType = i_Element.getAttribute("DATATYPE"); if (ElementType == "text" || ElementType == "textarea" || ElementType == "password") { if (ElementName.indexOf("_Time") < 0) 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.id; if (ElementName == "") 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 = int_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 { var Priv = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate"); // IDS_FORMS_TOOL_JS_INVALID_ITEM_ERROR displayStatusBar(Priv.GetResourcedString(IDS_FORMS_TOOL_JS_INVALID_ITEM_ERROR), GrooveMessageBoxIcon_Error); } } } // Set the value for each field depending on the element type. if (ElementType == "text" || ElementType == "textarea" || ElementType == "password") { if (ElementDataType == "Date") { // Will be new code for date and time fields. // Commenting out for now so I can check in. var DateValue = ""; var TimeValue = ""; if (ElementValue != INVALID_DATE) { try { var DateFormat = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").CreateDateFormatStyleFromAttributeValue(i_Element.getAttribute("FORMAT")); var NumberValue = Number(ElementValue); if (!isNaN(NumberValue)) { var FieldTypeAttribute = i_Element.getAttribute("FIELDTYPE"); if (FieldTypeAttribute == FormObjectType_DateTime) { var DateTimeEnum = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").FormatDateAndTime(NumberValue, DateFormat, 3); if (DateTimeEnum.HasMore()) DateValue = DateTimeEnum.OpenNext(); if (DateTimeEnum.HasMore()) TimeValue = DateTimeEnum.OpenNext(); } else DateValue = getScriptHostQI("IGrooveFormsToolUIDelegate").FormatDate(NumberValue, DateFormat); } } catch (error) { } } if (g_IsReadOnly && !g_IsFormPreview) { ElementPreview.innerText = DateValue; if (FieldTypeAttribute == FormObjectType_DateTime) ElementPreview.innerText += " " + TimeValue; } i_Element.value = DateValue; if (FieldTypeAttribute == FormObjectType_DateTime) { var TimeElement = document.getElementById(ElementName + "_Time"); if (TimeElement != null) TimeElement.value = TimeValue; } } 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.value || ElementValue == "true") && 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 { var Priv = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate"); if (g_IsPreviewPane) { // IDS_FORMS_TOOL_JS_PREVIEW_RECORD_DELETED_ERROR and IDS_FORMS_TOOL_JS_RECORD_DELETED_TITLE getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayOKMessageBox(Priv.GetResourcedString(IDS_FORMS_TOOL_JS_PREVIEW_RECORD_DELETED_ERROR), Priv.GetResourcedString(IDS_FORMS_TOOL_JS_RECORD_DELETED_TITLE)); location.replace("FormsBlankPage.html"); } else if (!g_IsNew && !g_IsSearch && !g_IsFormPreview && !g_IsPrinting) { // IDS_FORMS_TOOL_JS_EDIT_RECORD_DELETED_ERROR and IDS_FORMS_TOOL_JS_RECORD_DELETED_TITLE getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayOKMessageBox(Priv.GetResourcedString(IDS_FORMS_TOOL_JS_EDIT_RECORD_DELETED_ERROR), Priv.GetResourcedString(IDS_FORMS_TOOL_JS_RECORD_DELETED_TITLE)); 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("onclick", onClickHandler); // Don't add blur and focus for button elements. if (ElementType != "button") { i_Element.attachEvent("onblur", onBlurHandler); i_Element.attachEvent("onfocus", onFocusHandler); } // OnChange is only supported by text INPUT, TEXTAREA, and SELECT. if (ElementType == "text" || ElementType == "textarea" || ElementType.indexOf("select") == 0) { i_Element.attachEvent("onchange", onChangeHandler); var FieldTypeAttribute = i_Element.getAttribute("FIELDTYPE"); if (FieldTypeAttribute == FormObjectType_DateTime) { var TimeElement = document.getElementById(ElementName + "_Time"); if (TimeElement != null) TimeElement.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") { // Make sure the time text box is set to read-only for date/time fields. var FieldTypeAttribute = i_Element.getAttribute("FIELDTYPE"); if (FieldTypeAttribute == FormObjectType_DateTime) { var TimeElement = document.getElementById(ElementName + "_Time"); if (TimeElement != null) TimeElement.readOnly = true; } // Make sure the date picker button is disabled for date fields. 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") g_RichTextObjects.push(i_Object); else if (ObjectDataType == "Attachments") g_AttachmentsObject = i_Object; else if (ObjectDataType == "Contact") g_ContactFields.push(i_Object); else if (ObjectDataType == "View") g_DataListObjects.push(i_Object); } // ===================================================== // === 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) { // Get the enum of data list names that need to be added. var ViewNameArray = new Array(); for (var i = 0; i < g_DataListObjects.length; i++) ViewNameArray.push(g_DataListObjects[i].id); g_AttachmentsElement = getScriptHostQI("IGrooveFormsToolUIDelegateHTMLDocumentPrivate").AddHTMLDocumentForForm(document, FormRecord, int_CreateBSTREnumFromArray(ViewNameArray)); } Transaction.Commit(); } catch (error) { //alert("Transaction aborted in addDocument [" + error.description + "]"); Transaction.Abort(); } } } function removeDocument() { // Unregister all registered contacts. for (var FieldName in g_RegisteredContactFields) { unregisterContact(g_RegisteredContactFields[FieldName], FieldName); } if (!g_IsFormPreview) { getScriptHostQI("IGrooveFormsToolUIDelegateHTMLDocumentPrivate").RemoveHTMLDocument(document); g_InitializedDocumentShare = false; } } // ===================================================== // === 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]; var RichTextName = RichTextObject.id; // Make sure the object is marked as unitialized. RichTextObject.removeAttribute("ISINITIALIZED"); // 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); setCommandDisabledState(RichTextName + "SpellCheck", true); setCommandDisabledState(RichTextName + "Hyperlink", true); } var RichTextObjectName = null; try { RichTextObjectName = RichTextObject.IGrooveComponent.OpenName(); } catch (error) { } if (RichTextObjectName != null && RichTextObjectName != "") { // Make sure the object is marked as initialized. RichTextObject.setAttribute("ISINITIALIZED", "true"); if (!g_IsSearch && !g_IsFormPreview) { 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 && !g_IsPrinting)) { // 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 DisabledAttribute = RichTextObject.getAttribute("ISDISABLEDBYSCRIPT"); var IsSearchableAttribute = RichTextObject.getAttribute("ISSEARCHABLE"); if (ReadOnlyAttribute != null || DisabledAttribute != null || g_IsReadOnly || (g_IsSearch && IsSearchableAttribute == null)) IsReadOnly = true; int_DisableRichTextField(RichTextObject, IsReadOnly); setCommandDisabledState(RichTextObjectName + "Spellcheck", !RichTextObject.CanCheckSpelling); 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 { 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 { if (g_EnableTextViewCount < 10) { g_EnableTextViewCount++; window.setTimeout("enableTextView(" + i_Index + ")", 250); } } g_IsInitializingTextView = false; } function enableContactFields() { for (var i = 0; i < g_ContactFields.length; i++) { var ContactField = g_ContactFields[i]; var ContactFieldName = ContactField.id; var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction(); try { var FormRecord = GetFormRecord(); if (FormRecord != null && FormRecord.HasField(ContactFieldName)) { var Contact = FormRecord.OpenField(ContactFieldName); displayContactInfo(Contact, ContactFieldName, false); } Transaction.Commit(); } catch (error) { //alert("Transaction aborted in enableContactFields(" + i + ") [" + error.description + "]"); Transaction.Abort(); } } } function registerContactFields() { for (var i = 0; i < g_ContactFields.length; i++) { var ContactField = g_ContactFields[i]; if (ContactField != null) { var ContactFieldName = ContactField.id; var Contact; var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction(); try { var FormRecord = GetFormRecord(); if (FormRecord != null && FormRecord.HasField(ContactFieldName)) Contact = FormRecord.OpenField(ContactFieldName); Transaction.Commit(); if (Contact != null) registerContact(Contact, ContactFieldName); } catch (error) { //alert("Transaction aborted in registerContactFields(" + i + ") [" + error.description + "]"); Transaction.Abort(); } } } } function enableDocumentShare() { if (g_AttachmentsObject == null) return; if (g_InitializedDocumentShare) return; if (g_IsSearch || g_IsFormPreview || g_IsPrinting) { setCommandDisabledState(g_AttachmentsObject.id + "Add", true); setCommandDisabledState(g_AttachmentsObject.id + "Launch", true); setCommandDisabledState(g_AttachmentsObject.id + "Save", true); setCommandDisabledState(g_AttachmentsObject.id + "Delete", true); } g_IsInitializingDocumentShare = true; if (!g_IsFormPreview) { try { if (g_AttachmentsObject.Properties2.Initialized) { var IsReadOnly = false; var ReadOnlyAttribute = g_AttachmentsObject.getAttribute("ISREADONLY"); var DisabledAttribute = g_AttachmentsObject.getAttribute("ISDISABLEDBYSCRIPT"); if (ReadOnlyAttribute != null || DisabledAttribute != null || g_IsReadOnly || g_IsSearch) IsReadOnly = true; int_DisableAttachmentsField(g_AttachmentsObject, 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.id + "_label"); if (objAttachmentLabel != null) objAttachmentLabel.style.display = DisplayStyle; var objAttachmentField = document.getElementById(g_AttachmentsObject.id + "_field"); if (objAttachmentField != null) objAttachmentField.style.display = DisplayStyle; } if (!g_IsPrinting && !g_IsSearch) { getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").SetCurrentDocumentShareView(g_AttachmentsObject.object, g_AttachmentsObject.id); g_InitializedDocumentShare = true; } } else { if (g_EnableDocumentShareCount < 10) { g_EnableDocumentShareCount++; window.setTimeout("enableDocumentShare()", 250); } } } catch (error) { if (g_EnableDocumentShareCount < 10) { g_EnableDocumentShareCount++; window.setTimeout("enableDocumentShare()", 250); } } } g_IsInitializingDocumentShare = false; } function enableDataList(i_Index) { if (!g_IsFormPreview) { try { var DataListObject = g_DataListObjects[i]; if (DataListObject.IGrooveDataListDisplay.Initialized) getScriptHostQI("IGrooveFormsToolUIDelegateViewPrivate").EnableDataList(document, DataListObject); else { if (g_EnableDataListCount < 10) { g_EnableDataListCount++; setTimeout("enableDataList(" + i_Index + ")", 250); } } } catch (error) { if (g_EnableDataListCount < 10) { g_EnableDataListCount++; window.setTimeout("enableDataList(" + i_Index + ")", 250); } } } } function setCommandDisabledState(i_Name, i_IsReadOnly) { var objCommand = document.getElementById(i_Name); var objCommandButton = document.getElementById(i_Name + "Button"); if (objCommand && objCommandButton) { objCommand.setAttribute("COMMANDDISABLED", i_IsReadOnly); if (i_IsReadOnly) objCommandButton.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=50);"; else objCommandButton.style.filter = ""; } } 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 InheritAttribute = i_Object.getAttribute("INHERIT"); if (InheritAttribute != null && InheritAttribute != "") { var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction(); try { var ObjectName = i_Object.id; if (InheritAttribute == "FormsInheritSelf") InheritAttribute = ObjectName; var ParentRecord = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").OpenRecord(g_SelectedID); if (ParentRecord.HasField(InheritAttribute)) { var FormRecord = openCurrentRecord(); if (FormRecord != null) { var FieldTypeAttribute = i_Object.getAttribute("FIELDTYPE"); if (FieldTypeAttribute == FormObjectType_Attachments || FieldTypeAttribute == FormObjectType_RichText) FormRecord.SetField(ObjectName, ParentRecord.OpenField(InheritAttribute)); else if (FieldTypeAttribute == FormObjectType_Contact) FormRecord.SetField(ObjectName, ParentRecord.OpenField(InheritAttribute)); if (FieldTypeAttribute == FormObjectType_Attachments) reinitAttachments(); } } Transaction.Commit(); } catch (error) { //alert("Transaction aborted in inheritFieldValue [" + error.description + "]"); Transaction.Abort(); } } } } // ===================================================== // === Option Utility === // ===================================================== function addNewOption(i_Name) { var Priv = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate"); try { var DocumentElement = document.getElementById(i_Name); if (DocumentElement != null) { // IDS_FORMS_TOOL_JS_ADD_CUSTOM_ENTRY_TITLE and IDS_FORMS_TOOL_JS_ADD_CUSTOM_ENTRY_TEXT var AddOptionResult = getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayTextInputDialog(Priv.GetResourcedString(IDS_FORMS_TOOL_JS_ADD_CUSTOM_ENTRY_TITLE), Priv.GetResourcedString(IDS_FORMS_TOOL_JS_ADD_CUSTOM_ENTRY_TEXT)); if (AddOptionResult.Result == GrooveDialogBoxResultCode_OK) { insertNewOptionUnique(DocumentElement, AddOptionResult.Data, AddOptionResult.Data, true); DocumentElement.fireEvent("onchange"); } } } catch (error) { // IDS_FORMS_TOOL_JS_OPTION_ERROR getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayError(Priv.GetResourcedString(IDS_FORMS_TOOL_JS_OPTION_ERROR)); } } function insertNewOption(i_Element, i_Value, i_Text, i_IsSelected) { var NewOption = document.createElement("OPTION"); NewOption.value = i_Value; // Make sure to only display the first 100 characters. if (i_Text.length > 100) i_Text = i_Text.substring(0, 96) + "..."; NewOption.text = i_Text; i_Element.options.add(NewOption); if (i_IsSelected) i_Element.value = i_Value; } function insertNewOptionUnique(i_Element, i_Value, i_Text, i_IsSelected) { // Check the list to see if the option already exists. for (var i = 0; i < i_Element.options.length; i++) { if (i_Element.options[i].value == i_Value) return; } insertNewOption(i_Element, i_Value, i_Text, i_IsSelected); } // ===================================================== // === Data Submission === // ===================================================== function submitData() { if (!g_IsFormPreview && typeof OnBeforeSubmitData != "undefined" && !processCallout(OnBeforeSubmitData)) { // Let the host know that submit was cancelled so it won't navigate. getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").SubmitCancelled(); getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").ReEnableCommand(); return true; } // Only continue if data saved with no errors. if (submitDataNoNavigate()) { if (!g_IsFormPreview && typeof OnAfterSubmitData != "undefined" && !processCallout(OnAfterSubmitData)) { // Let the host know that submit was cancelled so it won't navigate. getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").SubmitCancelled(); getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").ReEnableCommand(); 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; } } } function submitDataNoNavigate() { g_BypassEventCallouts = true; // 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]; if (DocumentElement.getAttribute("DATATYPE") == "RichText") validateRequired(DocumentElement); else DocumentElement.fireEvent("onblur"); } // Validate that all required contact fields have a contact. var DocumentSpans = document.getElementsByTagName("SPAN"); for (var i = 0; i < DocumentSpans.length; i++) { if (DocumentSpans[i].getAttribute("DATATYPE") == "Contact") validateRequired(DocumentSpans[i]); } g_BypassEventCallouts = false; // 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") { var Priv = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate"); // IDS_FORMS_TOOL_JS_INVALID_FORM_VALUES and IDS_FORMS_TOOL_JS_INVALID_FORM_VALUES_TITLE getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayOKMessageBox(Priv.GetResourcedString(IDS_FORMS_TOOL_JS_INVALID_FORM_VALUES), Priv.GetResourcedString(IDS_FORMS_TOOL_JS_INVALID_FORM_VALUES_TITLE)); getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").HasValidationErrors = true; g_IsCreateAnother = false; // Enable the Save and Save and Create Another buttons. getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").ReEnableCommand(); return false; } } getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").HasValidationErrors = false; var ParentIDHasBeenReset = false; if (g_IsNew && g_IsResponse && !g_SaveAsMain && !getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").IsValidRecord(g_SelectedID)) { var Priv = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate"); // IDS_FORMS_TOOL_JS_DELETED_RESPONSE_ERROR and IDS_FORMS_TOOL_JS_DELETED_RESPONSE_TITLE getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayOKMessageBox(Priv.GetResourcedString(IDS_FORMS_TOOL_JS_DELETED_RESPONSE_ERROR), Priv.GetResourcedString(IDS_FORMS_TOOL_JS_DELETED_RESPONSE_TITLE)); getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").HasValidationErrors = true; g_IsCreateAnother = false; return; } 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); } var PropagateUpdatesArray = 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); var PropagateUpdatesAttribute = DocumentElement.getAttribute("PROPAGATEUPDATES"); if (PropagateUpdatesAttribute != null) { var DocumentElementName = DocumentElement.id; if (DocumentElementName == "") DocumentElementName = DocumentElement.name; PropagateUpdatesArray.push(DocumentElementName); } } // Iterate through contact fields to set values in the record. var DocumentSpans = document.getElementsByTagName("SPAN"); for (var i = 0; i < DocumentSpans.length; i++) { if (DocumentSpans[i].getAttribute("DATATYPE") == "Contact") { var DocumentElement = DocumentSpans[i]; setFormElementValue(DocumentElement, FormRecord); var PropagateUpdatesAttribute = DocumentElement.getAttribute("PROPAGATEUPDATES"); if (PropagateUpdatesAttribute != null) { var DocumentElementName = DocumentElement.id; if (DocumentElementName == "") DocumentElementName = DocumentElement.name; PropagateUpdatesArray.push(DocumentElementName); } } } // 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); } // Make sure the UIDelegate knows that the auto-create record has been created. if (getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").NeedToAutoCreateRecord()) getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").AutoCreateRecordCreated(); } // Propagate updates to the children of this record. propagateUpdates(PropagateUpdatesArray, FormRecord); // Set the dirty bit to false. int_setIsDirty(false); Transaction.Commit(); return true; } catch (error) { //alert("Transaction aborted in submitDataNoNavigate [" + error.description + "]"); Transaction.Abort(); return false; } } function setFormElementValue(i_Element, i_Record) { var ElementName = i_Element.id; if (ElementName == "") ElementName = i_Element.name; var ElementType = i_Element.type; var ElementDataType = i_Element.getAttribute("DATATYPE"); 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) 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); var FieldTypeAttribute = i_Element.getAttribute("FIELDTYPE"); if (FieldTypeAttribute == FormObjectType_Date) { // Make sure to set the time to noon to handle time zones slightly better. var objDate = new Date(ElementValue); objDate.setHours(12); objDate.setMinutes(0); objDate.setSeconds(0); ElementValue = objDate.valueOf(); } } else ElementValue = INVALID_DATE; // If this is a search add the field to the query. if (g_IsSearch) { if (ElementName == "_CreatedSearch") ElementName = "_Created"; if (ElementName == "_ModifiedSearch") ElementName = "_Modified"; if (ElementValue != INVALID_DATE) addToCurrentSearch(ElementName, ElementValue.toString()); } else { var RecordValue = i_Record.OpenField(ElementName); if (RecordValue != ElementValue) i_Record.SetField(ElementName, ElementValue); } } else if (ElementDataType != "Time") { // 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) 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) 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) 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) 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) i_Record.SetField(ElementName, ElementValue); } } else if (ElementDataType == "RichText") { if (g_IsSearch) { // Get the plain text out of the rich text object. var PlainText = getPlainText(i_Element); 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 (!i_Element.TextContent.IsEmpty()) i_Record.SetField(ElementName, RichTextElement); else { // Set the field back to it's default element if they are the same. var DefaultElement = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").GetDefaultValueAsElement(i_Record, ElementName); if (DefaultElement.Equals(RichTextElement)) i_Record.SetField(ElementName, DefaultElement); 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 (AttachmentCount > 0) i_Record.SetField(ElementName, g_AttachmentsElement); else { // Set the field back to it's default element var DefaultElement = getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").GetDefaultValueAsElement(i_Record, ElementName); i_Record.SetField(ElementName, DefaultElement); } } } } else if (ElementDataType == "Contact") { if (!g_IsSearch) { var ContactURL = i_Element.getAttribute("CONTACTURL"); if (!g_IsNew || (g_IsNew && ContactURL != null && ContactURL != "")) { var Contact = g_RegisteredContactFields[ElementName]; var RecordValue = i_Record.OpenField(ElementName); // Set the contact if it has changed. if (RecordValue != Contact) { // If the contact was removed, set it to a null pointer. var ContactType = i_Element.getAttribute("CONTACTTYPE"); if (ContactType == "removed") i_Record.SetField(ElementName, getScriptHostQI("IGrooveFormsToolUIDelegateFormPrivate").CreateNullPointer()); else i_Record.SetField(ElementName, Contact); } } } } } } } function addToCurrentSearch(i_Name, i_Value) { if (typeof i_Value != "undefined" && i_Value != null && i_Value.toString() != "") getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").AddToSearchQuery(i_Name, i_Value); } function propagateUpdates(i_FieldNameArray, i_Record) { if (!g_IsNew && !g_IsSearch && i_Record != null && i_FieldNameArray.length > 0) { if (!g_IsFormPreview && typeof OnBeforePropagateUpdates != "undefined" && !processCallout(OnBeforePropagateUpdates)) return true; var bSuccess = true; if (!getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").UpdateAllFieldsInChildRecords(int_CreateBSTREnumFromArray(i_FieldNameArray), i_Record)) { var Priv = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate"); // IDS_FORMS_TOOL_JS_PROPAGATION_ERROR displayStatusBar(Priv.GetResourcedString(IDS_FORMS_TOOL_JS_PROPAGATION_ERROR), GrooveMessageBoxIcon_Error); bSuccess = false; } if (!g_IsFormPreview && typeof OnAfterPropagateUpdates != "undefined" && !processCalloutWithParameter(OnAfterPropagateUpdates, bSuccess)) return true; } } // ===================================================== // === 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++) { var InitializedAttribute = g_RichTextObjects[i].getAttribute("ISINITIALIZED"); if (InitializedAttribute == null) { 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; var SourceElementName = SourceElement.id; if (SourceElementName == "") SourceElementName = SourceElement.name; int_updateLookups(false, SourceElementName); } 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]; var DocumentElementName = DocumentElement.id; if (DocumentElementName == "") DocumentElementName = DocumentElement.name; if (DocumentElementName != 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; if (FieldName == "") FieldName = i_Element.name; 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.toLowerCase() == "true") bReturnUnique = true; var bNoCache = false; if (NoCache.toLowerCase() == "true") bNoCache = true; // Get the true key value from a field if it is a field name. if (KeyValueIsFieldName.toLowerCase() == "true") { 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 { var Priv = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate"); // IDS_FORMS_TOOL_JS_LOOKUP_ERROR var MsgFormatEnum = CreateBSTREnumFromArray([KeyValue, FieldName]); displayStatusBar(Priv.MessageFormat(IDS_FORMS_TOOL_JS_LOOKUP_ERROR, MsgFormatEnum), 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 (!i_IsInitial) { if (ElementTagName == "SELECT") { 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 (ElementTagName == "DIV") i_Element.innerText = ""; else 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) { // If the lookup is unique don't add duplicate options. if (bReturnUnique) insertNewOptionUnique(i_Element, strValue, strValue, false); else 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) { //alert("Transaction aborted in updateLookup [" + error.description + "]"); 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 != "") { var IsValueFound = false; for (var i = 0; i < i_Element.options.length; i++) { if (i_Element.options[i].value == PreviousDropDownValue) { i_Element.options[i].selected = true; IsValueFound = true; break; } } var CustomAttribute = i_Element.getAttribute("CUSTOM"); if (CustomAttribute != null && !IsValueFound) insertNewOption(i_Element, PreviousDropDownValue, PreviousDropDownValue, true); } // 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.id + "Add", true); setCommandDisabledState(g_AttachmentsObject.id + "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.id + "Add", !EnableButtons); setCommandDisabledState(g_AttachmentsObject.id + "Delete", !EnableButtons); addDocument(); if (g_AttachmentsObject.Properties2.Initialized) g_AttachmentsObject.Properties2.SetReadOnlyMode(!EnableButtons); } } // ===================================================== // === Rich Text Utility === // ===================================================== function getPlainText(i_TextView) { // Prepare text view for direct TOM access. i_TextView.Freeze(true); i_TextView.HideDecorations(true); // Retrieve TOM document from text view. var TextCache = i_TextView.TextCache; var TCDocument = TextCache.Document; // Retrieve plain text from the document (see "tom" typelib for tomForward). var Range = TCDocument.Range(0, 1073741823); var PlainText = Range.Text; // We're done accessing the TOM directly. i_TextView.HideDecorations(false); TextCache.Synchronize(1); i_TextView.Freeze(false); return PlainText; } // ===================================================== // === 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 "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(); } else { if (getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DoesRecordExist(g_RecordID)) return getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").OpenRecord(g_RecordID); else return null; } } }