This commit is contained in:
Andy Howard
2024-11-26 11:33:22 +00:00
parent 8b872cc8f3
commit c8b5df5909
56 changed files with 1122 additions and 860 deletions
@@ -56,21 +56,17 @@
return $pnl.msgs.append($('<div class="sbm-message">' + sbm.msg.dataNoneFound + '</div>')).fadeIn(500);
for (let itemIdx = 0; itemIdx < items.length; itemIdx++)
$table.append(co.populateItem(co.getItemTemplate(), items[itemIdx]));
sbm.configureItemTable(co.config, $table);
}
co.populateItem = function ($item, item)
{
if (!item) return;
$pnl.msgs.hide().empty();
$item.prop('id', co.getItemId(item));
$('.ContactName', $item).text(item.displayName);
$('.ContactType', $item).text(item.typeDesc);
sbm.populateItemValues(co.config, $item, item.field.value);
let prefix = co.config.column.prefix;
if (item.associationCount)
$('.ContactAssociationCount', $item).text(item.associationCount).on('click', function () { co.onClickAssociationCount(item); }).addClass('sbm-action-text');
$('.ContactAddress', $item).text(item.addressSummary);
$('.ContactContact', $item).text(item.contact);
$('.ContactPhone', $item).text(item.phone);
$('.ContactNotes', $item).text(item.notes);
$('.ContactStatusDesc', $item).text(item.statusDesc).removeStatusClasses().addClass('sbm-status-' + item.statusCode.toLowerCase());
$('.' + prefix + 'Associations', $item).text(item.associationCount).off('click').on('click', function () { co.onClickAssociationCount(item); }).addClass('sbm-action-text');
$('.' + prefix + 'Status', $item).removeStatusClasses().addClass('sbm-status-' + item.statusCode.toLowerCase());
// Actions.
var $bgr = $('.sbm-burger', $item).hide();
let $mnu = $('ul.sbm-dropdown-menu', $bgr).empty();
@@ -78,7 +74,7 @@
{
let fnUpd = function () { co.updateItem(item) };
$mnu.append(co.getItemMenuOption(sbm.lbl.edit, fnUpd, 'sbm-edit'));
$('.ContactName', $item).off('click').on('click', fnUpd).addClass('sbm-action-text');
$('.' + prefix + 'Name', $item).off('click').on('click', fnUpd).addClass('sbm-action-text');
$item.off('dblclick').on('dblclick', fnUpd);
}
$bgr.toggle(!!$('.sbm-dropdown-item', $mnu).length);
@@ -121,10 +117,9 @@
co.createItem = function (cfg, title)
{
co.clearItem(cfg);
let frm = $frm.item;
$('.ContactStatus', frm).val(co.data.defaultStatusCode).prop('readonly', false);
co.configureItemControls(cfg);
co.openItemDlg(title);
let $ctrls = $('.sbm-input,.sbm-textarea,.sbm-select', $frm.item);
$ctrls.filter('.ContactStatus').val(co.data.defaultStatusCode);
co.openItemDlg(cfg, title);
}
co.clearItem = function (cfg)
{
@@ -135,30 +130,13 @@
if (cfg.isGroup) $('.ContactIsGroup', frm).val(1);
sbm.populateSelectCodeDesc('#cbContactType', co.data.organisationTypes);
sbm.populateSelectCodeDesc('#cbContactTitle', co.data.titles);
sbm.selectOrAdd('#cbContactTitle', "", "")
sbm.populateSelectCodeDesc('#cbContactSalutation', co.data.salutations);
sbm.populateSelectCodeDesc('#cbContactStatus', co.data.statuses);
}
sbm.clearItemForm = function ($frm)
co.openItemDlg = function (cfg, title)
{
sbm.clearControlErrors($frm);
$('.sbm-input,.sbm-textarea,.sbm-select,.sbm-checkbox', $frm).val('').prop('readonly', false).prop('disabled', false).removeAttr('checked');
}
co.configureItemControls = function (cfg)
{
sbm.configureItemControls($frm.item, cfg);
}
sbm.configureItemControls = function ($frm, cfg)
{
//sbm.debug('configureItemControls', cfg);
let fld = cfg.field || {};
let $ctrl = $('.sbm-form-control', $frm.item).show();
(fld.hide || []).forEach(function (v, i, a) { $ctrl.filter('.' + cfg.field.prefix + v).hide().find('.sbm-input,.sbm-textarea,.sbm-select,.sbm-checkbox').prop('disabled', true); });
(fld.readonly || []).forEach(function (v, i, a) { $ctrl.filter('.' + cfg.field.prefix + v).find('.sbm-input,.sbm.textarea,.sbm-select,.sbm-checkbox').prop('readonly', true).prop('disabled', true); });
}
co.openItemDlg = function (title)
{
if (title)$dlg.item.dialog('option', 'title', title);
sbm.configureItemControls(cfg, $frm.item);
$dlg.item.dialog('option', 'title', title);
sbm.openDialog($dlg.item, 640, 600);
}
@@ -172,25 +150,18 @@
co.onUpdateItem = function (response)
{
//sbm.debug('onUpdateItem', response);
co.clearItem(response.config);
if (!response.success) return;
let cfg = response.config || {};
co.clearItem(cfg);
let item = response.contact;
sbm.populateFormValues(cfg, $frm.item, item.field.value);
let $ctrls = $('.sbm-input,.sbm-textarea,.sbm-select,.sbm-checkbox', $frm.item);
$ctrls.filter('.ContactId').val(item.id);
$ctrls.filter('.ContactExists').val(1);
$ctrls.filter('.ContactType').val(item.typeCode);
$ctrls.filter('.ContactProspect').prop('checked', !!item.prospect);
$ctrls.filter('.ContactNotes').val(item.notes);
$ctrls.filter('.ContactStatus').val(item.statusCode);
sbm.populateFieldValues(response.config, $frm.item, item.field);
co.configureItemControls(response.config);
co.openItemDlg(sbm.dlg.title.updateContact);
}
sbm.populateFieldValues = function (cfg, $frm, fld)
{
let val = (fld || {}).value || [];
let $ctrl = $('.sbm-form-control', $frm.item).show();
for (var name in val) { $ctrl.filter('.' + cfg.field.prefix + name).find('.sbm-input,.sbm-textarea,.sbm-select').val(val[name]).end().find('.sbm-checkbox').prop('checked',!!val[name]); };
co.openItemDlg(cfg, sbm.dlg.title.updateContact);
}
//--------------------------------------------------------------
@@ -205,6 +176,7 @@
sbm.refreshControlValues(response.controlValues);
if (!response.success) return;
$dlg.item.dialog('close');
$pnl.msgs.hide().empty();
var item = response.contact;
var $item = $('#' + co.getItemId(item), $pnl.table);
@@ -219,11 +191,12 @@
//--------------------------------------------------------------
co.onClickAssociationCount = function (item)
{
sbm.debug('onClickAssociationCount');
if (!item.id) return;
sbm.doPleaseWait();
let frm = $frm.itemId;
$('.ContactId', frm).val(item.id);
frm.prop('action', sbm.url.base + 'Association').submit();
//sbm.doPleaseWait();
//let frm = $frm.itemId;
//$('.ContactId', frm).val(item.id);
//frm.prop('action', sbm.url.base + 'Association').submit();
}
//--------------------------------------------------------------