284 lines
11 KiB
JavaScript
284 lines
11 KiB
JavaScript
/*
|
|
* Account page scripts.
|
|
*/
|
|
|
|
(function (win, doc, undef)
|
|
{
|
|
"use strict";
|
|
|
|
//--------------------------------------------------------------
|
|
sax.refreshProfile = function ()
|
|
{
|
|
setTimeout(sax.refreshProfileContactInfo, 50);
|
|
setTimeout(sax.refreshProfileSportsInfo, 50);
|
|
setTimeout(sax.refreshProfileOrganisationsInfo, 50);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
sax.refreshProfileContactInfo = function ()
|
|
{
|
|
var $section = $('.sax-panel-section.ProfileContact');
|
|
$section.removeClass('sax-edit').addClass('sax-populating');
|
|
$('.sax-property', $section).hide();
|
|
sax.showDataRefreshingMsg($section);
|
|
sax.refreshProfileContact(sax.onRefreshProfileContactInfo);
|
|
}
|
|
sax.refreshProfileContactForm = function ()
|
|
{
|
|
if (!sax.closeEditPanels()) return;
|
|
sax.refreshProfileContact(sax.onRefreshProfileContactForm);
|
|
}
|
|
sax.refreshProfileContact = function (callbackFn)
|
|
{
|
|
delete sax.page.profileContactChanged;
|
|
sax.ajaxProfileContact = sax.ajaxProfileContact || { url: sax.url.base + 'Account/Ajax/GetProfileContact', formId: 'frmNavigate', noWaitIcon: true };
|
|
sax.ajaxProfileContact.callbackFn = callbackFn;
|
|
sax.doAjaxRequest(sax.ajaxProfileContact, 50);
|
|
}
|
|
sax.onRefreshProfileContactInfo = function (response)
|
|
{
|
|
sax.debug('onRefreshProfileContactInfo', response);
|
|
if (!response || !response.success || !response.contact) return;
|
|
var $section = $('.sax-panel-section.ProfileContact');
|
|
$('.sax-message', $section).stop(true, false).fadeOut(200).empty();
|
|
$('.sax-value', $section).empty();
|
|
sax.refreshInfo($section, 'AccountEmailAddress', response.contact.emailAddress);
|
|
sax.refreshInfo($section, 'AccountName', response.contact.displayName);
|
|
sax.refreshInfo($section, 'AccountLocation', response.contact.locationCaption);
|
|
sax.showNoInfoMsg($section);
|
|
$section.removeClass('sax-populating');
|
|
}
|
|
sax.onRefreshProfileContactForm = function (response)
|
|
{
|
|
sax.debug('onRefreshProfileContactForm', response);
|
|
if (!response || !response.success) return;
|
|
var $section = $('.sax-panel-section.ProfileContact');
|
|
$('.sax-message', $section).stop(true, false).fadeOut(200).empty();
|
|
sax.refreshInput($section, 'AccountEmailAddress', response.contact.emailAddress);
|
|
sax.refreshSelect($section, 'AccountTitle', response.contact.title);
|
|
sax.refreshInput($section, 'AccountFirstName', response.contact.firstName);
|
|
sax.refreshInput($section, 'AccountLastName', response.contact.lastName);
|
|
sax.refreshInput($section, 'AccountRegionIdCountry', response.contact.regionIdCountry);
|
|
sax.refreshInput($section, 'AccountRegionCaptionCountry', response.contact.regionCaptionCountry);
|
|
sax.refreshInput($section, 'AccountRegionIdProvince', response.contact.regionIdProvince);
|
|
sax.refreshInput($section, 'AccountRegionCaptionProvince', response.contact.regionCaptionProvince);
|
|
$section.addClass('sax-edit');
|
|
}
|
|
sax.doStoreProfileContact = function ()
|
|
{
|
|
sax.clearControlErrors();
|
|
sax.ajaxStoreProfileContact = sax.ajaxStoreProfileContact || { url: sax.url.base + 'Account/Ajax/StoreProfileContact', formId: 'frmProfileContact', callbackFn: sax.onStoreProfileContact };
|
|
sax.doAjaxRequest(sax.ajaxStoreProfileContact, 50);
|
|
}
|
|
sax.onStoreProfileContact = function (response)
|
|
{
|
|
sax.refreshControlValues(response.controlValues);
|
|
if (!response || !response.success)
|
|
return;
|
|
sax.refreshProfileContactInfo();
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
sax.selectRegionCountry = function ()
|
|
{
|
|
sax.data.selectRegion.fn.selectRegion({ caption: sax.dlg.title.selectRegionCountry, regionId: $('#ifAccountRegionIdCountry').val(), fnCallback: sax.onSelectRegionCountry })
|
|
}
|
|
sax.onSelectRegionCountry = function (region)
|
|
{
|
|
sax.debug(region);
|
|
sax.clearControlError($('#ifAccountRegionIdCountry').val(region.id));
|
|
$('#ifAccountRegionCaptionCountry').val(region ? region.name : '');
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
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.ajaxProfileSports = sax.ajaxProfileSports || { url: sax.url.base + 'Account/Ajax/GetProfileSports', formId: 'frmNavigate', noWaitIcon: true };
|
|
sax.ajaxProfileSports.callbackFn = callbackFn;
|
|
sax.doAjaxRequest(sax.ajaxProfileSports, 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();
|
|
|
|
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];
|
|
let $item = $tmpl.clone().prop('id', 'ProSpt_' + item.id);
|
|
$('.sax-header .sax-action.sax-edit', $item).on('click', function (evt) { sax.updateProfileSport(item.id); });
|
|
$('.SportName', $item).text(item.sportName);
|
|
$items.append($item);
|
|
}
|
|
$items.show();
|
|
sax.showNoInfoMsg($section);
|
|
$section.removeClass('sax-populating');
|
|
}
|
|
sax.addProfileSport = function ()
|
|
{
|
|
sax.debug('addProfileSport');
|
|
let $dlg = sax.$dlg.profileSport;
|
|
$('.UserSportId,.ProfileSportExists,#ifProfileSportId,#ifProfileSport', $dlg).val('');
|
|
$('#pbSelectSport', $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.ajaxProfileSport = sax.ajaxProfileSport || { url: sax.url.base + 'Account/Ajax/GetProfileSport', formId: 'frmProfileSportId', callbackFn: sax.doUpdateProfileSport };
|
|
sax.doAjaxRequest(sax.ajaxProfileSport, 50);
|
|
}
|
|
sax.doUpdateProfileSport = function (response)
|
|
{
|
|
sax.debug('doUpdateProfileSport', response);
|
|
let $dlg = sax.$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);
|
|
$('#pbSelectSport', $dlg).hide();
|
|
$dlg.dialog('option', 'title', sax.dlg.title.updateUserSport);
|
|
sax.openDialog($dlg, 480, 400);
|
|
}
|
|
sax.selectUserSport = function (sport)
|
|
{
|
|
sax.debug('selectUserSport');
|
|
sax.data.selectSport.fn.selectSport({ caption: sax.dlg.title.selectSport, sportId: $('#frmProfileSport #ifProfileSportId').val(), 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.ajaxStoreProfileSport = sax.ajaxStoreProfileSport || { url: sax.url.base + 'Account/Ajax/StoreProfileSport', formId: 'frmProfileSport', callbackFn: sax.onStoreProfileSport };
|
|
sax.doAjaxRequest(sax.ajaxStoreProfileSport, 50);
|
|
}
|
|
sax.onStoreProfileSport = function (response)
|
|
{
|
|
sax.refreshControlValues(response.controlValues);
|
|
if (!response || !response.success)
|
|
return;
|
|
sax.$dlg.profileSport.dialog('close');
|
|
sax.refreshProfileSportsInfo();
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
sax.refreshProfileOrganisationsInfo = function (delay)
|
|
{
|
|
var $section = $('.sax-panel-section.ProfileOrganisations');
|
|
$section.removeClass('sax-edit').addClass('sax-populating');
|
|
$('.sax-property', $section).hide();
|
|
sax.showDataRefreshingMsg($section);
|
|
sax.refreshProfileOrganisations(sax.onRefreshProfileOrganisationsInfo);
|
|
}
|
|
sax.refreshProfileOrganisations = function (callbackFn)
|
|
{
|
|
//sax.debug('refreshProfileOrganisations');
|
|
delete sax.page.profileOrganisationsChanged;
|
|
sax.ajaxProfileOrganisations = sax.ajaxProfileOrganisations || { url: sax.url.base + 'Account/Ajax/GetProfileOrganisations', formId: 'frmNavigate', noWaitIcon: true };
|
|
sax.ajaxProfileOrganisations.callbackFn = callbackFn;
|
|
sax.doAjaxRequest(sax.ajaxProfileOrganisations, 50);
|
|
}
|
|
sax.onRefreshProfileOrganisationsInfo = function (response)
|
|
{
|
|
sax.debug('onRefreshProfileOrganisationsInfo', response);
|
|
if (!response || !response.success) return;
|
|
var $section = $('.sax-panel-section.ProfileOrganisations');
|
|
$('.sax-message', $section).stop(true, false).fadeOut(200).empty();
|
|
|
|
let items = response.organisations;
|
|
if (!items) return;
|
|
let $items = $('.sax-panel-results.Organisations', $section).empty();
|
|
let $tmpl = $('.sax-panel-item-template .sax-panel-item.Organisation', $section);
|
|
for (let itemIdx = 0; itemIdx < items.length; itemIdx++)
|
|
{
|
|
let item = items[itemIdx];
|
|
let $item = $tmpl.clone().prop('id', 'ProOrg_' + item.id);
|
|
$('.OrganisationName', $item).text(item.name);
|
|
$items.append($item);
|
|
}
|
|
$items.show();
|
|
sax.showNoInfoMsg($section);
|
|
$section.removeClass('sax-populating');
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
sax.showDataRefreshingMsg = function ($section)
|
|
{
|
|
//$('.sax-message', $section).html(sax.msg.dataRefreshing).fadeIn(200);
|
|
}
|
|
sax.showNoInfoMsg = function ($section)
|
|
{
|
|
if (!$('.sax-value', $section).text().length)
|
|
$('.sax-message', $section).html(sax.msg.noInformation).fadeIn(200);
|
|
}
|
|
sax.closeEditPanels = function ()
|
|
{
|
|
if (sax.page.profileContactChanged || sax.page.profileSportsChanged || sax.page.profileOrganisationsChanged)
|
|
{
|
|
sax.doAlert(sax.msg.changesMade);
|
|
return false;
|
|
}
|
|
$('.sax-panel-section').removeClass('sax-edit');
|
|
return true;
|
|
}
|
|
sax.refreshInfo = function ($section, name, value)
|
|
{
|
|
$('.sax-property.' + name + ' .sax-value', $section).html(value).closest('.sax-property').toggle(!!value);
|
|
}
|
|
sax.refreshInput = function ($section, name, value)
|
|
{
|
|
$('.sax-control input.' + name, $section).val(value);
|
|
}
|
|
sax.refreshTextArea = function ($section, name, value)
|
|
{
|
|
$('.sax-control textarea.' + name, $section).val(value);
|
|
}
|
|
sax.refreshSelect = function ($section, name, value)
|
|
{
|
|
var $select = $('.sax-control select.' + name, $section);
|
|
$select.val(value).scrollTop(0);
|
|
sax.setItemsSelectedLabel($select);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
$(function ()
|
|
{
|
|
$('.sax-panel-section.ProfileContact .sax-action.sax-edit').on('click', function (evt) { sax.refreshProfileContactForm(); });
|
|
$('input,textarea,select', '.sax-panel-section.ProfileContact').on('change', function () { sax.clearControlErrors(); sax.page.profileContactChanged = true; });
|
|
|
|
$('.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'); };
|
|
sax.$dlg.profileSport = $('#dlgProfileSport').dialog(opt);
|
|
|
|
setTimeout(sax.refreshProfile, 200);
|
|
});
|
|
|
|
}(window, window.document));
|
|
|
|
/* The End */ |