Files
Saxonite/Workspace/SaxoniteCoreWebOnline/wwwroot/js/sax-reg-sel.js
T
andy 9f22b522df v1.3.0 Restructure Saxonite workspace and upgrade to .NET 10 (#1)
Move Saxonite’s projects into a dedicated `Workspace` folder and align the solution with .NET 10 and the current Common workspace. Update encryption integration, test project structure and coverage, and repository guidance and upgrade notes.

- Relocate application and library projects while retaining Git rename history.
- Split tests into Admin, Online, and Shared projects; add representative behavioral and serialization tests.
- Update Common integration, application version, and repository documentation.

Application version: 1.3.0

Reviewed-on: #1
Co-authored-by: andy <andy@sarand.com>
2026-10-16 18:24:16 +01:00

132 lines
4.7 KiB
JavaScript

/*
* Region selection.
*/
(function (win, doc, undef)
{
"use strict";
let sr = sax.mdl.selectRegion = sax.mdl.selectRegion || {};
sr.regions = {}; sr.fn = {}; sr.ajax = {}; sr.itemIdPrefix = 'Rgn_';
//--------------------------------------------------------------
/*
* Region selection config:
* - caption - dialog title.
* - regionId - currently selected region.
* - typesInc[] - included region types.
* - typesExc[] - excluded region types.
* - fnCallback - method to call on completion to store selected region.
*/
sr.fn.selectRegion = function (cfg)
{
sr.cfg = cfg;
sr.regionId = cfg.regionId;
if (sr.regions.length) sr.fn.showSelectRegion();
else
{
sr.ajax.regions = sr.ajax.regions || { url: sax.url.base + 'Reference/Ajax/GetRegions', formId: 'frmNavigate', callbackFn: sr.fn.refreshRegionsAndSelect };
sax.doAjaxRequest(sr.ajax.regions, 20);
}
}
sr.fn.refreshRegionsAndSelect = function (response)
{
//sax.debug('refreshRegionsAndSelect', response);
if (!response || !response.success) return;
sr.regions = response.regions;
sr.fn.showSelectRegion();
}
sr.fn.showSelectRegion = function ()
{
$('.SelectedRegionName', sr.$dlg).text(sr.fn.getRegionName(sr.regionId));
$('#ifRegionFilter', sr.$dlg).val('');
sr.fn.displayRegions();
sax.openDialog(sr.$dlg.dialog('option', { title: sr.cfg.caption || 'Select Region' }), sr.cfg.width || 400, sr.cfg.height || 800);
}
//--------------------------------------------------------------
sr.fn.compareRegions = function (a, b)
{
var comparison = a.name.toLowerCase().localeCompare(b.name.toLowerCase());
if (comparison === 0)
return a.name.localeCompare(b.name);
return comparison;
}
//--------------------------------------------------------------
sr.fn.displayRegions = function ()
{
let filter = $('#ifRegionFilter', sr.$dlg).val();
let reFilter = new RegExp(sax.escapeRegExp((filter || '').trim()), 'i');
let $regionsAvail = $('.sax-selectRegion-regions.AvailableRegions', sr.$dlg).empty();
let $regionTmpl = $('.sax-panel-item-template .sax-panel-item.Region', sr.$dlg);
let regions = [...sr.regions];
let typesInc = sr.cfg.typesInc || [];
let typesExc = sr.cfg.typesExc || [];
regions.sort(sr.fn.compareRegions);
for (let rgnIdx = 0; rgnIdx < regions.length; rgnIdx++)
{
let region = regions[rgnIdx];
let id = region.id;
if (filter && !region.name.match(reFilter)) continue;
if (typesInc.length && !typesInc.includes(region.regionType)) continue;
if (typesExc.length && typesExc.includes(region.regionType)) continue;
let $region = $regionTmpl.clone();
$region.on('click', function () { sr.fn.onClickRegion(region, $region); }).on('dblclick', function () { sr.fn.onDblClickRegion(region, $region); }).find('.RegionName').text(region.name).end();
if (id == sr.regionId) $region.addClass('sel');
$regionsAvail.append($region);
}
}
sr.fn.getRegion = function (id)
{
for (let rgnIdx = 0; rgnIdx < sr.regions.length; rgnIdx++)
{
let region = sr.regions[rgnIdx];
if (region.id == id) return region;
}
}
sr.fn.getRegionName = function (id)
{
let region = sr.fn.getRegion(id);
return region ? region.name : '';
}
//--------------------------------------------------------------
sr.fn.onClickRegion = function (region, $region)
{
$('.SelectedRegionName', sr.$dlg).text(sr.fn.getRegionName(sr.regionId = region.id));
$('.sax-panel-item.Region', sr.$dlg).removeClass('sel');
$region.addClass('sel');
}
sr.fn.onDblClickRegion = function (region, $region)
{
sr.regionId = region.id;
sr.fn.storeSelectRegion();
}
sr.fn.storeSelectRegion = function ()
{
if (!sr.regionId) return;
let region = sr.fn.getRegion(sr.regionId);
if (!region) return;
if (sr.cfg.fnCallback) sr.cfg.fnCallback(region);
sr.$dlg.dialog('close');
sr.fn.cleanUp();
}
sr.fn.cleanUp = function ()
{
delete sr.cfg;
delete sr.regionId;
}
//--------------------------------------------------------------
sr.fn.onDlgSize = function ()
{
let $pnl = $('.sax-selectRegion-regions.AvailableRegions', sr.$dlg);
$pnl.outerHeight(Math.floor(sr.$dlg.innerHeight() - $pnl.position().top - ($pnl.outerHeight(true) - $pnl.innerHeight())));
}
//--------------------------------------------------------------
$(function ()
{
var opt = sax.dlgOpts();
opt.open = function (evt, ui) { sr.fn.onDlgSize(); };
opt.resize = function (evt, ui) { sr.fn.onDlgSize(); };
opt.buttons[sax.dlg.btn.ok] = function () { sr.fn.storeSelectRegion(); };
opt.buttons[sax.dlg.btn.cancel] = function () { sr.fn.cleanUp(); $(this).dialog('close'); };
sr.$dlg = $('#dlgSelectRegion').dialog(opt);
});
//--------------------------------------------------------------
}(window, window.document));
/* The End */