Commit 2582aed4 authored by Mal's avatar Mal

Put checkout button at top of Cart module.

Check for empty username in Purchase module.
parent e4855d06
......@@ -262,6 +262,8 @@ class Cart extends Base {
$content .= '</ul>';
}
}
$content .= '<div id="cart-total"></div>'.
'<button id="cart-checkout">Go to checkout</button><br>';
$mysqli = connect_db();
$query = 'SELECT name, image, short, price, variable, minimum, download '.
......@@ -325,8 +327,7 @@ class Cart extends Base {
$this->Log('Cart->Content: '.$mysqli->error);
}
$mysqli->close();
$content .= '</form><br><div id="cart-total"></div>'.
'<button id="cart-checkout">Go to checkout</button>'.
$content .= '</form>'.
'<div id="cart-item-dialog"></div>'.
'<div id="cart-checkout-dialog" class="hidden">'.
'<div id="cart-summary"></div>'.
......@@ -355,7 +356,7 @@ class Cart extends Base {
'<div id="cart-checkout-info"></div>'.
'</form>'.
'</div>';
$edit = '';
$edit = '<br>';
if (can_edit_page()) {
$edit = '<button id="cart-edit-button"></button>'.
'<div id="cart-editor"></div>';
......
......@@ -165,9 +165,16 @@ if (!this.dobrado.purchase) {
if (ui) {
user = ui.item.value;
}
currentProduct = null;
$("#purchase-product-input").val("");
$("#purchase-price-input").val("");
$("#purchase-quantity-input").val("");
setFormControls();
// If the user was never set, return now that the form is cleared.
if (user === "") {
return;
}
// When the user is changed need to reload the grid with their data,
// or create a new data set for this user if it doesn't exist.
if (purchase.data[user]) {
......@@ -184,12 +191,6 @@ if (!this.dobrado.purchase) {
}
$("#purchase-form .order .name").html(user);
$("#purchase-form .order").show();
currentProduct = null;
$("#purchase-product-input").val("");
$("#purchase-price-input").val("");
$("#purchase-quantity-input").val("");
setFormControls();
// Update the nextWeek checkbox when the user is changed.
$("#purchase-next-week-input").prop("checked", false);
$.each(purchase.nextWeek, function(i, item) {
......@@ -211,6 +212,10 @@ if (!this.dobrado.purchase) {
function showPurchase(row) {
var user = $("#purchase-name-input").val();
if (user === "") {
return false;
}
var data = purchase.data[user][row];
$("#purchase-product-input").val(data.name);
$("#purchase-quantity-input").val(data.quantity);
......@@ -324,6 +329,10 @@ if (!this.dobrado.purchase) {
$("#purchase-price-input").val("");
$("#purchase-quantity-input").val("");
setFormControls();
// If the user was never set, return now that the form is cleared.
if (user === "") {
return false;
}
if (dobrado.localStorage()) {
localStorage["purchase"] = JSON.stringify(purchase);
......@@ -351,6 +360,11 @@ if (!this.dobrado.purchase) {
}
function add() {
var user = $("#purchase-name-input").val();
if (user === "") {
return false;
}
// If the user hasn't specified a date in the future, need to record a
// timestamp for the item that is relative to the server, so calculate
// the elapsed time since the orginial timestamp was requested.
......@@ -361,7 +375,6 @@ if (!this.dobrado.purchase) {
if (time > purchaseTime) {
purchaseTime = time;
}
var user = $("#purchase-name-input").val();
var product = currentProduct.name;
var price = currentProduct.price;
var quantity = parseFloat($("#purchase-quantity-input").val());
......@@ -466,6 +479,10 @@ if (!this.dobrado.purchase) {
function nextWeek() {
var user = $("#purchase-name-input").val();
if (user === "") {
return;
}
if ($(this).is(":checked")) {
purchase.nextWeek.push(user);
}
......@@ -485,6 +502,10 @@ if (!this.dobrado.purchase) {
function processed() {
var newUser = true;
var user = $("#purchase-name-input").val();
if (user === "") {
return;
}
$.each(purchase.processed, function(i, item) {
if (item === user) {
newUser = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment