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,163 +8,169 @@
/*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,
//----------------- END MODULE SCOPE VARIABLES --------------- configModule,
initModule;
//----------------- END MODULE SCOPE VARIABLES ---------------
//------------------- BEGIN UTILITY METHODS ------------------ //------------------- BEGIN UTILITY METHODS ------------------
//-------------------- END 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(); var submitData = app.utilB.objectifyFormDataArray(formData);
$.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("site", submitData, function (res) {
//is this a new record? if (res.error) {
if (stateMap.id != 'new') { $.gevent.publish("app-show-error", res.msg);
//put id into the form data }
submitData.id = stateMap.id; });
} else {
app.api.update('site', submitData, function (res) { //create new record
if (res.error) { app.api.create("site", submitData, function (res) {
$.gevent.publish('app-show-error',res.msg); if (res.error) {
} $.gevent.publish("app-show-error", res.msg);
});
} else { } else {
//create new record page(
app.api.create('site', submitData, function (res) { "#!/customerSiteEdit/" +
if (res.error) { res.id +
$.gevent.publish('app-show-error',res.msg); "/" +
} else { stateMap.context.params.cust_id
page('#!/customerSiteEdit/' + res.id + '/' + stateMap.context.params.cust_id); );
return false; return false;
}
});
} }
return false; //prevent default });
}; }
return false; //prevent default
};
//ONDELETE
//
onDelete = function (event) {
event.preventDefault();
$.gevent.publish("app-clear-error");
//ONDELETE var r = confirm("Are you sure you want to delete this record?");
// if (r == true) {
onDelete = function (event) { //--------------------------------------------
event.preventDefault(); //==== DELETE THE site and it's children ====
$.gevent.publish('app-clear-error'); app.api.remove("site/" + stateMap.id, function (res) {
if (res.error) {
var r = confirm("Are you sure you want to delete this record?"); $.gevent.publish("app-show-error", res.msg);
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;
}
});
//--------------------
} else { } 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 ------------------- if (stateMap.context.params.cust_id) {
//CONFIGMODULE //Append customer id as a hidden form field for referential integrity
// $("<input />")
configModule = function (context) { .attr("type", "hidden")
stateMap.context = context.context; .attr("name", "customerId")
if (stateMap.context.params.id) { .attr("value", stateMap.context.params.cust_id)
stateMap.id = stateMap.context.params.id; .appendTo("#frm");
}
};
//INITMODULE //fetch existing record
// app.api.get(
initModule = function ($container) { "customer/" + stateMap.context.params.cust_id + "/name",
if (typeof $container === 'undefined') { function (res) {
$container = $('#app-shell-main-content'); if (res.error) {
} $.gevent.publish("app-show-error", res.msg);
} else {
$container.html(Handlebars.templates['app.customerSiteEdit']({})); title = "Site - " + res.name;
var title = "Site"; if (stateMap.id != "new") {
//fetch existing record
if (stateMap.context.params.cust_id) { app.api.get("site/" + stateMap.id, function (res) {
//Append customer id as a hidden form field for referential integrity
$('<input />').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) {
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; //fill out form
if (stateMap.id != 'new') { app.utilB.formData(res);
//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");
}
} }
}); });
} else {
//it's a new record, set default
$("#legacyV7").prop("checked", true);
$("#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
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 if (stateMap.id != "new") {
app.nav.contextClear(); app.nav.contextAddLink("purchases/" + stateMap.id, "Purchases", "basket");
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') { // return public methods
app.nav.contextAddLink("purchases/" + stateMap.id, "Purchases", "basket"); return {
configModule: configModule,
} initModule: initModule
};
}; //------------------- END PUBLIC METHODS ---------------------
})();
// return public methods
return {
configModule: configModule,
initModule: initModule
};
//------------------- END PUBLIC METHODS ---------------------
}());

View File

@@ -19,19 +19,26 @@
<input class="form-control" type="text" id="stateProvince" name="stateProvince" value=""> <input class="form-control" type="text" id="stateProvince" name="stateProvince" value="">
</div> </div>
</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">
<div class="form-check"> <div class="form-check">
<label class="form-check-label" for="legacyV7"> <label class="form-check-label" for="legacyV7">
<input class="form-check-input" type="checkbox" name="legacyV7" id="legacyV7"> <input class="form-check-input" type="checkbox" name="legacyV7" id="legacyV7">
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