88 lines
3.1 KiB
JavaScript
88 lines
3.1 KiB
JavaScript
/*
|
|
* Admin - User page scripts.
|
|
*/
|
|
|
|
(function (win, doc, undef)
|
|
{
|
|
"use strict";
|
|
let os = sax.organisationSelection = sax.organisationSelection || { data: {}, fn: {}, $dlg: {}, itemIdPrefix: 'Org_' };
|
|
|
|
//--------------------------------------------------------------
|
|
/*
|
|
* Organisation selection config:
|
|
* - caption - dialog title.
|
|
* - width: preferred dialog width (default: 400).
|
|
* - height: preferred dialog height (default: 400).
|
|
* - fnCallback - method to call on completion.
|
|
*/
|
|
os.fn.openDialog = function (cfg)
|
|
{
|
|
//sax.debug('openDialog', cfg);
|
|
os.fn.init();
|
|
os.cfg = cfg;
|
|
sax.openDialog(os.$dlg.dialog('option', { title: cfg.caption || os.dlgTitleSelectOrganisation || 'Select Organisation' }), os.cfg.width || 480, os.cfg.height || 600);
|
|
}
|
|
os.fn.refreshOrganisations = function (delay)
|
|
{
|
|
//sax.debug('refreshOrganisations');
|
|
os.ajaxRefreshResults = os.ajaxRefreshResults || { url: sax.url.base + 'Organisation/Ajax/GetList', formId: 'frmOrganisationSelectionFilter', callbackFn: os.fn.doRefreshResults };
|
|
sax.doAjaxRequest(os.ajaxRefreshResults, delay || 50);
|
|
}
|
|
os.fn.doRefreshResults = function (response)
|
|
{
|
|
//sax.debug('os.doRefreshResults', response);
|
|
if (!response.success) return;
|
|
let $results = $('.sax-selection-results.Organisations', os.$dlg).empty().hide();
|
|
let $tmpl = $('.sax-panel-item-template .sax-panel-item.Organisation', os.$dlg);
|
|
let items = response.organisations;
|
|
if (items)
|
|
{
|
|
for (let itemIdx = 0; itemIdx < items.length; itemIdx++)
|
|
{
|
|
let item = items[itemIdx];
|
|
let $item = $tmpl.clone().prop('id', os.itemIdPrefix + item.id).on('click', function () { os.fn.onClickOrganisation(item); }).on('dblclick', function () { os.fn.onDblClickOrganisation(item); });
|
|
$('.Name', $item).text(item.name);
|
|
$results.append($item);
|
|
}
|
|
}
|
|
$results.fadeIn(200);
|
|
}
|
|
os.fn.onClickOrganisation = function (item)
|
|
{
|
|
//sax.debug('onClickOrganisation', item);
|
|
os.data.item = item;
|
|
$('.sax-panel-item.Organisation', os.$dlg).removeClass('sel');
|
|
$('.sax-panel-item.Organisation#' + os.itemIdPrefix + item.id, os.$dlg).addClass('sel');
|
|
}
|
|
os.fn.onDblClickOrganisation = function (item)
|
|
{
|
|
//sax.debug('onDblClickCode', item);
|
|
os.data.item = item;
|
|
os.fn.confirmSelection();
|
|
}
|
|
os.fn.confirmSelection = function ()
|
|
{
|
|
//sax.debug('confirmSelection', os.data.item);
|
|
if (!os.data.item) return;
|
|
if (os.cfg.fnCallback) os.cfg.fnCallback(os.data.item.id, os.data.item.name);
|
|
os.$dlg.dialog('close');
|
|
delete os.cfg;
|
|
delete os.data.item;
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
os.fn.init = function ()
|
|
{
|
|
if (!os.$dlg) return;
|
|
var opt = sax.dlgOpts();
|
|
opt.open = function () { os.fn.refreshOrganisations(200); };
|
|
opt.buttons[sax.dlg.btn.ok] = function () { os.fn.confirmSelection(); };
|
|
opt.buttons[sax.dlg.btn.cancel] = function () { $(this).dialog('close'); };
|
|
os.$dlg = $('#dlgOrganisationSelection').dialog(opt);
|
|
|
|
$('.sax-input.FilterOrganisation', os.$dlg).on('input', function () { sax.organisationSelection.fn.refreshOrganisations(250); });
|
|
}
|
|
|
|
}(window, window.document));
|
|
|
|
/* The End */ |