221 lines
10 KiB
JavaScript
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 ()
|
|
{
|
|
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.data.genders = response.genders;
|
|
sax.data.months = response.months;
|
|
$('.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.refreshTextArea($section, 'AccountAbout', response.contact.about);
|
|
let $selGender = $('#cbAccountGender');
|
|
if (response.genders && response.genders.length)
|
|
sax.populateSelectCodeDesc($('#cbAccountGender'), response.genders);
|
|
sax.refreshSelect($section, 'AccountGender', response.contact.gender || '');
|
|
sax.refreshDob();
|
|
sax.refreshSelect($section, 'AccountDobYear', response.contact.dobYear);
|
|
sax.refreshDob();
|
|
sax.refreshSelect($section, 'AccountDobMonth', response.contact.dobMonth);
|
|
sax.refreshDob();
|
|
sax.refreshSelect($section, 'AccountDobDay', response.contact.dobDay);
|
|
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.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.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)
|
|
{
|
|
$dlg.selectContactImage.dialog('close');
|
|
$('img.AccountContact', $section).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 ()
|
|
{
|
|
sax.$pnl.proCon = $('.sax-panel-section.ProfileContact');
|
|
$('.sax-action.sax-edit', sax.$pnl.proCon).on('click', function (evt) { sax.refreshProfileContactForm(); });
|
|
$('input,textarea', sax.$pnl.proCon).on('input', function () { sax.clearControlErrors(); sax.page.profileContactChanged = true; });
|
|
$('select', sax.$pnl.proCon).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); });
|
|
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 */ |