diff --git a/wwwroot/js/app.customerSiteEdit.js b/wwwroot/js/app.customerSiteEdit.js index 5f3abf7..19c1599 100644 --- a/wwwroot/js/app.customerSiteEdit.js +++ b/wwwroot/js/app.customerSiteEdit.js @@ -8,163 +8,169 @@ /*global $, app */ app.customerSiteEdit = (function () { - 'use strict'; - //---------------- BEGIN MODULE SCOPE VARIABLES -------------- - var - stateMap = {}, - onSave, onDelete, configModule, initModule; - //----------------- END MODULE SCOPE VARIABLES --------------- + "use strict"; + //---------------- BEGIN MODULE SCOPE VARIABLES -------------- + var stateMap = {}, + onSave, + onDelete, + configModule, + initModule; + //----------------- 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) { + onSave = function (event) { + event.preventDefault(); + $.gevent.publish("app-clear-error"); + //get form data + var formData = $("form").serializeArray({ + checkboxesAsBools: true + }); - event.preventDefault(); - $.gevent.publish('app-clear-error'); - //get form data - var formData = $("form").serializeArray({ - checkboxesAsBools: true - }); + var submitData = app.utilB.objectifyFormDataArray(formData); - 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; - - //is this a new record? - if (stateMap.id != 'new') { - //put id into the form data - submitData.id = stateMap.id; - - app.api.update('site', submitData, function (res) { - if (res.error) { - $.gevent.publish('app-show-error',res.msg); - } - }); + app.api.update("site", submitData, function (res) { + if (res.error) { + $.gevent.publish("app-show-error", res.msg); + } + }); + } else { + //create new record + app.api.create("site", submitData, function (res) { + if (res.error) { + $.gevent.publish("app-show-error", res.msg); } else { - //create new record - app.api.create('site', submitData, function (res) { - if (res.error) { - $.gevent.publish('app-show-error',res.msg); - } else { - page('#!/customerSiteEdit/' + res.id + '/' + stateMap.context.params.cust_id); - return false; - } - }); + page( + "#!/customerSiteEdit/" + + res.id + + "/" + + stateMap.context.params.cust_id + ); + return false; } - return false; //prevent default - }; + }); + } + return false; //prevent default + }; + //ONDELETE + // + onDelete = function (event) { + event.preventDefault(); + $.gevent.publish("app-clear-error"); - //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 THE site and it's children ==== - app.api.remove('site/' + stateMap.id, function (res) { - if (res.error) { - $.gevent.publish('app-show-error',res.msg); - } else { - //deleted, return to customers list - page('#!/customerSites/' + stateMap.context.params.cust_id); - return false; - } - }); - //-------------------- - + var r = confirm("Are you sure you want to delete this record?"); + if (r == true) { + //-------------------------------------------- + //==== DELETE THE site and it's children ==== + app.api.remove("site/" + stateMap.id, function (res) { + if (res.error) { + $.gevent.publish("app-show-error", res.msg); } else { - return false; + //deleted, return to customers list + page("#!/customerSites/" + stateMap.context.params.cust_id); + return false; } - return false; //prevent default? - }; + }); + //-------------------- + } else { + return false; + } + return false; //prevent default? + }; + //-------------------- 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"); + } - //-------------------- END EVENT HANDLERS -------------------- + $container.html(Handlebars.templates["app.customerSiteEdit"]({})); + var title = "Site"; - //------------------- BEGIN PUBLIC METHODS ------------------- - //CONFIGMODULE - // - configModule = function (context) { - stateMap.context = context.context; - if (stateMap.context.params.id) { - stateMap.id = stateMap.context.params.id; - } - }; + if (stateMap.context.params.cust_id) { + //Append customer id as a hidden form field for referential integrity + $("") + .attr("type", "hidden") + .attr("name", "customerId") + .attr("value", stateMap.context.params.cust_id) + .appendTo("#frm"); - //INITMODULE - // - initModule = function ($container) { - if (typeof $container === 'undefined') { - $container = $('#app-shell-main-content'); - } - - $container.html(Handlebars.templates['app.customerSiteEdit']({})); - var title = "Site"; - - if (stateMap.context.params.cust_id) { - //Append customer id as a hidden form field for referential integrity - $('').attr('type', 'hidden') - .attr('name', "customerId") - .attr('value', stateMap.context.params.cust_id) - .appendTo('#frm'); - - //fetch existing record - app.api.get('customer/' + stateMap.context.params.cust_id + '/name', function (res) { + //fetch existing record + app.api.get( + "customer/" + stateMap.context.params.cust_id + "/name", + function (res) { + if (res.error) { + $.gevent.publish("app-show-error", res.msg); + } else { + title = "Site - " + res.name; + if (stateMap.id != "new") { + //fetch existing record + app.api.get("site/" + stateMap.id, function (res) { if (res.error) { - $.gevent.publish('app-show-error',res.msg); + $.gevent.publish("app-show-error", res.msg); } else { - title = 'Site - ' + res.name; - if (stateMap.id != 'new') { - //fetch existing record - app.api.get('site/' + 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 - $("#legacyV7").val(true); - $("#dbId").val("v7_no_dbid"); - } + //fill out form + app.utilB.formData(res); } - }); + }); + } else { + //it's a new record, set default + $("#legacyV7").prop("checked", true); + $("#dbId").val("v7_no_dbid"); + } + } } + ); + } - // bind actions - $('#btn-save').bind('click', onSave); - $('#btn-delete').bind('click', onDelete); + // bind actions + $("#btn-save").bind("click", onSave); + $("#btn-delete").bind("click", onDelete); + //Context menu + app.nav.contextClear(); + app.nav.contextAddLink( + "customerEdit/" + stateMap.context.params.cust_id, + "Customer", + "account" + ); + app.nav.contextAddLink( + "customerSites/" + stateMap.context.params.cust_id, + "Sites", + "city" + ); - //Context menu - app.nav.contextClear(); - app.nav.contextAddLink("customerEdit/" + stateMap.context.params.cust_id, "Customer", "account"); - app.nav.contextAddLink("customerSites/" + stateMap.context.params.cust_id, "Sites", "city"); + if (stateMap.id != "new") { + app.nav.contextAddLink("purchases/" + stateMap.id, "Purchases", "basket"); + } + }; - if (stateMap.id != 'new') { - app.nav.contextAddLink("purchases/" + stateMap.id, "Purchases", "basket"); - - } - - }; - - - - - // return public methods - return { - configModule: configModule, - initModule: initModule - }; - //------------------- END PUBLIC METHODS --------------------- -}()); \ No newline at end of file + // return public methods + return { + configModule: configModule, + initModule: initModule + }; + //------------------- END PUBLIC METHODS --------------------- +})(); diff --git a/wwwroot/js/templates/app.customerSiteEdit.handlebars b/wwwroot/js/templates/app.customerSiteEdit.handlebars index e31a454..81a7397 100644 --- a/wwwroot/js/templates/app.customerSiteEdit.handlebars +++ b/wwwroot/js/templates/app.customerSiteEdit.handlebars @@ -19,19 +19,26 @@ -
\n
\n