Consolidate User Context
This commit is contained in:
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* Commodity page scripts.
|
||||
*/
|
||||
|
||||
(function (win, doc, undef)
|
||||
{
|
||||
"use strict";
|
||||
sbm.itemIdPrefix = 'Itm_';
|
||||
var $results;
|
||||
|
||||
//--------------------------------------------------------------
|
||||
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.ajax.refreshResults = sbm.ajax.refreshResults || { url: sbm.url.base + 'Commodity/Ajax/List', formId: 'frmCommodityFilter', callbackFn: sbm.doRefreshResults };
|
||||
sbm.doAjaxRequest(sbm.ajax.refreshResults, delay || 50);
|
||||
sbm.awaitingRefreshResponse = true;
|
||||
}
|
||||
sbm.getItemTemplate = function ()
|
||||
{
|
||||
return $('.sbm-panel-item-template .sbm-panel-item.Commodity', $results);
|
||||
}
|
||||
sbm.getDropdownItemTemplate = function ()
|
||||
{
|
||||
return $('.sbm-panel-item-template .sbm-dropdown-menu.Commodity li.sbm-dropdown-item', $results);
|
||||
}
|
||||
sbm.doRefreshResults = function (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, '#frmCommodityFilter', sbm.refreshResults);
|
||||
if (!response.success) return;
|
||||
// Reference data - Statuses.
|
||||
if (response.defaultStatusCode) sbm.data.defaultStatusCode = response.defaultStatusCode;
|
||||
if (response.statuses)
|
||||
sbm.populateSelectCodeDesc('#cbCommodityStatus', response.statuses);
|
||||
// Items.
|
||||
var items = response.commodies;
|
||||
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.fadeIn(50);
|
||||
}
|
||||
sbm.populateItem = function ($item, item)
|
||||
{
|
||||
if (!item) return;
|
||||
$item.prop('id', sbm.itemIdPrefix + item.id);
|
||||
$('.CommodityName', $item).text(item.displayName);
|
||||
$('.CommodityType', $item).text(item.typeDesc);
|
||||
$('.CommodityAssociationCount', $item).on('click', function () { sbm.onClickAssociationCount(item.id); }).toggle(item.associationCount).find('.AssociationCount').text(item.associationCount);
|
||||
$('.CommodityAddress', $item).text(item.addressSummary);
|
||||
$('.CommodityNotes', $item).text(item.notes);
|
||||
$('.StatusDesc', $item).text(item.statusDesc).addClass('sbm-status-' + item.statusCode.toLowerCase());
|
||||
$('.sbm-caption .sbm-action').toggleClass('sbm-action', !item.deleted);
|
||||
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) }));
|
||||
$('.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();
|
||||
return $item;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sbm.createItem = function ()
|
||||
{
|
||||
let $frm = sbm.$frm.commodity;
|
||||
$('.CommodityId,input[type="text"],textarea,select', $frm).val('');
|
||||
$('.CommodityStatus', $frm).val(sbm.data.defaultStatusCode);
|
||||
sbm.clearControlErrors();
|
||||
sbm.$dlg.commodity.dialog('option', 'title', sbm.dlg.title.createCommodity);
|
||||
sbm.openDialog(sbm.$dlg.commodity, 600, 600);
|
||||
}
|
||||
sbm.doCreateItem = function ()
|
||||
{
|
||||
sbm.storeItem();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sbm.updateItem = function (id)
|
||||
{
|
||||
$('.CommodityId', sbm.$frm.commodityId).val(id);
|
||||
sbm.ajax.updateItem = sbm.ajax.updateItem || { url: sbm.url.base + 'Commodity/Ajax/GetItem', formId: 'frmCommodityId', callbackFn: sbm.onUpdateItem };
|
||||
sbm.doAjaxRequest(sbm.ajax.updateItem, 50);
|
||||
}
|
||||
sbm.onUpdateItem = function (response)
|
||||
{
|
||||
//sbm.debug('onUpdateItem', response);
|
||||
let $frm = sbm.$frm.commodity;
|
||||
$('.CommodityId,input[type="text"],textarea,select', $frm).val('');
|
||||
if (!response.success) return;
|
||||
let item = response.commodity;
|
||||
$('.CommodityId', $frm).val(item.id);
|
||||
$('.CommodityType', $frm).val(item.typeCode);
|
||||
$('.CommodityName', $frm).val(item.name);
|
||||
$('.CommodityNotes', $frm).val(item.notes);
|
||||
$('.CommodityStatus', $frm).val(item.statusCode);
|
||||
sbm.clearControlErrors();
|
||||
sbm.$dlg.commodity.dialog('option', 'title', sbm.dlg.title.updateCommodity);
|
||||
sbm.openDialog(sbm.$dlg.commodity, 600, 600);
|
||||
}
|
||||
sbm.doUpdateItem = function ()
|
||||
{
|
||||
sbm.storeItem();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sbm.storeItem = function ()
|
||||
{
|
||||
sbm.ajax.storeItem = sbm.ajax.storeItem || { url: sbm.url.base + 'Commodity/Ajax/StoreItem', formId: 'frmCommodity', callbackFn: sbm.onStoreItem };
|
||||
sbm.doAjaxRequest(sbm.ajax.storeItem, 50);
|
||||
}
|
||||
sbm.onStoreItem = function (response)
|
||||
{
|
||||
//sbm.debug('onStoreItem', response);
|
||||
sbm.refreshControlValues(response.controlValues);
|
||||
if (!response.success) return;
|
||||
sbm.$dlg.commodity.dialog('close');
|
||||
|
||||
var item = response.commodity;
|
||||
var $item = $('#' + sbm.itemIdPrefix + item.id);
|
||||
if (!$item.length)
|
||||
{
|
||||
$item = $('.sbm-panel-item-template .sbm-panel-item.Commodity', $results).clone();
|
||||
$('.sbm-panel-item-list', $results).prepend($item).show();
|
||||
}
|
||||
$item.replaceWith(sbm.populateItem(sbm.getItemTemplate(), item));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
sbm.onClickAssociationCount = function (id)
|
||||
{
|
||||
if (!(id * 1)) return;
|
||||
sbm.doPleaseWait();
|
||||
let $frm = $('#frmCommodityId');
|
||||
$('.CommodityId', $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(); });
|
||||
$('.sbm-input, .sbm-textarea').on('input', function () { sbm.clearControlError(this); });
|
||||
$('.sbm-select').on('change', function () { sbm.clearControlError(this); });
|
||||
|
||||
sbm.$frm.filter = $('#frmCommodityFilter');
|
||||
$('.FilterCommodity', sbm.$frm.filter).on('input', function () { sbm.refreshResults(250); });
|
||||
$('.FilterCommodityCategory,.FilterCommodityStatusCategory', sbm.$frm.filter).on('change', function () { sbm.refreshResults(50); });
|
||||
sbm.$frm.commodityId = $('#frmCommodityId');
|
||||
sbm.$frm.commodity = $('#frmCommodity');
|
||||
$results = $('.sbm-panel-results');
|
||||
|
||||
var opt = sbm.dlgOpts();
|
||||
opt.buttons[sbm.dlg.btn.ok] = function () { sbm.doCreateItem(); };
|
||||
opt.buttons[sbm.dlg.btn.cancel] = function () { $(this).dialog('close'); };
|
||||
sbm.$dlg.commodity = $('#dlgCommodity').dialog(opt);
|
||||
|
||||
setTimeout(sbm.refreshResults, 250);
|
||||
});
|
||||
|
||||
}(window, window.document));
|
||||
|
||||
/* The End */
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Admin - Affiliate page scripts.
|
||||
* Contact page scripts.
|
||||
*/
|
||||
|
||||
(function (win, doc, undef)
|
||||
@@ -61,7 +61,9 @@
|
||||
$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); }).find('.AssociationCount').text(item.associationCount);
|
||||
$('.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);
|
||||
$('.StatusDesc', $item).text(item.statusDesc).addClass('sbm-status-' + item.statusCode.toLowerCase());
|
||||
$('.sbm-caption .sbm-action').toggleClass('sbm-action', !item.deleted);
|
||||
if (!item.deleted)
|
||||
|
||||
Reference in New Issue
Block a user