This commit is contained in:
2020-06-09 22:40:57 +00:00
parent 1406e5cdc9
commit 0a6cf1469a
3 changed files with 153 additions and 145 deletions

View File

@@ -8,11 +8,13 @@
/*global $, app */ /*global $, app */
app.customerSiteEdit = (function () { app.customerSiteEdit = (function () {
'use strict'; "use strict";
//---------------- BEGIN MODULE SCOPE VARIABLES -------------- //---------------- BEGIN MODULE SCOPE VARIABLES --------------
var var stateMap = {},
stateMap = {}, onSave,
onSave, onDelete, configModule, initModule; onDelete,
configModule,
initModule;
//----------------- END MODULE SCOPE VARIABLES --------------- //----------------- END MODULE SCOPE VARIABLES ---------------
//------------------- BEGIN UTILITY METHODS ------------------ //------------------- BEGIN UTILITY METHODS ------------------
@@ -21,9 +23,8 @@ app.customerSiteEdit = (function () {
//------------------- BEGIN EVENT HANDLERS ------------------- //------------------- BEGIN EVENT HANDLERS -------------------
onSave = function (event) { onSave = function (event) {
event.preventDefault(); event.preventDefault();
$.gevent.publish('app-clear-error'); $.gevent.publish("app-clear-error");
//get form data //get form data
var formData = $("form").serializeArray({ var formData = $("form").serializeArray({
checkboxesAsBools: true checkboxesAsBools: true
@@ -31,24 +32,28 @@ app.customerSiteEdit = (function () {
var submitData = app.utilB.objectifyFormDataArray(formData); var submitData = app.utilB.objectifyFormDataArray(formData);
//is this a new record? //is this a new record?
if (stateMap.id != 'new') { if (stateMap.id != "new") {
//put id into the form data //put id into the form data
submitData.id = stateMap.id; submitData.id = stateMap.id;
app.api.update('site', submitData, function (res) { app.api.update("site", submitData, function (res) {
if (res.error) { if (res.error) {
$.gevent.publish('app-show-error',res.msg); $.gevent.publish("app-show-error", res.msg);
} }
}); });
} else { } else {
//create new record //create new record
app.api.create('site', submitData, function (res) { app.api.create("site", submitData, function (res) {
if (res.error) { if (res.error) {
$.gevent.publish('app-show-error',res.msg); $.gevent.publish("app-show-error", res.msg);
} else { } else {
page('#!/customerSiteEdit/' + res.id + '/' + stateMap.context.params.cust_id); page(
"#!/customerSiteEdit/" +
res.id +
"/" +
stateMap.context.params.cust_id
);
return false; return false;
} }
}); });
@@ -56,37 +61,32 @@ app.customerSiteEdit = (function () {
return false; //prevent default return false; //prevent default
}; };
//ONDELETE //ONDELETE
// //
onDelete = function (event) { onDelete = function (event) {
event.preventDefault(); event.preventDefault();
$.gevent.publish('app-clear-error'); $.gevent.publish("app-clear-error");
var r = confirm("Are you sure you want to delete this record?"); var r = confirm("Are you sure you want to delete this record?");
if (r == true) { if (r == true) {
//-------------------------------------------- //--------------------------------------------
//==== DELETE THE site and it's children ==== //==== DELETE THE site and it's children ====
app.api.remove('site/' + stateMap.id, function (res) { app.api.remove("site/" + stateMap.id, function (res) {
if (res.error) { if (res.error) {
$.gevent.publish('app-show-error',res.msg); $.gevent.publish("app-show-error", res.msg);
} else { } else {
//deleted, return to customers list //deleted, return to customers list
page('#!/customerSites/' + stateMap.context.params.cust_id); page("#!/customerSites/" + stateMap.context.params.cust_id);
return false; return false;
} }
}); });
//-------------------- //--------------------
} else { } else {
return false; return false;
} }
return false; //prevent default? return false; //prevent default?
}; };
//-------------------- END EVENT HANDLERS -------------------- //-------------------- END EVENT HANDLERS --------------------
//------------------- BEGIN PUBLIC METHODS ------------------- //------------------- BEGIN PUBLIC METHODS -------------------
@@ -102,31 +102,34 @@ app.customerSiteEdit = (function () {
//INITMODULE //INITMODULE
// //
initModule = function ($container) { initModule = function ($container) {
if (typeof $container === 'undefined') { if (typeof $container === "undefined") {
$container = $('#app-shell-main-content'); $container = $("#app-shell-main-content");
} }
$container.html(Handlebars.templates['app.customerSiteEdit']({})); $container.html(Handlebars.templates["app.customerSiteEdit"]({}));
var title = "Site"; var title = "Site";
if (stateMap.context.params.cust_id) { if (stateMap.context.params.cust_id) {
//Append customer id as a hidden form field for referential integrity //Append customer id as a hidden form field for referential integrity
$('<input />').attr('type', 'hidden') $("<input />")
.attr('name', "customerId") .attr("type", "hidden")
.attr('value', stateMap.context.params.cust_id) .attr("name", "customerId")
.appendTo('#frm'); .attr("value", stateMap.context.params.cust_id)
.appendTo("#frm");
//fetch existing record //fetch existing record
app.api.get('customer/' + stateMap.context.params.cust_id + '/name', function (res) { app.api.get(
"customer/" + stateMap.context.params.cust_id + "/name",
function (res) {
if (res.error) { if (res.error) {
$.gevent.publish('app-show-error',res.msg); $.gevent.publish("app-show-error", res.msg);
} else { } else {
title = 'Site - ' + res.name; title = "Site - " + res.name;
if (stateMap.id != 'new') { if (stateMap.id != "new") {
//fetch existing record //fetch existing record
app.api.get('site/' + stateMap.id, function (res) { app.api.get("site/" + stateMap.id, function (res) {
if (res.error) { if (res.error) {
$.gevent.publish('app-show-error',res.msg); $.gevent.publish("app-show-error", res.msg);
} else { } else {
//fill out form //fill out form
app.utilB.formData(res); app.utilB.formData(res);
@@ -134,37 +137,40 @@ app.customerSiteEdit = (function () {
}); });
} else { } else {
//it's a new record, set default //it's a new record, set default
$("#legacyV7").val(true); $("#legacyV7").prop("checked", true);
$("#dbId").val("v7_no_dbid"); $("#dbId").val("v7_no_dbid");
} }
} }
}); }
);
} }
// bind actions // bind actions
$('#btn-save').bind('click', onSave); $("#btn-save").bind("click", onSave);
$('#btn-delete').bind('click', onDelete); $("#btn-delete").bind("click", onDelete);
//Context menu //Context menu
app.nav.contextClear(); app.nav.contextClear();
app.nav.contextAddLink("customerEdit/" + stateMap.context.params.cust_id, "Customer", "account"); app.nav.contextAddLink(
app.nav.contextAddLink("customerSites/" + stateMap.context.params.cust_id, "Sites", "city"); "customerEdit/" + stateMap.context.params.cust_id,
"Customer",
"account"
);
app.nav.contextAddLink(
"customerSites/" + stateMap.context.params.cust_id,
"Sites",
"city"
);
if (stateMap.id != 'new') { if (stateMap.id != "new") {
app.nav.contextAddLink("purchases/" + stateMap.id, "Purchases", "basket"); app.nav.contextAddLink("purchases/" + stateMap.id, "Purchases", "basket");
} }
}; };
// return public methods // return public methods
return { return {
configModule: configModule, configModule: configModule,
initModule: initModule initModule: initModule
}; };
//------------------- END PUBLIC METHODS --------------------- //------------------- END PUBLIC METHODS ---------------------
}()); })();

View File

@@ -21,8 +21,8 @@
</div> </div>
<div class="col-sm-6"> <div class="col-sm-6">
<div class="form-group"> <div class="form-group">
<label for="dbId">Raven database Id</label> <label for="dbType">Database type</label>
<input class="form-control" type="text" id="dbId" name="dbId" value=""> <input class="form-control" type="text" id="dbType" name="dbType" value="">
</div> </div>
</div> </div>
<div class="col-sm-6"> <div class="col-sm-6">
@@ -32,6 +32,13 @@
Legacy / AyaNova 7</label> Legacy / AyaNova 7</label>
</div> </div>
</div> </div>
<div class="col-sm-6">
<div class="form-group">
<label for="dbId">Raven database Id</label>
<input class="form-control" type="text" id="dbId" name="dbId" value="">
</div>
</div>
<div class="col-sm-6"> <div class="col-sm-6">
<div class="form-check"> <div class="form-check">
<label class="form-check-label" for="networked"> <label class="form-check-label" for="networked">
@@ -39,12 +46,7 @@
Networked</label> Networked</label>
</div> </div>
</div> </div>
<div class="col-sm-6">
<div class="form-group">
<label for="dbType">Database type</label>
<input class="form-control" type="text" id="dbType" name="dbType" value="">
</div>
</div>
{{!-- <div class="col-sm-6"> {{!-- <div class="col-sm-6">
<div class="form-group"> <div class="form-group">
<label for="serverOS">Server OS</label> <label for="serverOS">Server OS</label>

File diff suppressed because one or more lines are too long