1const form = $("#newsSubscriptionForm"); 2 3const renderAlert = (alertType, code) => { 4 const alert = $("#newsletterSubscriptionAlert"); 5 6 // Remove current CSS classes 7 alert.removeClass(); 8 // Add new CSS classes for alert colour 9 alert.addClass(`alert alert-${alertType}`); 10 11 // Render alert for any errors 12 if (code === 205 || code === 207 || code === 400 || code === 500) { 13 alert.html("An error has occured, please try again later..."); 14 } 15 16 // Render alert for currently subscribed email 17 if (code == 409) { 18 alert.html("You are already subscribed for newsletter alerts!"); 19 } 20 21 // Render alert for new email subscription 22 if (code == 201) { 23 alert.html("You have successfully signed-up for newsletter alerts!"); 24 } 25 26 // Render alert for re-subscribed email 27 if (code == 200) { 28 alert.html("You have successfully re-subscribed for newsletter alerts!"); 29 } 30}; 31 32const handleSubmit = (e) => { 33 e.preventDefault(); 34 35 // Get values from form 36 const email = $("#email").val(); 37 const consent = $("#consentToTrackInput").is(":checked"); 38 39 try { 40 // Make request to NewsletterSubscriptionSurfaceController.cs 41 $.get("/umbraco/surface/jpnewslettersurface/addsubscriber", { email: email, consent: consent }, (data) => { 42 // Parse response from request as JSON Object 43 const obj = JSON.parse(data); 44 45 // * Condition for an UN-SUCCESSFULL response 46 if (obj.code === 205 || obj.code === 207 || obj.code === 400) { 47 // 48 renderAlert("danger", obj.code); 49 } 50 51 // * Condition for a SUCCESSFULL response 52 if (obj.code === 200 || obj.code === 201) { 53 if (obj.subscriberStatus) { 54 // Conflict HTTP Response for existing email 55 renderAlert("warning", 409); 56 } else if (obj.resubscribed) { 57 // OK HTTP Response for resubscribed email 58 renderAlert("warning", 200); 59 } else { 60 // Created HTTP Response for new email 61 renderAlert("success", 201); 62 } 63 } 64 }).fail(() => { 65 // Internal error 66 renderAlert("danger", 500); 67 }); 68 } catch (error) { 69 throw error; 70 } 71}; 72 73form.submit(handleSubmit);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.