/*global define*/ /** * Sends a request for validate,cancel or Schedule a pickup request to USPS. * * @class de_epages.usps.ui.packagepickup * * @uses jQuery * @uses ep * @uses ep.ajax * * @since 6.17.2 * */ define('de_epages/usps/ui/packagepickup', [ 'jquery', 'ep', '$dict!ep/dict', '$ready!', 'ep/ajax', 'ep/fn/busy' ], function ($, ep, epDict) { 'use strict'; /** * @param {jQuery} PickUpFields The DOM node that contains all the used elements. * @param {String} ShippingLabelID Number of the shipping label affected. * @param {jQuery} PickupDateDiv The DOM node of the Pick up Date. * @param {jQuery} PackageLocation The DOM node of the input which contains the package location. * @param {jQuery} SpecialInstructions The DOM node of the input which contains the Special Instructions. * @param {jQuery} PickUpInfo The DOM node of the div element that contains the messages. * @param {jQuery} ConfirmationNumberdiv The DOM node of the div element that contains confirmation number. * @param {String} PickUpRequestButton The DOM node of the button that leads to do a request. * @param {String} PickUpCancelButton The DOM node of the button that leads to cancel a request. * @param {String} PickUpAvailabilityButton The DOM node of the button that leads to check the availability for the request. * @param {Boolean} IsUnity Informs if we must use Unity classes or standard ePages6. */ return function (PickUpFields, ShippingLabelID, PickupDateDiv, PackageLocation, SpecialInstructions, PickUpInfo, ConfirmationNumberdiv, PickUpRequestButton, PickUpCancelButton, PickUpAvailabilityButton, IsUnity) { PickUpRequestButton.on('click', function () { PickUpFields.busy('show'); ep.ajax({ data: { ObjectID: ShippingLabelID, PackageLocation: PackageLocation.val(), SpecialInstructions: SpecialInstructions.val(), ChangeAction: 'JSONUSPSPickUpRequest' }, cache: false, type: "POST", dataType: "json" }).done(function (data) { PickUpFields.busy('hide'); if (data.ReturnCode === 1) { if (IsUnity) { PickUpInfo.empty() .append(data.ErrorDesc) .attr('class', 'ep-notification-warning'); } else { PickUpInfo.empty() .append(data.ErrorDesc) .attr('class', 'DialogMessage MessageWarning'); } } else { if (IsUnity) { PickUpInfo.empty() .append('Confirmation Number: ' + data.ReturnMessage) .attr('class', 'ep-notification-info'); } else { PickUpInfo.empty() .append('Confirmation Number: ' + data.ReturnMessage) .attr('class', 'DialogMessage MessageInfo'); } ConfirmationNumberdiv.empty() .append(data.ReturnMessage); PickupDateDiv.empty() .append(data.ScheduledDay); PackageLocation.attr('disabled', 'disabled'); SpecialInstructions.attr('disabled', 'disabled'); PickUpRequestButton.attr('disabled', 'disabled'); PickUpCancelButton.removeAttr("disabled"); PickUpAvailabilityButton.attr('disabled', 'disabled'); } }).fail(function (errJSON) { PickUpFields.busy('hide'); var errMessage; var thisJSON = $.parseJSON(errJSON.responseText || "null"); if (thisJSON.Errors[0].Reason === 'FORMAT_NOT_INTEGER') { errMessage = epDict.translate('{PickupLocationNotValid}'); } else { errMessage = thisJSON.Errors[0].Reason; } if (IsUnity) { PickUpInfo.empty() .append(errMessage) .attr('class', 'ep-notification-warning'); } else { PickUpInfo.empty() .append(errMessage) .attr('class', 'DialogMessage MessageWarning'); } }); }); PickUpCancelButton.on('click', function () { PickUpFields.busy('show'); ep.ajax({ data: { ObjectID: ShippingLabelID, ChangeAction: 'JSONUSPSPickUpCancelRequest' }, cache: false, type: "POST", dataType: "json" }).done(function (data) { PickUpFields.busy('hide'); if (data.ReturnCode === 1) { if (IsUnity) { PickUpInfo.empty() .append(data.ErrorDesc) .attr('class', 'ep-notification-warning'); } else { PickUpInfo.empty() .append(data.ErrorDesc) .attr('class', 'DialogMessage MessageWarning'); } } else { if (IsUnity) { PickUpInfo.empty() .append(data.ReturnMessage) .attr('class', 'ep-notification-info'); } else { PickUpInfo.empty() .append(data.ReturnMessage) .attr('class', 'DialogMessage MessageInfo'); } ConfirmationNumberdiv.empty() .append('Canceled'); PickupDateDiv.empty() .append('-'); PackageLocation.removeAttr("disabled"); SpecialInstructions.removeAttr("disabled"); PickUpRequestButton.removeAttr("disabled"); PickUpCancelButton.attr('disabled', 'disabled'); PickUpAvailabilityButton.removeAttr("disabled"); } }).fail(function (errJSON) { PickUpFields.busy('hide'); var thisJSON = $.parseJSON(errJSON.responseText || "null"); var errMessage = thisJSON.Errors[0].Reason; if (IsUnity) { PickUpInfo.empty() .append(errMessage) .attr('class', 'ep-notification-warning'); } else { PickUpInfo.empty() .append(errMessage) .attr('class', 'DialogMessage MessageWarning'); } }); }); PickUpAvailabilityButton.on('click', function () { PickUpFields.busy('show'); ep.ajax({ // AJAX request data: { ObjectID: ShippingLabelID, PackageLocation: PackageLocation.val(), SpecialInstructions: SpecialInstructions.val(), ChangeAction: 'JSONUSPSPickUpAvailabilityRequest' }, cache: false, type: "POST", dataType: "json" }).done(function (data) { PickUpFields.busy('hide'); if (data.ReturnCode === 1) { if (IsUnity) { PickUpInfo.empty() .append(data.ErrorDesc) .attr('class', 'ep-notification-warning'); } else { PickUpInfo.empty() .append(data.ErrorDesc) .attr('class', 'DialogMessage MessageWarning'); } } else { var message = 'Day:' + data.DayOftheWeek + ' Date:' + data.ReturnedDate + ' Carrier Route:' + data.CarrierRoute; if (IsUnity) { PickUpInfo.empty() .append(message) .attr('class', 'ep-notification-info'); } else { PickUpInfo.empty() .append(message) .attr('class', 'DialogMessage MessageInfo'); } } }).fail(function (errJSON) { PickUpFields.busy('hide'); var errMessage; var thisJSON = $.parseJSON(errJSON.responseText || "null"); if (thisJSON.Errors[0].Reason === 'FORMAT_NOT_INTEGER') { errMessage = epDict.translate('{PickupLocationNotValid}'); } else { errMessage = thisJSON.Errors[0].Reason; } if (IsUnity) { PickUpInfo.empty() .append(errMessage) .attr('class', 'ep-notification-warning'); } else { PickUpInfo.empty() .append(errMessage) .attr('class', 'DialogMessage MessageWarning'); } }); }); }; });