3.0.1.6 Addresses

This commit is contained in:
Andy Howard
2025-05-05 16:00:32 +01:00
parent 047f9db390
commit 527943b861
88 changed files with 3261 additions and 370 deletions
@@ -5,7 +5,7 @@
(function (win, doc, undef)
{
"use strict";
let co = sbm.mdl.Contacts = { env: {} };
let co = sbm.mdl.contacts = { env: {} };
//--------------------------------------------------------------
co.refreshConfig = function (env, delay)
@@ -81,8 +81,9 @@
let fnUpd = function () { co.updateItem(env, item.id) };
$mnu.append(co.getItemMenuOption(env, sbm.lbl.edit, fnUpd, 'sbm-edit'));
$item.off('dblclick').on('dblclick', fnUpd).find('.' + prefix + 'Name').off('click').on('click', fnUpd).addClass('sbm-action-text');
if (!item.isOwner && !item.isCust) $mnu.append(co.getItemMenuOption(env, sbm.lbl.createCust, function () { co.createCustomer(env, item.id, item.name); }, 'sbm-add'));
if (!item.isOwner && !item.isSupp) $mnu.append(co.getItemMenuOption(env, sbm.lbl.createSupp, function () { co.createSupplier(env, item.id, item.name); }, 'sbm-add'));
if (!item.isOwner && !item.isCust) $mnu.append(co.getItemMenuOption(env, sbm.lbl.createCust, function () { co.createCustomer(env, $item, item); }, 'sbm-add'));
if (!item.isOwner && !item.isSupp) $mnu.append(co.getItemMenuOption(env, sbm.lbl.createSupp, function () { co.createSupplier(env, $item, item); }, 'sbm-add'));
$mnu.append(co.getItemMenuOption(env, sbm.lbl.addresses, function () { co.maintainAddresses(env, $item, item); }, 'sbm-mail'));
}
$bgr.toggle(!!$('.sbm-dropdown-item', $mnu).length);
}
@@ -126,6 +127,39 @@
return $opt.find('div.sbm-label').text(lbl).end().on('click', fn).addClass(cls);
}
//--------------------------------------------------------------
co.createCustomer = function (env, $item, item)
{
co.createAssociation(env, $item, item, 'CUS');
}
co.createSupplier = function (env, $item, item)
{
co.createAssociation(env, $item, item, 'SUP');
}
co.createAssociation = function (env, $item, item, type)
{
sbm.fn.createAssociation({ type: type, target: { id: item.id, name: item.name }, fnSuccess: function () { co.refreshItem(env, $item, item); } });
}
//--------------------------------------------------------------
co.maintainAddresses = function (env, $item, item)
{
sbm.fn.maintainAddresses({ item: { label: sbm.lbl.contact, type: sbm.itemType.contact, id: item.id, caption: item.name }, fnSuccess: function () { co.refreshItem(env, $item, item); } });
}
co.refreshItem = function (env, $item, item)
{
let $frm = env.$frm.itemId;
$('.ContactId', $frm).val(item.id);
let fn = function (env, response)
{
if (!response.success) return;
co.populateItem(env, $item, response.contact);
sbm.configureItemTable(env.data.cfgList, env.$pnl.table);
}
sbm.doAjaxRequest(env.ajax.refreshItem = env.ajax.refreshItem || { url: sbm.url.base + 'Contact/Ajax/GetItem', formSel: $frm, callbackFn: function (response) { fn(env, response); } }, 50);
}
//--------------------------------------------------------------
co.createItem = function (env, cfg, title)
{
@@ -167,7 +201,7 @@
}
co.onUpdateItem = function (env, response)
{
//sbm.debug('onUpdateItem', env, response);
sbm.debug('onUpdateItem', env, response);
if (!response.success) return;
let cfg = response.config || {};
co.clearItem(env, cfg);
@@ -183,27 +217,6 @@
co.openItemDlg(env, cfg, sbm.dlg.title.updateContact);
}
//--------------------------------------------------------------
co.createCustomer = function (env, id, name)
{
co.createAssociation(env, 'CUS', id, name);
}
co.createSupplier = function (env, id, name)
{
co.createAssociation(env, 'SUP', id, name);
}
co.createAssociation = function (env, type, id, name)
{
sbm.fn.createAssociation({ type: type, target: { id: id, name: name }, fnSuccess: function (item) { co.onCreateAssociation(env, item); } });
}
co.onCreateAssociation = function (env, item)
{
//sbm.debug('onCreateAssociation', env, item);
let $frm = env.$frm.itemId;
$('.ContactId', $frm).val(item.id);
sbm.doAjaxRequest(env.ajax.refreshItem = env.ajax.refreshItem || { url: sbm.url.base + 'Contact/Ajax/GetItem', formSel: $frm, callbackFn: function (response) { co.onStoreItem(env, response); } }, 50);
}
//--------------------------------------------------------------
co.storeItem = function (env)
{
@@ -325,7 +338,6 @@
co.env.maint = co.initEnv('.sbm-panel.Contacts');
if (co.env.maint.$pnl.items.length) setTimeout(function () { co.refreshResults(co.env.maint); }, 250);
co.env.select = co.initEnv('#dlgContactSelect');
co.env.select.$frm.filter.find('.FilterContactType option[value="GRP"]').remove();
if (co.env.select.$pnl.items.length) setTimeout(function () { co.refreshConfig(co.env.select); }, 250);
});