$j(document).ready(function(){ // prevent a second click for 1 seconds. $j(document).on("click","a", function(e) { $j(e.target).click(do_nothing()); setTimeout(function(){$j(e.target).unbind('click', do_nothing());}, 1000); }); // Update search link href with request param $j('a[id*=simpleSearchLink]').on("click", function(event) { var searchTerm = $j('input[id*=simpleSearchField]').val(); var iot = $j('select[id*=selectSearchIn]').val(); var url = $j(this).attr('href'); var index = url.lastIndexOf('?', 0); if (index != -1) { url = url.substring(0, index); } $j(this).attr('href', url + "?iotype=" + iot + "&page=1&searchterm=" + searchTerm); }); addDataChangedWarningDialog(); /* Highlighting selected rows on page refresh */ var objListView = "[id*=datatableObjectsList]"; var checkboxes= $j(objListView).children('input[id*=selectChkBox]'); //var checkboxes= document.getElementById("objectListView:dataAreaForm:input"); if($j(checkboxes)) { $j(checkboxes).each(function() { if($j(this).is(':checked')) { $j(this).closest("tr").addClass("highlight"); } }); } $(document).on("click","a[href^='#']",function(e){ var href = $(e.target).attr("href"); if(href){ focusOnJQuery(href.split("?")[0]); } }); if (window.location.hash) { focusOnJQuery(window.location.hash); } }); /** * String begins with */ String.prototype.startWith = function (string) { return(this.indexOf(string) == 0); }; /** * String ends with */ String.prototype.endWith = function (string) { return this.indexOf(string, this.length - string.length) !== -1; }; /** * String contains */ String.prototype.contains = function (string) { return(this.indexOf(string) > -1); }; /** * Warning message on leaving edit page via anchor links */ function addDataChangedWarningDialog() { $j("a:not([id*=ioWizardView], [id*=actionLogView], [id*=statusLogView], [id*=relClaim_], [id*=simpleSearchLink2], [id*=reportsLink], [id*=statusChangeChildForm])") .not( "a.more-list.to-open-popup" ) /* don't show on opening the 'More' menu in the header. */ .not( ".skip-nav a" ) .on("click", function(event) { var parent = $j(this).parents('form'); if(typeof parent === "undefined" || typeof parent[0] === "undefined" || parent[0].id != "ioWizardView:ioWizardForm") { showWarningMsgPanel(event, this); } }); } /** * Toggle sibling div components with id toggleGroup */ function toggleSiblinks(element, prettyMapReference) { if(prettyMapReference == '#') { openSiblinks(element); } else { // proper URL, redirect to URL window.open(prettyMapReference,'_self'); } return false; } function openSiblinks(element) { var parent = $j(element).parent(); $j('[id*=toggleGroup]').each(function() { var thisParent = $j(this).parent(); if(parent[0].id != thisParent[0].id) { // do not display all subgroups. other than the // subgroup of the currently clicked item setDisplayNone($j(this)); } else { // if its the clicked element, toggle display elementToggle($j(this)); } }); // get all links $j('[id*=anlinks]').each(function() { // if same toggle if(this.id == element.id) { // if its the same element as the clicked, the toggle arrows elementToggle($j(this).children('[id*=arrow]')); if($j(this).children('[id*=arrowOpen]').is(":visible")) { $j(this).attr("aria-expanded", "true"); } else { $j(this).attr("aria-expanded", "false"); } } else { // all other links, show arrow close unsetDisplayNone($j(this).children('[id*=arrowClose]')); setDisplayNone($j(this).children('[id*=arrowOpen]')); $j(this).attr("aria-expanded", "false"); } }); } function elementToggle(elementSelector) { $j(elementSelector).each(function() { $j(this).toggle(); }); } function setDisplayNone(elementSelector) { $j(elementSelector).each(function() { $j(this).css('display','none'); }); } function unsetDisplayNone(elementSelector) { $j(elementSelector).each(function() { $j(this).css('display',''); }); } /* * Unsaved changes while leaving edit page. */ function showWarningMsgPanel(event, source) { var isDataChanged = $j('[id*=dataChanged]').val(); if (isDataChanged=='true') { event.stopImmediatePropagation(); event.preventDefault(); var navUrlField = $j('[id*=navigation_url]'); var navHref = $j(source).attr('href'); if(navUrlField != null) { if (!navHref || navHref == '#' || navHref.startWith('javascript:')) { navHref = '/mypages/overview'; } navUrlField.val(navHref); } var id = $("div[id$=datachangedWarnPanel]").attr('id'); RichFaces.$(id).show(); } } function hideWarningMsgPanel() { var id = $("div[id$=datachangedWarnPanel]").attr('id'); RichFaces.$(id).hide(); } /** * */ function setDataChanged(value) { var isDataChanged = $j('[id*=dataChanged]'); if (isDataChanged.length > 0) { isDataChanged.val(value); } } /** * Invoked during setup of a htmleditor to enable on key up event listener */ function htmlEditorOnKeyUpEventSetup(ed, event) { event.onKeyUp.add(function(ed, event) { submitValue('ioWizardView:ioWizardForm'); }); } /** * function to submit search button for search * if user have clicked enter button. */ function submitSearchButton(buttonId, e) { var keycode; if (window.event) { keycode = window.event.keyCode; } else if (e) { keycode = e.which; } else { return true; } if (keycode == 13) { var obj = $j('[id*=' + buttonId +']'); if(obj != null) { obj.click(); } } return true; } function do_nothing() { return false; } /* * This is moved from deduplicationDialog.xhtml * @returns {undefined} */ function toggleRadio() { $j("[id*=selectAddNewTypeM]").removeAttr("checked"); $j("[id*=selectAddNewTypeI]").removeAttr("checked"); } /* * This is moved from deduplicationDialog.xhtml * @param {type} element * @returns {undefined} */ function toggleRadioButton(element) { var pattern = /(.+)deduplicationRadio(\d)(:.+)/; var myId = element.id; pattern.exec(myId); var prefix = RegExp.$1; var myNr = RegExp.$2; var suffix = RegExp.$3; var partnerNr; if (myNr == "0") { partnerNr = "1"; } else { partnerNr = "0"; } var partnerId = prefix + "deduplicationRadio" + partnerNr + suffix; if ($j("[id*='" + partnerId+"']")) { $j("input[id*='" + partnerId + "']").removeAttr("checked"); } } /* * This moved from externalLookupDialog.xhtml * @param {type} publId * @returns {undefined} */ function selectOnlyThisRadioButton(publId) { var inputElems = document.getElementsByTagName("input"); for (i = 0; i < inputElems.length; i++) { if (inputElems[i].type == 'radio') { if (inputElems[i].name.search("publicationSearchResults:" + publId) == -1) { if (!inputElems[i].disabled) inputElems[i].checked = false; } else inputElems[i].checked = true; } } } /* * This is moved from batchrelate.xhtml * @returns {undefined} */ function closeFlyout(popOverID) { $j('#objectListView\\:dataAreaForm\\:' + popOverID + '').css('display', 'none'); } /** * Informs whether comment by status change flyout was changed. * * @param {type} mode: listview or editpage * @returns {Boolean} */ function isCommentChanged(mode) { // ids of hidden fields var commentChangeListView = "hiddenCommentChangeList"; var commentChangeEditPage = "hiddenCommentChangeEdit"; var commentChange; switch (mode) { case 'listview': commentChange = commentChangeListView; break; case 'editpage': commentChange = commentChangeEditPage; break; default: throw 'Comment by status change: undefined mode.'; } return $j("[id*='" + commentChange + "']").text() === 'true'; } /** * This function is used to change message by comment area in status change flyouts. * Used by onfocus event only: if you click to comment area, then hint text disappears. * * Used in statusProcessPanel.jsp, statuschange.jsp & statuschangeone.jsp * * @param {type} mode: listview or editpage * @param {type} comment id of element where comment stored * @returns {undefined} */ function doOnFocus(mode, comment) { //onFocus: if value of comment is equal to hintText, then the value is set to null var commentID = $j("[id*='" + comment + "']"); if (commentID.val() === commentID.text() || !isCommentChanged(mode)) { commentID.val(''); commentID.removeClass('commentStatusChangeDefault'); commentID.addClass('commentStatusChangeUser'); } } /** * Method to define the value of CommentChange hidden field * * @param {type} mode: listview or editpage * @param {type} value: 'true' or 'false' */ function setCommentChange(mode, value) { // ids of hidden fields var commentChangeListView = "hiddenCommentChangeList"; var commentChangeEditPage = "hiddenCommentChangeEdit"; var commentChange; switch (mode) { case 'listview': commentChange = commentChangeListView; break; case 'editpage': commentChange = commentChangeEditPage; break; default: throw 'Comment by status change: undefined mode.'; } $j("[id*='" + commentChange + "']").text(value); } /** * This function is used to change message by comment area in status change flyouts. * Used by onblur event only: if you click from comment area to some othe element, * then hint text appears. * * Used in statusProcessPanel.jsp, statuschange.jsp, statuschangeone.jsp & * additionaliteminfo.jsp * * @param {type} mode: listview or editpage * @param {type} comment id of element where comment stored * @returns {undefined} */ function doOnBlur(mode, comment) { //disabled comment area var elementID = $j("[id*='" + comment + "']"); if (elementID.attr('disabled') === 'disabled') { elementID.val($j("[id*='CommentAreaDisabledMessage']").text()); elementID.addClass('commentStatusChangeDefault'); elementID.removeClass('commentStatusChangeUser'); return; } //checks comment value is null or not. if (!isCommentChanged(mode) || elementID.val() === "") { elementID.val($j("[id*='CommentChangeDefaultMessage']").text()); elementID.removeClass('commentStatusChangeUser'); elementID.addClass('commentStatusChangeDefault'); } } /** * Method to define the value of CommentChange hidden field * * @param {type} mode: listview or editpage * @param {type} value: 'true' or 'false' */ function setCommentChange(mode, value) { // ids of hidden fields var commentChangeListView = "hiddenCommentChangeList"; var commentChangeEditPage = "hiddenCommentChangeEdit"; var commentChange; switch (mode) { case 'listview': commentChange = commentChangeListView; break; case 'editpage': commentChange = commentChangeEditPage; break; default: throw 'Comment by status change: undefined mode.'; } $j("[id*='" + commentChange + "']").text(value); } /** * disables comment text area in given flyout * * @param {type} thisFlyout * @returns {undefined} */ function disableCommentArea(thisFlyout) { // do not disable in edit page by create mode and create in popup mode // get boolean values from strings var createMode = ($j("[id*='createMode']").text() === 'true'); var createPopupMode = ($j("[id*='createPopupMode']").text() === 'true'); if(createMode || createPopupMode) { return; } var textArea = $j(thisFlyout).find('.statusChangeArea'); // disable comment field textArea.attr('disabled', 'disabled'); // and put label for disabled area textArea.val($j("[id*='CommentAreaDisabledMessage']").text()); // change styles textArea.addClass('commentStatusChangeDefault'); textArea.removeClass('commentStatusChangeUser'); } /** * copies current comment of comment area to the temp comment field * mode: listview or editpage */ function copyToTempComment(mode, commentArea) { // get content of comment area var content = $j(commentArea).val(); // copy content to hidden comment field $j("[id*='tempComment']").text(content); var defaultMessage = $j("[id*='CommentChangeDefaultMessage']").text(); var commentChange; if(content === defaultMessage || content === '') { commentChange = false; } else { commentChange = true; } setCommentChange(mode, commentChange); } /** * enables/disables the comment area depends on chooden status * if current status is choosen, then disable * */ function checkCommentArea(status) { // get current flyout var flyout = $j(status).closest('.statusChangeAreaContainer'); var textArea = $j(flyout).find(".statusChangeArea"); var isDisabled = textArea.attr('disabled'); // get boolean values from strings var createMode = ($j("[id*='createMode']").text() === 'true'); var createPopupMode = ($j("[id*='createPopupMode']").text() === 'true'); // do not disable in edit page by create mode and create in popup mode if(createMode || createPopupMode) { if(isDisabled === 'disabled') { // enable comment field textArea.removeAttr('disabled'); // add label for enabled area textArea.val($j("[id*='CommentChangeDefaultMessage']").text()); } return; } // compare after click on status if status has changed var statusOnBegin = $j("[id*='hiddenStatusOnBegin']").text(); var statusText = $j(status)[0].childNodes[0].nodeValue; if (!$j(status).hasClass('.disabledStat') && statusText === statusOnBegin) { if(isDisabled !== 'disabled') { // disable comment field textArea.attr('disabled', 'disabled'); // add label for disabled area textArea.val($j("[id*='CommentAreaDisabledMessage']").text()); textArea.addClass('commentStatusChangeDefault'); textArea.removeClass('commentStatusChangeUser'); } } else { // enable comment field textArea.removeAttr('disabled'); // a comment was added? if (isCommentChanged('editpage') || isCommentChanged('listview')) { // add stored comment from hidden field to comment area textArea.val($j("[id*='tempComment']").text()); textArea.removeClass('commentStatusChangeDefault'); textArea.addClass('commentStatusChangeUser'); textArea.trigger('focus'); } else { // add default message to comment area textArea.val($j("[id*='CommentChangeDefaultMessage']").text()); textArea.trigger('blur'); } } } function updateFloatingFooterPosition() { var footerHeight = $(".footer").height(); if($(window).scrollTop() + $(window).height() > $(document).height() - footerHeight) { var value = footerHeight - ($(document).height() - ($(window).scrollTop() + $(window).height())); $(".blueTabBar.floatingFooter").css("bottom",value); } else { $(".blueTabBar.floatingFooter").css("bottom",0); } } $(window).scroll(function() { updateFloatingFooterPosition(); }); $(window).resize(function() { updateFloatingFooterPosition(); }); $(window).on("load",function() { updateFloatingFooterPosition(); }); function focusElement(el) { $j("[id*='"+el+"']").focus(); }