From 0c9b945f7bf8c39b71a0849480afd64234eb6556 Mon Sep 17 00:00:00 2001 From: abijah Date: Fri, 28 Aug 2009 18:22:13 +0000 Subject: [PATCH] Added pre-submit data verification for invoice and receipt. The checking is pretty thin, but it's a start. I don't want to do more, as I'm sure there are lots of data validation tools out there and would prefer to go that route. git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@806 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/views/customers/receipt.ctp | 37 +++++++++++++++++++++++++++++--- site/views/leases/invoice.ctp | 34 +++++++++++++++++++++++++++-- 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/site/views/customers/receipt.ctp b/site/views/customers/receipt.ctp index ff121cd..fe79d8b 100644 --- a/site/views/customers/receipt.ctp +++ b/site/views/customers/receipt.ctp @@ -35,10 +35,40 @@ Configure::write('debug', '0'); }); // pre-submit callback -function verifyRequest(formData, jqForm, options) { +function verifyRequest(formData, jqForm, options) { + //$("#debug").html(''); + for (var i = 0; i < formData.length; ++i) { + //$("#debug").append(i + ') ' + dump(formData[i]) + '
'); + if (formData[i]['name'] == "data[Customer][id]" && + !(formData[i]['value'] > 0)) { + //$("#debug").append('

Missing Customer ID'); + alert("Must select a customer first"); + return false; + } + + if (formData[i]['name'] == "data[Transaction][stamp]" && + formData[i]['value'] == '') { + //$("#debug").append('

Bad Stamp'); + alert("Must enter a valid date stamp"); + return false; + } + + // Terrible way to accomplish this... + for (var j = 0; j < 20; ++j) { + if (formData[i]['name'] == "data[Entry]["+j+"][amount]" && + !(formData[i]['value'] > 0)) { + //$("#debug").append('

Bad Amount'); + alert("Must enter a valid amount"); + return false; + } + } + + } + + //$("#debug").append('OK'); + //return false; + $('#results').html('Working ...'); - // here we could return false to prevent the form from being submitted; - // returning anything other than false will allow the form submit to continue return true; } @@ -370,6 +400,7 @@ Configure::write('debug', '0'); showCurrentAtPos: 0, dateFormat: 'mm/dd/yy' }); + $("#customer-id").val(0); $("#receipt-customer-name").html("INTERNAL ERROR"); $("#receipt-balance").html("INTERNAL ERROR"); $("#receipt-charges-caption").html("Outstanding Charges"); diff --git a/site/views/leases/invoice.ctp b/site/views/leases/invoice.ctp index da0e3af..48974e8 100644 --- a/site/views/leases/invoice.ctp +++ b/site/views/leases/invoice.ctp @@ -43,9 +43,38 @@ Configure::write('debug', '0'); // pre-submit callback function verifyRequest(formData, jqForm, options) { + //$("#debug").html(''); + for (var i = 0; i < formData.length; ++i) { + //$("#debug").append(i + ') ' + dump(formData[i]) + '
'); + if (formData[i]['name'] == "data[Lease][id]" && + !(formData[i]['value'] > 0)) { + //$("#debug").append('

Missing Lease ID'); + alert("Must select a lease first"); + return false; + } + + if (formData[i]['name'] == "data[Transaction][stamp]" && + formData[i]['value'] == '') { + //$("#debug").append('

Bad Stamp'); + alert("Must enter a valid date stamp"); + return false; + } + + // Terrible way to accomplish this... + for (var j = 0; j < 20; ++j) { + if (formData[i]['name'] == "data[Entry]["+j+"][amount]" && + !(formData[i]['value'] > 0)) { + //$("#debug").append('

Bad Amount'); + alert("Must enter a valid amount"); + return false; + } + } + } + + //$("#debug").append('OK'); + //return false; + $('#results').html('Working ...'); - // here we could return false to prevent the form from being submitted; - // returning anything other than false will allow the form submit to continue return true; } @@ -308,6 +337,7 @@ Configure::write('debug', '0'); showCurrentAtPos: 0, dateFormat: 'mm/dd/yy' }); + $("#lease-id").val(0); $("#invoice-lease").html("INTERNAL ERROR"); $("#invoice-unit").html("INTERNAL ERROR"); $("#invoice-customer").html("INTERNAL ERROR");