228 lines
9.1 KiB
JavaScript
228 lines
9.1 KiB
JavaScript
/*
|
|
* Organisation - Opportunities page scripts.
|
|
*/
|
|
|
|
(function (win, doc, undef)
|
|
{
|
|
"use strict";
|
|
sax.itemIdPrefix = 'Itm_';
|
|
|
|
//--------------------------------------------------------------
|
|
sax.refreshResults = function (delay)
|
|
{
|
|
var $results = $('.sax-panel-results');
|
|
sax.data.userCanManageOpportunities = false;
|
|
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/GetOpportunityList', formId: 'frmOpportunityFilter', 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 $panel = $('#pnlOpportunities');
|
|
$('.sax-action.sax-item-create', $panel).hide();
|
|
var $results = $('.sax-panel-results', $panel);
|
|
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', $results);
|
|
if (!response.success) return;
|
|
// Reference data - Opportunity types.
|
|
if (response.opportunityTypes)
|
|
sax.populateSelectCodeDesc('#cbOpportunityType', response.opportunityTypes);
|
|
// Items.
|
|
sax.data.userCanManageOpportunities = (response.user && response.user.canManage);
|
|
$('#pnlOpportunities .sax-panel-filter .sax-action.sax-item-create').toggle(sax.data.userCanManageOpportunities);
|
|
var items = response.opportunities;
|
|
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);
|
|
}
|
|
$('.sax-action.sax-item-update', $items).toggle(sax.data.userCanManageOpportunities);
|
|
$items.fadeIn(50);
|
|
}
|
|
sax.populateItem = function ($item, item)
|
|
{
|
|
if (!item) return;
|
|
$item.prop('id', sax.itemIdPrefix + item.id);
|
|
$('.OpportunityType', $item).text(item.typeDesc);
|
|
$('.OpportunityPosition', $item).text(item.position);
|
|
$('.OpportunityOutline', $item).text(item.outline);
|
|
$('.OpportunityRegionCaption', $item).text(item.regionCaption);
|
|
$('.OpportunitySportCaption', $item).text(item.sportCaption);
|
|
$('.OpportunityCreatedOn', $item).text(item.createdOnFmt);
|
|
$('.OpportunityPublishedOn', $item).text(item.publishedOnFmt);
|
|
$('.OpportunityPublished', $item).toggle(!!item.publishedOnFmt);
|
|
$('.OpportunityExpiresOn', $item).text(item.expiresOnFmt);
|
|
$('.OpportunityExpires', $item).toggle(!!item.expiresOnFmt);
|
|
$('.OpportunityStatusDesc', $item).text(item.statusDesc);
|
|
$('.sax-caption .sax-action, .sax-actions .sax-action.sax-item-update', $item).off('click').on('click', function () { sax.updateItem(item.id) });
|
|
$item.off('dblclick').on('dblclick', function () { sax.updateItem(item.id) });
|
|
$('.sax-panel-results .sax-panel-messages').hide().empty();
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
sax.selectFilterOrganisation = function ()
|
|
{
|
|
if (!sax.data.memberOrganisations)
|
|
sax.getMemberOrganisations(sax.showSelectOrganisation);
|
|
else sax.showSelectOrganisation();
|
|
}
|
|
sax.getMemberOrganisations = function (fnCallback)
|
|
{
|
|
let handleMemberOrganisationsResponse = function (response)
|
|
{
|
|
sax.debug('handleUserOrgsResponse', response);
|
|
if (!response.success) return;
|
|
sax.data.memberOrganisations = response.organisations;
|
|
if (fnCallback) fnCallback();
|
|
}
|
|
sax.ajaxUserOrgs = sax.ajaxUserOrgs || { url: sax.url.base + 'Organisation/Ajax/GetMemberOrganisationList', formId: 'frmNavigate', callbackFn: handleMemberOrganisationsResponse };
|
|
sax.doAjaxRequest(sax.ajaxUserOrgs);
|
|
}
|
|
sax.showSelectOrganisation = function ()
|
|
{
|
|
//sax.debug('sax.selectFilterOrganisation');
|
|
sax.selectOrganisation.fn.selectOrganisation({ caption: sax.dlg.title.selectOrganisation, items: sax.data.memberOrganisations, fnCallback: sax.onOrganisationSelected });
|
|
}
|
|
sax.onOrganisationSelected = function (id, name)
|
|
{
|
|
//sax.debug('sax.onOrganisationSelected', id, name);
|
|
$('#frmOpportunityFilter #ifFilterOrganisationId, #frmOpportunity #ifOpportunityOrganisationId').val(id);
|
|
$('#frmOpportunityFilter #ifFilterOrganisation').val(name);
|
|
sax.refreshResults(50);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
sax.selectRegion = function ()
|
|
{
|
|
sax.data.selectRegion.fn.selectRegion({ caption: sax.dlg.title.selectRegion, regionId: $('#ifOpportunityRegionId').val(), fnCallback: sax.onSelectRegion })
|
|
}
|
|
sax.onSelectRegion = function (region)
|
|
{
|
|
sax.clearControlError($('#ifOpportunityRegionId').val(region.id));
|
|
$('#ifOpportunityRegionCaption').val(region ? region.name : '');
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
sax.selectSport = function ()
|
|
{
|
|
sax.data.selectSport.fn.selectSport({ caption: sax.dlg.title.selectSport, sportId: $('#ifOpportunitySportId').val(), fnCallback: sax.onSelectSport })
|
|
}
|
|
sax.onSelectSport = function (sport)
|
|
{
|
|
sax.clearControlError($('#ifOpportunitySportId').val(sport.id));
|
|
$('#ifOpportunitySportCaption').val(sport ? sport.name : '');
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
sax.createItem = function ()
|
|
{
|
|
if (!sax.data.userCanManageOpportunities) return;
|
|
sax.clearItem();
|
|
sax.$dlg.opportunity.dialog('option', 'title', sax.dlg.title.createOpportunity);
|
|
sax.openDialog(sax.$dlg.opportunity, 600, 600);
|
|
}
|
|
sax.clearItem = function ()
|
|
{
|
|
$('#ifOpportunityId,#ifOpportunityExists,#ifOpportunityRegionId,#ifOpportunitySportId,input[type="text"],textarea,select', sax.$frm.opportunity).val('');
|
|
sax.clearControlErrors();
|
|
}
|
|
sax.doCreateItem = function ()
|
|
{
|
|
sax.storeItem();
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
sax.updateItem = function (id)
|
|
{
|
|
if (!sax.data.userCanManageOpportunities) return;
|
|
$('.OpportunityId', sax.$frm.opportunityId).val(id);
|
|
sax.ajaxUpdateItem = sax.ajaxUpdateItem || { url: sax.url.base + 'Organisation/Ajax/GetOpportunity', formId: 'frmOpportunityId', callbackFn: sax.onUpdateItem };
|
|
sax.doAjaxRequest(sax.ajaxUpdateItem, 50);
|
|
}
|
|
sax.onUpdateItem = function (response)
|
|
{
|
|
//sax.debug('onUpdateItem', response);
|
|
sax.clearItem();
|
|
if (!response.success) return;
|
|
let $frm = sax.$frm.opportunity;
|
|
let item = response.opportunity;
|
|
$('#ifOpportunityId', $frm).val(item.id);
|
|
$('#ifOpportunityExists', $frm).val(1);
|
|
$('#cbOpportunityType', $frm).val(item.typeCode);
|
|
$('#ifOpportunityPosition', $frm).val(item.position);
|
|
$('#ifOpportunityOutline', $frm).val(item.outline);
|
|
$('#ifOpportunityRegionId', $frm).val(item.regionIdPrimary);
|
|
$('#ifOpportunityRegionCaption', $frm).val(item.regionCaption);
|
|
$('#ifOpportunitySportId', $frm).val(item.sportIdPrimary);
|
|
$('#ifOpportunitySportCaption', $frm).val(item.sportCaption);
|
|
$('#cbOpportunityStatusCode', $frm).val(item.statusCode);
|
|
sax.clearControlErrors();
|
|
sax.$dlg.opportunity.dialog('option', 'title', sax.dlg.title.updateOpportunity);
|
|
sax.openDialog(sax.$dlg.opportunity, 600, 600);
|
|
}
|
|
sax.doUpdateItem = function ()
|
|
{
|
|
sax.storeItem();
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
sax.storeItem = function ()
|
|
{
|
|
sax.ajaxStoreItem = sax.ajaxStoreItem || { url: sax.url.base + 'Organisation/Ajax/StoreOpportunity', formId: 'frmOpportunity', 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.opportunity.dialog('close');
|
|
|
|
var item = response.opportunity;
|
|
var $item = $('#' + sax.itemIdPrefix + item.id);
|
|
if (!$item.length)
|
|
{
|
|
var $results = $('.sax-panel-results');
|
|
$item = $('.sax-panel-item-template .sax-panel-item', $results).clone();
|
|
$('.sax-panel-item-list', $results).prepend($item).show();
|
|
}
|
|
sax.populateItem($item, item)
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
$(function ()
|
|
{
|
|
$('.sax-action.sax-item-create').on('click', function () { sax.createItem(); });
|
|
$('.sax-action.sax-results-refresh').on('click', function () { sax.refreshResults(); });
|
|
$('.OpportunityFilter', '#frmOpportunityFilter').keypress(function (event)
|
|
{
|
|
if (event.keyCode == 13) setTimeout(sax.refreshResults, 50);
|
|
});
|
|
sax.$frm.opportunityId = $('#frmOpportunityId');
|
|
sax.$frm.opportunity = $('#frmOpportunity');
|
|
$('.sax-input', sax.$frm.opportunity).on('input', function () { sax.clearControlError(this); });
|
|
|
|
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.opportunity = $('#dlgOpportunity').dialog(opt);
|
|
|
|
setTimeout(sax.refreshResults, 250);
|
|
});
|
|
|
|
}(window, window.document));
|
|
|
|
/* The End */ |