255 lines
9.9 KiB
JavaScript
255 lines
9.9 KiB
JavaScript
/*
|
|
* Admin - Organisation Association scripts.
|
|
*/
|
|
|
|
(function (win, doc, undef)
|
|
{
|
|
"use strict";
|
|
let oa = sax.mdl.organisationAssociations = { data: {}, ajax: {}, itemIdPrefix: 'oa_' };
|
|
let $pnl = oa.$pnl = {}, $frm = oa.$frm = {}, $dlg = oa.$dlg = {};
|
|
|
|
//--------------------------------------------------------------
|
|
oa.refreshResults = function (delay)
|
|
{
|
|
if (!oa.awaitingRefreshResponse)
|
|
{
|
|
var $items = $('.sax-panel-item-list', $pnl.results).fadeOut(200).empty();
|
|
var $msgs = $('.sax-panel-messages', $pnl.results).hide().empty().append($('<div class="sax-message">' + sax.msg.dataQuerying + '</div>')).fadeIn(200);
|
|
}
|
|
oa.ajax.refreshResults = oa.ajax.refreshResults || { url: sax.url.base + 'Organisation/Ajax/GetAssociationList', formId: 'frmAssociationFilter', callbackFn: oa.doRefreshResults };
|
|
sax.doAjaxRequest(oa.ajax.refreshResults, delay || 50);
|
|
oa.awaitingRefreshResponse = true;
|
|
}
|
|
oa.doRefreshResults = function (response)
|
|
{
|
|
//sax.debug('doRefreshResults', response);
|
|
delete oa.awaitingRefreshResponse;
|
|
sax.refreshControlValues(response.controlValues);
|
|
var $msgs = $('.sax-panel-messages', $pnl.results).hide().empty();
|
|
var $items = $('.sax-panel-item-list', $pnl.results).hide().empty();
|
|
sax.refreshPaging(response, '#frmAssociationFilter', oa.refreshResults);
|
|
if (!response.success) return;
|
|
// Reference data - association types.
|
|
if (response.associationTypes && response.associationTypes.length)
|
|
oa.data.associationTypes = response.associationTypes;
|
|
// Reference data - Statuses.
|
|
if (response.defaultStatusCode) oa.data.defaultStatusCode = response.defaultStatusCode;
|
|
if (response.statuses)
|
|
sax.populateSelectCodeDesc('#cbAssociationStatus', response.statuses);
|
|
// Menu.
|
|
var $bgr = $('.sax-burger', $pnl.filter).hide();
|
|
var $mnu = $('ul.sax-dropdown-menu', $bgr).empty();
|
|
$mnu.append(oa.getFilterMenuOption(sax.lbl.refresh, function () { oa.refreshResults(); }, 'sax-refresh'));
|
|
$mnu.append(oa.getFilterMenuOption(sax.lbl.add, function () { oa.createItem(); }, 'sax-add'));
|
|
$bgr.toggle(!!$('.sax-dropdown-item', $mnu).length);
|
|
// Items.
|
|
var items = response.associations;
|
|
if (!items.length)
|
|
return $msgs.append($('<div class="sax-message">' + sax.msg.dataNoneFound + '</div>')).fadeIn(500);
|
|
for (let itemIdx = 0; itemIdx < items.length; itemIdx++)
|
|
$items.append(oa.populateItem(oa.getItemTemplate(), items[itemIdx]));
|
|
$items.fadeIn(50);
|
|
}
|
|
oa.populateItem = function ($item, item)
|
|
{
|
|
if (!item) return;
|
|
$item.prop('id', oa.getItemIdProp(item.id));
|
|
let assoc = item.assoc || {};
|
|
let org = item.organisationAssoc || {};
|
|
$('.OrganisationName', $item).text(org.name);
|
|
$('.AssociationLabel', $item).text(assoc.label);
|
|
$('.Sport', $item).text(org.sport);
|
|
$('.Region', $item).text(org.region);
|
|
$('.sax-caption .sax-action').toggleClass('sax-action', !item.deleted);
|
|
let $mnu = $('ul.sax-dropdown-menu', $item).empty();
|
|
if (!item.deleted)
|
|
{
|
|
let fnUpdItm = function () { oa.updateItem(item, $item) };
|
|
$mnu.append(oa.getItemMenuOption(sax.lbl.edit, fnUpdItm, 'sax-edit'));
|
|
$item.on('click', '.sax-header .sax-caption', fnUpdItm).on('dblclick', fnUpdItm);
|
|
$mnu.append(oa.getItemMenuOption(sax.lbl.remove, function () { oa.removeItem(item, $item) }, 'sax-remove'));
|
|
}
|
|
$('.sax-burger', $item).toggle(!!$('.sax-dropdown-item', $mnu).length);
|
|
$('.sax-panel-messages', $pnl.results).hide().empty();
|
|
return $item;
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
oa.getItemIdProp = function (id)
|
|
{
|
|
return oa.itemIdPrefix + id;
|
|
}
|
|
oa.getFilterDropdownTemplate = function ()
|
|
{
|
|
return $('.sax-panel-item-template .sax-dropdown-menu.AssociationFilter li.sax-dropdown-item', $pnl.filter).clone();
|
|
}
|
|
oa.getItemTemplate = function ()
|
|
{
|
|
return $('.sax-panel-item-template .sax-panel-item.Association', $pnl.results).clone();
|
|
}
|
|
oa.getItemDropdownTemplate = function ()
|
|
{
|
|
return $('.sax-panel-item-template .sax-dropdown-menu.Association li.sax-dropdown-item', $pnl.results).clone();
|
|
}
|
|
oa.getFilterMenuOption = function (lbl, fn, cls)
|
|
{
|
|
return oa.getMenuOption(oa.getFilterDropdownTemplate(), lbl, fn, cls);
|
|
}
|
|
oa.getItemMenuOption = function (lbl, fn, cls)
|
|
{
|
|
return oa.getMenuOption(oa.getItemDropdownTemplate(), lbl, fn, cls);
|
|
}
|
|
oa.getMenuOption = function ($opt, lbl, fn, cls)
|
|
{
|
|
return $opt.find('div.sax-label').text(lbl).end().on('click', fn).addClass(cls);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
oa.selectFilterOrganisation = function ()
|
|
{
|
|
sax.selectOrganisation.fn.openDialog({ caption: sax.dlg.title.selectOrganisation, fnCallback: oa.onFilterOrganisationSelected });
|
|
}
|
|
oa.onFilterOrganisationSelected = function (id, name)
|
|
{
|
|
$('#ifFilterOrganisationId', $frm.filter).val(id);
|
|
$('#ifFilterOrganisation', $frm.filter).val(name);
|
|
oa.refreshResults(50);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
oa.selectAssocOrganisation = function ()
|
|
{
|
|
sax.selectOrganisation.fn.openDialog({ caption: sax.dlg.title.selectOrganisation, fnCallback: oa.onAssocOrganisationSelected });
|
|
}
|
|
oa.onAssocOrganisationSelected = function (id, name)
|
|
{
|
|
$('.OrganisationIdAssoc', $frm.assoc).val(id);
|
|
$('.OrganisationNameAssoc', $frm.assoc).val(name);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
oa.createItem = function ()
|
|
{
|
|
oa.clearItem();
|
|
let frm = $frm.assoc;
|
|
$('.NewItem', frm).val(1);
|
|
$('.OrganisationId', frm).val($('.OrganisationId', $frm.filter).val());
|
|
$('.OrganisationName', frm).val($('.OrganisationName', $frm.filter).val());
|
|
sax.openAssocDialog();
|
|
}
|
|
oa.clearItem = function ()
|
|
{
|
|
let frm = $frm.assoc;
|
|
$('.ItemAssociationId,.NewItem,.OrganisationId,.OrganisationIdAssoc,input[type="text"],textarea,select', frm).val('');
|
|
sax.populateSelect($('.sax-select.AssociationTypeOption', $frm.assoc), oa.data.associationTypes, 'type', 'label');
|
|
sax.clearControlErrors(frm);
|
|
}
|
|
sax.openAssocDialog = function ()
|
|
{
|
|
sax.openDialog($dlg.assoc, 640, 480);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
oa.updateItem = function (item, $item)
|
|
{
|
|
$('.ItemAssociationId', $frm.assocId).val(item.id);
|
|
$('.OrganisationId', $frm.assocId).val($('.OrganisationId', $frm.filter).val());
|
|
oa.ajax.getItemAssoc = oa.ajax.getItemAssoc || { url: sax.url.base + 'Organisation/Ajax/GetAssociation', formId: 'frmAssociationId', callbackFn: oa.onUpdateItem };
|
|
sax.doAjaxRequest(oa.ajax.getItemAssoc, 50);
|
|
}
|
|
oa.onUpdateItem = function (response)
|
|
{
|
|
//sax.debug('onUpdateItemAssociation', response);
|
|
if (!response.success) return;
|
|
oa.clearItem();
|
|
// Association.
|
|
let item = response.association || {};
|
|
let assoc = item.assoc || {};
|
|
let org = item.organisation || {};
|
|
let orgAssoc = item.organisationAssoc || {};
|
|
let frm = $frm.assoc;
|
|
|
|
$('input.ItemAssociationId', frm).val(item.id);
|
|
$('input.NewItem', frm).val(0);
|
|
$('input.OrganisationId', frm).val(org.id);
|
|
$('.OrganisationName input.OrganisationName', frm).val(org.name);
|
|
$('.AssociationTypeOption select.AssociationTypeOption', frm).val(assoc.type);
|
|
$('.OrganisationIdAssoc input.OrganisationIdAssoc', frm).val(orgAssoc.id);
|
|
$('.OrganisationIdAssoc .OrganisationNameAssoc', frm).val(orgAssoc.name);
|
|
|
|
sax.openAssocDialog();
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
oa.storeItem = function ()
|
|
{
|
|
oa.ajax.storeItemAssoc = oa.ajax.storeItemAssoc || { url: sax.url.base + 'Organisation/Ajax/StoreAssociation', formId: 'frmOrganisationAssociation', callbackFn: oa.onStoreItem };
|
|
sax.doAjaxRequest(oa.ajax.storeItemAssoc, 50);
|
|
}
|
|
oa.onStoreItem = function (response)
|
|
{
|
|
//sax.debug('onStoreItemAssociation', response);
|
|
sax.refreshControlValues(response.controlValues, $frm.assoc);
|
|
if (!response.success) return;
|
|
$dlg.assoc.dialog('close');
|
|
oa.refreshItem(response.association);
|
|
}
|
|
oa.refreshItem = function (item)
|
|
{
|
|
var $item = $('#' + oa.getItemIdProp(item.id));
|
|
if (!$item.length)
|
|
{
|
|
$item = oa.getItemTemplate();
|
|
$('.sax-panel-item-list', $pnl.results).prepend($item).show();
|
|
}
|
|
oa.populateItem($item, item);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
oa.removeItem = function (item, $item)
|
|
{
|
|
sax.debug('removeItem')
|
|
oa.clearItem();
|
|
let frm = $frm.assoc;
|
|
$('.ItemAssociationId', frm).val(item.id);
|
|
$('.OrganisationId', frm).val(item.organisation.id);
|
|
$('.OrganisationIdAssoc', frm).val(item.organisationAssoc.id);
|
|
oa.ajax.getRemoveItem = oa.ajax.getRemoveItem || { url: sax.url.base + 'Organisation/Ajax/RemoveAssociation', formId: frm.prop('id'), callbackFn: oa.onRemoveItem };
|
|
sax.doAjaxRequest(oa.ajax.getRemoveItem, 50);
|
|
}
|
|
oa.onRemoveItem = function (response)
|
|
{
|
|
sax.debug('', response)
|
|
if (!response.success) return;
|
|
oa.refreshResults();
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
$(function ()
|
|
{
|
|
$pnl.assocs = $('.sax-panel.OrganisationAssociations');
|
|
$pnl.filter = $('.sax-panel-filter', $pnl.assocs);
|
|
$pnl.results = $('.sax-panel-results', $pnl.assocs);
|
|
|
|
$frm.filter = $('#frmAssociationFilter', $pnl.assocs);
|
|
$frm.filter.on('dblclick', '#ifFilterOrganisation', oa.selectFilterOrganisation).on('click', '#pbFilterOrganisationSelect', oa.selectFilterOrganisation);
|
|
|
|
$frm.assocId = $('#frmAssociationId');
|
|
|
|
var opt = sax.dlgOpts();
|
|
opt.buttons[sax.dlg.btn.ok] = function () { oa.storeItem(); };
|
|
opt.buttons[sax.dlg.btn.cancel] = function () { $(this).dialog('close'); };
|
|
$dlg.assoc = $('#dlgOrganisationAssociation').dialog(opt);
|
|
|
|
$frm.assoc = $('#frmOrganisationAssociation', $dlg.assoc);
|
|
$frm.assoc.on('input', '.sax-input', function () { sax.clearControlError(this); });
|
|
$frm.assoc.on('change', '.sax-select', function () { sax.clearControlError(this); });
|
|
$frm.assoc.on('dblclick', '.OrganisationAssoc', oa.selectAssocOrganisation).on('click', '#pbAssocOrganisationSelect', oa.selectAssocOrganisation);
|
|
|
|
setTimeout(oa.refreshResults, 250);
|
|
});
|
|
|
|
//--------------------------------------------------------------
|
|
}(window, window.document));
|
|
|
|
/* The End */ |