69 lines
2.6 KiB
JavaScript
69 lines
2.6 KiB
JavaScript
/*
|
|
* Contact Methods script.
|
|
*/
|
|
|
|
(function (win, doc, undef)
|
|
{
|
|
"use strict";
|
|
let cm = sax.mdl.contactMethods = { fn: {}, data: {}, ajax: {} };
|
|
let $dlg = cm.$dlg = {};
|
|
|
|
//--------------------------------------------------------------
|
|
/*
|
|
* Config:
|
|
* fnCallback Method to call to apply changes.
|
|
* methods Full list of methods.
|
|
* methodsUsed List of methods already in use.
|
|
* method Current selected method (if updating).
|
|
* value Current value.
|
|
*/
|
|
sax.editContactMethod = cm.fn.edit = function (cfg)
|
|
{
|
|
cm.fn.init();
|
|
cm.data.cfg = cfg || {};
|
|
cm.$mth.empty();
|
|
for (let mth of cfg.methods || [])
|
|
{
|
|
if (mth.code && mth.code == cfg.method || !(cfg.methodsUsed || []).includes(mth.code))
|
|
cm.$mth.append($('<option>').prop('value', mth.code).text(mth.desc));
|
|
}
|
|
cm.$mth.val(cfg.method).attr('disabled', cfg.method && cm.$mth.val() == cfg.method ? true : null);
|
|
cm.$val.val(cfg.value);
|
|
sax.openDialog($dlg.conMth, 600, 240);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
cm.fn.applyChanges = function ()
|
|
{
|
|
cm.ajax.applyChanges = cm.ajax.applyChanges || { url: sax.url.base + 'Reference/Ajax/ValidateContactMethod', callbackFn: cm.fn.onApplyChanges };
|
|
cm.ajax.applyChanges.formData = new FormData();
|
|
cm.ajax.applyChanges.formData.append("__RequestVerificationToken", $('#frmNavigate input[name="__RequestVerificationToken"]').val());
|
|
cm.ajax.applyChanges.formData.append("ContactMethod", $('select[name="ContactMethod"]', $dlg.conMth).val());
|
|
cm.ajax.applyChanges.formData.append("ContactValue", $('input[name="ContactValue"]', $dlg.conMth).val());
|
|
sax.doAjaxRequest(cm.ajax.applyChanges, 50);
|
|
}
|
|
cm.fn.onApplyChanges = function (response)
|
|
{
|
|
if (!response) return;
|
|
sax.refreshControlValues(response.controlValues, $dlg.conMth);
|
|
if (!response.success) return;
|
|
$dlg.conMth.dialog('close');
|
|
if (cm.data.cfg.fnCallback) cm.data.cfg.fnCallback(cm.$mth.val(), $('option:selected', cm.$mth).text(), cm.$val.val());
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
cm.fn.init = function ()
|
|
{
|
|
if ($dlg.conMth) return;
|
|
var opt = sax.dlgOpts();
|
|
opt.buttons[sax.dlg.btn.ok] = function () { cm.fn.applyChanges(); };
|
|
opt.buttons[sax.dlg.btn.cancel] = function () { $(this).dialog('close'); };
|
|
$dlg.conMth = $('#dlgContactMethod').dialog(opt);
|
|
cm.$mth = $('.sax-select.ContactMethod', $dlg.conMth);
|
|
cm.$val = $('.sax-input.ContactValue', $dlg.conMth);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
}(window, window.document));
|
|
|
|
/* The End */ |