Contacts and Commodities
This commit is contained in:
@@ -6,127 +6,152 @@
|
||||
{
|
||||
"use strict";
|
||||
sbm.itemIdPrefix = 'Itm_';
|
||||
var $results;
|
||||
let $pnl = sbm.$pnl;
|
||||
let $frm = sbm.$frm;
|
||||
let $dlg = sbm.$dlg;
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sbm.refreshResults = function (delay)
|
||||
{
|
||||
if (!sbm.awaitingRefreshResponse)
|
||||
{
|
||||
var $items = $('.sbm-panel-item-list', $results).fadeOut(200).empty();
|
||||
var $msgs = $('.sbm-panel-messages', $results).hide().empty().append($('<div class="sbm-message">' + sbm.msg.dataQuerying + '</div>')).fadeIn(200);
|
||||
$('.sbm-burger', $pnl.filter).hide();
|
||||
$('.sbm-panel-item-list', $pnl.results).fadeOut(200).empty();
|
||||
$('.sbm-panel-messages', $pnl.results).hide().empty().append($('<div class="sbm-message">' + sbm.msg.dataQuerying + '</div>')).fadeIn(200);
|
||||
}
|
||||
sbm.ajax.refreshResults = sbm.ajax.refreshResults || { url: sbm.url.base + 'Contact/Ajax/List', formId: 'frmAffiliateFilter', callbackFn: sbm.doRefreshResults };
|
||||
sbm.ajax.refreshResults = sbm.ajax.refreshResults || { url: sbm.url.base + 'Contact/Ajax/List', formId: 'frmContactFilter', callbackFn: sbm.doRefreshResults };
|
||||
sbm.doAjaxRequest(sbm.ajax.refreshResults, delay || 50);
|
||||
sbm.awaitingRefreshResponse = true;
|
||||
}
|
||||
sbm.getFilterDropdownTemplate = function ()
|
||||
{
|
||||
return $('.sbm-panel-item-template .sbm-dropdown-menu.ContactFilter li.sbm-dropdown-item', $pnl.filter).clone();
|
||||
}
|
||||
sbm.getItemTemplate = function ()
|
||||
{
|
||||
return $('.sbm-panel-item-template .sbm-panel-item.Affiliate', $results);
|
||||
return $('.sbm-panel-item-template .sbm-panel-item.Contact', $pnl.results).clone();
|
||||
}
|
||||
sbm.getDropdownItemTemplate = function ()
|
||||
sbm.getItemDropdownTemplate = function ()
|
||||
{
|
||||
return $('.sbm-panel-item-template .sbm-dropdown-menu.Affiliate li.sbm-dropdown-item', $results);
|
||||
return $('.sbm-panel-item-template .sbm-dropdown-menu.Contact li.sbm-dropdown-item', $pnl.results).clone();
|
||||
}
|
||||
sbm.doRefreshResults = function (response)
|
||||
{
|
||||
sbm.debug('doRefreshResults', response);
|
||||
//sbm.debug('doRefreshResults', response);
|
||||
delete sbm.awaitingRefreshResponse;
|
||||
sbm.refreshControlValues(response.controlValues);
|
||||
var $msgs = $('.sbm-panel-messages', $results).hide().empty();
|
||||
var $items = $('.sbm-panel-item-list', $results).hide().empty();
|
||||
var $tmpl = sbm.getItemTemplate();
|
||||
sbm.refreshPaging(response, '#frmAffiliateFilter', sbm.refreshResults);
|
||||
var $msgs = $('.sbm-panel-messages', $pnl.results).hide().empty();
|
||||
var $items = $('.sbm-panel-item-list', $pnl.results).hide().empty();
|
||||
sbm.refreshPaging(response, '#frmContactFilter', sbm.refreshResults);
|
||||
if (!response.success) return;
|
||||
// Reference data - Statuses.
|
||||
if (response.defaultStatusCode) sbm.data.defaultStatusCode = response.defaultStatusCode;
|
||||
if (response.statuses)
|
||||
sbm.populateSelectCodeDesc('#cbAffiliateStatus', response.statuses);
|
||||
sbm.populateSelectCodeDesc('#cbContactStatus', response.statuses);
|
||||
// Menu.
|
||||
var $bgr = $('.sbm-burger', $pnl.filter).hide();
|
||||
var $mnu = $('ul.sbm-dropdown-menu', $bgr).empty();
|
||||
$mnu.append(sbm.getFilterMenuOption(sbm.lbl.refresh, function () { sbm.refreshResults(); }));
|
||||
$mnu.append(sbm.getFilterMenuOption(sbm.lbl.createOrg, function () { sbm.createItem(); }));
|
||||
$mnu.append(sbm.getFilterMenuOption(sbm.lbl.createInd, function () { sbm.createItem(1); }));
|
||||
$bgr.toggle(!!$('.sbm-dropdown-item', $mnu).length);
|
||||
// Items.
|
||||
var items = response.affiliates;
|
||||
if (!items.length)
|
||||
return $msgs.append($('<div class="sbm-message">' + sbm.msg.dataNoneFound + '</div>')).fadeIn(500);
|
||||
for (let itemIdx = 0; itemIdx < items.length; itemIdx++)
|
||||
{
|
||||
let item = items[itemIdx];
|
||||
let $item = $tmpl.clone();
|
||||
sbm.populateItem($item, item);
|
||||
$items.append($item);
|
||||
}
|
||||
$items.append(sbm.populateItem(sbm.getItemTemplate(), items[itemIdx]));
|
||||
$items.fadeIn(50);
|
||||
}
|
||||
sbm.populateItem = function ($item, item)
|
||||
{
|
||||
if (!item) return;
|
||||
$item.prop('id', sbm.itemIdPrefix + item.id);
|
||||
$('.AffiliateName', $item).text(item.displayName);
|
||||
$('.AffiliateType', $item).text(item.typeDesc);
|
||||
$('.AffiliateAssociationCount', $item).on('click', function () { sbm.onClickAssociationCount(item.id); }).toggle(item.associationCount).find('.AssociationCount').text(item.associationCount);
|
||||
$('.AffiliateAddress', $item).text(item.addressSummary);
|
||||
$('.AffiliateNotes', $item).text(item.notes);
|
||||
$('.ContactName', $item).text(item.displayName);
|
||||
$('.ContactType', $item).text(item.typeDesc);
|
||||
$('.ContactAssociationCount', $item).on('click', function () { sbm.onClickAssociationCount(item.id); }).toggle(item.associationCount).find('.AssociationCount').text(item.associationCount);
|
||||
$('.ContactAddress', $item).text(item.addressSummary);
|
||||
$('.ContactNotes', $item).text(item.notes);
|
||||
$('.StatusDesc', $item).text(item.statusDesc).addClass('sbm-status-' + item.statusCode.toLowerCase());
|
||||
$('.sbm-caption .sbm-action').toggleClass('sbm-action', !item.deleted);
|
||||
let $mnu = $('ul.sbm-dropdown-menu', $item).empty();
|
||||
if (!item.deleted)
|
||||
{
|
||||
let $mnu = $('ul.sbm-dropdown-menu', $item);
|
||||
$mnu.append(sbm.getDropdownItemTemplate().clone().find('div.sbm-label').text(sbm.lbl.edit).end().on('click', function () { sbm.updateItem(item.id) }));
|
||||
if (item.awaiting)
|
||||
$mnu.append(sbm.getDropdownItemTemplate().clone().find('div.sbm-label').text(sbm.lbl.activate).end().on('click', function () { sbm.activateItem(item.id) }));
|
||||
$mnu.append(sbm.getItemMenuOption(sbm.lbl.edit, function () { sbm.updateItem(item.id) }));
|
||||
$('.sbm-header .sbm-action.sbm-item-update', $item).off('click').on('click', function () { sbm.updateItem(item.id) });
|
||||
$item.off('dblclick').on('dblclick', function () { sbm.updateItem(item.id) });
|
||||
}
|
||||
$('.sbm-burger', $item).toggle(!!$('.sbm-burger .sbm-dropdown-menu .sbm-dropdown-item', $item).length);
|
||||
$('.sbm-panel-messages', $results).hide().empty();
|
||||
$('.sbm-burger', $item).toggle(!!$('.sbm-dropdown-item', $mnu).length);
|
||||
$('.sbm-panel-messages', $pnl.results).hide().empty();
|
||||
return $item;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sbm.createItem = function ()
|
||||
sbm.getFilterMenuOption = function (lbl, fn)
|
||||
{
|
||||
let $frm = sbm.$frm.affiliate;
|
||||
$('.AffiliateId,input[type="text"],textarea,select', $frm).val('');
|
||||
$('.AffiliateStatus', $frm).val(sbm.data.defaultStatusCode);
|
||||
sbm.clearControlErrors();
|
||||
sbm.$dlg.affiliate.dialog('option', 'title', sbm.dlg.title.createAffiliate);
|
||||
sbm.openDialog(sbm.$dlg.affiliate, 600, 600);
|
||||
return sbm.getMenuOption(sbm.getFilterDropdownTemplate(), lbl, fn);
|
||||
}
|
||||
sbm.doCreateItem = function ()
|
||||
sbm.getItemMenuOption = function (lbl, fn)
|
||||
{
|
||||
sbm.storeItem();
|
||||
return sbm.getMenuOption(sbm.getItemDropdownTemplate(), lbl, fn);
|
||||
}
|
||||
sbm.getMenuOption = function ($opt, lbl, fn)
|
||||
{
|
||||
return $opt.find('div.sbm-label').text(lbl).end().on('click', fn);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sbm.createItem = function (ind)
|
||||
{
|
||||
let frm = $frm.contact;
|
||||
sbm.clearControlErrors(frm);
|
||||
$('.AffiliateId,.ContactExists,input[type="text"],textarea,select', frm).val('');
|
||||
$('.ContactIndividual', frm).val(!!ind ? 1 : null);
|
||||
$('.ContactStatus', frm).val(sbm.data.defaultStatusCode);
|
||||
sbm.toggleContactControls(ind);
|
||||
$dlg.contact.dialog('option', 'title', sbm.dlg.title.createContact);
|
||||
sbm.openDialog($dlg.contact, 600, 600);
|
||||
}
|
||||
sbm.toggleContactControls = function (ind)
|
||||
{
|
||||
let frm = $frm.contact;
|
||||
$('.sbm-form-control.ContactType,.sbm-form-control.ContactName', frm).toggle(!ind).find('input,select').prop('disabled', !!ind);
|
||||
$('.sbm-form-control.ContactFirstName,.sbm-form-control.ContactLastName', frm).toggle(!!ind).find('input,select').prop('disabled', !ind);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sbm.updateItem = function (id)
|
||||
{
|
||||
$('.AffiliateId', sbm.$frm.affiliateId).val(id);
|
||||
sbm.ajax.updateItem = sbm.ajax.updateItem || { url: sbm.url.base + 'Contact/Ajax/GetItem', formId: 'frmAffiliateId', callbackFn: sbm.onUpdateItem };
|
||||
$('.AffiliateId', $frm.contactId).val(id);
|
||||
sbm.ajax.updateItem = sbm.ajax.updateItem || { url: sbm.url.base + 'Contact/Ajax/GetItem', formId: 'frmContactId', callbackFn: sbm.onUpdateItem };
|
||||
sbm.doAjaxRequest(sbm.ajax.updateItem, 50);
|
||||
}
|
||||
sbm.onUpdateItem = function (response)
|
||||
{
|
||||
//sbm.debug('onUpdateItem', response);
|
||||
let $frm = sbm.$frm.affiliate;
|
||||
$('.AffiliateId,input[type="text"],textarea,select', $frm).val('');
|
||||
let frm = $frm.contact;
|
||||
$('.AffiliateId,input[type="text"],textarea,select', frm).val('');
|
||||
if (!response.success) return;
|
||||
let item = response.affiliate;
|
||||
$('.AffiliateId', $frm).val(item.id);
|
||||
$('.AffiliateType', $frm).val(item.typeCode);
|
||||
$('.AffiliateName', $frm).val(item.name);
|
||||
$('.AffiliateNotes', $frm).val(item.notes);
|
||||
$('.AffiliateStatus', $frm).val(item.statusCode);
|
||||
sbm.toggleContactControls(item.individual);
|
||||
$('.AffiliateId', frm).val(item.id);
|
||||
$('.ContactExists', frm).val(1);
|
||||
$('.ContactIndividual', frm).val(!!item.individual ? 1 : null);
|
||||
$('.ContactType', frm).val(item.typeCode);
|
||||
$('.ContactName', frm).val(item.name);
|
||||
$('.ContactFirstName', frm).val(item.firstName);
|
||||
$('.ContactLastName', frm).val(item.lastName);
|
||||
$('.ContactNotes', frm).val(item.notes);
|
||||
$('.ContactStatus', frm).val(item.statusCode);
|
||||
sbm.clearControlErrors();
|
||||
sbm.$dlg.affiliate.dialog('option', 'title', sbm.dlg.title.updateAffiliate);
|
||||
sbm.openDialog(sbm.$dlg.affiliate, 600, 600);
|
||||
}
|
||||
sbm.doUpdateItem = function ()
|
||||
{
|
||||
sbm.storeItem();
|
||||
$dlg.contact.dialog('option', 'title', sbm.dlg.title.updateContact);
|
||||
sbm.openDialog($dlg.contact, 600, 600);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sbm.storeItem = function ()
|
||||
{
|
||||
sbm.ajax.storeItem = sbm.ajax.storeItem || { url: sbm.url.base + 'Contact/Ajax/StoreItem', formId: 'frmAffiliate', callbackFn: sbm.onStoreItem };
|
||||
sbm.ajax.storeItem = sbm.ajax.storeItem || { url: sbm.url.base + 'Contact/Ajax/StoreItem', formId: 'frmContact', callbackFn: sbm.onStoreItem };
|
||||
sbm.doAjaxRequest(sbm.ajax.storeItem, 50);
|
||||
}
|
||||
sbm.onStoreItem = function (response)
|
||||
@@ -134,14 +159,14 @@
|
||||
//sbm.debug('onStoreItem', response);
|
||||
sbm.refreshControlValues(response.controlValues);
|
||||
if (!response.success) return;
|
||||
sbm.$dlg.affiliate.dialog('close');
|
||||
$dlg.contact.dialog('close');
|
||||
|
||||
var item = response.affiliate;
|
||||
var $item = $('#' + sbm.itemIdPrefix + item.id);
|
||||
if (!$item.length)
|
||||
{
|
||||
$item = $('.sbm-panel-item-template .sbm-panel-item.Affiliate', $results).clone();
|
||||
$('.sbm-panel-item-list', $results).prepend($item).show();
|
||||
$item = sbm.getItemTemplate();
|
||||
$('.sbm-panel-item-list', $pnl.results).prepend($item).show();
|
||||
}
|
||||
$item.replaceWith(sbm.populateItem(sbm.getItemTemplate(), item));
|
||||
}
|
||||
@@ -151,30 +176,31 @@
|
||||
{
|
||||
if (!(id * 1)) return;
|
||||
sbm.doPleaseWait();
|
||||
let $frm = $('#frmAffiliateId');
|
||||
$('.AffiliateId', $frm).val(id);
|
||||
$frm.prop('action', sbm.url.base + 'Association').submit();
|
||||
let frm = $frm.contactId;
|
||||
$('.AffiliateId', frm).val(id);
|
||||
frm.prop('action', sbm.url.base + 'Association').submit();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
$(function ()
|
||||
{
|
||||
$('.sbm-panel-filter .sbm-action.sbm-item-create').on('click', function () { sbm.createItem(); });
|
||||
$('.sbm-panel-filter .sbm-action.sbm-results-refresh').on('click', function () { sbm.refreshResults(); });
|
||||
$pnl.contacts = $('.sbm-panel.Contacts');
|
||||
$pnl.filter = $('.sbm-panel-filter', $pnl.contacts);
|
||||
$pnl.results = $('.sbm-panel-results', $pnl.contacts);
|
||||
|
||||
$('.sbm-input, .sbm-textarea').on('input', function () { sbm.clearControlError(this); });
|
||||
$('.sbm-select').on('change', function () { sbm.clearControlError(this); });
|
||||
|
||||
sbm.$frm.filter = $('#frmAffiliateFilter');
|
||||
$('.FilterAffiliate', sbm.$frm.filter).on('input', function () { sbm.refreshResults(250); });
|
||||
$('.FilterAffiliateCategory,.FilterAffiliateStatusCategory', sbm.$frm.filter).on('change', function () { sbm.refreshResults(50); });
|
||||
sbm.$frm.affiliateId = $('#frmAffiliateId');
|
||||
sbm.$frm.affiliate = $('#frmAffiliate');
|
||||
$results = $('.sbm-panel-results');
|
||||
$frm.filter = $('#frmContactFilter');
|
||||
$('.FilterContact', $frm.filter).on('input', function () { sbm.refreshResults(250); });
|
||||
$('.FilterContactType', $frm.filter).on('change', function () { sbm.refreshResults(50); });
|
||||
$frm.contactId = $('#frmContactId');
|
||||
$frm.contact = $('#frmContact');
|
||||
|
||||
var opt = sbm.dlgOpts();
|
||||
opt.buttons[sbm.dlg.btn.ok] = function () { sbm.doCreateItem(); };
|
||||
opt.buttons[sbm.dlg.btn.ok] = function () { sbm.storeItem(); };
|
||||
opt.buttons[sbm.dlg.btn.cancel] = function () { $(this).dialog('close'); };
|
||||
sbm.$dlg.affiliate = $('#dlgAffiliate').dialog(opt);
|
||||
$dlg.contact = $('#dlgContact').dialog(opt);
|
||||
|
||||
setTimeout(sbm.refreshResults, 250);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user