Files
Saxonite/SaxoniteCoreWebOnline/wwwroot/js/sax-pro-spt.js
T
2022-12-12 14:20:49 +00:00

185 lines
7.5 KiB
JavaScript

/*
* Account page scripts.
*/
(function (win, doc, undef)
{
//--------------------------------------------------------------
"use strict";
let ps = sax.mdl.profileSports = { ajax: {}, data: {}, $pnl: {}, $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();
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);
$('#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)
{
let cfg = { fnCallback: ps.applySportContact, contactTypes: ps.data.contactTypes, titles: ps.data.titles, typesUsed: ps.getUsedContactTypes(), contact: contact};
return cfg;
}
ps.getUsedContactTypes = function ()
{
return $('input[name="Contacts.ContactTypes"]', $frm.org).map(function () { return $(this).val(); }).get();
}
ps.addSportContact = function ()
{
//sax.debug('addSportContact');
ps.showSportContact(ps.getSportContactCfg());
}
ps.editSportContact= function (contact)
{
//sax.debug('editSportContact');
ps.showSportContact(ps.getSportContactCfg(contact));
}
ps.showSportContact=function(cfg)
{
sax.mdl.sportContact.showSportContact(cfg);
}
ps.getConId = function (contact)
{
return 'SptCon_' + contact.type;
}
ps.applySportContact = function (contact)
{
//sax.debug('applySportContact', contact);
}
//--------------------------------------------------------------
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);
});
//--------------------------------------------------------------
}(window, window.document));
/* The End */