Files
Saxonite/SaxoniteCoreWebOnline/wwwroot/js/sax-usr-spt.js
T
2021-08-19 17:25:41 +01:00

127 lines
5.2 KiB
JavaScript

/*
* Account page scripts.
*/
(function (win, doc, undef)
{
"use strict";
let $pnl = sax.$pnl, $dlg = sax.$dlg, $frm = sax.$frm;
//--------------------------------------------------------------
sax.refreshProfileSportsInfo = function (delay)
{
var $section = $('.sax-panel-section.ProfileSports');
$section.removeClass('sax-edit').addClass('sax-populating');
$('.sax-property', $section).hide();
sax.showDataRefreshingMsg($section);
sax.refreshProfileSports(sax.onRefreshProfileSportsInfo);
}
sax.refreshProfileSports = function (callbackFn)
{
//sax.debug('refreshProfileSports');
delete sax.page.profileSportsChanged;
sax.ajax.profileSports = sax.ajax.profileSports || { url: sax.url.base + 'Account/Ajax/GetProfileSports', formId: 'frmNavigate', noWaitIcon: true };
sax.ajax.profileSports.callbackFn = callbackFn;
sax.doAjaxRequest(sax.ajax.profileSports, 50);
}
sax.onRefreshProfileSportsInfo = function (response)
{
//sax.debug('onRefreshProfileSportsInfo', response);
if (!response || !response.success) return;
var $section = $('.sax-panel-section.ProfileSports');
$('.sax-message', $section).stop(true, false).fadeOut(200).empty();
sax.profile.sports.Ids = [];
let items = response.sports;
if (!items) return;
let $items = $('.sax-panel-results.ProfileSports', $section).empty();
let $tmpl = $('.sax-panel-item-template .sax-panel-item.ProfileSport', $section);
for (let itemIdx = 0; itemIdx < items.length; itemIdx++)
{
let item = items[itemIdx];
sax.profile.sports.Ids.push(item.sportId);
let $item = $tmpl.clone().prop('id', 'ProSpt_' + item.id);
$('.sax-header .sax-action.sax-edit', $item).on('click', function (evt) { sax.updateProfileSport(item.id); });
$('.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($section);
$section.removeClass('sax-populating');
}
sax.addProfileSport = function ()
{
//sax.debug('addProfileSport');
let dlg = $dlg.profileSport;
$('.UserSportId,.ProfileSportExists,#ifProfileSportId,input.sax-input,select.sax-select', dlg).val('');
$('.SelectSport', dlg).show();
dlg.dialog('option', 'title', sax.dlg.title.addUserSport);
sax.openDialog(dlg, 480, 400);
}
sax.updateProfileSport = function (id)
{
//sax.debug('updateProfileSport', id);
$('#frmProfileSportId .UserSportId').val(id);
sax.ajax.profileSport = sax.ajax.profileSport || { url: sax.url.base + 'Account/Ajax/GetProfileSport', formId: 'frmProfileSportId', callbackFn: sax.doUpdateProfileSport };
sax.doAjaxRequest(sax.ajax.profileSport, 50);
}
sax.doUpdateProfileSport = function (response)
{
//sax.debug('doUpdateProfileSport', response);
let dlg = $dlg.profileSport;
let item = response.sport;
$('.UserSportId', dlg).val(item.id);
$('.ProfileSportExists', dlg).val(1);
$('#ifProfileSportId', dlg).val(item.sportId);
$('#ifProfileSport', dlg).val(item.sportName);
$('#cbProfileSportParticipation', dlg).val(item.sportParticipationCode);
$('#cbProfileSportOfficiating', dlg).val(item.sportOfficiatingCode);
$('.SelectSport', dlg).hide();
dlg.dialog('option', 'title', sax.dlg.title.updateUserSport);
sax.openDialog(dlg, 480, 400);
}
sax.selectUserSport = function (sport)
{
//sax.debug('selectUserSport');
let excludeIds = $.grep(sax.profile.sports.Ids, function (value) { return !sport || value != sport.id; });
sax.data.selectSport.fn.selectSport({ caption: sax.dlg.title.selectSport, sportId: $('#frmProfileSport #ifProfileSportId').val(), excludeIds: excludeIds, fnCallback: sax.onSelectUserSport })
}
sax.onSelectUserSport = function (sport)
{
sax.clearControlError($('#ifProfileSportId').val(sport ? sport.id : ''));
$('#ifProfileSport').val(sport ? sport.name : '');
}
sax.storeProfileSport = function ()
{
//sax.debug('storeProfileSport');
sax.clearControlErrors();
sax.ajax.storeProfileSport = sax.ajax.storeProfileSport || { url: sax.url.base + 'Account/Ajax/StoreProfileSport', formId: 'frmProfileSport', callbackFn: sax.onStoreProfileSport };
sax.doAjaxRequest(sax.ajax.storeProfileSport, 50);
}
sax.onStoreProfileSport = function (response)
{
sax.refreshControlValues(response.controlValues);
if (!response || !response.success) return;
$dlg.profileSport.dialog('close');
sax.refreshProfileSportsInfo();
}
//--------------------------------------------------------------
$(function ()
{
$('.sax-panel-section.ProfileSports .sax-action.sax-add').on('click', function (evt) { sax.addProfileSport(); });
var opt = sax.dlgOpts();
opt.buttons[sax.dlg.btn.ok] = function () { sax.storeProfileSport(); };
opt.buttons[sax.dlg.btn.cancel] = function () { $(this).dialog('close'); };
$dlg.profileSport = $('#dlgProfileSport').dialog(opt);
});
//--------------------------------------------------------------
}(window, window.document));
/* The End */