From 06b31c3d397213c8b3630f90c4ba69e63b1e3435 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Fri, 25 Nov 2022 00:17:51 +0000 Subject: [PATCH] fixed bug not saving quantity for purchase --- notes/deploy.txt | 2 +- util/RfVersion.cs | 2 +- wwwroot/default.htm | 116 ++-- wwwroot/js/app.api.js | 2 +- wwwroot/js/app.purchaseEdit.js | 504 +++++++++--------- .../js/templates/app.purchaseEdit.handlebars | 111 +++- wwwroot/js/templates/app.purchases.handlebars | 2 +- .../js/templates/app.rfsettings.handlebars | 2 +- wwwroot/js/templates/app.shell.handlebars | 8 +- 9 files changed, 406 insertions(+), 343 deletions(-) diff --git a/notes/deploy.txt b/notes/deploy.txt index c932d90..5c4ea0d 100644 --- a/notes/deploy.txt +++ b/notes/deploy.txt @@ -5,7 +5,7 @@ 1) SET VERSION SET app.api RFVERSION property -RENAME ?rfv=6.27 parameter in default.htm to the new version so all files update on mobile +RENAME ?rfv=6.28 parameter in default.htm to the new version so all files update on mobile 1.5) Run buildtemplates.bat if handlebars templates have changed at all diff --git a/util/RfVersion.cs b/util/RfVersion.cs index 686c0cd..29c86c6 100644 --- a/util/RfVersion.cs +++ b/util/RfVersion.cs @@ -2,7 +2,7 @@ namespace rockfishCore.Util { public static class RfVersion { - public const string NumberOnly="6.27"; + public const string NumberOnly="6.28"; public const string Full = "Rockfish server " + NumberOnly; } } \ No newline at end of file diff --git a/wwwroot/default.htm b/wwwroot/default.htm index 99088f8..8204522 100644 --- a/wwwroot/default.htm +++ b/wwwroot/default.htm @@ -11,76 +11,76 @@ Rockfish loading.... - - - - - + + + + + - - - - + + + + - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + \ No newline at end of file diff --git a/wwwroot/js/app.api.js b/wwwroot/js/app.api.js index b8c96fe..10ab59c 100644 --- a/wwwroot/js/app.api.js +++ b/wwwroot/js/app.api.js @@ -30,7 +30,7 @@ app.api = (function () { licenseEmailResponse, test; - RockFishVersion = "6.27"; + RockFishVersion = "6.28"; ////////////////////////////////////////////////////////////////////////////////////// // NOT AUTHORIZED ERROR HANDLER diff --git a/wwwroot/js/app.purchaseEdit.js b/wwwroot/js/app.purchaseEdit.js index fe8057a..74cd822 100644 --- a/wwwroot/js/app.purchaseEdit.js +++ b/wwwroot/js/app.purchaseEdit.js @@ -7,269 +7,267 @@ /*global $, app */ -app.purchaseEdit = (function() { - "use strict"; - //---------------- BEGIN MODULE SCOPE VARIABLES -------------- - var stateMap = {}, - onSave, - onDelete, - onRenew, - configModule, - initModule, - onPasteNotes; - //----------------- END MODULE SCOPE VARIABLES --------------- +app.purchaseEdit = (function () { + "use strict"; + //---------------- BEGIN MODULE SCOPE VARIABLES -------------- + var stateMap = {}, + onSave, + onDelete, + onRenew, + configModule, + initModule, + onPasteNotes; + //----------------- END MODULE SCOPE VARIABLES --------------- - //------------------- BEGIN UTILITY METHODS ------------------ - //-------------------- END UTILITY METHODS ------------------- + //------------------- BEGIN UTILITY METHODS ------------------ + //-------------------- END UTILITY METHODS ------------------- - //------------------- BEGIN EVENT HANDLERS ------------------- + //------------------- BEGIN EVENT HANDLERS ------------------- - onSave = function(event) { - event.preventDefault(); - $.gevent.publish("app-clear-error"); - //get form data - var formData = $("form").serializeArray({ - checkboxesAsBools: true - }); - - var submitData = app.utilB.objectifyFormDataArray(formData); - - //is this a new record? - if (stateMap.id != "new") { - //put id into the form data - submitData.id = stateMap.id; - - app.api.update("purchase", submitData, function(res) { - if (res.error) { - $.gevent.publish("app-show-error", res.msg); - } - }); - } else { - //create new record - app.api.create("purchase", submitData, function(res) { - if (res.error) { - $.gevent.publish("app-show-error", res.msg); - } else { - page( - "#!/purchaseEdit/" + res.id + "/" + stateMap.context.params.site_id - ); - return false; - } - }); - } - return false; //prevent default - }; - - onRenew = function(event) { - event.preventDefault(); - $.gevent.publish("app-clear-error"); - - if (stateMap.id == "new") { - $.gevent.publish( - "app-show-error", - "Save this record before attempting to renew it" - ); - return false; - } - stateMap.id = "new"; - - //case 3396, no more renewal or dupe names - // var nm = $('#name').val(); - // nm = "DUPE-" + nm; - // $('#name').val(nm); - - //case 3396, set values accordingly - - //Clear salesOrderNumber - $("#salesOrderNumber").val(""); - - //set purchaseDate to today - $("#purchaseDate").val( - moment() - .toISOString() - .substring(0, 10) - ); - - //set expireDate to plus one year from today - $("#expireDate").val( - moment() - .add(1, "years") - .toISOString() - .substring(0, 10) - ); - - //clear the couponCode - $("#couponCode").val(""); - - //clear the notes - $("#notes").val(""); - - $("#renewNoticeSent").prop("checked", false); - $("#cancelDate").val(""); - - return false; //prevent default - }; - - //ONDELETE - // - onDelete = function(event) { - event.preventDefault(); - $.gevent.publish("app-clear-error"); - - var r = confirm("Are you sure you want to delete this record?"); - if (r == true) { - //==== DELETE ==== - app.api.remove("purchase/" + stateMap.id, function(res) { - if (res.error) { - $.gevent.publish("app-show-error", res.msg); - } else { - //deleted, return to master list - page("#!/purchases/" + stateMap.context.params.site_id); - return false; - } - }); - } else { - return false; - } - return false; //prevent default? - }; - - onPasteNotes = function(event) { - var clipboardData, pastedData; - var e = event.originalEvent; - - // // Stop data actually being pasted into div - // e.stopPropagation(); - // e.preventDefault(); - - // Get pasted data via clipboard API - clipboardData = e.clipboardData || window.clipboardData; - pastedData = clipboardData.getData("Text"); - - //Iterate through the lines looking for the SHareIt name=value lines (they all contain equal signs) - var lines = pastedData.split("\n"); // lines is an array of strings - var purchaseData = {}; - - // Loop through all lines - for (var j = 0; j < lines.length; j++) { - var thisLine = lines[j]; - if (thisLine.includes("=")) { - var thisElement = thisLine.split("="); - purchaseData[thisElement[0].trim()] = thisElement[1].trim(); - } - } - - //Now have an object with the value pairs in it - if (purchaseData["ShareIt Ref #"]) { - $("#salesOrderNumber").val(purchaseData["ShareIt Ref #"]); - } - - // if (purchaseData["E-Mail"]) { - // $("#email").val(purchaseData["E-Mail"]); - // } - }; - - //-------------------- END EVENT HANDLERS -------------------- - - //------------------- BEGIN PUBLIC METHODS ------------------- - //CONFIGMODULE - // - configModule = function(context) { - stateMap.context = context.context; - if (stateMap.context.params.id) { - stateMap.id = stateMap.context.params.id; - } - }; - - //INITMODULE - // - initModule = function($container) { - if (typeof $container === "undefined") { - $container = $("#app-shell-main-content"); - } - - $container.html(Handlebars.templates["app.purchaseEdit"]({})); - var title = "Purchase"; - - if (!stateMap.context.params.site_id) { - throw "app.purchaseEdit.js::initModule - There is no stateMap.context.params.site_id!"; - } - - //Append master record id as a hidden form field for referential integrity - $("") - .attr("type", "hidden") - .attr("name", "siteId") - .attr("value", stateMap.context.params.site_id) - .appendTo("#frm"); - - //fetch entire site record to get name *and* customer id which is required for redundancy - - //RFC - get site name and customer name for form - - app.api.get("site/" + stateMap.context.params.site_id, function(res) { - if (res.error) { - $.gevent.publish("app-show-error", res.msg); - } else { - //Also append customer ID redundantly - $("") - .attr("type", "hidden") - .attr("name", "customerId") - .attr("value", res.customerId) - .appendTo("#frm"); - title = "Purchase - " + res.name; + onSave = function (event) { + + event.preventDefault(); + $.gevent.publish("app-clear-error"); + //get form data + var formData = $("form").serializeArray({ + checkboxesAsBools: true + }); + var submitData = app.utilB.objectifyFormDataArray(formData); + //serializeArray method doesn't handle "Number" type inputs at all + //just ignores them so we need to do it here manually + submitData['quantity']=Number($("#quantity").val()); + //I know, it's weird, but it wasn't required way back in the day and the plan is to replace rockfish with a Vue/vuetify app anyway. + console.log({ formData: formData, submitData: submitData }); + //is this a new record? if (stateMap.id != "new") { - //fetch existing record - app.api.get("purchase/" + stateMap.id, function(res) { - if (res.error) { - $.gevent.publish("app-show-error", res.msg); - } else { - //fill out form - app.utilB.formData(res); - } - }); + //put id into the form data + submitData.id = stateMap.id; + + app.api.update("purchase", submitData, function (res) { + if (res.error) { + $.gevent.publish("app-show-error", res.msg); + } + }); } else { - //it's a new record, set default - $("#quantity").val(1); - $("#purchaseDate").val(new Date().toISOString().substring(0, 10)); - $("#expireDate").val( - moment() - .add(1, "years") - .toISOString() - .substring(0, 10) - ); - $("#vendorName").val("ShareIt"); - + //create new record + app.api.create("purchase", submitData, function (res) { + if (res.error) { + $.gevent.publish("app-show-error", res.msg); + } else { + page( + "#!/purchaseEdit/" + + res.id + + "/" + + stateMap.context.params.site_id + ); + return false; + } + }); } - - } - }); + return false; //prevent default + }; - //Context menu - app.nav.contextClear(); - app.nav.contextAddLink( - "purchases/" + stateMap.context.params.site_id, - "Purchases", - "basket" - ); + onRenew = function (event) { + event.preventDefault(); + $.gevent.publish("app-clear-error"); - // bind actions - $("#btn-save").bind("click", onSave); - $("#btn-delete").bind("click", onDelete); - $("#btn-renew").bind("click", onRenew); - $("#notes").bind("paste", onPasteNotes); + if (stateMap.id == "new") { + $.gevent.publish( + "app-show-error", + "Save this record before attempting to renew it" + ); + return false; + } + stateMap.id = "new"; - //Autocomplete - app.utilB.autoComplete("name", "purchase.name"); - app.utilB.autoComplete("productCode", "purchase.productCode"); - app.utilB.autoComplete("vendorName", "purchase.vendorName"); - }; + //case 3396, no more renewal or dupe names + // var nm = $('#name').val(); + // nm = "DUPE-" + nm; + // $('#name').val(nm); - // return public methods - return { - configModule: configModule, - initModule: initModule - }; - //------------------- END PUBLIC METHODS --------------------- + //case 3396, set values accordingly + + //Clear salesOrderNumber + $("#salesOrderNumber").val(""); + + //set purchaseDate to today + $("#purchaseDate").val(moment().toISOString().substring(0, 10)); + + //set expireDate to plus one year from today + $("#expireDate").val( + moment().add(1, "years").toISOString().substring(0, 10) + ); + + //clear the couponCode + $("#couponCode").val(""); + + //clear the notes + $("#notes").val(""); + + $("#renewNoticeSent").prop("checked", false); + $("#cancelDate").val(""); + + return false; //prevent default + }; + + //ONDELETE + // + onDelete = function (event) { + event.preventDefault(); + $.gevent.publish("app-clear-error"); + + var r = confirm("Are you sure you want to delete this record?"); + if (r == true) { + //==== DELETE ==== + app.api.remove("purchase/" + stateMap.id, function (res) { + if (res.error) { + $.gevent.publish("app-show-error", res.msg); + } else { + //deleted, return to master list + page("#!/purchases/" + stateMap.context.params.site_id); + return false; + } + }); + } else { + return false; + } + return false; //prevent default? + }; + + onPasteNotes = function (event) { + var clipboardData, pastedData; + var e = event.originalEvent; + + // // Stop data actually being pasted into div + // e.stopPropagation(); + // e.preventDefault(); + + // Get pasted data via clipboard API + clipboardData = e.clipboardData || window.clipboardData; + pastedData = clipboardData.getData("Text"); + + //Iterate through the lines looking for the SHareIt name=value lines (they all contain equal signs) + var lines = pastedData.split("\n"); // lines is an array of strings + var purchaseData = {}; + + // Loop through all lines + for (var j = 0; j < lines.length; j++) { + var thisLine = lines[j]; + if (thisLine.includes("=")) { + var thisElement = thisLine.split("="); + purchaseData[thisElement[0].trim()] = thisElement[1].trim(); + } + } + + //Now have an object with the value pairs in it + if (purchaseData["ShareIt Ref #"]) { + $("#salesOrderNumber").val(purchaseData["ShareIt Ref #"]); + } + + // if (purchaseData["E-Mail"]) { + // $("#email").val(purchaseData["E-Mail"]); + // } + }; + + //-------------------- END EVENT HANDLERS -------------------- + + //------------------- BEGIN PUBLIC METHODS ------------------- + //CONFIGMODULE + // + configModule = function (context) { + stateMap.context = context.context; + if (stateMap.context.params.id) { + stateMap.id = stateMap.context.params.id; + } + }; + + //INITMODULE + // + initModule = function ($container) { + if (typeof $container === "undefined") { + $container = $("#app-shell-main-content"); + } + + $container.html(Handlebars.templates["app.purchaseEdit"]({})); + var title = "Purchase"; + + if (!stateMap.context.params.site_id) { + throw "app.purchaseEdit.js::initModule - There is no stateMap.context.params.site_id!"; + } + + //Append master record id as a hidden form field for referential integrity + $("") + .attr("type", "hidden") + .attr("name", "siteId") + .attr("value", stateMap.context.params.site_id) + .appendTo("#frm"); + + //fetch entire site record to get name *and* customer id which is required for redundancy + + //RFC - get site name and customer name for form + + app.api.get("site/" + stateMap.context.params.site_id, function (res) { + if (res.error) { + $.gevent.publish("app-show-error", res.msg); + } else { + //Also append customer ID redundantly + $("") + .attr("type", "hidden") + .attr("name", "customerId") + .attr("value", res.customerId) + .appendTo("#frm"); + title = "Purchase - " + res.name; + + if (stateMap.id != "new") { + //fetch existing record + app.api.get("purchase/" + stateMap.id, function (res) { + if (res.error) { + $.gevent.publish("app-show-error", res.msg); + } else { + //fill out form + app.utilB.formData(res); + } + }); + } else { + //it's a new record, set default + $("#quantity").val(1); + $("#purchaseDate").val( + new Date().toISOString().substring(0, 10) + ); + $("#expireDate").val( + moment().add(1, "years").toISOString().substring(0, 10) + ); + $("#vendorName").val("ShareIt"); + } + } + }); + + //Context menu + app.nav.contextClear(); + app.nav.contextAddLink( + "purchases/" + stateMap.context.params.site_id, + "Purchases", + "basket" + ); + + // bind actions + $("#btn-save").bind("click", onSave); + $("#btn-delete").bind("click", onDelete); + $("#btn-renew").bind("click", onRenew); + $("#notes").bind("paste", onPasteNotes); + + //Autocomplete + app.utilB.autoComplete("name", "purchase.name"); + app.utilB.autoComplete("productCode", "purchase.productCode"); + app.utilB.autoComplete("vendorName", "purchase.vendorName"); + }; + + // return public methods + return { + configModule: configModule, + initModule: initModule + }; + //------------------- END PUBLIC METHODS --------------------- })(); diff --git a/wwwroot/js/templates/app.purchaseEdit.handlebars b/wwwroot/js/templates/app.purchaseEdit.handlebars index 1cef35c..7c549c3 100644 --- a/wwwroot/js/templates/app.purchaseEdit.handlebars +++ b/wwwroot/js/templates/app.purchaseEdit.handlebars @@ -1,88 +1,153 @@
-
- +
- -
-
-
-
- - +
+
+
+ + +
+
+
- +
- +
- +
+ + Renew notice sent
- +
- +
- {{!--
+ {{!
-
--}} +
}}
- +
-
- -
- +
\ No newline at end of file diff --git a/wwwroot/js/templates/app.purchases.handlebars b/wwwroot/js/templates/app.purchases.handlebars index d9878ea..f9925d6 100644 --- a/wwwroot/js/templates/app.purchases.handlebars +++ b/wwwroot/js/templates/app.purchases.handlebars @@ -1,3 +1,3 @@ -
+
\ No newline at end of file diff --git a/wwwroot/js/templates/app.rfsettings.handlebars b/wwwroot/js/templates/app.rfsettings.handlebars index a095827..efcd058 100644 --- a/wwwroot/js/templates/app.rfsettings.handlebars +++ b/wwwroot/js/templates/app.rfsettings.handlebars @@ -1,5 +1,5 @@
-
+
diff --git a/wwwroot/js/templates/app.shell.handlebars b/wwwroot/js/templates/app.shell.handlebars index 3e32709..e150b81 100644 --- a/wwwroot/js/templates/app.shell.handlebars +++ b/wwwroot/js/templates/app.shell.handlebars @@ -1,7 +1,7 @@