// // MDR Javascript // Based on Mootools library framework // $Id$ // var RAMPSCore = new Class( { Implements: [Options,Events], options: { base_url: "", current_tab: "", suppressDisplay: "false", currentBrowser: "", eisQuestion: "Please note: By checking this box, you are indicating that you are completing, or will complete, an Environmental Impact Statement (EIS) for this project. For nearly all projects, an EIS is not required. If you have completed, or are in the process of completing an EIS for this project, click 'OK' to confirm. Otherwise, click 'Cancel.'", firstBuildingSelection: "" }, getFirstBuildingSelection: function() { return this.options.firstBuildingSelection; }, initialize: function( options ) { this.setOptions( options ); // // Try some browser detection for extra CSS rules outside of IE if( Browser.Engine.trident ) { /** IE **/ if( Browser.Engine.version == "4" ) { this.options.currentBrowser = "ie6"; } else if( Browser.Engine.version == "5" ) { this.options.currentBrowser = "ie7"; } else { this.options.currentBrowser = "ie"; } } else if( Browser.Engine.gecko ) { /** Primarily firefox **/ this.options.currentBrowser = "firefox"; } else if( Browser.Engine.webkit ) { /** Google Chrome, Safari and Konqueror **/ this.options.currentBrowser = "webkit"; } window.addEvent('domready',function() { // // Prepopulate part50&part58 if( $('ram_part58') && $('ram_part50') ) { var p58Check = $('ram_part58').get('checked'); var p50Check = $('ram_part50').get('checked'); if( p58Check ) { $('ram_part50').set('disabled',true); } else if( p50Check ) { $('ram_part58').set('disabled',true); } else { //eeeerrror } } if( $('ram_reviewLevelEA') ) { // // Need to prepopulate the checks? boxNames = new Array('ram_reviewLevelER','ram_reviewLevelCE', 'ram_reviewLevelEA', 'ram_reviewLevelEIS'); boxNames.each( function(box) { var isChecked = $(box).get('checked'); if( isChecked) { var boxName = $(box).get('value'); switch(boxName) { case 'ER': $('ceStatusReview').setStyle('display','block'); break; case 'CE': $('catExStatusReview').setStyle('display','block'); $('ram_reviewLevelEIS').set('disabled',true); $('ram_reviewLevelEA').set('disabled',true); break; case 'EA': $('eaStatusReview').setStyle('display','block'); $('ram_reviewLevelEIS').set('disabled',true); $('ram_reviewLevelCE').set('disabled',true); break; case 'EIS': $('eisStatusReview').setStyle('display','block'); $('ram_reviewLevelEA').set('disabled',true); $('ram_reviewLevelCE').set('disabled',true); break; } } }); } }); }, /** * Get the current browser * @return Current browser with version number at end if IE **/ getCurrentBrowser: function() { return this.options.currentBrowser; }, // // Public methods // initHelperSys: function() { // // Called from the module class, only as needed var openForHelpers = $('div.helperText'); if( openForHelpers && openForHelpers.length > 0 ) { var languageObj = new Language(); openForHelpers.each( function(el) { // // Need to inject the helper image if( Browser.Engine.trident && Browser.Engine.version == 4 ) { var helperElement = new Element( 'img', { 'src': 'resources/images/forms/help.gif', 'class' : 'helperImage', 'title' : languageObj.getString(el.id) }); } else { var helperElement = new Element( 'img', { 'src': 'resources/images/forms/help.png', 'class' : 'helperImage', 'title' : languageObj.getString(el.id) }); } // // Inject at the end of the DIV helperElement.inject(el); //delete helperElement; }); var helperImages = $('img.helperImage'); if( helperImages && helperImages.length > 0 ) { var myTips = new Tips(helperImages, { className: 'helperImageText', offsets: {'x':-9, 'y':-52}, fixed: true, onShow: function(tip) { tip.setStyle('opacity','0.9') } }); } } }, /** * Switches the header tab based on request.getAttribute("CURRENT_TAB") **/ switchCurrentTab: function() { var tabShort = this.options.current_tab; if( $(tabShort) ) { $(tabShort).addClass('current'); } if( $(tabShort+'Expand') ) { $(tabShort+'Expand').setStyle('display', 'block'); } }, /** * Sets the .current attribute to the sidebar * @param The section ID to use */ setCurrentFlow:function( sectionID ) { if( $( sectionID ) ) { $( sectionID ).addClass('current'); } }, /** * Checks the change state on the NEPA Review Level part * @param Link back to the checkbox **/ nepaChangeState:function( obj ) { var boxName = obj.value; var boxState = obj.checked; if( boxState==true ) { switch(boxName) { case 'ER': this.openNepaWindow('ceStatusReview'); break; case 'CE': this.openNepaWindow('catExStatusReview'); this.nepaToggle( ['ram_reviewLevelEIS','ram_reviewLevelEA'],['ram_reviewLevelER'] ); break; case 'EA': this.nepaToggle( ['ram_reviewLevelEIS','ram_reviewLevelCE'],['ram_reviewLevelER','ram_reviewLevelEA'] ); this.openNepaWindow('eaStatusReview'); this.closeNepaWindow('eisStatusReview'); break; case 'EIS': if( (confirm(this.options.eisQuestion))) { this.nepaToggle( ['ram_reviewLevelEA','ram_reviewLevelCE'],['ram_reviewLevelER','ram_reviewLevelEIS'] ); this.openNepaWindow('eisStatusReview'); this.closeNepaWindow('eaStatusReview'); } else { obj.checked = false; } break; } } else { switch(boxName) { case 'ER': this.closeNepaWindow('ceStatusReview'); break; case 'CE': this.closeNepaWindow('catExStatusReview'); this.nepaToggle(['skip'],['ram_reviewLevelEIS','ram_reviewLevelEA']); break; case 'EA': this.closeNepaWindow('eaStatusReview'); this.nepaToggle(['skip'],['ram_reviewLevelCE','ram_reviewLevelEIS']); break; case 'EIS': this.closeNepaWindow('eisStatusReview'); this.nepaToggle(['skip'],['ram_reviewLevelCE','ram_reviewLevelEA']); break; } return true; } }, /** * Checks the change state on the Part 50 and Part 58 at project level * @param Link back to the checkbox **/ partChangeState:function( obj ) { var boxName = obj.name; var boxState = obj.checked; if( boxState==true ) { switch(boxName) { case 'ram_part50': this.nepaToggle( ['ram_part58'],['ram_part50']); break; case 'ram_part58': this.nepaToggle( ['ram_part50'],['ram_part58'] ); break; } } else { switch(boxName) { case 'ram_part50': this.nepaToggle(['skip'],['ram_part58']); break; case 'ram_part58': this.nepaToggle(['skip'],['ram_part50']); break; } return true; } }, /** * Toggles the state for multiple checkboxes at once * @param The array of checkboxes to be disabled * @param The array of checkboxes to be enabled **/ nepaToggle: function( arrayOff, arrayOn ) { if( $type( arrayOff ) != "array" || $type( arrayOn ) != "array" ) { return null; } arrayOff.each( function(el) { if( $(el) ) { $( el ).set( "disabled", true ); } }); arrayOn.each( function(el2) { $( el2 ).set( "disabled", false ); }); }, /** * unchecks the state for multiple radiobuttons at once * @param The array of radiobuttons to be unchecked **/ nepaToggleradio: function(array1) { array1.each( function(el) { if( $(el) ) { if($(e1).checked){ $( el ).set( "checked", false ); } } }); }, /** * Opens a particular NEPA window * @param The ID of the box to open */ openNepaWindow: function(what) { $(what).setStyle('display','block'); }, /** * Close a certain window * @param ID of the box to close **/ closeNepaWindow: function(what) { $(what).setStyle('display','none'); }, /** * Flip through the pages of awards */ doAwardPaging: function() { var toPaige = $('gtp').get('value'); if( toPaige>paging_max_page ) { alert( 'Page number has to be between 1 and '+paging_max_page ); } else { window.location = "awardList.do?cmd=doInit&pg="+toPaige; } }, /** * Send to controller to find a specific award */ findAwardByID: function() { var awardID = $('findAwardID').get('value'); window.location = "awardList.do?cmd=doAwardSearch&awardID="+awardID; }, /** * Send to controller to find a specific award */ findAwardByPhaCode: function() { var phaCode = $('findPhaCode').get('value'); window.location = "awardList.do?cmd=doAwardSearchByPhaCode&phaCode="+phaCode; }, /** * Send to controller to find specific awards by PHA code */ findPHAByID: function() { var phaID = $('findPHACode').get('value'); window.location = "recipientAdmin.do?cmd=doInit&phaID="+phaID; }, /** * Send to controller to find a specific group */ findGroupByName: function(locale,userId) { var groupName = $('findGroupName').get('value'); if( locale=="glist" ) { window.location = "awardAdmin.do?cmd=doGroupSearch&groupName="+groupName; } else { window.location = "awardAdmin.do?cmd=doUserGroup&userId="+userId+"&groupName="+groupName; } }, findGroupByPha: function(locale,userId) { var groupName = $('findGroupPha').get('value'); if( locale=="glist" ) { window.location = "awardAdmin.do?cmd=doGroupSearchByAwardPha&phaCode="+groupName; } else { window.location = "awardAdmin.do?cmd=doUserGroup&userId="+userId+"&groupName="+groupName; } }, findGroupByAward: function(locale,userId) { var groupName = $('findGroupAward').get('value'); if( locale=="glist" ) { window.location = "awardAdmin.do?cmd=doGroupSearchByAwardPha&awardId="+groupName; } else { window.location = "awardAdmin.do?cmd=doUserGroup&userId="+userId+"&groupName="+groupName; } }, /** * Send to controller to find a specific user */ findUserByHUDID: function() { var userId = $('findHUDID').get('value'); var userRole = $('userRole').get('value'); window.location = "awardAdmin.do?cmd=doUserSearch&userId="+userId+'&userRole='+ userRole; }, /** * Send to controller to find a specific user */ findUserByName: function() { var userName = $('findNAME').get('value'); var userRole = $('userRole').get('value'); window.location = "awardAdmin.do?cmd=doUserSearch&userName="+userName+'&userRole='+ userRole; }, findUserByPHA: function() { var userName = $('findPha').get('value'); var userRole = $('userRole').get('value'); window.location = "awardAdmin.do?cmd=doUserSearchByAwardPha&phaCode="+userName+'&userRole='+ userRole; }, findUserByAward: function() { var userName = $('findAward').get('value'); var userRole = $('userRole').get('value'); window.location = "awardAdmin.do?cmd=doUserSearchByAwardPha&awardId="+userName+'&userRole='+ userRole; }, /** * Open the help system window */ openHelpWindow: function() { var newWindow = window.open( 'awardList.do?cmd=doHelpText', 'HelpSystem', 'width=800,height=700,location=no,toolbars=no,status=no,scrollbars=yes' ); if( newWindow == null ) { alert( 'Please disable your pop-up blocked and try again.' ); } }, /** * Controls the Create Group/Create User * forms on Award Admin * @param A reference back to the input button */ submitAwardAdminForm: function(type) { switch( type ) { case 'group': $('awardAdminCMD').set('value','doNewGroup'); break; case 'user': $('awardAdminCMD').set('value','doNewUser'); break; } $('awardAdminForm').submit(); }, /** * Just handles submitting the Group form */ submitGroupForm: function() { $('awardAdminForm').submit(); }, /** * Just handles submitting the User form */ submitUserForm: function() { $('awardAdminForm').submit(); }, /** * Takes all the checkboxes for the groups, creates a CSL out of it **/ addUserToGroups: function() { var checkedGroups = new Array(); var x=0; $$('input.uGroupCheck').each( function(el) { if( el.get('checked') ) { checkedGroups[ x ] = el.get('name'); x++; } }); $('adminGroupIds').set('value', ( checkedGroups.join(",") ) ); $('awardAdminForm').submit(); }, /** * Flags a user before they go and delete a project * @param The award ID that the project is a part of * @param The project ID to delete * @deprecated * @see RAMPS.genericDelete() **/ confirmProjectDelete: function( awardId, projectId, isPerf ) { var actionUrl = "awardList.do?cmd=doDelete&awardId="+awardId+"&projectId="+projectId+"&isPerf="+isPerf; this.genericDelete(actionUrl, 'Are you sure you want to delete this report?'); }, confirmUserDelete: function( userId ) { var actionUrl = "awardAdmin.do?cmd=doDeleteUser&hudId=" + userId; this.genericDelete(actionUrl, null); }, confirmDelete: function( actionUrl ) { this.genericDelete(actionUrl, null); }, /** * Generic delete action for the RAMPS system * @param URL to the Struts Action handling the delete * @param Optional, you can specify your own delete text here **/ genericDelete: function( deleteAction, optText ) { var text = optText; if( text==null ) { text = "Are you sure you want to delete this item? This action cannot be reversed."; } if( confirm(text) ) { window.location=deleteAction; } }, /** * Switches the 2nd level menu LI to current based on * request.getAttribute("CURRENT_SECTION") * @param The element ID of the LI to switch */ switchCurrentSection: function(styleId) { if( $(styleId) ) { $(styleId).addClass('current'); } }, /** * Main AJAX function. Executes AJAX action, populates container and flips * the AJAX loading dialog on and off automatically * @param The URL to be accessed via AJAX * @param Element ID of the container to be updated by the * Ajax return * @param If using a Comments style template Div, this will flip the * wrapper "on" and give it a drag handle * @param If using a custom AJAX loading string, give the element ID of the * custom loader here * @see AjaxCallBack() */ AjaxRequest: function( actionUrl, updateContainer, showWrapper, customLoader ) { // // Build the full URL if( actionUrl.test("http") ) { var xml_request = actionUrl; } else { var xml_request = this.options.base_url + actionUrl; } // // Pop the loading screen if( $(customLoader) ) { $( customLoader ).setStyle( 'display', '' ); } else if( $('ajax-loader') ) { $( 'ajax-loader' ).setStyle( 'display', '' ); this.centerElement('ajax-loader'); } var Ajax = new Request( { url: xml_request, method: 'get', headers: { 'If-Modified-Since': 'Sat, 1 Jan 2000 00:00:00 GMT' }, update: $( updateContainer ), onSuccess: function( responseText, responseXML ) { // // Update the inner html if( $(updateContainer) && ( RAMPS.options.suppressDisplay == "false" ) ) { $(updateContainer).set('html', responseText ).setStyle('display',''); } else { RAMPS.options.ajaxResponse = responseText; RAMPS.options.ajaxResponseXML = responseXML; } // // Reset? if( RAMPS.options.suppressDisplay == "true" ) { RAMPS.options.suppressDisplay = "false"; } if( $(showWrapper) ) { $( showWrapper ).setStyle( 'display', 'block' ); $( showWrapper ).makeDraggable( { handle: $( showWrapper+'-handle' ) } ); } // // Flip the loader off last, instead of first if( $(customLoader) ) { $( customLoader ).setStyle( 'display','none'); } else if( $('ajax-loader') ) { $( 'ajax-loader' ).setStyle( 'display', 'none' ); } } }).send(); }, /** * Simple function for calling an API, updating a container and exiting. No loader, etc * @param String The URL to be called * @param String The container to update, but DOES NOT auto-show **/ SimpleAjax: function( actionUrl, updateContainer ) { // // Build the full URL var xml_request = ( actionUrl.test("http") ) ? actionUrl : this.options.base_url + actionUrl; var Ajax = new Request( { url: xml_request, method: 'get', headers: { 'If-Modified-Since': 'Sat, 1 Jan 2000 00:00:00 GMT' }, update: $( updateContainer ), onSuccess: function( responseText, responseXML ) { $(updateContainer).set('html', responseText ); } }).send(); }, /** * Function usually used as a debug for Ajax calls. * If the AJAX request is not empty, it will throw an alert * @param The URL to be accessed by the call * @param The Element ID of the HTML container that should be updated * @see AjaxRequest() */ AjaxCallBack: function( actionUrl, updateContainer) { // // Build the full URL if( actionUrl.test("http") ) { var xml_request = actionUrl; } else { var xml_request = this.options.base_url + actionUrl; } if( $('ajax-loader') ) { $( 'ajax-loader' ).setStyle( 'display', '' ); this.centerElement('ajax-loader'); } var Ajax = new Request( { url: xml_request, method: 'get', headers: { 'If-Modified-Since': 'Sat, 1 Jan 2000 00:00:00 GMT' }, update: $( updateContainer ), onSuccess: function( responseText, responseXML ) { if( $('ajax-loader') ) { $( 'ajax-loader' ).setStyle( 'display', 'none' ); } if(responseText!=''){ alert(responseText); } } }).send(); }, /** * This function should be called right before an Ajax call * that you DONT want to update anything on the screen. * This also supresses the AJAX loading box */ silentUi: function() { this.options.suppressDisplay = "true"; }, /** * Tries to center an HTML element using window coords * @param The element ID of the container that needs to be centered */ centerElement: function( el ) { // // Get the HV pos var elCoords = $(el).getCoordinates(); var elLeft = ( (( window.getWidth() - elCoords['width'] ) /2) ); var elTop = ( (( window.getHeight() /2 ) - elCoords['height'] /2) ); // // Set the values $(el).setStyle( 'left', elLeft ).setStyle( 'top', elTop ); }, hangElementToEdge: function(sourceElement, clickX, clickY) { var elTop = clickY; var elLeft = clickX; if ((window.getWidth() - clickX) <= 300 ) { elLeft = clickX - 300; if (elLeft < 0) elLeft = 0; } if ((window.getHeight() - clickY) <= 150 ) { elTop = clickY - 150; if (elTop < 0) elTop = 0; } // // Set the values $(sourceElement).setStyle( 'left', elLeft ).setStyle( 'top', elTop ); }, /** * Toggles the user dashboard links on or off */ toggleUserDashboard: function() { if( $('interiorLinks') ) { if( $('interiorLinks').getStyle('display').test("block") ) { // //Flip the image first $('userIMG').set('src', 'resources/images/icons/user_gray.png'); $('userIMG').set('title', 'Open User Dashboard').set('alt', 'Open User Dashboard'); $('interiorLinks').setStyle('display', 'none'); $('userDashboard').setStyle('border-bottom', '1px solid #036'); $('userID').setStyle('border-bottom', '0'); } else { // // Flip the image first $('userIMG').set('src', 'resources/images/icons/user_grayMinus.png'); $('userIMG').set('title', 'Close User Dashboard').set('alt', 'Close User Dashboard'); $('userDashboard').setStyle('border-bottom', '0'); $('userID').setStyle('border-bottom', '1px solid #036'); $('interiorLinks').setStyle('display', 'block'); } } }, /** * This checks and accepts every RFC valid email address * @param The email address that needs checking * @return True if email is valid, false if it isn't */ checkValidEmail: function(email) { if( !email ) { return false; } if( email.test("^[A-Za-z0-9_\+-]+(\.[A-Za-z0-9_\+-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*\.([A-Za-z]{2,4})$") ) { return true; } else if( email.test("^[A-Za-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+(\.[A-Za-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*\.([A-Za-z]{2,})$") ) { return true; } else { return false; } }, toggleDivs: function( toggleOn, toggleOff ) { toggleOn.each( function(item) { if(item!='skip' && $(item) ) { $(item).setStyle('display','block'); } }); toggleOff.each( function(item) { if(item!='skip' && $(item) ) { $(item).setStyle('display','none'); } }); } });