367 lines
16 KiB
JavaScript
367 lines
16 KiB
JavaScript
/*
|
|
* Account page scripts.
|
|
*/
|
|
|
|
(function (win, doc, undef)
|
|
{
|
|
"use strict";
|
|
sax.classFileDrag = 'sax-file-drag';
|
|
sax.profile = { contact: {}, sports: {}, organisations: {} };
|
|
|
|
//--------------------------------------------------------------
|
|
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.ajax.profileContact = sax.ajax.profileContact || { url: sax.url.base + 'Account/Ajax/GetProfileContact', formId: 'frmNavigate', noWaitIcon: true };
|
|
sax.ajax.profileContact.callbackFn = callbackFn;
|
|
sax.doAjaxRequest(sax.ajax.profileContact, 50);
|
|
}
|
|
sax.onRefreshProfileContactInfo = function (response)
|
|
{
|
|
//sax.debug('onRefreshProfileContactInfo', response);
|
|
if (!response || !response.success || !response.contact) return;
|
|
$('.sax-panel-section').show();
|
|
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);
|
|
$('img.AccountContact', $section).prop('src', 'Image/Account/Contact/Profile?' + (new Date()).getTime());
|
|
sax.showNoInfoMsg($section);
|
|
$section.removeClass('sax-populating');
|
|
}
|
|
sax.onRefreshProfileContactForm = function (response)
|
|
{
|
|
//sax.debug('onRefreshProfileContactForm', response);
|
|
if (!response || !response.success) return;
|
|
$('.sax-panel-section').hide();
|
|
var $section = $('.sax-panel-section.ProfileContact').show();
|
|
$('.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);
|
|
$('img.AccountContact', $section).prop('src', 'Image/Account/Contact/Profile?' + (new Date()).getTime());
|
|
$section.addClass('sax-edit');
|
|
}
|
|
sax.doStoreProfileContact = function ()
|
|
{
|
|
sax.clearControlErrors();
|
|
sax.ajax.storeProfileContact = sax.ajax.storeProfileContact || { url: sax.url.base + 'Account/Ajax/StoreProfileContact', formId: 'frmProfileContact', callbackFn: sax.onStoreProfileContact };
|
|
sax.doAjaxRequest(sax.ajax.storeProfileContact, 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.onDropContactImage = function (evt)
|
|
{
|
|
//sax.debug('onDropContactImage', evt);
|
|
let files = evt.originalEvent.dataTransfer.files;
|
|
if (files.length < 1) return;
|
|
if (files.length > 1) return sax.doAlert(sax.dlg.title.imageUpload, sax.msg.uploadImageSingle);
|
|
sax.onDropContactImageFile(files[0], $('#frmProfileContact'));
|
|
}
|
|
sax.onDropContactImageFile = function (file, context)
|
|
{
|
|
//sax.debug('onDropContactImageFile', file, context);
|
|
if (file.size > sax.maxProfileImageSize) return sax.doAlert(sax.dlg.title.imageUpload, sax.msg.uploadFileSizeMax.format(sax.formatFileSize(sax.maxProfileImageSize)));
|
|
if (file.type != 'image/jpg' && file.type != 'image/jpeg' && file.type != 'image/png') return sax.doAlert(sax.dlg.title.imageUpload, sax.msg.uploadFileTypeInvalid.format(sax.getFileType(file)));
|
|
$(".UploadMessage", context).text(sax.msg.uploadingFile.format(file.name));
|
|
$('img.ContactImageUploadProgress', context).fadeIn(200);
|
|
sax.clearControlError(sax.$pnl.contactImageDrag);
|
|
sax.data.contactImageUploadContext = context;
|
|
|
|
sax.ajax.uploadContactImage = sax.ajax.uploadContactImage || { url: sax.url.base + 'Account/Ajax/UploadContactImage', callbackFn: sax.handleContactImageUploadResponse, noWaitIcon: true };
|
|
sax.ajax.uploadContactImage.formData = new FormData();
|
|
sax.ajax.uploadContactImage.formData.append("__RequestVerificationToken", $('#frmNavigate input[name="__RequestVerificationToken"]').val());
|
|
sax.ajax.uploadContactImage.formData.append("AccountContactImage", file);
|
|
sax.doAjaxRequest(sax.ajax.uploadContactImage, 50);
|
|
}
|
|
sax.handleContactImageUploadResponse = function (response)
|
|
{
|
|
let context = sax.data.contactImageUploadContext;
|
|
//sax.debug('handleContactImageUploadResponse', response, context);
|
|
if (!response) return;
|
|
var $section = $('.sax-panel-section.ProfileContact');
|
|
sax.refreshControlValues(response.controlValues, context);
|
|
$(".UploadMessage", context).empty();
|
|
$('img.ContactImageUploadProgress', context).hide();
|
|
if (response.success)
|
|
{
|
|
sax.$dlg.selectContactImage.dialog('close');
|
|
$('img.AccountContact', $section).prop('src', 'Image/Account/Contact/Profile?' + (new Date()).getTime());
|
|
}
|
|
}
|
|
sax.selectContactImage = function ()
|
|
{
|
|
let $dlg = sax.$dlg.selectContactImage.dialog('option', { title: sax.dlg.title.imageUpload });
|
|
$('#ifContactImage', $dlg).val('');
|
|
sax.openDialog($dlg, 560, 240);
|
|
}
|
|
sax.uploadContactImage = function ()
|
|
{
|
|
let $dlg = sax.$dlg.selectContactImage;
|
|
let $fileCtrl = $('#ifContactImage', $dlg);
|
|
if (!$fileCtrl.length || !$fileCtrl[0].files.length)
|
|
return sax.doAlert(sax.dlg.title.imageUpload, sax.msg.uploadFileSelect);
|
|
let file = $fileCtrl[0].files[0];
|
|
sax.onDropContactImageFile(file, $dlg);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
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); });
|
|
$('.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 = sax.$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 = 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);
|
|
$('#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;
|
|
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.ajax.profileOrganisations = sax.ajax.profileOrganisations || { url: sax.url.base + 'Account/Ajax/GetProfileOrganisations', formId: 'frmNavigate', noWaitIcon: true };
|
|
sax.ajax.profileOrganisations.callbackFn = callbackFn;
|
|
sax.doAjaxRequest(sax.ajax.profileOrganisations, 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);
|
|
$('.OrganisationSport', $item).text(item.sportName);
|
|
$('.OrganisationRegion', $item).text(item.regionName);
|
|
$('.OrganisationMemberCount', $item).toggle(!!item.memberCount).find('.MemberCount').text(item.memberCount);
|
|
$('.OrganisationOpportunityCount', $item).toggle(!!item.opportunityCount).find('.MemberCount').text(item.opportunityCount);
|
|
$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.$pnl.contactImageDrag = $('#pnlContactImageDrop')
|
|
.on("dragenter", function (evt) { sax.haltEvent(evt); })
|
|
.on("dragover", function (evt) { sax.haltEvent(evt); if (!sax.$pnl.contactImageDrag.hasClass(sax.classFileDrag)) sax.$pnl.contactImageDrag.addClass(sax.classFileDrag); })
|
|
.on("dragleave", function (evt) { sax.haltEvent(evt); sax.$pnl.contactImageDrag.removeClass(sax.classFileDrag); })
|
|
.on("drop", function (evt) { sax.haltEvent(evt); sax.$pnl.contactImageDrag.removeClass(sax.classFileDrag); sax.onDropContactImage(evt); });
|
|
|
|
$('.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);
|
|
var opt = sax.dlgOpts();
|
|
opt.buttons[sax.dlg.btn.ok] = function () { sax.uploadContactImage(); };
|
|
opt.buttons[sax.dlg.btn.cancel] = function () { $(this).dialog('close'); };
|
|
sax.$dlg.selectContactImage = $('#dlgSelectContactImage').dialog(opt);
|
|
|
|
setTimeout(sax.refreshProfile, 200);
|
|
});
|
|
|
|
}(window, window.document));
|
|
|
|
/* The End */ |