147 lines
5.4 KiB
JavaScript
147 lines
5.4 KiB
JavaScript
/*
|
|
* Admin - Organisation page scripts.
|
|
*/
|
|
"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;
|
|
// 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);
|
|
$('.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.createItem = function ()
|
|
{
|
|
$('.OrganisationId,input[type="text"],textarea,select', sax.$frm.organisation).val('');
|
|
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);
|
|
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('keydown', function () { sax.clearControlError(this); });
|
|
|
|
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);
|
|
});
|
|
|
|
//--------------------------------------------------------------
|