Files
Saxonite/SaxoniteCoreWebOnline/wwwroot/js/sax-usr-spt.js
T
2022-03-04 18:15:23 +00:00

130 lines
5.3 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;
ps.data = {};
//--------------------------------------------------------------
sax.refreshProfileSportsInfo = function (delay)
{
$pnl.proSpt.removeClass('sax-edit').addClass('sax-populating');
$('.sax-property', $pnl.proSpt).hide();
sax.showDataRefreshingMsg($pnl.proSpt);
sax.refreshProfileSports(ps.onRefreshProfileSportsInfo);
}
sax.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();
sax.profile.sports.Ids = [];
let items = response.sports;
if (!items) return;
let $items = $('.sax-panel-results.ProfileSports', $pnl.proSpt).empty();
let $tmpl = $('.sax-panel-item-template .sax-panel-item.ProfileSport', $pnl.proSpt);
for (let itemIdx = 0; itemIdx < items.length; itemIdx++)
{
let item = items[itemIdx];
sax.profile.sports.Ids.push(item.sportId);
let $item = $tmpl.clone();
$('.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);
$('.SportParticipationValue', $item).text(item.sportParticipation);
$('.SportParticipation', $item).toggle(!!item.sportParticipation);
$('.SportOfficiatingValue', $item).text(item.sportOfficiating);
$('.SportOfficiating', $item).toggle(!!item.sportOfficiating);
$items.append($item);
}
$items.show();
sax.showNoInfoMsg($pnl.proSpt);
$pnl.proSpt.removeClass('sax-populating');
}
ps.addProfileSport = function ()
{
//sax.debug('addProfileSport');
let dlg = $dlg.proSpt;
$('.UserSportId,.ProfileSportExists,#ifProfileSportId,input.sax-input,textarea.sax-textarea,select.sax-select', dlg).val('');
$('.SelectSport', dlg).show();
dlg.dialog('option', 'title', sax.dlg.title.addUserSport);
sax.openDialog(dlg, 640, 480);
}
ps.updateProfileSport = function (item)
{
//sax.debug('updateProfileSport', item);
$('#frmProfileSportId .UserSportId').val(item.id);
ps.ajax.profileSport = ps.ajax.profileSport || { url: sax.url.base + 'Account/Ajax/GetProfileSport', formId: 'frmProfileSportId', callbackFn: ps.doUpdateProfileSport };
sax.doAjaxRequest(ps.ajax.profileSport, 50);
}
ps.doUpdateProfileSport = function (response)
{
//sax.debug('doUpdateProfileSport', response);
let dlg = $dlg.proSpt;
let item = response.sport;
$('.UserSportId', dlg).val(item.id);
$('.ProfileSportExists', dlg).val(1);
$('#ifProfileSportId', dlg).val(item.sportId);
$('#ifProfileSport', dlg).val(item.sportName);
$('#ifProfileSportAbout', dlg).val(item.sportAbout);
$('#cbProfileSportParticipation', dlg).val(item.sportParticipationCode);
$('#cbProfileSportOfficiating', dlg).val(item.sportOfficiatingCode);
$('.SelectSport', dlg).hide();
dlg.dialog('option', 'title', sax.dlg.title.updateUserSport);
sax.openDialog(dlg, 640, 480);
}
sax.selectUserSport = function (sport)
{
//sax.debug('selectUserSport');
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: $('#frmProfileSport #ifProfileSportId').val(), excludeIds: excludeIds, fnCallback: ps.onSelectUserSport })
}
ps.onSelectUserSport = function (sport)
{
sax.clearControlError($('#ifProfileSportId').val(sport ? sport.id : ''));
$('#ifProfileSport').val(sport ? sport.name : '');
}
ps.storeProfileSport = function ()
{
//sax.debug('storeProfileSport');
sax.clearControlErrors();
ps.ajax.storeProfileSport = ps.ajax.storeProfileSport || { url: sax.url.base + 'Account/Ajax/StoreProfileSport', formId: 'frmProfileSport', callbackFn: ps.onStoreProfileSport };
sax.doAjaxRequest(ps.ajax.storeProfileSport, 50);
}
ps.onStoreProfileSport = function (response)
{
sax.refreshControlValues(response.controlValues);
if (!response || !response.success) return;
$dlg.proSpt.dialog('close');
sax.refreshProfileSportsInfo();
}
//--------------------------------------------------------------
$(function ()
{
$pnl.proSpt = $('.sax-panel-section.ProfileSports');
$('.sax-action.sax-add', $pnl.proSpt).on('click', function (evt) { ps.addProfileSport(); });
var opt = sax.dlgOpts();
opt.buttons[sax.dlg.btn.ok] = function () { ps.storeProfileSport(); };
opt.buttons[sax.dlg.btn.cancel] = function () { $(this).dialog('close'); };
$dlg.proSpt = $('#dlgProfileSport').dialog(opt);
});
//--------------------------------------------------------------
}(window, window.document));
/* The End */