// SINGLE AVAILABLE VALUES EDITOR function SingleAvailableValuesEditor(dropDownID) { this.dropDownID = dropDownID; } SingleAvailableValuesEditor.prototype.ValidateInput = function() { var dropDown = document.getElementById(this.dropDownID); var valid = ((dropDown) && (dropDown.selectedIndex > 0)); return (valid) ? "" : "Select a value."; } SingleAvailableValuesEditor.prototype.ToggleEnable = function() { var dropDown = document.getElementById(this.dropDownID); if (dropDown) { dropDown.disabled = (dropDown.disabled) ? false : true; } } SingleAvailableValuesEditor.prototype.Init = function() { var dropDown = document.getElementById(this.dropDownID); if (dropDown) { var editor = this; dropDown.onchange = function() { editor.ValueChanged(); }; if (dropDown.options.length > 0) { var reportViewer = GetReportViewer(); if (reportViewer) { dropDown.options[0].text = reportViewer.GetString("ReportParametersSelectAValueText"); } } } } SingleAvailableValuesEditor.prototype.ValueChanged = function() { if (this.OnValueChanged) { this.OnValueChanged(); } } // TEXTBOX EDITOR (Float, Int, String) function TextboxEditor(textBoxID, valueType, allowBlank) { this.textBoxID = textBoxID; this.valueType = valueType; this.allowBlank = allowBlank; } TextboxEditor.prototype.Init = function() { var textBox = document.getElementById(this.textBoxID); if (textBox) { var editor = this; textBox.onchange = function() { editor.ValueChanged(); }; } } TextboxEditor.prototype.ValueChanged = function() { if (this.OnValueChanged) { this.OnValueChanged(); } } TextboxEditor.prototype.ValidateInput = function() { var textBox = document.getElementById(this.textBoxID); if (textBox) { return ValidateValueType(textBox.value, this.valueType, this.allowBlank); } return ""; } TextboxEditor.prototype.ToggleEnable = function() { var textBox = document.getElementById(this.textBoxID); if (textBox) { textBox.disabled = (textBox.disabled) ? false : true; } } // PARAMETERS function ParametersPage(editors, viewReportButtonID, errorMessage) { this.editors = editors; this.viewReportButtonID = viewReportButtonID; this.errorMessage = errorMessage; } ParametersPage.prototype.Validate = function() { var result = ""; var valid = true; for (var i = 0; i < this.editors.length; i++) { var editor = eval(this.editors[i]); if (editor) { result = editor.ValidateInput(); if (result != "") { valid = false; } } } return valid; } ParametersPage.prototype.Init = function(initMode) { this.ResizeFrame(); if ((this.errorMessage) && (this.errorMessage != "")) { alert(this.errorMessage); } if ((this.editors) && (this.editors.length > 0)) { for (var i = 0; i < this.editors.length; i++) { var editor = eval(this.editors[i]); if ((editor) && (editor.Init)) { editor.Init(); } } } var previewButton = document.getElementById(this.viewReportButtonID); var reportViewer = GetReportViewer(); if ((previewButton) && (reportViewer)) { previewButton.value = reportViewer.GetString("ReportParametersPreviewButtonText"); } if ("init" == initMode) { if (previewButton) { previewButton.click(); } } else if ("preview" == initMode) { if (this.Validate()) { if ((reportViewer) && (reportViewer.UpdateParamReport)) { reportViewer.UpdateParamReport(); } } } else { this.Validate(); } } ParametersPage.prototype.ResizeFrame = function() { var form = document.forms[0]; if (form) { var iframe = GetFrameElement(); if (iframe) { iframe.style.height = form.offsetHeight + "px"; } } } // PARAMETER EDITORS function ParameterEditor(valueEditorID, nullSelectID, notValidImageID) { this.valueEditorID = valueEditorID; this.nullSelectID = nullSelectID; this.notValidImageID = notValidImageID; } ParameterEditor.prototype.Init = function() { var valueEditor = eval(this.valueEditorID); var nullSelect = document.getElementById(this.nullSelectID); var paramEditor = this; var valueChangedCallback = function() { paramEditor.ValueChanged(); }; var invalidValueImage = document.getElementById(this.notValidImageID); var reportViewer = GetReportViewer(); if ((reportViewer) && (invalidValueImage)) { invalidValueImage.title = reportViewer.GetString("ReportParametersInvalidValueText"); } if (nullSelect) { var nullInput = nullSelect.childNodes[0]; if (nullInput) { var oldClickHandler = nullInput.onclick; nullInput.onclick = function () { if ((typeof(oldClickHandler) != 'undefined') && (null != oldClickHandler)) { oldClickHandler(); } valueChangedCallback(); }; if (nullInput.childNodes.length > 1) { var label = nullInput.childNodes[1]; if ((label) && (reportViewer)) { label.firstChild.nodeValue = reportViewer.GetString("ReportParametersNullText"); } } } } if (valueEditor) { if (valueEditor.Init) { valueEditor.Init(); } valueEditor.OnValueChanged = valueChangedCallback; if ((valueEditor.ToggleEnable) && (nullSelect) && (nullSelect.childNodes[0].checked)) { valueEditor.ToggleEnable(); } } } ParameterEditor.prototype.ValidateInput = function() { var nullSelect = document.getElementById(this.nullSelectID); if ((nullSelect) && (nullSelect.childNodes[0].checked)) { return ""; } return this.Validate(); } ParameterEditor.prototype.Validate = function() { var valueEditor = eval(this.valueEditorID); if ((valueEditor) && (valueEditor.ValidateInput)) { var result = valueEditor.ValidateInput(); var image = document.getElementById(this.notValidImageID); if (image) { if ("" == result) { image.style.display = "none"; } else { image.style.display = ""; } } return result; } return ""; } ParameterEditor.prototype.OnValueChanged = function() { if (this.DoPostback) { document.pendingPostback = true; setTimeout(this.DoPostback, 0); } this.Validate(); } ParameterEditor.prototype.ValueChanged = function() { this.OnValueChanged(); } // BOOLEAN EDITOR function BooleanEditor(radioButtonID) { this.radioButtonID = radioButtonID; } BooleanEditor.prototype.ToggleEnable = function() { var radioButtonList = document.getElementById(this.radioButtonID); if (radioButtonList) { radioButtonList.disabled = (radioButtonList.disabled) ? false : true; } } BooleanEditor.prototype.Init = function() { var radioButtonList = document.getElementById(this.radioButtonID); if (radioButtonList) { var inputs = radioButtonList.getElementsByTagName("INPUT"); if (inputs) { var editor = this; for (var i = 0; i < inputs.length; i++) { var input = inputs[i]; input.onclick = function() { editor.ValueChanged(); }; var label = input.nextSibling; var text = ""; var reportViewer = GetReportViewer(); switch (i) { case 0: text = reportViewer.GetString("ReportParametersTrueValueLabel"); break; case 1: text = reportViewer.GetString("ReportParametersFalseValueLabel"); break; } label.firstChild.nodeValue = text; } } } return false; } BooleanEditor.prototype.ValueChanged = function() { if (this.OnValueChanged) { this.OnValueChanged(); } } BooleanEditor.prototype.ValidateInput = function() { var radioButtonList = document.getElementById(this.radioButtonID); var inputs = radioButtonList.getElementsByTagName("INPUT"); if (inputs) { for (var i = 0; i < inputs.length; i++) { if (inputs[i].checked) return ""; } } return "Blank value."; } // CALENDAR EDITOR function DateTimeEditor(textBoxID, enabledImageID, disabledImageID) { this.textBoxID = textBoxID; this.enabledImageID = enabledImageID; this.disabledImageID = disabledImageID; } DateTimeEditor.prototype.Show = function() { var reportViewer = GetReportViewer(); if ((reportViewer) && (reportViewer.ShowCalendar)) { var textBox = document.getElementById(this.textBoxID); textBoxLocation = GetAbsolutePosition(textBox); var left = textBoxLocation.Left; var top = textBoxLocation.Top + textBox.offsetHeight; reportViewer.ShowCalendar(this, { Left: left, Top: top }); } } DateTimeEditor.prototype.GetSelectedDate = function() { var textBox = document.getElementById(this.textBoxID); return textBox.value; } DateTimeEditor.prototype.UpdateDate = function(selectedDate) { var textBox = document.getElementById(this.textBoxID); textBox.value = selectedDate; this.ValueChanged(); } DateTimeEditor.prototype.ValueChanged = function() { if (this.OnValueChanged) { this.OnValueChanged(); } } DateTimeEditor.prototype.ToggleEnable = function() { var textBox = document.getElementById(this.textBoxID); if (textBox) { textBox.disabled = (textBox.disabled) ? false : true; } ToggleDisplay(document.getElementById(this.enabledImageID)); ToggleDisplay(document.getElementById(this.disabledImageID)); } DateTimeEditor.prototype.ValidateInput = function() { var textBox = document.getElementById(this.textBoxID); var validValue = ((textBox) && (textBox.value) && (textBox.value.length > 0)); return (validValue) ? "" : "Blank value."; } //--------------------------- // MULTILINE VALUE EDITOR function MultilineValueEditor(textBoxID, editorID, allowBlank, valueType) { this.textBoxID = textBoxID; this.editorID = editorID; this.valueType = valueType; this.allowBlank = allowBlank && (valueType == "String"); } MultilineValueEditor.prototype.GetTextArea = function(popupPlaceholder) { var textAreas = popupPlaceholder.getElementsByTagName("TEXTAREA"); var textArea = null; if (textAreas && textAreas.length > 0) { textArea = textAreas[0]; } return textArea; } MultilineValueEditor.prototype.GetValue = function(popupPlaceholder) { var textBox = document.getElementById(this.textBoxID); var editor = document.getElementById(this.editorID); var textArea = this.GetTextArea(popupPlaceholder); if (textBox && editor && textArea) { var newline = "\r\n"; if (textArea.value.indexOf("\r\n") == -1) { if (textArea.value.indexOf("\n") > -1) { newline = "\n"; } else if (textArea.value.indexOf("\r") > -1) { newline = "\r"; } } var values = textArea.value.split(newline); var result = ""; for (var i = 0; i < values.length; i++) { var stringValue = values[i]; if (!this.allowBlank) { stringValue = stringValue.replace(/^\s*/, "").replace(/\s*$/, ""); } if (((!this.allowBlank) && (stringValue.length > 0)) || (this.allowBlank)) { if ((i > 0) && (result.length > 0)) { result += "; " + stringValue; } else { result = stringValue; } } } textBox.value = result; this.ValueChanged(); } } MultilineValueEditor.prototype.UpdateState = function(editorPopup) { var textArea = this.GetTextArea(editorPopup); var textBox = document.getElementById(this.textBoxID); if (textArea && textBox) { textArea.value = textBox.value.replace(/; /g, "\r\n"); } } MultilineValueEditor.prototype.ValueChanged = function() { if (this.OnValueChanged) { this.OnValueChanged(); } } MultilineValueEditor.prototype.Show = function() { if (document.activeEditor != this) { var textBox = document.getElementById(this.textBoxID); if (!textBox.disabled) { var textArea = document.getElementById(this.editorID).childNodes[0]; textArea.value = textBox.value.replace(/; /g,"\r\n").replace(/;/g,"\r\n"); ShowMultiValuePopup(this); } } else { CloseEditorPopup(); } } MultilineValueEditor.prototype.ToggleEnable = function() { ToggleTextBoxEnable(this.textBoxID); } MultilineValueEditor.prototype.ValidateInput = function() { var textBox = document.getElementById(this.textBoxID); if (textBox) { var values = textBox.value.split("; "); for (var i = 0; i < values.length; i++) { var result = ValidateValueType(values[i], this.valueType, this.allowBlank); if (result != "") return result; } } return ""; } MultilineValueEditor.prototype.GetPopupEditor = function() { return document.getElementById(this.editorID); } // -------------------------- // MULTICHECKBOX VALUE EDITOR function MultiCheckBoxValueEditor(textBoxID, editorID, allowBlank) { this.textBoxID = textBoxID; this.editorID = editorID; this.allowBlank = allowBlank; this.allowBlank = false; this.currentValues = null; } MultiCheckBoxValueEditor.prototype.Init = function() { var reportViewer = GetReportViewer(); var editor = this.GetPopupEditor(); if ((reportViewer) && (editor)) { var table = GetTableElement(editor); SetCheckBoxLabel(table, 0, reportViewer.GetString("ReportParametersSelectAllText")); } } MultiCheckBoxValueEditor.prototype.GetValue = function(editorPopup) { if (editorPopup) { var table = GetTableElement(editorPopup); if (table) { var value = ''; for (var i = 1; i < table.rows.length; i++) { var checkBox = GetCheckBox(table, i); if ((checkBox) && (checkBox.checked)) { if (value.length > 0) { value += "; "; } value += checkBox.Label; } } var textBox = document.getElementById(this.textBoxID); if (textBox) { textBox.value = value; } } this.ValueChanged(); } } function GetTableElement(container) { var tables = container.getElementsByTagName("TABLE"); var table = null; if ((tables) && (tables.length > 0)) { return tables[0]; } } MultiCheckBoxValueEditor.prototype.ValueChanged = function() { if (this.OnValueChanged) { this.OnValueChanged(); } } MultiCheckBoxValueEditor.prototype.Show = function() { if (document.activeEditor != this) { var textBox = document.getElementById(this.textBoxID); if (!textBox.disabled) { ShowMultiValuePopup(this); } } else { CloseEditorPopup(); } } MultiCheckBoxValueEditor.prototype.ToggleEnable = function() { ToggleTextBoxEnable(this.textBoxID); } MultiCheckBoxValueEditor.prototype.ValidateInput = function() { var textBox = document.getElementById(this.textBoxID); if (textBox) { if (this.allowBlank) return ""; if ((textBox.value) && (textBox.value.length > 0)) return ""; return "Blank value."; } } MultiCheckBoxValueEditor.prototype.GetPopupEditor = function() { return document.getElementById(this.editorID); } MultiCheckBoxValueEditor.prototype.UpdateState = function(editorPopup) { var table = GetTableElement(editorPopup); var textBox = document.getElementById(this.textBoxID); var values = textBox.value.split("; "); for (var i = 1; i < table.rows.length; i++) { var checkBox = GetCheckBox(table, i); if (checkBox) { checkBox.checked = false; for (var j = 0; j < values.length; j++) { if (checkBox.Label == values[j]) { checkBox.checked = true; break; } } } } var selectAll = true; for (var i = 1; i < table.rows.length; i++) { var checkBox = GetCheckBox(table, i); if ((checkBox) && (!checkBox.checked)) { selectAll = false; } } if (selectAll) { var checkBox = GetCheckBox(table, 0); if (checkBox) { checkBox.checked = true; } } } // GLOBAL function ShowMultiValuePopup(multiValueEditor) { CloseEditorPopup(); if (!document.pendingPostback) { var textBox = document.getElementById(multiValueEditor.textBoxID); var editorPopup = document.getElementById(multiValueEditor.editorID); if ((textBox) && (editorPopup)) { var absolutePosition = GetAbsolutePosition(textBox); var top = absolutePosition.Top + textBox.offsetHeight; var left = absolutePosition.Left; var width = textBox.offsetWidth; var editorHeight = editorPopup.style.height; var reportViewer = GetReportViewer(); if ((reportViewer) && (reportViewer.ShowEditorPopup)) { reportViewer.ShowEditorPopup(multiValueEditor, { Top: top, Left: left, Width: width, Height: editorHeight }); } document.activeEditor = multiValueEditor; } } } function GetAbsolutePosition(element) { var top = 0; var left = 0; while ((null != element) && (element != document.body)) { if (element.style.position == "absolute") { element = null; break; }; top += element.offsetTop; left += element.offsetLeft; element = element.offsetParent; } if (null != element) { left += element.offsetLeft; top += element.offsetTop; } return { Left:left, Top:top }; } function ShowCalendar(calendarID, src, textBoxID) { var cal = document.getElementById(calendarID); if (cal) { if (cal.style.display == 'none') { var textBox = document.getElementById(textBoxID); if (textBox) { var absolutePosition = GetAbsolutePosition(textBox); cal.style.top = absolutePosition.Top + textBox.offsetHeight; cal.style.left = absolutePosition.Left; } cal.style.display=''; cal.src = src } else cal.style.display='none'; }; } function FormClick() { CloseEditorPopup(); } function CloseEditorPopup() { var reportViewer = GetReportViewer(); if ((reportViewer) && (reportViewer.HideEditorPopup)) { reportViewer.HideEditorPopup(); } document.activeEditor = null; } function GetFrameElement() { var window = document.parentWindow; if (!window) window = document.contentWindow; if (!window) window = document.defaultView; return (window) ? window.frameElement : null; } function GetReportViewer() { var frameElement = GetFrameElement(); if (frameElement) { var reportViewer = frameElement.ReportViewer; frameElement.ReportViewer if (reportViewer) { return reportViewer; } } return null; } function SetCheckBoxLabel(table, rowIndex, labelText) { if ((table) && (table.rows) && (table.rows.length > 0)) { var firstCell = table.rows[rowIndex].cells[0]; if (firstCell) { var inputs = firstCell.getElementsByTagName("INPUT"); var checkBox = null; if ((inputs) && (inputs.length > 0)) { checkBox = inputs[0]; } if (checkBox) { var label = checkBox.nextSibling; if ((label != null) && (label.firstChild != null)) { label.firstChild.nodeValue = labelText; } } } } } function GetCheckBox(table, rowIndex) { if ((table) && (table.rows) && (table.rows.length > 0)) { var firstCell = table.rows[rowIndex].cells[0]; if (firstCell) { var inputs = firstCell.getElementsByTagName("INPUT"); var checkBox = null; if ((inputs) && (inputs.length > 0)) { checkBox = inputs[0]; } if (checkBox) { var label = checkBox.nextSibling; var labelStr = " "; if (label != null && label.firstChild != null) labelStr = label.firstChild.nodeValue; if (labelStr == "") labelStr = " "; checkBox.Label = labelStr; return checkBox; } } } return null; } function OnClickSelectAllCheckBox(tableID) { var table = document.getElementById(tableID); if (table) { var checked = GetCheckBox(table, 0).checked; for (var i = 0; i < table.rows.length; i++) { var checkBox = GetCheckBox(table, i); checkBox.checked = checked; } } } function OnClickCheckBox(tableID) { var table = document.getElementById(tableID); if (table) { var checked = true; for (var i = 1; i < table.rows.length; i++) { var checkBox = GetCheckBox(table, i); if (!checkBox.checked) { checked = false; break; }; } var checkBox = GetCheckBox(table, 0); checkBox.checked = checked; } } function DisableControl(controlID) { var ctrl = document.getElementById(controlID); if (ctrl) ctrl.disabled = !ctrl.disabled; }; function ToggleDisplay(el) { if (el) { el.style.display = (el.style.display == "none") ? "" : "none"; } } function ToggleTextBoxEnable(textBoxID) { var textBox = document.getElementById(textBoxID); if (textBox) { textBox.disabled = (textBox.disabled) ? false : true; textBox.className = (textBox.disabled) ? "DisabledTextInput" : ""; } } function ValidateValueType(value, type, allowBlank) { var valid = true; value = value.replace(/^\s*/, "").replace(/\s*$/, ""); if ((!allowBlank) && (value.length == 0)) return "Blank value"; switch (type) { case "Float": var floatValue = parseFloat(value); valid = !isNaN(floatValue); break; case "Integer": valid = false; if ((value.indexOf(".") == -1) && (value.indexOf(",") == -1)) { var value = parseInt(value); valid = !isNaN(value); } break; } return (valid) ? "" : "Invalid " + type + " value"; } document.CloseEditorPopup = CloseEditorPopup; if ((typeof(Sys) != "undefined") && (typeof(Sys.Application) != "undefined")) { Sys.Application.notifyScriptLoaded(); }