Files
Saxonite/Workspace/SaxoniteCoreWebOnline/wwwroot/js/sax-pro-spt.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

222 lines
9.4 KiB
JavaScript

/*
* Account page scripts.
*/
(function (win, doc, undef)
{
//--------------------------------------------------------------
"use strict";
let ps = sax.mdl.profileSports = { ajax: {}, data: {}, $pnl: {}, $tmpl: {}, $dlg: {}, $frm: {} };
let $pnl = ps.$pnl, $dlg = ps.$dlg, $frm = ps.$frm;
//--------------------------------------------------------------
sax.refreshProfileSportsInfo = function (delay)
{
$pnl.proSpt.removeClass('sax-edit').addClass('sax-populating');
$('.sax-property', $pnl.proSpt).hide();
sax.showDataRefreshingMsg($pnl.proSpt);
ps.refreshProfileSports(ps.onRefreshProfileSportsInfo);
}
ps.refreshProfileSports = function (callbackFn)
{
//sax.debug('refreshProfileSports');
delete sax.page.profileSportsChanged;
ps.ajax.profileSports = ps.ajax.profileSports || { url: sax.url.base + 'Account/Ajax/GetProfileSports', formId: 'frmNavigate', noWaitIcon: true };
ps.ajax.profileSports.callbackFn = callbackFn;
sax.doAjaxRequest(ps.ajax.profileSports, 50);
}
ps.onRefreshProfileSportsInfo = function (response)
{
//sax.debug('onRefreshProfileSportsInfo', response);
if (!response || !response.success) return;
$('.sax-message', $pnl.proSpt).stop(true, false).fadeOut(200).empty();
ps.data.contactTypes = response.contactTypes;
ps.data.titles = response.titles;
sax.profile.sports.Ids = [];
let items = response.sports;
if (!items) return;
let $items = $('.sax-panel-results.ProfileSports', $pnl.proSpt).empty();
for (let itemIdx = 0; itemIdx < items.length; itemIdx++)
$items.append(ps.populateItem(ps.getItemTemplate(), items[itemIdx]));
$items.show();
sax.showNoInfoMsg($pnl.proSpt);
$pnl.proSpt.removeClass('sax-populating');
}
ps.populateItem = function ($item, item)
{
if (!item) return;
sax.profile.sports.Ids.push(item.sportId);
$('.sax-header .sax-action.sax-edit', $item).on('click', function (evt) { ps.updateProfileSport(item); });
$('.sax-content', $item).on('dblclick', function (evt) { ps.updateProfileSport(item); });
$('.sax-header .sax-action.sax-experience', $item).on('click', function (evt) { sax.showSportExperience(item); });
$('.SportName', $item).text(item.sportName);
$('.SportParticipatingValue', $item).text(item.sportParticipating);
$('.SportParticipating', $item).toggle(!!item.sportParticipating);
$('.SportPreparingValue', $item).text(item.sportPreparing);
$('.SportPreparing', $item).toggle(!!item.sportPreparing);
$('.SportOfficiatingValue', $item).text(item.sportOfficiating);
$('.SportOfficiating', $item).toggle(!!item.sportOfficiating);
return $item;
}
//--------------------------------------------------------------
ps.getItemTemplate = function ()
{
return $('.sax-panel-item-template .sax-panel-item.ProfileSport', $pnl.proSpt).clone();
}
//--------------------------------------------------------------
ps.addProfileSport = function ()
{
//sax.debug('addProfileSport');
ps.clearProfileSport();
ps.openProfileSportDialog(sax.dlg.title.addUserSport);
}
ps.openProfileSportDialog = function (title)
{
if (title) $dlg.spt.dialog('option', 'title', title);
sax.openDialog($dlg.spt, 680, 560);
}
ps.clearProfileSport = function ()
{
let dlg = $dlg.spt;
$('.UserSportId,.ProfileSportExists,#ifProfileSportId,input.sax-input,textarea.sax-textarea,select.sax-select', dlg).val('');
$('.SelectSport', dlg).show();
$pnl.sptConTbl.empty();
sax.clearControlErrors(dlg);
}
ps.updateProfileSport = function (item)
{
//sax.debug('updateProfileSport', item, $frm.sptId);
$('.UserSportId', $frm.sptId).val(item.id);
ps.ajax.profileSport = ps.ajax.profileSport || { url: sax.url.base + 'Account/Ajax/GetProfileSport', formId: $frm.sptId.prop('id'), callbackFn: ps.doUpdateProfileSport };
sax.doAjaxRequest(ps.ajax.profileSport, 50);
}
ps.doUpdateProfileSport = function (response)
{
//sax.debug('doUpdateProfileSport', response);
ps.clearProfileSport();
let dlg = $dlg.spt;
let frm = $frm.spt;
let item = response.sport;
$('.UserSportId', frm).val(item.id);
$('.ProfileSportExists', frm).val(1);
$('#ifProfileSportId', frm).val(item.sportId);
$('#ifProfileSport', frm).val(item.sportName);
$('#ifProfileSportAbout', frm).val(item.sportAbout);
let contacts = item.contacts || [];
for (let idx = 0; idx < contacts.length; idx++)
{
let contact = contacts[idx];
$pnl.sptConTbl.append(ps.populateSportContact(ps.$tmpl.sptCon.clone(), contact));
}
ps.sortSptCons();
$('#cbProfileSportParticipating', frm).val(item.sportParticipatingCode);
$('#cbProfileSportPreparing', frm).val(item.sportPreparingCode);
$('#cbProfileSportOfficiating', frm).val(item.sportOfficiatingCode);
$('.SelectSport', frm).hide();
ps.openProfileSportDialog(sax.dlg.title.updateUserSport);
}
//--------------------------------------------------------------
ps.selectUserSport = function (sport)
{
//sax.debug('selectUserSport');
if (!!$('.UserSportId', $frm.spt).val()) return;
let excludeIds = $.grep(sax.profile.sports.Ids, function (value) { return !sport || value != sport.id; });
sax.mdl.selectSport.fn.selectSport({ caption: sax.dlg.title.selectSport, sportId: $('#ifProfileSportId', $frm.spt).val(), excludeIds: excludeIds, fnCallback: ps.onSelectUserSport })
}
ps.onSelectUserSport = function (sport)
{
sax.clearControlError($('#ifProfileSportId').val(sport ? sport.id : ''));
$('#ifProfileSport').val(sport ? sport.name : '');
}
//--------------------------------------------------------------
ps.getSportContactCfg = function (contact)
{
return { fnCallback: ps.applySportContact, contactTypes: ps.data.contactTypes, titles: ps.data.titles, contactTypesUsed: !contact ? ps.getUsedContactTypes() : [], contact: contact };
}
ps.getUsedContactTypes = function ()
{
return $('.SportContacts input[name="Contacts.ContactType"]', $frm.org).map(function () { return $(this).val(); }).get();
}
ps.addSportContact = function ()
{
ps.editSportContact();
}
ps.editSportContact = function (contact)
{
sax.mdl.sportContact.showSportContact(ps.getSportContactCfg(contact));
}
ps.clearSportContact = function (contact)
{
$('#' + po.getSptConId(contact), $pnl.sptConTbl).remove();
po.sortSptCons();
}
ps.getSptConId = function (contact)
{
return 'SptCon_' + contact.contactType;
}
ps.applySportContact = function (contact)
{
//sax.debug('applySportContact', contact);
let $sptCon = $('#' + ps.getSptConId(contact));
if (!$sptCon.length) $pnl.sptConTbl.append($sptCon = ps.$tmpl.sptCon.clone());
ps.populateSportContact($sptCon, contact);
ps.sortSptCons();
}
ps.populateSportContact = function ($sptCon, contact)
{
$sptCon.prop('id', ps.getSptConId(contact));
$('.sax-label', $sptCon).text(contact.contactTypeDesc);
$('.sax-value.Name', $sptCon).text((contact.title + " " + contact.firstName + " " + contact.lastName).trim());
$('.sax-value.Details', $sptCon).text(contact.emailAddress);
$('input[name="Contacts.ContactType"]', $sptCon).val(contact.contactType);
$('input[name="Contacts.Title"]', $sptCon).val(contact.title);
$('input[name="Contacts.FirstName"]', $sptCon).val(contact.firstName);
$('input[name="Contacts.LastName"]', $sptCon).val(contact.lastName);
$('input[name="Contacts.EmailAddress"]', $sptCon).val(contact.emailAddress);
$('input[name="Contacts.Phone"]', $sptCon).val(contact.phone);
$sptCon.on('click', '.sax-action.sax-edit', function () { ps.editSportContact(contact); });
$sptCon.on('click', '.sax-action.sax-remove', function () { ps.clearSportContact(contact); });
return $sptCon;
}
ps.sortSptCons = function ()
{
let $rows = $pnl.sptConTbl.find('tr').detach().sort(function (a, b)
{
return $('.sax-label', a).text().localeCompare($('.sax-label', b).text());
}).appendTo($pnl.sptConTbl);
$('input[name="Contacts.Count"]', $pnl.sptCons).val($rows.length);
}
//--------------------------------------------------------------
ps.storeProfileSport = function ()
{
//sax.debug('storeProfileSport');
sax.clearControlErrors();
ps.ajax.storeProfileSport = ps.ajax.storeProfileSport || { url: sax.url.base + 'Account/Ajax/StoreProfileSport', formId: $frm.spt.prop('id'), callbackFn: ps.onStoreProfileSport };
sax.doAjaxRequest(ps.ajax.storeProfileSport, 50);
}
ps.onStoreProfileSport = function (response)
{
sax.refreshControlValues(response.controlValues, $frm.spt);
if (!response || !response.success) return;
$dlg.spt.dialog('close');
sax.refreshProfileSportsInfo();
}
//--------------------------------------------------------------
$(function ()
{
$pnl.proSpt = $('.sax-panel-section.ProfileSports');
$('.sax-action.sax-add', $pnl.proSpt).on('click', function (evt) { ps.addProfileSport(); });
$frm.sptId = $('#frmProfileSportId', $pnl.proSpt);
var opt = sax.dlgOpts();
opt.buttons[sax.dlg.btn.ok] = function () { ps.storeProfileSport(); };
opt.buttons[sax.dlg.btn.cancel] = function () { $(this).dialog('close'); };
$dlg.spt = $('#dlgProfileSport').dialog(opt);
$frm.spt = $('#frmProfileSport', $dlg.spt);
$frm.spt.on('dblclick', '.ProfileSport.sax-input', ps.selectUserSport);
$frm.spt.on('click', '.SelectSport.sax-button', ps.selectUserSport);
$frm.spt.on('click', '.SportContacts .sax-action.sax-add', ps.addSportContact);
$pnl.sptCons = $('.SportContacts', $dlg.spt);
$pnl.sptConTbl = $('.Contacts table.sax-data', $pnl.sptCons);
ps.$tmpl.sptCon = $('.sax-panel-item-template .Contact', $pnl.sptCons).detach();
});
//--------------------------------------------------------------
}(window, window.document));
/* The End */