Skip to content

Commit

Permalink
Spruce up jquery load errors, allow adults to select address (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
rechner committed Feb 12, 2024
1 parent 91197b7 commit 403bdd8
Show file tree
Hide file tree
Showing 10 changed files with 354 additions and 339 deletions.
2 changes: 1 addition & 1 deletion registration/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async function postJSON(url, body) {
})
}

$("body").ready(function (e) {
$(document).ready(function (e) {
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
Expand Down
4 changes: 1 addition & 3 deletions registration/static/js/upgrade.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
$("body").ready(function () {
$(document).ready(function () {
$("#cancel").click(function (e) {
$.getJSON(URL_REGISTRATION_FLUSH, function (data) {
window.location.reload();
});
});


});
4 changes: 3 additions & 1 deletion registration/templates/registration/attendee-locate.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ <h1>Registration Upgrade - {{ event }}</h1>

<script type="text/javascript">

$("#lookup").click(doRegister);
$(document).ready(function () {
$("#lookup").click(doRegister);
});

function doRegister() {
$("form").validator('validate');
Expand Down
93 changes: 48 additions & 45 deletions registration/templates/registration/attendee-upgrade.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,58 +160,61 @@ <h3 data-content="name"></h3>
var levelTemplateData = [];
var shirtSizes = [];

$("body").ready(function () {
$.getJSON("{% url 'registration:pricelevels' %}", function (data) {
levelData = data;
var prevLevel = 50;
if (currentLevel && currentLevel.hasOwnProperty("basePrice")) {
prevLevel = parseFloat(currentLevel.basePrice);
}
$.each(data, function (key, val) {
let currentPrice = val.base_price - prevLevel;
if (currentPrice > 0) {
levelTemplateData.push({
name: val.name,
price: "$" + currentPrice,
levelId: "level_" + val.id,
});
$(document).ready(function () {
$("body").ready(function () {
$.getJSON("{% url 'registration:pricelevels' %}", function (data) {
levelData = data;
var prevLevel = 50;
if (currentLevel && currentLevel.hasOwnProperty("basePrice")) {
prevLevel = parseFloat(currentLevel.basePrice);
}
$.each(data, function (key, val) {
let currentPrice = val.base_price - prevLevel;
if (currentPrice > 0) {
levelTemplateData.push({
name: val.name,
price: "$" + currentPrice,
levelId: "level_" + val.id,
});
}
});
$("#levelContainer").loadTemplate($("#levelTemplate"), levelTemplateData);
$(".changeLevel").hide();
if (shirtSizes.length > 0) {
$(".selectLevel")[0].click();
}

});
$("#levelContainer").loadTemplate($("#levelTemplate"), levelTemplateData);
$(".changeLevel").hide();
if (shirtSizes.length > 0) {
$(".selectLevel")[0].click();
}
$.getJSON("{% url 'registration:shirtsizes' %}", function (data) {
shirtSizes = data;
if (levelTemplateData.length > 0) {
$(".selectLevel")[0].click();
}
});
});

$("#levelContainer").on('click', 'a.selectLevel', function () {
clearLevels();
var levelId = $(this).attr('id').split('_')[1];
$.each(levelTemplateData, function (key, val) {
var id = val.levelId.split('_')[1];
if (id == levelId) {
$("#regLevel").val(val.name);
$("#levelContainer").loadTemplate($("#levelTemplate"), val);
$(".changeLevel").show();
$(".selectLevel").text("Selected!");
generateOptions(id);
return false;
}
});
});
$.getJSON("{% url 'registration:shirtsizes' %}", function (data) {
shirtSizes = data;
if (levelTemplateData.length > 0) {
$(".selectLevel")[0].click();
}
$("#levelContainer").on('click', 'a.changeLevel', function () {
$("#levelContainer").loadTemplate($("#levelTemplate"), levelTemplateData);
$("#regLevel").val("");
$(".changeLevel").hide();
});
});

$("#levelContainer").on('click', 'a.selectLevel', function () {
clearLevels();
var levelId = $(this).attr('id').split('_')[1];
$.each(levelTemplateData, function (key, val) {
var id = val.levelId.split('_')[1];
if (id == levelId) {
$("#regLevel").val(val.name);
$("#levelContainer").loadTemplate($("#levelTemplate"), val);
$(".changeLevel").show();
$(".selectLevel").text("Selected!");
generateOptions(id);
return false;
}
});
});
$("#levelContainer").on('click', 'a.changeLevel', function () {
$("#levelContainer").loadTemplate($("#levelTemplate"), levelTemplateData);
$("#regLevel").val("");
$(".changeLevel").hide();
});
var clearLevels = function () {
$.each(levelTemplateData, function (key, val) {
$("#" + val.levelId).text("Select " + val.name);
Expand Down
144 changes: 72 additions & 72 deletions registration/templates/registration/checkout.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,21 @@ <h3>Extra Donations</h3>
{% if event.collectBillingAddress %}
<h3>Billing Information</h3>

{% if not hasMinors and event.collectAddress %}
{% if event.collectAddress %}
<div class="form-group">
<label for="useFrom" class="col-sm-3 control-label">Use Billing Info From</label>
<div class="col-sm-9">
<select id="useFrom" class="form-control">
<option value="" selected>The Fields Below</option>
{% for oi in orderItems %}
{% if not oi.attendee.isMinor %}
{% if oi.attendee %}
<option
value="{{ forloop.counter0 }}">{% attendee_get_first oi.attendee %} {{ oi.attendee.lastName }}</option>
{% else %}
<option value="{{ forloop.counter0 }}">{{ oi.badge.attendee }}</option>
{% endif %}
{% endif %}
{% endfor %}
</select>
</div>
Expand Down Expand Up @@ -359,81 +361,79 @@ <h3>There are no attendees in your order</h3>
</script>
{% endif %}
<script type="text/javascript">
$(document).ready(function () {
//$("#donateCharity").change(setTwoNumberDecimal);
//$("#donateOrg").change(setTwoNumberDecimal);

$(".deleteAttendee").click(function (e) {
const id = this.id.split('_')[1];
const data = {'id': id};
$.ajax({
"type": "POST",
"dataType": "json",
"url": URL_REGISTRATION_REMOVE_FROM_CART,
"data": JSON.stringify(data),
"beforeSend": function (xhr, settings) {
console.log("Before Send");
$.ajaxSettings.beforeSend(xhr, settings);
},
"error": function (result, status, error) {
alert(`An error has occurred. If this error continues, please contact ${EVENT_REGISTRATION_EMAIL} for assistance.`);
},
"success": function (result, status) {
if (result.success) {
window.location.reload();
} else {
alert(`An error has occurred: ${result.message}. If this error continues, please contact ${EVENT_REGISTRATION_EMAIL} for assistance.`);
}
}
});
});

$("#addAnother").click(function () {
window.location = URL_REGISTRATION_INDEX;
});

//$("#donateCharity").change(setTwoNumberDecimal);
//$("#donateOrg").change(setTwoNumberDecimal);

$(".deleteAttendee").click(function (e) {
const id = this.id.split('_')[1];
const data = {'id': id};
$.ajax({
"type": "POST",
"dataType": "json",
"url": URL_REGISTRATION_REMOVE_FROM_CART,
"data": JSON.stringify(data),
"beforeSend": function (xhr, settings) {
console.log("Before Send");
$.ajaxSettings.beforeSend(xhr, settings);
},
"error": function (result, status, error) {
alert(`An error has occurred. If this error continues, please contact ${EVENT_REGISTRATION_EMAIL} for assistance.`);
},
"success": function (result, status) {
if (result.success) {
window.location.reload();
} else {
alert(`An error has occurred: ${result.message}. If this error continues, please contact ${EVENT_REGISTRATION_EMAIL} for assistance.`);
}
}
});
});

$("#addAnother").click(function () {
window.location = URL_REGISTRATION_INDEX;
});

$("#cancel").click(function () {
const cancel = window.confirm("Are you sure you want to cancel your registration? This will remove all attendees from your order.");
if (cancel == false) {
return;
}
$("#cancel").click(function () {
const cancel = window.confirm("Are you sure you want to cancel your registration? This will remove all attendees from your order.");
if (cancel == false) {
return;
}

$.getJSON(URL_REGISTRATION_CANCEL_ORDER, function (data) {
window.location = URL_REGISTRATION_INDEX;
});
});
$.getJSON(URL_REGISTRATION_CANCEL_ORDER, function (data) {
window.location = URL_REGISTRATION_INDEX;
});
});

$("#apply_discount").click(function (e) {
const discount = $("#discount").val();
if (discount == '') {
alert("You must enter a discount to apply.");
return;
}
const data = {'discount': discount};
$.ajax({
"type": "POST",
"dataType": "json",
"url": URL_REGISTRATION_DISCOUNT,
"data": JSON.stringify(data),
"beforeSend": function (xhr, settings) {
console.log("Before Send");
$.ajaxSettings.beforeSend(xhr, settings);
},
"error": function (result, status, error) {
alert(`An error has occurred. If this error continues, please contact ${EVENT_REGISTRATION_EMAIL} for assistance.`);
},
"success": function (result, status) {
if (result.success) {
window.location.reload();
} else {
alert(`An error has occurred: ${result.message} If this error continues, please contact ` +
`${EVENT_REGISTRATION_EMAIL} for assistance.`);
}
}
});
$("#apply_discount").click(function (e) {
const discount = $("#discount").val();
if (discount == '') {
alert("You must enter a discount to apply.");
return;
}
const data = {'discount': discount};
$.ajax({
"type": "POST",
"dataType": "json",
"url": URL_REGISTRATION_DISCOUNT,
"data": JSON.stringify(data),
"beforeSend": function (xhr, settings) {
console.log("Before Send");
$.ajaxSettings.beforeSend(xhr, settings);
},
"error": function (result, status, error) {
alert(`An error has occurred. If this error continues, please contact ${EVENT_REGISTRATION_EMAIL} for assistance.`);
},
"success": function (result, status) {
if (result.success) {
window.location.reload();
} else {
alert(`An error has occurred: ${result.message} If this error continues, please contact ` +
`${EVENT_REGISTRATION_EMAIL} for assistance.`);
}
}
});
});
});


</script>
{% endblock %}
Loading

0 comments on commit 403bdd8

Please sign in to comment.