$(document).ready( function() { $('.loader').hide(); initiateDatePicker(); $('#sub-menu').hide(); $('#menu').click( function() { $('#sub-menu').slideToggle('fast'); }); $('#body-section').click( function() { $('#sub-menu').slideUp('fast'); }); }); function initiateDatePicker() { $('#req_dueDate').change( function() { var eInput = '
'; $(this).parent().replaceWith( eInput ); $( '.notice_window' ).removeClass( 'hidden' ); $('#datepicker').datepicker( { minDate: 0 } ); }); } function loadSection( sURL ) { $.ajax({ method: 'GET', url: sURL, dataType: 'html', beforeSend: function() { $( '#loader' ).show(); }, success: function( oHTML ) { $( '#loader' ).hide(); $( '#body-section' ).empty().html( oHTML ); initiateDatePicker(); } }); } function filePathValidation( which ) { var sData = 'filePath=' + which.value; var sId = which.getAttribute( 'id' ); if( which.value.length > 0 ) { $.ajax({ method: 'POST', url: 'index.cfm?do=validate', data: sData, beforeSend: function() { $('.loader').show(); }, success: function( response ) { $('.loader').hide(); if( response == false ) { $('#' + sId ).removeClass('ico_file'); $('#' + sId ).removeClass('ico_approved'); $('#' + sId ).addClass('ico_error'); } else { $('#' + sId ).removeClass('ico_file'); $('#' + sId ).removeClass('ico_error'); $('#' + sId ).addClass('ico_approved'); } } }); } else { $('#' + sId ).addClass('ico_file'); $('#' + sId ).removeClass('ico_error'); $('#' + sId ).removeClass('ico_approved'); } } function addMore() { var sId = $('input[type=text]:last').attr('id'); var nFileId = parseInt( sId.slice(-1) ) + 1; var eRow = '
'; $('.ico_add').before( eRow ); } function submitRequestForm( oForm, sAction ) { //alert( 'submitRequestForm function triggered' ); var validated = true; var dataArray = $( '#' + oForm ).serializeArray(); $( dataArray ).each( function( i ) { var eInput = $('[name=' + dataArray[i].name + ']' ); if( eInput.prop( 'required' ) && eInput.val() == '' ) { eInput.css( 'background-color', '#FCC9C9' ); alert( eInput.attr( 'message' ) ); validated = false; return validated; } else if ( eInput.hasClass( 'ico_error' ) ) { alert( 'Incorrect pathname!' ); validated = false; return validated; } else { eInput.css( 'background-color', '#FFFFFF' ); } }); if( validated ) { $.ajax({ method: 'POST', url: sAction, data: dataArray, beforeSend: function() { $( '.loader' ).show(); }, success: function( data ) { $( '.loader' ).hide(); updateRequestCounter(); displayNotice( 'Your request has been sent.', 2500 ); loadSection( 'index.cfm?ajax=request' ); } }); } } function updateRequestCounter() { $.ajax({ method: 'POST', url: 'index.cfm?do=updateRequestCounter', success: function( data ) { $( '#notification_badge' ).empty().append( data ); } }); } function assignedTo( which, nId ) { nAssignedTo = $('#assignedTo_' + nId ).val(); eButton = ''; if( nAssignedTo != -1 ) { $.ajax({ type: 'POST', url: 'index.cfm?do=assign', data: 'memberId=' + nAssignedTo + '&trackingId=' + nId, beforeSend: function() { $('.loader').show(); }, success: function( response ) { $('.loader').hide(); $( which ).parent().prev().text('Assigned To ' + response ); $( which ).replaceWith( eButton ); displayNotice( 'Assigned', 2000 ); } }); } } function requestCompleted( nId ) { var requestCompleted = true; /* verify every file is checked before completing the request */ $('.file_' + nId ).each( function() { if( !$(this).prop("checked") ) { alert( 'Make sure all the files you deployed are checked off.' ); requestCompleted = false; return requestCompleted; } }); /* request is compeleted once all files are checked */ if( requestCompleted ) { document.forms.frm_requestCompleted.trackingId.value = nId; $.ajax({ type: 'POST', url: 'index.cfm?do=completeRequest', data: $( '#frm_requestCompleted' ).serialize(), beforeSend: function() { $('.loader').show(); }, success: function( data ) { $('.loader').hide(); $('#request_wrapper_' + nId ).slideUp( 'slow' ); updateRequestCounter(); displayNotice( 'Request is completed.', 2000 ); }, error: function() { console.log( $.makeArray(arguments) ); } }); } } function displayNotice( data, nDuration ) { $( '#notice_message' ).empty().append( data ); $( '#sent_notice' ).fadeIn( 400, function() { $( this ).delay( nDuration ).fadeOut( 'slow' ); }); }