'use strict'; var procNum = -1; var jobId = -1; var offerLetterId = -1; var offerLetterResponseCodes = []; var offerLetterAttachments = []; var applicantName = ''; // This is effectively called when entering this "view" it can act as the init function. function handleViewOffer(data) { resetMyApplicationsController(); procNum = data["PROC_NUM"]; jobId = data["JOB_ID"]; offerLetterId = data["OFFER_LETTER_ID"]; var formattedJobCity = data["JOB_CITY"]; var formattedJobState = data["JOB_STATE"]; var formattedJobPositionName = data["JOB_POSITION_NAME"]; applicantName = data["APPLICANTNAME"]; $('.incompleteOfferedWarning').hide(); getOfferLetterBody(offerLetterId, procNum) .done(function(data) { var offerLetter = data.letterBody; var offerLetterResponse = data.responseCode; var formattedDate = ""; if (data.sentDate) { var formattedDate = "Offered on: " + moment(data.sentDate).format("MM/DD/YYYY"); } var signedDate = ""; if (data.responseDate) { var signedDate = moment(data.responseDate).format("MM-DD-YYYY"); } if (data.position_type && data.position_name) { formattedJobPositionName = data.position_name + ': ' + data.position_type; } if (data.city) { formattedJobCity = data.city; } if (data.state) { formattedJobState = data.state; } $(".head .head-line-1").html("View Offer Letter"); $("#offer_form_appl .head-line-2").html(formattedJobPositionName + ', ' + formattedJobCity + ',' + formattedJobState); $(".head .head-line-2").html(''); $("#offer_form_appl .head-line-3").html(formattedDate); $(".offer-letter-body pre").html(offerLetter); $("#grid_form_appl").hide(); $("#offer_forms_appl").show(); $("#left-menu-div .steps").hide(); $('#offer-letter-signature').hide(); //always hide and we will show if we need to. $("#offer_form_appl #latestOfferLetterDownloadLink").attr("onclick", 'downloadOfferLetter('+ offerLetterId +')'); getOfferLetterAttachments(offerLetterId).done(function (res) { offerLetterAttachments = res; buildAttachmentsList(offerLetterAttachments); }) .fail(function(err) { console.log(err); }); getOfferLetterResponseCodes().done(function(res) { offerLetterResponseCodes = _.sortBy(res.responseCodes, function (o) { return o.responseDesc; }); if (offerLetterResponse) { var foundCode = _.find(offerLetterResponseCodes, function(code) { return code.responseCode === offerLetterResponse }); if (foundCode && foundCode.responseType === 'Accept') { acceptedOfferSucessCallback(); $('#signed-by').html('Digitally Signed By ' + applicantName + ' Date: ' + signedDate); $('#signed-by-2').html('Signature of Applicant'); $('#offer-letter-signature').show(); } else if (foundCode && (foundCode.responseType === 'Counter' || foundCode.responseType === 'Decline')) { $('#signed-by').html(applicantName + ' Declined Offer On ' + signedDate); $('#signed-by-2').html('Reason: ' + foundCode.responseDesc); $('#offer-letter-signature').show(); declinedOfferSuccessCallback(foundCode.responseDesc); } else { declinedOfferSuccessCallback(); } } getAllOfferLettersForJob(procNum).done(function(offers) { var filteredOffers = _.reject(offers, function (offer) { if (offer.id === offerLetterId) { return true; } if (!offer.letterBody) { return true; } }); _.each(filteredOffers, function(theOffer) { formattedJobPositionName = jobPositionName; formattedJobState = jobState; formattedJobCity = jobCity; if (theOffer.position_type && theOffer.position_name) { formattedJobPositionName = theOffer.position_name + ': ' + theOffer.position_type; } if (theOffer.city) { formattedJobCity = theOffer.city; } if (theOffer.state) { formattedJobState = theOffer.state; } var rCode = _.find(offerLetterResponseCodes, function (code) { return code.responseCode === theOffer.responseCode; }); if (rCode && rCode.responseType === 'Accept') { theOffer.responseType = 'Accept'; } else if (rCode && (rCode.responseType === 'Decline' || rCode.responseType === 'Counter')) { theOffer.responseType = 'Decline'; theOffer.responseDesc = rCode.responseDesc; } $('#page-7 .content-page #offer_forms_appl').append(buildOfferLetterHistoricalForm(theOffer, formattedJobCity, formattedJobState, formattedJobPositionName)); }); }); }) .fail(function(err) { console.log(err); }); }) .fail(function(err) { console.log(err); }); } function handleAcceptOfferLetter(e) { if (e.target.classList.contains('disabled')) { e.preventDefault(); return; } var acceptModal = new AcceptOfferModalController({ procNum: procNum, offerLetterId: offerLetterId, responseCodes: offerLetterResponseCodes, saveSuccessCallback: acceptedOfferSucessCallback, saveErrorCallback: acceptedOfferSucessCallback }); acceptModal.show(); } function handleDeclineOfferLetter(e) { if (e.target.classList.contains('disabled')) { e.preventDefault(); return; } var filteredResponseCodes = _.reject(offerLetterResponseCodes, function (val) { return val.responseType === 'Accept'; }); var declineModal = new DeclineOfferModalController({ procNum: procNum, offerLetterId: offerLetterId, responseCodes: filteredResponseCodes, saveSuccessCallback: declinedOfferSuccessCallback, saveErrorCallback: declinedOfferSuccessCallback }); declineModal.show(); } function acceptedOfferSucessCallback() { $('#acceptOfferButton').text('Offer Accepted'); disableDeclineButton(); disableAcceptButton(); var signedDate = moment().format("MM-DD-YYYY"); $('#signed-by').html('Digitally Signed By ' + applicantName + ' Date: ' + signedDate); $('#offer-letter-signature').show(); } function declinedOfferSuccessCallback(responseDesc) { $('#declineOfferButton').text('Offer Declined'); disableDeclineButton(); disableAcceptButton(); var signedDate = moment().format("MM-DD-YYYY"); $('#signed-by').html(applicantName + ' Declined Offer On ' + signedDate); $('#signed-by-2').html('Reason: ' + responseDesc); $('#offer-letter-signature').show(); } function disableDeclineButton() { var declineButton = $('#declineOfferButton'); declineButton.addClass('disabled'); } function disableAcceptButton() { var acceptButton = $('#acceptOfferButton'); acceptButton.addClass('disabled'); } function resetMyApplicationsController() { // Reset the globals to defaults. procNum = -1; jobId = -1; offerLetterId = 1; offerLetterResponseCodes = []; offerLetterAttachments = []; // Remove disabled classes from buttons $('#acceptOfferButton').removeClass('disabled'); $('#declineOfferButton').removeClass('disabled'); $('#acceptOfferButton').text("Accept Offer"); $('#declineOfferButton').text("Decline Offer"); $('#offerLetterAcceptPassword').val(''); $('.offer-letter-attachments #attachmentList').empty(); $('#offer_forms_appl .offer-form-appl').remove(); } // promisified function to get offer letter response codes. function getOfferLetterResponseCodes() { return $.ajax({ url: "/offerletters/responseCodes", type: "GET", global: false, contentType: "application/json", headers: { "x-auth-token": apiToken.API_TOKEN, "x-auth-id": apiToken.USER_ID }, }); } //Getting and displaying the Offer Letter Body // promisified function to get offer letter response codes. function getOfferLetterBody(offerLetterId, procNum) { return $.ajax({ url: "/offerletters/"+offerLetterId+"/job/"+procNum+"", type: "GET", global: false, contentType: "application/json", headers: { "x-auth-token": apiToken.API_TOKEN, "x-auth-id": apiToken.USER_ID }, }); } function getAllOfferLettersForJob(procNum) { return $.ajax({ url: "/offerletters/job/"+procNum+"", type: "GET", global: false, contentType: "application/json", headers: { "x-auth-token": apiToken.API_TOKEN, "x-auth-id": apiToken.USER_ID }, }); } function downloadOfferLetter(olId) { window.open('application/OfferDisplay_PDF.cfm?offer_letter_id='+olId,'_new','height=768px,width=1024px'); } // promisified function to get offer letter attachments. function getOfferLetterAttachments(letterId) { return $.ajax({ url: "/offerletters/" + letterId + "/job/" + procNum + "/attachments", type: "GET", global: false, contentType: "application/json", headers: { "x-auth-token": apiToken.API_TOKEN, "x-auth-id": apiToken.USER_ID }, }); } function buildAttachmentsList(attachments) { _.each(attachments, function (attachment) { var downloadUrl = 'application/get_OfferAttachment.cfm?offer_letter_id='+offerLetterId+'&document_id='+attachment.id+'&job_num='+procNum; $('.offer-letter-attachments #attachmentList').append( $('