223 lines
8.3 KiB
JavaScript
223 lines
8.3 KiB
JavaScript
/*
|
|
* Admin - Organisation page scripts.
|
|
*/
|
|
|
|
(function (win, doc, undef)
|
|
{
|
|
"use strict";
|
|
sax.itemIdPrefix = 'Itm_';
|
|
|
|
//--------------------------------------------------------------
|
|
sax.refreshResults = function (delay)
|
|
{
|
|
var $results = $('.sax-panel-results');
|
|
if (!sax.awaitingRefreshResponse)
|
|
{
|
|
var $items = $('.sax-panel-item-list', $results).fadeOut(200).empty();
|
|
var $msgs = $('.sax-panel-messages', $results).hide().empty().append($('<div class="sax-message">' + sax.msg.dataQuerying + '</div>')).fadeIn(200);
|
|
}
|
|
sax.ajaxRefreshResults = sax.ajaxRefreshResults || { url: sax.url.base + 'Organisation/Ajax/GetList', formId: 'frmOrganisationFilter', callbackFn: sax.doRefreshResults };
|
|
sax.doAjaxRequest(sax.ajaxRefreshResults, delay || 50);
|
|
sax.awaitingRefreshResponse = true;
|
|
}
|
|
sax.doRefreshResults = function (response)
|
|
{
|
|
sax.debug('doRefreshResults', response);
|
|
delete sax.awaitingRefreshResponse;
|
|
sax.refreshControlValues(response.controlValues);
|
|
var $results = $('.sax-panel-results');
|
|
var $msgs = $('.sax-panel-messages', $results).hide().empty();
|
|
var $items = $('.sax-panel-item-list', $results).hide().empty();
|
|
var $templ = $('.sax-panel-item-template .sax-panel-item.Organisation', $results);
|
|
if (!response.success) return;
|
|
// Reference data - Statuses.
|
|
if (response.defaultStatusCode) sax.data.defaultStatusCode = response.defaultStatusCode;
|
|
if (response.statuses)
|
|
sax.populateSelectCodeDesc('#cbOrganisationStatus', response.statuses);
|
|
// Items.
|
|
var items = response.organisations;
|
|
if (!items.length)
|
|
return $msgs.append($('<div class="sax-message">' + sax.msg.dataNoneFound + '</div>')).fadeIn(500);
|
|
for (let itemIdx = 0; itemIdx < items.length; itemIdx++)
|
|
{
|
|
let item = items[itemIdx];
|
|
let $item = $templ.clone();
|
|
sax.populateItem($item, item);
|
|
$items.append($item);
|
|
}
|
|
$items.fadeIn(50);
|
|
}
|
|
sax.populateItem = function ($item, item)
|
|
{
|
|
if (!item) return;
|
|
$item.prop('id', sax.itemIdPrefix + item.id);
|
|
$('.OrganisationName', $item).text(item.name);
|
|
$('.OrganisationType', $item).text(item.typeDesc);
|
|
$('.OrganisationCategory', $item).text(item.categoryDesc);
|
|
$('.OrganisationRegion', $item).text(item.regionName);
|
|
$('.OrganisationSport', $item).text(item.sportName);
|
|
$('.OrganisationMemberCount', $item).on('click', function () { sax.onClickMemberCount(item.id); }).find('.MemberCount').text(item.memberCount);
|
|
$('.StatusDesc', $item).text(item.statusDesc);
|
|
$('.sax-action.sax-item-update', $item).off('click').on('click', function () { sax.updateItem(item.id) })
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
sax.selectRegion = function ()
|
|
{
|
|
if (!sax.data.regions)
|
|
{
|
|
let handleRegionsResponse = function (response)
|
|
{
|
|
if (response && response.success && response.regions)
|
|
sax.data.regions = response.regions;
|
|
sax.showSelectRegion();
|
|
}
|
|
sax.ajaxRegions = sax.ajaxRegions || { url: sax.url.base + 'Region/Ajax/GetList', formId: 'frmNavigate', callbackFn: handleRegionsResponse };
|
|
sax.doAjaxRequest(sax.ajaxRegions, 50);
|
|
}
|
|
else sax.showSelectRegion();
|
|
}
|
|
sax.showSelectRegion = function ()
|
|
{
|
|
sax.data.selectItem.fn.selectItem({ caption: sax.dlg.title.selectRegion, items: sax.data.regions, fnCallback: sax.onRegionSelected });
|
|
}
|
|
sax.onRegionSelected = function (rgn)
|
|
{
|
|
sax.debug('onRegionSelected', rgn);
|
|
let $frm = sax.$frm.organisation;
|
|
$('.OrganisationRegionId', $frm).val(rgn.id);
|
|
$('.OrganisationRegionCaption', $frm).val(rgn.name);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
sax.selectSport = function ()
|
|
{
|
|
if (!sax.data.sports)
|
|
{
|
|
let handleSportsResponse = function (response)
|
|
{
|
|
if (response && response.success && response.sports)
|
|
sax.data.sports = response.sports;
|
|
sax.showSelectSport();
|
|
}
|
|
sax.ajaxSports = sax.ajaxSports || { url: sax.url.base + 'Sport/Ajax/GetList', formId: 'frmNavigate', callbackFn: handleSportsResponse };
|
|
sax.doAjaxRequest(sax.ajaxSports, 50);
|
|
}
|
|
else sax.showSelectSport();
|
|
}
|
|
sax.showSelectSport = function ()
|
|
{
|
|
sax.data.selectItem.fn.selectItem({ caption: sax.dlg.title.selectSport, items: sax.data.sports, fnCallback: sax.onSportSelected });
|
|
}
|
|
sax.onSportSelected = function (rgn)
|
|
{
|
|
sax.debug('onSportSelected', rgn);
|
|
let $frm = sax.$frm.organisation;
|
|
$('.OrganisationSportId', $frm).val(rgn.id);
|
|
$('.OrganisationSportCaption', $frm).val(rgn.name);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
sax.createItem = function ()
|
|
{
|
|
let $frm = sax.$frm.organisation;
|
|
$('.OrganisationId,.OrganisationRegionId,.OrganisationSportId,input[type="text"],textarea,select', $frm).val('');
|
|
$('.OrganisationStatus', $frm).val(sax.data.defaultStatusCode);
|
|
sax.clearControlErrors();
|
|
sax.$dlg.organisation.dialog('option', 'title', sax.dlg.title.createOrganisation);
|
|
sax.openDialog(sax.$dlg.organisation, 600, 600);
|
|
}
|
|
sax.doCreateItem = function ()
|
|
{
|
|
sax.storeItem();
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
sax.updateItem = function (id)
|
|
{
|
|
$('.OrganisationId', sax.$frm.organisationId).val(id);
|
|
sax.ajaxUpdateItem = sax.ajaxUpdateItem || { url: sax.url.base + 'Organisation/Ajax/GetItem', formId: 'frmOrganisationId', callbackFn: sax.onUpdateItem };
|
|
sax.doAjaxRequest(sax.ajaxUpdateItem, 50);
|
|
}
|
|
sax.onUpdateItem = function (response)
|
|
{
|
|
//sax.debug('onUpdateItem', response);
|
|
let $frm = sax.$frm.organisation;
|
|
$('.OrganisationId,input[type="text"],textarea,select', $frm).val('');
|
|
if (!response.success) return;
|
|
let item = response.organisation;
|
|
$('.OrganisationId', $frm).val(item.id);
|
|
$('.OrganisationName', $frm).val(item.name);
|
|
$('.OrganisationType', $frm).val(item.typeCode);
|
|
$('.OrganisationCategory', $frm).val(item.categoryCode);
|
|
$('.OrganisationRegionId', $frm).val(item.regionId);
|
|
$('.OrganisationRegionCaption', $frm).val(item.regionName);
|
|
$('.OrganisationSportId', $frm).val(item.sportId);
|
|
$('.OrganisationSportCaption', $frm).val(item.sportName);
|
|
$('.OrganisationStatus', $frm).val(item.statusCode);
|
|
sax.clearControlErrors();
|
|
sax.$dlg.organisation.dialog('option', 'title', sax.dlg.title.updateOrganisation);
|
|
sax.openDialog(sax.$dlg.organisation, 600, 600);
|
|
}
|
|
sax.doUpdateItem = function ()
|
|
{
|
|
sax.storeItem();
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
sax.storeItem = function ()
|
|
{
|
|
sax.ajaxStoreItem = sax.ajaxStoreItem || { url: sax.url.base + 'Organisation/Ajax/StoreItem', formId: 'frmOrganisation', callbackFn: sax.onStoreItem };
|
|
sax.doAjaxRequest(sax.ajaxStoreItem, 50);
|
|
}
|
|
sax.onStoreItem = function (response)
|
|
{
|
|
//sax.debug('onStoreItem', response);
|
|
sax.refreshControlValues(response.controlValues);
|
|
if (!response.success) return;
|
|
sax.$dlg.organisation.dialog('close');
|
|
|
|
var item = response.organisation;
|
|
var $item = $('#' + sax.itemIdPrefix + item.id);
|
|
if (!$item.length)
|
|
{
|
|
var $results = $('.sax-panel-results');
|
|
$item = $('.sax-panel-item-template .sax-panel-item.Organisation', $results).clone();
|
|
$('.sax-panel-item-list', $results).prepend($item).show();
|
|
}
|
|
sax.populateItem($item, item)
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
sax.onClickMemberCount = function (id)
|
|
{
|
|
if (!(id * 1)) return;
|
|
sax.doPleaseWait();
|
|
let $frm = $('#frmOrganisationId');
|
|
$('.OrganisationId', $frm).val(id);
|
|
$frm.prop('action', sax.url.base + 'Organisation/Members').submit();
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
$(function ()
|
|
{
|
|
$('.sax-panel-filter .sax-action.sax-item-create').on('click', function () { sax.createItem(); });
|
|
$('.sax-panel-filter .sax-action.sax-results-refresh').on('click', function () { sax.refreshResults(); });
|
|
$('.sax-input').on('input', function () { sax.clearControlError(this); });
|
|
|
|
sax.$frm.filter = $('#frmOrganisationFilter');
|
|
$('.FilterOrganisation', sax.$frm.filter).on('input', function () { sax.refreshResults(250); });
|
|
sax.$frm.organisationId = $('#frmOrganisationId');
|
|
sax.$frm.organisation = $('#frmOrganisation');
|
|
|
|
var opt = sax.dlgOpts();
|
|
opt.buttons[sax.dlg.btn.ok] = function () { sax.doCreateItem(); };
|
|
opt.buttons[sax.dlg.btn.cancel] = function () { $(this).dialog('close'); };
|
|
sax.$dlg.organisation = $('#dlgOrganisation').dialog(opt);
|
|
|
|
setTimeout(sax.refreshResults, 250);
|
|
});
|
|
|
|
}(window, window.document));
|
|
|
|
/* The End */ |