108 lines
4.4 KiB
JavaScript
108 lines
4.4 KiB
JavaScript
/*
|
|
* Sport contacts.
|
|
*/
|
|
(function (win, doc, undef)
|
|
{
|
|
//--------------------------------------------------------------
|
|
"use strict";
|
|
let sc = sax.mdl.sportContact = { fn: {}, ajax: {}, data: {}, $pnl: {}, $dlg: {}, $frm: {}, $ctrl: {} };
|
|
//--------------------------------------------------------------
|
|
/*
|
|
* Sport Contact config:
|
|
* - caption - dialog title.
|
|
* - contact:
|
|
* - type
|
|
* - name
|
|
* - email
|
|
* - phone
|
|
* - typesUsed
|
|
* - fnCallback - method to call on completion to store details.
|
|
*/
|
|
sc.showSportContact = function (cfg)
|
|
{
|
|
//sax.debug('showSportContact', cfg);
|
|
sc.fn.cleanUp();
|
|
sc.data.cfg = cfg;
|
|
sc.populateContactTypes(cfg);
|
|
sc.populateTitles(cfg);
|
|
sc.fn.displaySportContact(cfg.contact || {});
|
|
sax.clearControlErrors(sc.$dlg.sptCnt);
|
|
sax.openDialog(sc.$dlg.sptCnt.dialog('option', { title: sc.data.cfg.caption || 'Sport Contact' }), sc.data.cfg.width || 640, sc.data.cfg.height || 320);
|
|
}
|
|
//--------------------------------------------------------------
|
|
sc.populateContactTypes = function (cfg)
|
|
{
|
|
let contact = cfg.contact || {};
|
|
sc.$ctrl.contactType.empty();
|
|
if (!contact.contactType)
|
|
sc.$ctrl.contactType.append($('<option>').prop('selected', true));
|
|
for (let typ of cfg.contactTypes || [])
|
|
{
|
|
if (typ.code && typ.code == cfg.contactType || !(cfg.contactTypesUsed || []).includes(typ.code))
|
|
sc.$ctrl.contactType.append($('<option>').prop('value', typ.code).text(typ.desc));
|
|
}
|
|
//sc.$ctrl.contactType.val(contact.contactType).attr('disabled', contact.contactType && sc.$ctrl.contactType.val() == contact.contactType ? true : null);
|
|
}
|
|
sc.populateTitles = function (cfg)
|
|
{
|
|
let contact = cfg.contact || {};
|
|
sc.$ctrl.title.empty();
|
|
sc.$ctrl.title.append($('<option>').prop('selected', true));
|
|
for (let typ of cfg.titles || [])
|
|
{
|
|
if (typ.code && typ.code == cfg.title || !(cfg.titlesUsed || []).includes(typ.code))
|
|
sc.$ctrl.title.append($('<option>').prop('value', typ.code).text(typ.desc));
|
|
}
|
|
}
|
|
sc.fn.displaySportContact = function (contact)
|
|
{
|
|
sc.$ctrl.emailAddress.val(contact.email);
|
|
}
|
|
//--------------------------------------------------------------
|
|
sc.fn.storeSportContact = function ()
|
|
{
|
|
//sax.debug('storeSportContact');
|
|
let cfg = sc.data.cfg;
|
|
sax.clearControlErrors(sc.$dlg.sptCnt);
|
|
let fn = function (response)
|
|
{
|
|
//sax.debug('storeSportContact handle response', response);
|
|
sax.refreshControlValues(response.controlValues, sc.$dlg.sptCnt);
|
|
if (!response.success || sax.hasControlErrors(sc.$dlg.sptCnt)) return;
|
|
let contact = { contactType: sc.$ctrl.contactType.val(), email: sc.$ctrl.emailAddress.val(), title: sc.$ctrl.title.val(), firstName: sc.$ctrl.firstName.val(), lastName: sc.$ctrl.lastName.val() };
|
|
if (cfg.fnCallback) cfg.fnCallback(contact);
|
|
sc.$dlg.sptCnt.dialog('close');
|
|
sc.fn.cleanUp();
|
|
}
|
|
sc.ajax.sportContact = sc.ajax.sportContact || { url: sax.url.base + 'Account/Ajax/ValidateProfileSportContact', formId: sc.$frm.sptCnt.prop('id'), callbackFn: fn };
|
|
sax.doAjaxRequest(sc.ajax.sportContact, 50);
|
|
}
|
|
//--------------------------------------------------------------
|
|
sc.fn.onDlgSize = function ()
|
|
{
|
|
}
|
|
sc.fn.cleanUp = function ()
|
|
{
|
|
$('.sax-input,.sax-textarea,.sax-select', sc.$frm.sptCnt).val('');
|
|
sc.data = {};
|
|
}
|
|
//--------------------------------------------------------------
|
|
$(function ()
|
|
{
|
|
var opt = sax.dlgOpts();
|
|
opt.open = function (evt, ui) { sc.fn.onDlgSize(); };
|
|
opt.resize = function (evt, ui) { sc.fn.onDlgSize(); };
|
|
opt.buttons[sax.dlg.btn.ok] = function () { sc.fn.storeSportContact(); };
|
|
opt.buttons[sax.dlg.btn.cancel] = function () { sc.fn.cleanUp(); $(this).dialog('close'); };
|
|
sc.$dlg.sptCnt = $('#dlgSportContact').dialog(opt);
|
|
sc.$frm.sptCnt = $('#frmProfileSportContact', sc.$dlg.sptCnt);
|
|
sc.$frm.sptCnt.on('input', '.sax-input, .sax-textarea', function () { sax.clearControlError(this); }).on('change', '.sax-select', function () { sax.clearControlError(this); });
|
|
sc.$ctrl.contactType = $('.sax-select.ContactType', sc.$frm.sptCnt);
|
|
sc.$ctrl.emailAddress = $('.sax-input.ContactEmailAddress', sc.$frm.sptCnt);
|
|
sc.$ctrl.title = $('.sax-select.ContactTitle', sc.$frm.sptCnt);
|
|
sc.$ctrl.firstName = $('.sax-input.ContactFirstName', sc.$frm.sptCnt);
|
|
sc.$ctrl.lastName = $('.sax-input.ContactLastName', sc.$frm.sptCnt);
|
|
});
|
|
//--------------------------------------------------------------
|
|
}(window, window.document));
|
|
/* The End */ |