Files
Saxonite/SaxoniteCoreWebOnline/wwwroot/js/sax-usr-pro.js
T
2022-05-16 15:01:01 +01:00

221 lines
10 KiB
JavaScript

/*
* Account page scripts.
*/
(function (win, doc, undef)
{
"use strict";
let $pnl = sax.$pnl, $dlg = sax.$dlg, $frm = sax.$frm;
//--------------------------------------------------------------
sax.refreshProfileContactInfo = function ()
{
if ($pnl.proCon.hasClass('sax-edit'))
$pnl.proCon.slideUp(750, function () { $pnl.proCon.removeClass('sax-edit').addClass('sax-populating').slideDown(750); });
$('.sax-property', $pnl.proCon).hide();
sax.showDataRefreshingMsg($pnl.proCon);
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').slideDown(750);
$('.sax-message', $pnl.proCon).stop(true, false).fadeOut(200).empty();
$('.sax-value', $pnl.proConInf).empty();
sax.refreshInfo($pnl.proConInf, 'AccountEmailAddress', response.contact.emailAddress);
sax.refreshInfo($pnl.proConInf, 'AccountName', response.contact.displayName);
sax.refreshInfo($pnl.proConInf, 'AccountLocation', response.contact.locationCaption);
$('img.AccountContact', $pnl.proConInf).prop('src', 'Image/Account/Contact/Profile?' + (new Date()).getTime());
sax.showNoInfoMsg($pnl.proConInf);
$pnl.proCon.removeClass('sax-populating');
}
sax.onRefreshProfileContactForm = function (response)
{
//sax.debug('onRefreshProfileContactForm', response);
if (!response || !response.success) return;
sax.data.genders = response.genders;
sax.data.months = response.months;
sax.data.imageContentTypes = response.imageContentTypes;
$('.sax-message', $pnl.proCon).stop(true, false).fadeOut(200).empty();
sax.refreshInput($pnl.proConFrm, 'AccountEmailAddress', response.contact.emailAddress);
sax.refreshSelect($pnl.proConFrm, 'AccountTitle', response.contact.title);
sax.refreshInput($pnl.proConFrm, 'AccountFirstName', response.contact.firstName);
sax.refreshInput($pnl.proConFrm, 'AccountLastName', response.contact.lastName);
sax.refreshTextArea($pnl.proConFrm, 'AccountAbout', response.contact.about);
let $selGender = $('#cbAccountGender');
if (response.genders && response.genders.length)
sax.populateSelectCodeDesc($('#cbAccountGender'), response.genders);
sax.refreshSelect($pnl.proConFrm, 'AccountGender', response.contact.gender || '');
sax.refreshDob();
sax.refreshSelect($pnl.proConFrm, 'AccountDobYear', response.contact.dobYear);
sax.refreshDob();
sax.refreshSelect($pnl.proConFrm, 'AccountDobMonth', response.contact.dobMonth);
sax.refreshDob();
sax.refreshSelect($pnl.proConFrm, 'AccountDobDay', response.contact.dobDay);
sax.refreshInput($pnl.proConFrm, 'AccountRegionIdCountry', response.contact.regionIdCountry);
sax.refreshInput($pnl.proConFrm, 'AccountRegionCaptionCountry', response.contact.regionCaptionCountry);
sax.refreshInput($pnl.proConFrm, 'AccountRegionIdProvince', response.contact.regionIdProvince);
sax.refreshInput($pnl.proConFrm, 'AccountRegionCaptionProvince', response.contact.regionCaptionProvince);
$('img.AccountContact', $pnl.proConFrm).prop('src', 'Image/Account/Contact/Profile?' + (new Date()).getTime());
$('.sax-panel-section').slideUp(750, function () { $pnl.proCon.addClass('sax-edit').slideDown(750); });
}
sax.storeProfileContact = 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.success) return;
sax.refreshProfileContactInfo();
}
//--------------------------------------------------------------
sax.refreshDob = function ()
{
//sax.debug('refreshDob', $('#cbAccountDobYear').val(), $('#cbAccountDobMonth').val(), $('#cbAccountDobDay').val());
let now = new Date();
let $selDobYear = $('#cbAccountDobYear');
if (!$('option', $selDobYear).length)
{
$selDobYear.append($('<option>'));
for (let y = now.getFullYear(); y >= now.getFullYear() - 110 - now.getFullYear() % 10; y--)
$selDobYear.append($('<option>').prop('value', y).text(y));
}
let yearVal = $selDobYear.val();
let $selDobMonth = $('#cbAccountDobMonth');
if (!$('option', $selDobMonth).length)
{
$selDobMonth.append($('<option>'));
for (let m = 1; m <= sax.data.months.length; m++)
$selDobMonth.append($('<option>').prop('value', m).text(sax.data.months[m - 1].desc));
}
if (!yearVal)
$selDobMonth.val('');
$selDobMonth.prop('disabled', !yearVal);
let monthVal = $selDobMonth.val();
let $selDobDay = $('#cbAccountDobDay');
let dayVal = $selDobDay.val();
$selDobDay.empty();
if (!!yearVal && !!monthVal)
{
$selDobDay.append($('<option>'));
for (let dt = new Date(yearVal, monthVal - 1, 1); dt.getMonth() == monthVal - 1; dt.setDate(dt.getDate() + 1))
$selDobDay.append($('<option>').prop('value', dt.getDate()).text(dt.getDate()));
$selDobDay.val(dayVal);
}
if (!monthVal)
$selDobDay.val('');
$selDobDay.prop('disabled', !monthVal);
}
//--------------------------------------------------------------
sax.selectRegionCountry = function ()
{
sax.mdl.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 ((sax.data.imageContentTypes||[]).indexOf(file.type) < 0) 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($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;
sax.refreshControlValues(response.controlValues, context);
$(".UploadMessage", context).empty();
$('img.ContactImageUploadProgress', context).hide();
if (response.success)
{
$dlg.selectContactImage.dialog('close');
$('img.AccountContact', $pnl.proConFrm).prop('src', 'Image/Account/Contact/Profile?' + (new Date()).getTime());
}
}
sax.selectContactImage = function ()
{
//sax.debug('selectContactImage');
let dlg = $dlg.selectContactImage.dialog('option', { title: sax.dlg.title.imageUpload });
$('#ifContactImage', dlg).val('');
sax.openDialog(dlg, 560, 240);
}
sax.uploadContactImage = function ()
{
let dlg = $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);
}
//--------------------------------------------------------------
$(function ()
{
$pnl.proCon = $('.sax-panel-section.ProfileContact');
$pnl.proConInf = $('.sax-panel-info', $pnl.proCon);
$pnl.proConFrm = $('.sax-panel-form', $pnl.proCon);
$('.sax-action.sax-edit', $pnl.proConInf).on('click', function (evt) { sax.refreshProfileContactForm(); });
$('.sax-content', $pnl.proConInf).on('dblclick', function (evt) { sax.refreshProfileContactForm(); });
$('input,textarea', $pnl.proConFrm).on('input', function () { sax.clearControlErrors(); sax.page.profileContactChanged = true; });
$('select', $pnl.proConFrm).on('change', function () { sax.clearControlErrors(); sax.page.profileContactChanged = true; });
$pnl.contactImageDrag = $('#pnlContactImageDrop')
.on("dragenter", function (evt) { sax.haltEvent(evt); })
.on("dragover", function (evt) { sax.haltEvent(evt); if (!$pnl.contactImageDrag.hasClass(sax.classFileDrag)) $pnl.contactImageDrag.addClass(sax.classFileDrag); })
.on("dragleave", function (evt) { sax.haltEvent(evt); $pnl.contactImageDrag.removeClass(sax.classFileDrag); })
.on("drop", function (evt) { sax.haltEvent(evt); $pnl.contactImageDrag.removeClass(sax.classFileDrag); sax.onDropContactImage(evt); });
var opt = sax.dlgOpts();
opt.buttons[sax.dlg.btn.ok] = function () { sax.uploadContactImage(); };
opt.buttons[sax.dlg.btn.cancel] = function () { $(this).dialog('close'); };
$dlg.selectContactImage = $('#dlgSelectContactImage').dialog(opt);
});
//--------------------------------------------------------------
}(window, window.document));
/* The End */