/** * This file is used for any global functions, components, reg exp, etc... * */ require(["dojo/parser","dojo/behavior","dojo/NodeList-traverse","dojo/NodeList-manipulate","bmo/EditableTooltip", "bmo/Dialog","bmo/PrintableDialog","dijit/Dialog","dijit/form/Form","dijit/form/ValidationTextBox", "dijit/form/DateTextBox","dijit/form/CurrencyTextBox","dijit/form/NumberTextBox","dojo/currency", "dijit/form/SimpleTextarea","dijit/form/CheckBox","dijit/form/Select","dijit/form/Button","dijit/form/ComboBox", "dijit/form/FilteringSelect","dojo/data/ItemFileReadStore","dojo/cookie","dojo/fx","dijit/layout/TabContainer", "dijit/layout/ContentPane","dojo/date","dojo/date/locale","dojox/widget/Standby"]); /** * BMO Namespace * Define all global components, reg exp. etc.. in this one-off object. * */ var BMO = { /** * Init function used mostly on page load but can be called whenever you need to reset. * */ init : function() { // init MessageManager BMO.MessageManager.init(); // When the close button is clicked, remove its container. // To do this, add class "closeBt" to the button's anchor and add class "closeBtContainer" to its container. dojo.query(".closeBt").forEach(function(closeBt) { dojo.connect(closeBt, "onclick", BMO.handleCloseBt); }); // Dynamically hide Toggle content (".morePanel") and toggle it open/close it when ".toggleContent" is clicked // both ".toggleContent" and ".morePanel" must live inside of (".toggleContainer") dojo.query(".morePanel:not(.visible)").style("display","none"); dojo.query(".toggleContent").forEach(function(toggle) { dojo.connect(toggle, "onclick", BMO._handleToggle); }); // Find all filter select fields and disable validation dojo.query(".filterSelect").forEach(function(node) { // The Payee Name in Add Payee page requires the validation var filter = dijit.byNode(node); if(filter.id != 'ptPayeeName' && filter.id != 'epostMailerName' && filter.id != 'filterPayee' && filter.id != 'filterPayeeScheduled') { // filterPayeeScheduled filter.validate = function (isFocused) { return true; } } }); dojo.query(".rbox").forEach(function(rbox, index, nodeList) { BMO.makeRound(rbox); }); BMO.equalizeHeights(); BMO.selectAllBoxes(); dojo.query(".ptDate, .etHasCal").forEach(function(target){ BMO.DateTextBoxFormat(target); }); dojo.query(".ptCalendar").forEach(function(node, index, nodelist){ _textField = nodelist.prev(); dojo.connect(node, "onclick", function(event){ event.preventDefault(); dijit.focus(_textField[index]); var dateTextBoxWidget = dijit.getEnclosingWidget(_textField[index]); if (dateTextBoxWidget == null){ dateTextBoxWidget = dijit.byId(_textField[index].id); } if(dateTextBoxWidget != null){ var disabled = dateTextBoxWidget.attr("disabled"); if(disabled != true) { dateTextBoxWidget.openDropDown(); } } }); }); }, /** * Event handler for when the user clicks on a close button (anything with .closeBt and parent .closeBtContainer) * */ handleCloseBt : function(event) { event.preventDefault(); var currentTargetNL = new dojo.NodeList(event.currentTarget); dojo.destroy(currentTargetNL.parents(".closeBtContainer")[0]); }, /** * Event handler for when a toggle link is clicked to show or hide the sibling panel (cotained in .toggleContainer) * */ _handleToggle: function(event) { event.preventDefault(); var toggleContainer = dojo.query(event.currentTarget).parents(".toggleContainer"); var toggleAllBt = toggleContainer.query(".toggleContent"); var togglePanel = toggleContainer.query('.morePanel')[0]; var toggleAllBt = toggleContainer.query(".toggleContent"); var togglePanel = toggleContainer.query('.morePanel')[0]; // custom toggle animation to slide information in or out var toggler = new dojo.fx.Toggler({ node: togglePanel, showFunc: dojo.fx.wipeIn, hideFunc: dojo.fx.wipeOut }); if (dojo.hasClass(togglePanel, "visible")) { toggler.hide(); dojo.removeClass(togglePanel,"visible"); toggleAllBt.removeClass("open"); toggleAllBt.addClass("close"); toggleContainer.removeClass("open"); dojo.attr(toggleAllBt[0], "aria-expanded", "false"); } else { toggler.show(); dojo.addClass(togglePanel,"visible"); toggleAllBt.removeClass("close"); toggleAllBt.addClass("open"); toggleContainer.addClass("open"); dojo.attr(toggleAllBt[0], "aria-expanded", "true"); } }, /** * Global Function to bind "Select All" checkbox to its children and vice versa * */ selectAllBoxes: function() { dojo.query(".selectAllCheckHead").forEach(function(masterCheckBox) { var context = dojo.query(masterCheckBox).closest(".bmoTable")[0], masterCheckBoxDijit = dijit.getEnclosingWidget(masterCheckBox), childCheckBox = dojo.query(".selectAllCheck", context); // Count the number of clicks to check or un-check the master checkbox childCheckBox.connect("onclick", function(event){ countChecks(masterCheckBoxDijit, childCheckBox); }); dojo.connect(masterCheckBoxDijit, "onClick", function(event) { dojo.forEach(childCheckBox, function(checkbox) { var checkboxDijit = dijit.getEnclosingWidget(checkbox); if (event.currentTarget.checked) { checkboxDijit.setChecked(true); } else { checkboxDijit.setChecked(false); } }); }); }); countChecks = function (masterCheckBoxDijit, childCheckBox) { var selectedChecks = childCheckBox.filter(".dijitChecked") if (selectedChecks.length === childCheckBox.length) { masterCheckBoxDijit.attr("checked", "checked"); } else { masterCheckBoxDijit.attr("checked", false); } }; }, /** * All form validation related components/modules etc... * */ formValidation : { /** * All reg exp. validations for form fields * */ regExpValidations : { email: "^\\w+((-\\w+)|(\\.\\w+)|(\\_\\w+)|(\\'\\w+))*\\@[A-Za-z0-9]+((\\.|-|_)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$", name: "^[0-9a-zA-ZÀÁÂÇÈÉÊÔÛÏÜàáâçèêéôûïü '\\-\\.]*$", numbers: "^[0-9]*$", address: "^[A-Za-z0-9 ._#-]*$", postalCode: "[ABCEGHJKLMNPRSTVXYabceghjklmnprstvxy][0-9][A-Za-z] ?[0-9][A-Za-z][0-9]", securityQuestion:".{3,40}", securityAnswer:"^[A-Za-z0-9\\-ÀÁÂÃÇÈÉÊËÌÍÎÏÒÓÖÙÚÛÜàáâãçèéêëìíîñòóôõöùúûü]{3,25}$", challengeQuestion:".{2,30}", paymentNumber:"^[0-9]$", accountNumber:"^[0-9 -]*$", bankCardNumber:"[0-9]{16}", creditCardNumber:"^[-+]?[0-9 -]+$", password:"[A-Za-z0-9]{6}", currentPassword:"[A-Za-z0-9]{4,6}", personalPhrase:"[A-Za-zéèêëàâîïôùûüçìòáíóúÉÈÊËÀÂÎÏÔÙÛÜÇÌÒÁÍÓÚ0-9 ]{10,50}", challengeAnswer:"^[A-Za-zéèêëàâîïôùûüçìòáíóúÉÈÊËÀÂÎÏÔÙÛÜÇÌÒÁÍÓÚ0-9 ]{2,30}$", regAnswer1:"[A-Za-z0-9 ]{2,30}", regAnswer2:"[A-Za-z0-9 ]{2,30}", regAnswer3:"[A-Za-z0-9 ]{2,30}", phoneNumber:"^(([0-9]{1})*[- .(]*([0-9a-zA-Z]{3})*[- .)]*[0-9a-zA-Z]{3}[- .]*[0-9a-zA-Z]{4})+$", masterCard:"^(5[1-5]){2}\d{14}*", nickName:"^[A-Za-z0-9éèêëàâîïôùûüçìòáíóúÉÈÊËÀÂÎÏÔÙÛÜÇÌÒÁÍÓÚ\. ',/\(\)&%@=-]*$", mcAccountNumber:"^[0-9^\s]{16}$", payeeName:"^[0-9a-zA-ZÀ-ÿ-, '/\.]{0,45}$", travelPhoneNumber: "^[0-9 -]*[0-9][0-9 -]*$", sfUserId: "^[a-zA-Z0-9]{6,25}$|^\\w+((-\\w+)|(\\.\\w+)|(\\_\\w+)|(\\'\\w+))*\\@[A-Za-z0-9]+((\\.|-|_)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$" }, /* * Validate only numbers * * @param target is a selector with which to target the validation * */ validateNumbersOnly : function (target) { var target = dijit.getEnclosingWidget(target); if (target) { dojo.attr(target,"invalidMessage",BMOContent.validationMessages.numbersOnly); dojo.attr(target,"regExp",BMO.formValidation.regExpValidations.numbers); } }, /* * Validate travel phone numbers * * @param target is a selector with which to target the validation * */ validateTravelPhoneNumber : function (target) { var target = dijit.getEnclosingWidget(target); if (target) { dojo.attr(target,"invalidMessage",BMOContent.validationMessages.numbersOnly); dojo.attr(target,"regExp",BMO.formValidation.regExpValidations.travelPhoneNumber); } }, /* * Validate Account Numbers * * @param target is a selector with which to target the validation * */ validateAccountNumbers : function (target) { var target = dijit.getEnclosingWidget(target); if (target){ dojo.attr(target,"invalidMessage",BMOContent.validationMessages.accountNumber); dojo.attr(target,"regExp",BMO.formValidation.regExpValidations.accountNumber); } }, /* * Validate Postal Code * * @param target is a selector with which to target the validation * */ validatePostalCode : function (target) { var target = dijit.getEnclosingWidget(target); if (target){ dojo.attr(target,"invalidMessage",BMOContent.validationMessages.postalCode); dojo.attr(target,"regExp",BMO.formValidation.regExpValidations.postalCode); } }, /* * Set up Email Validation * * @param target is a selector with which to target the validation * */ emailValidation : function (target) { if (target) { var target = dijit.getEnclosingWidget(target); target.attr("regExp",BMO.formValidation.regExpValidations.email); target.attr("invalidMessage",BMOContent.validationMessages.email); target.attr("maxLength",60); } }, /* * Set up Name Validation * * @param target is a selector with which to target the validation * */ nameValidation : function (target) { if (target) { var target = dijit.getEnclosingWidget(target); target.attr("regExp",BMO.formValidation.regExpValidations.name); target.attr("invalidMessage",BMOContent.validationMessages.name); target.attr("maxLength",300); } }, /* * Set up Credit card number Validation * * @param target is a selector with which to target the validation * */ creditCardNumberValidation : function (target, message) { if (target) { var target = dijit.getEnclosingWidget(target); target.attr("regExp",BMO.formValidation.regExpValidations.creditCardNumber); target.attr("invalidMessage",message); target.attr("maxLength",16); } }, /* * Set up card number Validation * * @param target is a selector with which to target the validation * */ cardNumberValidation : function (target, message) { if (target) { var target = dijit.getEnclosingWidget(target); target.attr("regExp",BMO.formValidation.regExpValidations.bankCardNumber); target.attr("invalidMessage",message); target.attr("maxLength",16); } }, /* * Set up Password Validation * * @param target is a selector with which to target the validation * */ passwordValidation : function (target) { if (target) { var target = dijit.getEnclosingWidget(target); target.attr("regExp",BMO.formValidation.regExpValidations.password); target.attr("invalidMessage",BMOContent.validationMessages.password); target.attr("maxLength",6); } }, /* * Set up Challenge Question validation * * @param target is a selector with which to target the validation * */ challengeValidation : function (target) { if (target) { var target = dijit.getEnclosingWidget(target); target.attr("regExp",BMO.formValidation.regExpValidations.challengeQuestion); target.attr("invalidMessage",BMOContent.validationMessages.challengeLength); target.attr("maxLength",30); } }, /* * Set up Address Validation * * @param target is a selector with which to target the validation * */ addressValidation : function (target) { if (target) { var target = dijit.getEnclosingWidget(target); target.attr("regExp",BMO.formValidation.regExpValidations.address); target.attr("invalidMessage",BMOContent.validationMessages.address); target.attr("maxLength",300); } }, /* * Set up Personal Phrase Validation * * @param target is a selector with which to target the validation * */ personalPhrase : function (target) { if (target) { var target = dijit.getEnclosingWidget(target); target.attr("regExp",BMO.formValidation.regExpValidations.personalPhrase); target.attr("invalidMessage",BMOContent.validationMessages.personalPhrase); } }, /* * Set up Amount Validation * * @param target is a selector with which to target the validation * @param minimum is the minimum value (integer) required for the field * @param maximum is the maximum value (integer) required for the field * */ amountValidation : function (target, minimum, maximum) { if (target) { var constraints = { min: minimum, max: maximum }; var target = dijit.getEnclosingWidget(target); target.attr("constraints",constraints); target.attr("rangeMessage",BMOContent.validationMessages.amountExceeds); target.attr("invalidMessage",BMOContent.validationMessages.amountNumber); } }, /* * Set up Phone Validation * * @param target is a selector with which to target the validation * */ phoneValidation : function (target) { if (target) { var target = dijit.getEnclosingWidget(target); target.attr("regExp",BMO.formValidation.regExpValidations.phoneNumber); target.attr("invalidMessage",BMOContent.validationMessages.phoneNumber); } }, /* * Set up Payee name validation * * @param target is a selector with which to target the validation * */ payeeNameValidation : function (target) { if (target) { var target = dijit.getEnclosingWidget(target); target.attr("regExp",BMO.formValidation.regExpValidations.payeeName); target.attr("invalidMessage",BMOContent.validationMessages.payeeName); } } }, /** * Creates an iframe container with "url" * */ createOverlayIframe: function(url) { return ''; }, /** * Dynamically inserts 6 empty divs to create rounded corners with minimal tmeplate html * Can be called in page for when widgets can be dragged and dropped * /*/ makeRound : function(rbox, rboxTemplate){ // Default template adds a top left, right, bottom left and right div and assumes "sliding doors" CSS for top/bottom borders var rboxTemplate = (typeof rboxTemplate == "undefined") ? "
" : rboxTemplate; // can't wrap outter with container and add classes, bc stuff like margins will need to be re-set (ie .summary-box .summary-box // .wrap(""+ messages +"
"; } else { var msgHTML = ""+ $message +"
"; } if($errorCode != null){ msgHTML = msgHTML + ""+ $errorCode +"
"; } var localeLangCode = BMOContent.language.code; if (localeLangCode == "en") { msgHTML = msgHTML + "Close"+ $message +"
"; var localeLangCode = BMOContent.language.code; if (localeLangCode == "en") { msgHTML = msgHTML + "Close