/* * Admin - Organisation Address scripts. */ (function (win, doc, undef) { "use strict"; let oa = sax.mdl.organisationAddress = { data: {}, ajax: {} }; let $pnl = oa.$pnl = {}, $frm = oa.$frm = {}, $dlg = oa.$dlg = {}; let mdlOrg = function () { return sax.mdl.organisations; } //-------------------------------------------------------------- oa.updateItemAddress = function (item, $item) { oa.init(); $('.OrganisationId', $frm.orgId).val(item.id); oa.ajax.updateItemAddr = oa.ajax.updateItemAddr || { url: sax.url.base + 'Organisation/Ajax/GetItem', formId: 'frmOrganisationId', callbackFn: oa.onUpdateItemAddress }; sax.doAjaxRequest(oa.ajax.updateItemAddr, 50); } oa.onUpdateItemAddress = function (response) { //sax.debug('onUpdateItemAddress', response); if (!response.success) return; // Address. let item = response.organisation; let addr = item.address || {}; let frm = $frm.orgAddr; $('input.OrganisationId', frm).val(item.id); $('input.OrganisationName', frm).val(item.name); $('input.AddressId', frm).val(addr.id); $('input.AddressLine1', frm).val(addr.line1); $('input.AddressLine2', frm).val(addr.line2); $('input.AddressLine3', frm).val(addr.line3); $('input.AddressTown', frm).val(addr.town); $('input.AddressRegionIdProvince', frm).val(addr.regionIdProvince); $('input.AddressProvince', frm).val(addr.regionNameProvince); $('input.AddressPostalCode', frm).val(addr.postalCode); $('input.AddressRegionIdCountry, input.AddressRegionNameCountry', frm).val(''); if (addr.regionIdCountry) { $('input.AddressRegionIdCountry', frm).val(addr.regionIdCountry); $('input.AddressRegionNameCountry', frm).val(addr.regionNameCountry); } else if (item.regionPrimary.country) { $('input.AddressRegionIdCountry', frm).val(item.regionPrimary.id); $('input.AddressRegionNameCountry', frm).val(item.regionPrimary.name); } sax.clearControlErrors(frm); sax.openDialog($dlg.orgAddr, 640, 480); } //-------------------------------------------------------------- oa.selectOrgAddrRegionCountry = function () { if (!mdlOrg().data.regions) mdlOrg().populateRegions(oa.showSelectOrgAddrRegionCountry); else oa.showSelectOrgAddrRegionCountry(); } oa.showSelectOrgAddrRegionCountry = function () { let regions = []; for (let rgn of mdlOrg().data.regions) if (rgn.regionType == 30) regions.push(rgn); sax.data.selectItem.fn.selectItem({ caption: sax.dlg.title.selectCountry, itemId: $('input.AddressRegionIdCountry', $frm.orgAddr).val(), items: regions, fnCallback: oa.onOrgAddrRegionCountrySelected }); } oa.onOrgAddrRegionCountrySelected = function (rgn) { //sax.debug('onRegionSelected', rgn); let frm = $frm.orgAddr; sax.clearControlError($('input.AddressRegionIdCountry', frm).val(rgn.id)); $('.AddressRegionNameCountry', frm).val(rgn.name); } //-------------------------------------------------------------- oa.storeItemAddress = function () { oa.ajax.storeItemAddr = oa.ajax.storeItemAddr || { url: sax.url.base + 'Organisation/Ajax/StoreItem', formId: 'frmOrganisationAddress', callbackFn: oa.onStoreItemAddress }; sax.doAjaxRequest(oa.ajax.storeItemAddr, 50); } oa.onStoreItemAddress = function (response) { //sax.debug('onStoreItemAddress', response); sax.refreshControlValues(response.controlValues, $frm.orgAddr); if (!response.success) return; $dlg.orgAddr.dialog('close'); mdlOrg().refreshItem(response.organisation); } //-------------------------------------------------------------- oa.init = function () { if ($frm.orgId) return; $frm.orgId = $('#frmOrganisationId'); // Organisation Address dialog. var opt = sax.dlgOpts(); opt.buttons[sax.dlg.btn.ok] = function () { oa.storeItemAddress(); }; opt.buttons[sax.dlg.btn.cancel] = function () { $(this).dialog('close'); }; $dlg.orgAddr = $('#dlgOrganisationAddress').dialog(opt); // Organisation Address form. $frm.orgAddr = $('#frmOrganisationAddress'); $frm.orgAddr.on('input', '.sax-input, .sax-textarea', function () { sax.clearControlError(this); }).on('change', '.sax-select', function () { sax.clearControlError(this); }); $frm.orgAddr.on('dblclick', '.AddressRegionNameCountry', oa.selectOrgAddrRegionCountry).on('click', '.AddressRegionCountrySelect', oa.selectOrgAddrRegionCountry); } //-------------------------------------------------------------- }(window, window.document)); /* The End */