/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ //Define global variable to store last auto-completer request object (jqXHR). var LAST_AUTOCOMP_REF = null; //default ajax request timeout in milliseconds var AJAX_REQUEST_TIMEOUT = 5000; // Check Box Select/Toggle Functions for Select/Toggle All function toggle(e) { e.checked = !e.checked; } function checkToggleDefault(e) { checkToggle(e, "selectAllForm"); } function checkToggle(e, formName) { var cform = document[formName]; if (e.checked) { var len = cform.elements.length; var allchecked = true; for (var i = 0; i < len; i++) { var element = cform.elements[i]; if (element.name.substring(0, 10) == "_rowSubmit" && !element.checked) { allchecked = false; } cform.selectAll.checked = allchecked; } } else { cform.selectAll.checked = false; } } function toggleAllDefault(e) { toggleAll(e, "selectAllForm"); } function toggleAll(e, formName) { var cform = document[formName]; var len = cform.elements.length; for (var i = 0; i < len; i++) { var element = cform.elements[i]; if (element.name.substring(0, 10) == "_rowSubmit" && element.checked != e.checked) { toggle(element); } } } function selectAllDefault() { selectAll("selectAllForm"); } function selectAll(formName) { var cform = document[formName]; var len = cform.elements.length; for (var i = 0; i < len; i++) { var element = cform.elements[i]; if ((element.name == "selectAll" || element.name.substring(0, 10) == "_rowSubmit") && !element.checked) { toggle(element); } } } function removeSelectedDefault() { removeSelected("selectAllForm"); } function removeSelected(formName) { var cform = document[formName]; cform.removeSelected.value = true; cform.submit(); } // highlight the selected row(s) function highlightRow(e,rowId){ var currentClassName = document.getElementById(rowId).className; if (e.checked) { if (currentClassName == '' ) { document.getElementById(rowId).className = 'selected'; } else if (currentClassName == 'alternate-row') { document.getElementById(rowId).className = 'alternate-rowSelected'; } } else { if (currentClassName == 'selected') { document.getElementById(rowId).className = ''; } else if (currentClassName == 'alternate-rowSelected') { document.getElementById(rowId).className = 'alternate-row'; } } } function highlightAllRows(e, halfRowId, formName){ var cform = document[formName]; var len = cform.elements.length; for (var i = 0; i < len; i++) { var element = cform.elements[i]; if (element.name.substring(0, 10) == "_rowSubmit") { highlightRow(e, halfRowId+element.name.substring(13)); } } } // popup windows functions function popUp(url, name, height, width) { popupWindow = window.open(url, name, 'location=no,scrollbars,width=' + width + ',height=' + height); } function popUpSmall(url, name) { popUp(url, name, '300', '450'); } function popUpPrint(printserver, screen1) { popUpPrint(printserver, screen1, null, null); } function popUpPrint(printserver, screen1, screen2) { popUpPrint(printserver, screen1, screen2, null); } function popUpPrint(printserver, screen1, screen2, screen3) { if (printserver == null) { printserver = "http://localhost:10080/"; // default print server port } if (screen1 != null) { screen1 = screen1.replace(/\:/g, "%3A"); screen1 = screen1.replace(/\//g, "%2F"); screen1 = screen1.replace(/\#/g, "%23"); screen1 = screen1.replace(/\?/g, "%3F"); screen1 = screen1.replace(/\=/g, "%3D"); url = printserver + screen1; window.open(url, "screen1", 'location=no,statusbar=1,menubar=0,scrollbars,width=60,height=10,top=0,left=0'); self.focus(); if (screen2 != null) { screen2 = screen2.replace(/\:/g, "%3A"); screen2 = screen2.replace(/\//g, "%2F"); screen2 = screen2.replace(/\#/g, "%23"); screen2 = screen2.replace(/\?/g, "%3F"); screen2 = screen2.replace(/\=/g, "%3D"); url = printserver + screen2; window.open(url, "screen2", 'location=no,statusbar=1,menubar=0,scrollbars,width=60,height=10,top=0,left=0'); self.focus(); if (screen3 != null) { screen3 = screen3.replace(/\:/g, "%3A"); screen3 = screen3.replace(/\//g, "%2F"); screen3 = screen3.replace(/\#/g, "%23"); screen3 = screen3.replace(/\?/g, "%3F"); screen3 = screen3.replace(/\=/g, "%3D"); url = printserver + screen3; window.open(url, "screen13", 'location=no,statusbar=1,menubar=0,scrollbars,width=60,height=10,top=0,left=0'); self.focus(); } } } } // Post a form from a pop up using the parent window function doPostViaParent(formName) { var theForm = document[formName]; var newForm = theForm.cloneNode(true); var hiddenDiv = document.createElement('div'); hiddenDiv.style.visibility = 'hidden'; hiddenDiv.appendChild(newForm); window.opener.document.body.appendChild(hiddenDiv); newForm.submit(); window.opener.focus(); } // From a child window, navigate the parent window to the supplied url function doGetViaParent(url) { window.opener.location = url; window.opener.focus(); } // hidden div functions function getStyleObject(objectId) { if (document.getElementById && document.getElementById(objectId)) { return document.getElementById(objectId).style; } else if (document.all && document.all(objectId)) { return document.all(objectId).style; } else if (document.layers && document.layers[objectId]) { return document.layers[objectId]; } else { return false; } } function changeObjectVisibility(objectId, newVisibility) { var styleObject = getStyleObject(objectId); if (styleObject) { styleObject.visibility = newVisibility; return true; } else { return false; } } // To use this in a link use a URL like this: javascript:confirmActionLink('You want to delete this party?', 'deleteParty?partyId=${partyId}') function confirmActionLink(msg, newLocation) { if (msg == null) { msg = "Are you sure you want to do this?"; } var agree = confirm(msg); if (agree) { if (newLocation != null) location.replace(newLocation); } } // To use this in a link use a URL like this: javascript:confirmActionFormLink('You want to update this party?', 'updateParty') function confirmActionFormLink(msg, formName) { if (msg == null) { msg = "Are you sure you want to do this?"; } var agree = confirm(msg); if (agree) { if (formName != null) document.forms[formName].submit(); } } // ===== Ajax Functions - based on jQuery.js ===== // /** Update an area (HTML container element). * @param areaId The id of the HTML container to update * @param target The URL to call to update the HTML container * @param targetParams The URL parameters */ function ajaxUpdateArea(areaId, target, targetParams) { if (areaId == "window") { targetUrl = target + "?" + targetParams.replace('?',''); window.location.assign(targetUrl); return; } waitSpinnerShow(); jQuery.ajax({ url: target, type: "POST", data: targetParams, success: function(data) { jQuery("#" + areaId).html(data); waitSpinnerHide(); }, error: function(data) {waitSpinnerHide()} }); } /** Update multiple areas (HTML container elements). * @param areaCsvString The area CSV string. The CSV string is a flat array in the * form of: areaId, target, target parameters [, areaId, target, target parameters...]. */ function ajaxUpdateAreas(areaCsvString) { var areaArray = areaCsvString.split(","); var numAreas = parseInt(areaArray.length / 3); for (var i = 0; i < numAreas * 3; i = i + 3) { var areaId = areaArray[i]; var target = areaArray[i + 1]; var targetParams = areaArray[i + 2]; // Remove the ? and the anchor flag from the parameters // not nice but works targetParams = targetParams.replace('#',''); targetParams = targetParams.replace('?',''); ajaxUpdateArea(areaId, target, targetParams); } } /** Update an area (HTML container element) periodically. * @param areaId The id of the HTML container to update * @param target The URL to call to update the HTML container * @param targetParams The URL parameters * @param interval The update interval, in seconds. */ function ajaxUpdateAreaPeriodic(areaId, target, targetParams, interval) { var intervalMillis = interval * 1000; jQuery.fjTimer({ interval: intervalMillis, repeat: true, tick: function(container, timerId){ jQuery.ajax({ url: target, type: "POST", data: targetParams, success: function(data) { jQuery("#" + areaId).html(data); waitSpinnerHide(); }, error: function(data) {waitSpinnerHide()} }); } }); } /** Submit request, update multiple areas (HTML container elements). * @param target The URL to call to update the HTML container * @param targetParams The URL parameters * @param areaCsvString The area CSV string. The CSV string is a flat array in the * form of: areaId, target, target parameters [, areaId, target, target parameters...]. */ function ajaxSubmitRequestUpdateAreas(target, targetParams, areaCsvString) { updateFunction = function(transport) { ajaxUpdateAreas(areaCsvString); } jQuery.ajax({ url: target, type: "POST", data: targetParams, success: updateFunction() }); } /** Submit form, update an area (HTML container element). * @param form The form element * @param areaId The id of the HTML container to update * @param submitUrl The URL to call to update the HTML container */ function submitFormInBackground(form, areaId, submitUrl) { submitFormDisableSubmits(form); updateFunction = function() { jQuery("#" + areaId).load(submitUrl); } jQuery.ajax({ url: jQuery(form).attr("action"), data: jQuery(form).serialize(), success: updateFunction() }); } /** Submit form, update multiple areas (HTML container elements). * @param form The form element * @param areaCsvString The area CSV string. The CSV string is a flat array in the * form of: areaId, target, target parameters [, areaId, target, target parameters...]. */ function ajaxSubmitFormUpdateAreas(form, areaCsvString) { waitSpinnerShow(); hideErrorContainer = function() { jQuery('#content-messages').html(''); jQuery('#content-messages').removeClass('errorMessage').fadeIn('fast'); } updateFunction = function(data) { if (data._ERROR_MESSAGE_LIST_ != undefined || data._ERROR_MESSAGE_ != undefined) { if (!jQuery('#content-messages').length) { //add this div just after app-navigation if(jQuery('#content-main-section')){ jQuery('#content-main-section' ).before('
'); } } jQuery('#content-messages').addClass('errorMessage'); if (data._ERROR_MESSAGE_LIST_ != undefined && data._ERROR_MESSAGE_ != undefined) { jQuery('#content-messages' ).html(data._ERROR_MESSAGE_LIST_ + " " + data._ERROR_MESSAGE_); } else if (data._ERROR_MESSAGE_LIST_ != undefined) { jQuery('#content-messages' ).html(data._ERROR_MESSAGE_LIST_); } else { jQuery('#content-messages' ).html(data._ERROR_MESSAGE_); } jQuery('#content-messages').fadeIn('fast'); } else { if (jQuery('#content-messages').length) { jQuery('#content-messages').html(''); jQuery('#content-messages').removeClass('errorMessage').fadeIn("fast"); } ajaxUpdateAreas(areaCsvString); } waitSpinnerHide(); } jQuery.ajax({ type: "POST", url: jQuery("#" + form).attr("action"), data: jQuery("#" + form).serialize(), success: function(data) { updateFunction(data); } }); } /** Enable auto-completion for text elements, with a possible span of tooltip class showing description. * @param areaCsvString The area CSV string. The CSV string is a flat array in the * form of: areaId, target, target parameters [, areaId, target, target parameters...]. */ function ajaxAutoCompleter(areaCsvString, showDescription, defaultMinLength, defaultDelay, formName){ var areaArray = areaCsvString.replace(/&/g, '&').split(","); var numAreas = parseInt(areaArray.length / 3); for (var i = 0; i < numAreas * 3; i = i + 3) { var initUrl = areaArray[i + 1]; if (initUrl.indexOf("?") > -1) var url = initUrl + "&" + areaArray[i + 2]; else var url = initUrl + "?" + areaArray[i + 2]; var div = areaArray[i]; // create a separated div where the result JSON Opbject will be placed if ((jQuery("#" + div + "_auto")).length < 1) { jQuery("
").insertBefore("#" + areaArray[i]); } jQuery("#" + div).autocomplete({ minLength: defaultMinLength, delay: defaultDelay, source: function(request, response){ jQuery.ajax({ url: url, type: "post", data: {term : request.term}, beforeSend: function (jqXHR, settings) { //If LAST_AUTOCOMP_REF is not null means an existing ajax auto-completer request is in progress, so need to abort them to prevent inconsistent behavior of autocompleter if (LAST_AUTOCOMP_REF != null && LAST_AUTOCOMP_REF.readyState != 4) { var oldRef = LAST_AUTOCOMP_REF; oldRef.abort(); //Here we are aborting the LAST_AUTOCOMP_REF so need to call the response method so that auto-completer pending request count handle in proper way response( [] ); } LAST_AUTOCOMP_REF= jqXHR; }, success: function(data) { // reset the autocomp field autocomp = undefined; jQuery("#" + div + "_auto").html(data); if (typeof autocomp != 'undefined') { jQuery.each(autocomp, function(index, item){ item.label = jQuery("
").html(item.label).text(); }) // autocomp is the JSON Object which will be used for the autocomplete box response(autocomp); } }, error: function(xhr, reason, exception) { if(exception != 'abort') { alert("An error occurred while communicating with the server:\n\n\nreason=" + reason + "\n\nexception=" + exception); } } }); }, select: function(event, ui){ //jQuery("#" + areaArray[0]).html(ui.item); jQuery("#" + areaArray[0]).val(ui.item.value); // setting a text field if (showDescription && (ui.item.value != undefined && ui.item.value != '')) { setLookDescription(areaArray[0], ui.item.label, areaArray[2], formName, showDescription) } } }); if (showDescription) { var lookupDescriptionLoader = new lookupDescriptionLoaded(areaArray[i], areaArray[i + 1], areaArray[i + 2], formName); lookupDescriptionLoader.update(); jQuery("#" + areaArray[i]).bind('change lookup:changed', function(){ lookupDescriptionLoader.update(); }); } } } function setLookDescription(textFieldId, description, params, formName, showDescription){ if (description) { var start = description.lastIndexOf(' ['); if (start != -1) { description = description.substring(0, start); // This sets a (possibly hidden) dependent field if a description-field-name is provided var dependentField = params.substring(params.indexOf("searchValueFieldName")); dependentField = jQuery("#" + formName + "_" + dependentField.substring(dependentField.indexOf("=") + 1)); var dependentFieldValue = description.substring(0, description.lastIndexOf(' ')) if (dependentField.length) { dependentField.val(dependentFieldValue); dependentField.trigger("change"); // let the 'hidden' field know its been changed } } var lookupWrapperEl = jQuery("#" + textFieldId).closest('.field-lookup'); if (lookupWrapperEl.length) { if (start == -1 && showDescription) { var start = description.indexOf(' '); if (start != -1 && description.indexOf('