mirror of
https://github.com/fspc/Yellow-Bike-Database.git
synced 2025-04-04 09:33:24 -04:00
Nows uses deferred.promise, and recognizes 'keypress' for history.
This commit is contained in:
parent
e47498a00a
commit
26a0721620
@ -17,8 +17,9 @@ $(function() {
|
||||
// Add focus for easier tab browsing
|
||||
// use .paid parent and hover & classes
|
||||
|
||||
// If page has not been reloaded after a shop period ends, prevent edit from working.
|
||||
// 1. If page has not been reloaded after a shop period ends, prevent edit from working.
|
||||
// Note: create transaction covered via a mysql_error()), but with a reload - header("Refresh:0;")
|
||||
// 2. Don't send event signal to the save button when shop is open
|
||||
$('[href*="trans_id="]').click(function(e){
|
||||
var remember_me;
|
||||
$.post("json/transaction.php", {shop_exist: 1}, function(data) {
|
||||
@ -27,11 +28,13 @@ $(function() {
|
||||
var start_new_shop = "Start New Shop";
|
||||
$("#current_shop").html(" <a href='shop_log.php'>" + start_new_shop + "</a>");
|
||||
} else {
|
||||
// First successful click
|
||||
remember_me = "unbind";
|
||||
}
|
||||
});
|
||||
if (remember_me == "unbind") {
|
||||
$('[href*="trans_id="]').on('click');
|
||||
// Second successful click
|
||||
//$('[href*="trans_id="]').on('click');
|
||||
}
|
||||
else {
|
||||
e.preventDefault();
|
||||
@ -39,7 +42,7 @@ $(function() {
|
||||
} );
|
||||
|
||||
// Do the same thing as previously, but for editing a transaction (could make a function :)
|
||||
$('#save_transaction').click(function(e){
|
||||
$('#save_transaction').on("click keypress", function(e){
|
||||
var remember_me;
|
||||
$.post("json/transaction.php", {shop_exist: 1}, function(data) {
|
||||
|
||||
@ -51,7 +54,7 @@ $(function() {
|
||||
}
|
||||
});
|
||||
if (remember_me == "unbind") {
|
||||
$('#save_transaction').on('click');
|
||||
$('#save_transaction').on('click keypress');
|
||||
}
|
||||
else {
|
||||
e.preventDefault();
|
||||
@ -66,7 +69,7 @@ $(function() {
|
||||
open_shop = data;
|
||||
var start_new_shop = "Start New Shop";
|
||||
|
||||
$("input[name='Submit43']").click(function(){
|
||||
$("input[name='Submit43']").on("click keypress", function(){
|
||||
$("#current_shop").html(" <a href='shop_log.php'>" + start_new_shop + "</a>");
|
||||
event.preventDefault();
|
||||
});
|
||||
@ -456,13 +459,21 @@ $(function() {
|
||||
|
||||
|
||||
// On save (or close) check for errors
|
||||
|
||||
function save_or_close(button_choice, type_of_button) {
|
||||
|
||||
// Deferred Promise, since we don't know when the click will be made,
|
||||
// it is an asynchronous function, and we need to know the returned result.
|
||||
var dfd = $.Deferred();
|
||||
|
||||
$(button_choice).on("click keypress", function(e) {
|
||||
|
||||
//function error_handler(input,error_span,error,error_text,event)
|
||||
var err1 = 0, err2 = 0, err3 = 0, err4 = 0, err5 = 0, err6 = 0, err7 = 0, err8 = 0;
|
||||
|
||||
$(button_choice).click(function(e) {
|
||||
console.log(e.which);
|
||||
|
||||
if (e.which === 13 || e.which === 1) {
|
||||
|
||||
// sold_to error
|
||||
if ( !$("[name='sold_to']").is("span") ) { // Patron already performed transaction and isn't logged in
|
||||
@ -533,13 +544,14 @@ $(function() {
|
||||
}
|
||||
} else {
|
||||
transaction_error.hide();
|
||||
dfd.resolve("Success");
|
||||
}
|
||||
|
||||
} // event type
|
||||
|
||||
});
|
||||
|
||||
if ( ( err1 + err2 + err3 + err4 + err5 + err6 + err7) == 0) {
|
||||
return "Success";
|
||||
}
|
||||
return dfd.promise()
|
||||
|
||||
} // end function save_or_close
|
||||
|
||||
@ -590,13 +602,17 @@ $(function() {
|
||||
var check_number_error = $("#check_number_error");
|
||||
//var check_number = $("#check_number").on("input");
|
||||
|
||||
var result = save_or_close($("#save_transaction"), "Save");
|
||||
// note: it is possible to close with all error conditions being satisfied,
|
||||
// however, it is no biggy.
|
||||
save_or_close($("#close_transaction"), "Close");
|
||||
|
||||
// Using deferred.promise .. pretty cool
|
||||
save_or_close($("#save_transaction"), "Save").done(function(success) {
|
||||
|
||||
console.log(success);
|
||||
|
||||
// Save history
|
||||
if (result === "Success") {
|
||||
if (success === "Success") {
|
||||
|
||||
transaction_id = $("input[name='transaction_id']").val();
|
||||
|
||||
@ -638,6 +654,8 @@ $(function() {
|
||||
} // End Save History
|
||||
|
||||
|
||||
}) // end function save_and_close
|
||||
|
||||
|
||||
// On reload if patron isn't logged in replace pull-down with patrons name
|
||||
if (sold_to.val() == "no_selection") {
|
||||
@ -764,7 +782,7 @@ $(function() {
|
||||
|
||||
|
||||
// If storage date is NULL, update to 0000-00-00 on save
|
||||
$("#save_transaction").click(function(e) {
|
||||
$("#save_transaction").on("click keypress", function(e) {
|
||||
|
||||
if ( !$("#date").val().length ) {
|
||||
$("#date").val("0000-00-00");
|
||||
|
Loading…
x
Reference in New Issue
Block a user