Files
Saxonite/SaxoniteCoreWebOnline/wwwroot/js/sax-usr-org.js
T
2021-11-20 15:17:48 +00:00

185 lines
7.7 KiB
JavaScript

/*
* Account page scripts.
*/
(function (win, doc, undef)
{
"use strict";
let po = sax.mdl.profileOrganisations = sax.mdl.profileOrganisations || { $pnl: {}, $dlg: {}, $frm: {} };
let $pnl = po.$pnl, $dlg = po.$dlg, $frm = po.$frm;
//--------------------------------------------------------------
sax.refreshProfileOrganisationsInfo = function (delay)
{
$pnl.section.removeClass('sax-edit').addClass('sax-populating');
$('.sax-property', $pnl.section).hide();
sax.showDataRefreshingMsg($pnl.section);
sax.refreshProfileOrganisations(po.onRefreshProfileOrganisationsInfo);
}
sax.refreshProfileOrganisations = function (callbackFn)
{
//sax.debug('refreshProfileOrganisations');
delete sax.page.profileOrganisationsChanged;
sax.ajax.profileOrganisations = sax.ajax.profileOrganisations || { url: sax.url.base + 'Account/Ajax/GetProfileOrganisations', formId: 'frmNavigate', noWaitIcon: true };
sax.ajax.profileOrganisations.callbackFn = callbackFn;
sax.doAjaxRequest(sax.ajax.profileOrganisations, 50);
}
po.onRefreshProfileOrganisationsInfo = function (response)
{
//sax.debug('onRefreshProfileOrganisationsInfo', response);
if (!response || !response.success) return;
$('.sax-message', $pnl.section).stop(true, false).fadeOut(200).empty();
let items = response.organisations;
if (!items) return;
let $items = $('.sax-panel-results.Organisations', $pnl.section).empty();
for (let itemIdx = 0; itemIdx < items.length; itemIdx++)
$items.append(po.populateItem(po.getItemTemplate(), items[itemIdx]));
$items.fadeIn(50);
sax.showNoInfoMsg($pnl.section);
$pnl.section.removeClass('sax-populating');
}
po.populateItem = function ($item, item)
{
if (!item) return;
$('.OrganisationName', $item).text(item.name);
$('.OrganisationSport', $item).text(item.sportName);
$('.OrganisationRegionCountry', $item).text(item.regionNameCountry);
$('.OrganisationMemberCount', $item).toggle(!!item.memberCount).find('.MemberCount').text(item.memberCount);
$('.OrganisationOpportunityCount', $item).toggle(!!item.opportunityCount).find('.MemberCount').text(item.opportunityCount);
let $bgr = $('.sax-burger', $item);
let $mnu = $('ul.sax-dropdown-menu', $bgr).empty();
if (item.admin)
{
let fnUpd = function () { po.updateOrganisation($item, item); };
$mnu.append(po.getItemMenuOption(sax.lbl.edit, fnUpd, 'sax-edit'));
$('.sax-caption .sax-action', $item).off('click').on('click', fnUpd);
$item.off('dblclick').on('dblclick', fnUpd);
}
else $('.sax-caption .sax-action', $item).removeClass('sax-action');
$bgr.toggle(!!$('.sax-dropdown-menu .sax-dropdown-item', $item).length);
return $item;
}
//--------------------------------------------------------------
po.getHeaderDropdownTemplate = function ()
{
return $('.sax-panel-item-template .sax-dropdown-menu.ProfileOrganisations li.sax-dropdown-item', $pnl.section).clone();
}
po.getItemTemplate = function ()
{
return $('.sax-panel-item-template .sax-panel-item.Organisation', $pnl.section).clone();
}
po.getItemDropdownTemplate = function ()
{
return $('.sax-panel-item-template .sax-dropdown-menu.ProfileOrganisation li.sax-dropdown-item', $pnl.section).clone();
}
po.getHeaderMenuOption = function (lbl, fn, cls)
{
return po.getMenuOption(po.getHeaderDropdownTemplate(), lbl, fn, cls);
}
po.getItemMenuOption = function (lbl, fn, cls)
{
return po.getMenuOption(po.getItemDropdownTemplate(), lbl, fn, cls);
}
po.getMenuOption = function ($opt, lbl, fn, cls)
{
return $opt.find('div.sax-label').text(lbl).end().on('click', fn).addClass(cls);
}
//--------------------------------------------------------------
po.updateOrganisation = function ($item, item)
{
//sax.debug('po.updateOrganisation', $item, item);
$('.OrganisationId', $frm.orgId).val(item.id);
sax.ajax.profileOrganisation = sax.ajax.profileOrganisation || { url: sax.url.base + 'Account/Ajax/GetProfileOrganisation', formId: 'frmProfileOrganisationId', callbackFn: po.doUpdateOrganisation };
sax.doAjaxRequest(sax.ajax.profileOrganisation, 50);
}
po.doUpdateOrganisation = function (response)
{
//sax.debug('doUpdateOrganisation', response);
if (!response || !response.success) return;
let item = response.organisation;
if (!item) return;
$('.OrganisationId', $frm.org).val(item.id);
$('.OrganisationName', $frm.org).val(item.name);
$('.OrganisationCategory', $frm.org).val(item.categoryCode);
$('.OrganisationType', $frm.org).val(item.typeCode);
$('.OrganisationSportId', $frm.org).val(item.sportId);
$('.OrganisationSportCaption', $frm.org).val(item.sportName);
$('.OrganisationRegionIdCountry', $frm.org).val(item.regionIdCountry);
$('.OrganisationRegionCaptionCountry', $frm.org).val(item.regionNameCountry);
let address = item.address || {};
$('input.OrganisationAddressId', $frm.org).val(address.id);
$('input.OrganisationAddressLine1', $frm.org).val(address.line1);
$('input.OrganisationAddressLine2', $frm.org).val(address.line2);
$('input.OrganisationAddressLine3', $frm.org).val(address.line3);
$('input.OrganisationAddressTown', $frm.org).val(address.town);
$('input.OrganisationAddressProvince', $frm.org).val(address.province);
$('input.OrganisationAddressCountry', $frm.org).val(address.country);
$('input.OrganisationAddressPostalCode', $frm.org).val(address.postalCode);
sax.openDialog($dlg.org, 600, 600);
}
po.storeOrganisation = function ()
{
let fn = function (response)
{
//sax.debug('handleStoreOrganisationResponse', response);
if (!response) return;
sax.refreshControlValues(response.controlValues, $frm.org);
if (!response.success) return;
$dlg.org.dialog('close');
po.cleanUp();
}
or.ajax.storeOrg = or.ajax.storeOrg || { url: sax.url.base + 'Account/Ajax/StoreProfileOrganisation', formId: 'frmProfileOrganisation', callbackFn: fn };
sax.doAjaxRequest(or.ajax.storeOrg, 50);
}
po.cleanUp = function ()
{
}
//--------------------------------------------------------------
po.selectOrgSport = function ()
{
sax.mdl.selectSport.fn.selectSport({ caption: sax.dlg.title.selectSport, sportId: $('.OrganisationSportId', $frm.org).val(), fnCallback: po.onSelectOrgSport })
}
po.onSelectOrgSport = function (sport)
{
sax.clearControlError($('.OrganisationSportId', $frm.org).val(sport.id));
$('.OrganisationSportCaption', $frm.org).val(sport ? sport.name : '');
}
//--------------------------------------------------------------
po.selectOrgRegionCountry = function ()
{
sax.mdl.selectRegion.fn.selectRegion({ caption: sax.dlg.title.selectRegion, regionId: $('.OrganisationRegionIdCountry', $frm.org).val(), typesInc: [30], fnCallback: po.onSelectOrgRegionCountry })
}
po.onSelectOrgRegionCountry = function (region)
{
sax.clearControlError($('.OrganisationRegionIdCountry', $frm.org).val(region.id));
$('.OrganisationRegionCaptionCountry', $frm.org).val(region ? region.name : '');
}
//--------------------------------------------------------------
$(function ()
{
$pnl.section = $('.sax-panel-section.ProfileOrganisations');
$frm.orgId = $('#frmProfileOrganisationId', $pnl.section);
var opt = sax.dlgOpts();
opt.buttons[sax.dlg.btn.ok] = function () { po.storeOrganisation(); };
opt.buttons[sax.dlg.btn.cancel] = function () { $(this).dialog('close'); };
$dlg.org = $('#dlgProfileOrganisation').dialog(opt);
$frm.org = $('#frmProfileOrganisation', $dlg.org);
$frm.org.on('dblclick', 'input.OrganisationSportCaption', po.selectOrgSport).on('click', 'button.SelectSport', po.selectOrgSport);
$frm.org.on('dblclick', 'input.OrganisationRegionCaptionCountry', po.selectOrgRegionCountry).on('click', 'button.SelectRegionCountry', po.selectOrgRegionCountry);
});
//--------------------------------------------------------------
}(window, window.document));
/* The End */