384 lines
15 KiB
JavaScript
384 lines
15 KiB
JavaScript
/*
|
|
* Admin - Reference - Golf page scripts.
|
|
*/
|
|
|
|
(function (win, doc, undef)
|
|
{
|
|
"use strict";
|
|
let rg = sax.refGolf = sax.refGolf || { ajax: {}, data: {}, fn: {}, $pnl: {}, $frm: {}, $dlg: {} };
|
|
rg.attr_id = 'sax-id';
|
|
rg.class_sel = 'sax-sel';
|
|
|
|
//--------------------------------------------------------------
|
|
/* Reference - Golf - Stats. */
|
|
rg.fn.refreshStats = function (delay)
|
|
{
|
|
rg.ajax.golfStats = rg.ajax.golfStats || { url: sax.url.base + 'Reference/Golf/Ajax/GetStats', formId: rg.$frm.filter.prop('id'), callbackFn: rg.fn.doRefreshStats };
|
|
sax.doAjaxRequest(rg.ajax.golfStats, delay || 50);
|
|
}
|
|
rg.fn.doRefreshStats = function (response)
|
|
{
|
|
if (!response.success) return;
|
|
let $msgs = $('.sax-panel-messages', rg.$pnl.stats).empty();
|
|
let $list = $('.sax-panel-item-list', rg.$pnl.stats).empty();
|
|
for (let groupIdx = 0; groupIdx < (response.groups || []).length; groupIdx++)
|
|
{
|
|
let group = response.groups[groupIdx];
|
|
$list.append(rg.fn.populateStatGroup(rg.fn.getStatGroupTemplate(), group.caption));
|
|
for (let statIdx = 0; statIdx < (group.stats || []).length; statIdx++)
|
|
{
|
|
let stat = group.stats[statIdx];
|
|
if (stat.value > 0) $list.append(rg.fn.populateStat(rg.fn.getStatTemplate(), stat.caption, stat.value));
|
|
}
|
|
}
|
|
}
|
|
rg.fn.populateStatGroup = function ($item, caption)
|
|
{
|
|
$('.GroupCaption', $item).text(caption);
|
|
return $item;
|
|
}
|
|
rg.fn.getStatGroupTemplate = function ()
|
|
{
|
|
return $('.sax-panel-item-template .GolfStatGroup', rg.$pnl.stats).clone();
|
|
}
|
|
rg.fn.populateStat = function ($item, caption, value)
|
|
{
|
|
$('.StatCaption', $item).text(caption);
|
|
$('.StatValue', $item).text(value);
|
|
return $item;
|
|
}
|
|
rg.fn.getStatTemplate = function ()
|
|
{
|
|
return $('.sax-panel-item-template .GolfStat', rg.$pnl.stats).clone();
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
/* Reference - Golf - Countries. */
|
|
rg.fn.clearCountries = function ()
|
|
{
|
|
rg.fn.clearProvinces();
|
|
rg.$pnl.countriesMsgs.empty();
|
|
rg.$pnl.countriesList.find('tbody tr').remove();
|
|
$('.FilterProvinceSearch', rg.$frm.provinces).val('');
|
|
}
|
|
rg.fn.refreshCountries = function (delay)
|
|
{
|
|
rg.fn.clearCountries();
|
|
rg.ajax.golfCountries = rg.ajax.golfCountries || { url: sax.url.base + 'Reference/Golf/Ajax/GetCountries', formId: rg.$frm.countries.prop('id'), callbackFn: rg.fn.doRefreshCountries };
|
|
sax.doAjaxRequest(rg.ajax.golfCountries, delay || 50);
|
|
}
|
|
rg.fn.doRefreshCountries = function (response)
|
|
{
|
|
//sax.debug('doRefreshCountries', response);
|
|
rg.fn.clearCountries();
|
|
if (!response.success) return;
|
|
let $list = rg.$pnl.countriesList;
|
|
$('tbody tr', $list).remove()
|
|
for (let countryIdx = 0; countryIdx < (response.countries || []).length; countryIdx++)
|
|
{
|
|
let $item = rg.fn.getCountryTemplate();
|
|
let item = response.countries[countryIdx];
|
|
$list.append(rg.fn.populateCountry($item, item));
|
|
if (countryIdx == 0 && response.countries.length == 1)
|
|
rg.fn.selectCountry($item, item);
|
|
}
|
|
}
|
|
rg.fn.populateCountry = function ($item, item)
|
|
{
|
|
$item.attr(rg.attr_id, item.id).on('click', function () { rg.fn.selectCountry($item, item); })
|
|
$('.CountryCode', $item).text(item.code);
|
|
$('.CountryName', $item).text(item.name);
|
|
if (item.provinceCountActive) $('.CountryProvinces', $item).text(item.provinceCountActive);
|
|
if (item.facilityCountActive) $('.CountryClubs', $item).text(item.facilityCountActive);
|
|
$('.CountryClubsPercent', $item).text(item.coursesPercentFmt);
|
|
if (item.priorityPopulate) $('.CountryPriority', $item).append(rg.fn.getTickIcon());
|
|
$('.CountryStatus', $item).append(rg.fn.getStatusIcon(item.statusCode.toLowerCase()));
|
|
return $item;
|
|
}
|
|
rg.fn.getCountryTemplate = function ()
|
|
{
|
|
return $('.sax-panel-item-template tr.GolfCountry', rg.$pnl.countries).clone();
|
|
}
|
|
rg.fn.selectCountry = function ($item, item)
|
|
{
|
|
//sax.debug('selectCountry', $item, item)
|
|
$('table.sax-item-list tbody tr', rg.$pnl.countries).removeClass(rg.class_sel);
|
|
$item.addClass(rg.class_sel);
|
|
setTimeout(function () { rg.fn.refreshProvinces(250); }, 50);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
/* Reference - Golf - Provinces. */
|
|
rg.fn.clearProvinces = function ()
|
|
{
|
|
rg.fn.clearCourses();
|
|
rg.$pnl.provincesMsgs.empty();
|
|
rg.$pnl.provincesList.find('tbody tr').remove();
|
|
$('.FilterCourseSearch', rg.$frm.courses).val('');
|
|
}
|
|
rg.fn.refreshProvinces = function (delay)
|
|
{
|
|
rg.fn.clearProvinces();
|
|
let countryId = rg.$pnl.countriesList.find('tbody tr.' + rg.class_sel).attr(rg.attr_id);
|
|
if (!countryId)
|
|
{
|
|
rg.$pnl.provincesMsgs.empty().text('Country must be selected.');
|
|
return;
|
|
}
|
|
$('.FilterCountryId', rg.$frm.provinces).val(countryId);
|
|
rg.ajax.golfProvinces = rg.ajax.golfProvinces || { url: sax.url.base + 'Reference/Golf/Ajax/GetProvinces', formId: rg.$frm.provinces.prop('id'), callbackFn: rg.fn.doRefreshProvinces };
|
|
sax.doAjaxRequest(rg.ajax.golfProvinces, delay || 50);
|
|
}
|
|
rg.fn.doRefreshProvinces = function (response)
|
|
{
|
|
//sax.debug('doRefreshProvinces', response);
|
|
rg.fn.clearProvinces();
|
|
if (!response.success) return;
|
|
let $list = rg.$pnl.provincesList;
|
|
$('tbody tr', $list).remove()
|
|
for (let provinceIdx = 0; provinceIdx < (response.provinces || []).length; provinceIdx++)
|
|
{
|
|
let $item = rg.fn.getProvinceTemplate();
|
|
let item = response.provinces[provinceIdx];
|
|
$list.append(rg.fn.populateProvince($item, item));
|
|
if (provinceIdx == 0 && response.provinces.length == 1)
|
|
rg.fn.selectProvince($item, item);
|
|
}
|
|
}
|
|
rg.fn.populateProvince = function ($item, item)
|
|
{
|
|
$item.attr(rg.attr_id, item.id).on('click', function () { rg.fn.selectProvince($item, item); })
|
|
$('.ProvinceCode', $item).text(item.code);
|
|
$('.ProvinceName', $item).text(item.name);
|
|
if (item.facilityCountActive) $('.ProvinceClubs', $item).text(item.facilityCountActive);
|
|
if (item.courseCountActive) $('.ProvinceCourses', $item).text(item.courseCountActive);
|
|
$('.ProvinceMarkers', $item).text(item.markersPercentFmt);
|
|
if (item.priorityPopulate) $('.ProvincePriority', $item).append(rg.fn.getTickIcon());
|
|
$('.ProvinceStatus', $item).append(rg.fn.getStatusIcon(item.statusCode.toLowerCase()));
|
|
return $item;
|
|
}
|
|
rg.fn.getProvinceTemplate = function ()
|
|
{
|
|
return $('.sax-panel-item-template tr.GolfProvince', rg.$pnl.provinces).clone();
|
|
}
|
|
rg.fn.selectProvince = function ($item, item)
|
|
{
|
|
//sax.debug('selectProvince', $item, item)
|
|
$('table.sax-item-list tbody tr', rg.$pnl.provinces).removeClass(rg.class_sel);
|
|
$item.addClass(rg.class_sel);
|
|
setTimeout(function () { rg.fn.refreshCourses(250); }, 50);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
/* Reference - Golf - Courses. */
|
|
rg.fn.clearCourses = function ()
|
|
{
|
|
rg.$pnl.coursesMsgs.empty();
|
|
rg.$pnl.coursesList.find('tbody tr').remove();
|
|
}
|
|
rg.fn.refreshCourses = function (delay)
|
|
{
|
|
rg.fn.clearCourses();
|
|
let provinceId = rg.$pnl.provincesList.find('tbody tr.' + rg.class_sel).attr(rg.attr_id);
|
|
if (!provinceId)
|
|
{
|
|
rg.$pnl.coursesMsgs.empty().text('Province must be selected.');
|
|
return;
|
|
}
|
|
$('.FilterProvinceId', rg.$frm.courses).val(provinceId);
|
|
rg.ajax.golfCourses = rg.ajax.golfCourses || { url: sax.url.base + 'Reference/Golf/Ajax/GetCourses', formId: rg.$frm.courses.prop('id'), callbackFn: rg.fn.doRefreshCourses };
|
|
sax.doAjaxRequest(rg.ajax.golfCourses, delay || 50);
|
|
}
|
|
rg.fn.doRefreshCourses = function (response)
|
|
{
|
|
//sax.debug('doRefreshCourses', response);
|
|
rg.fn.clearCourses();
|
|
if (!response.success) return;
|
|
let $list = rg.$pnl.coursesList;
|
|
$('tbody tr', $list).remove()
|
|
for (let courseIdx = 0; courseIdx < (response.courses || []).length; courseIdx++)
|
|
{
|
|
let $item = rg.fn.getCourseTemplate();
|
|
let item = response.courses[courseIdx];
|
|
$list.append(rg.fn.populateCourse($item, item));
|
|
if (courseIdx == 0 && response.courses.length == 1)
|
|
rg.fn.selectCourse($item, item);
|
|
}
|
|
}
|
|
rg.fn.populateCourse = function ($item, item)
|
|
{
|
|
$item.attr(rg.attr_id, item.id).on('click', function () { rg.fn.selectCourse($item, item); })
|
|
$('.CourseId', $item).text(item.usgaCourseId);
|
|
$('.CourseCaption', $item).text(item.caption);
|
|
$('.CourseLocation', $item).text(item.city || item.address2 || item.address1);
|
|
if (item.markerCountActive) $('.CourseMarkers', $item).text(item.markerCountActive);
|
|
if (item.priorityPopulate) $('.CoursePriority', $item).append(rg.fn.getTickIcon());
|
|
$('.CourseStatus', $item).append(rg.fn.getStatusIcon(item.statusCode.toLowerCase()));
|
|
return $item;
|
|
}
|
|
rg.fn.getCourseTemplate = function ()
|
|
{
|
|
return $('.sax-panel-item-template tr.GolfCourse', rg.$pnl.courses).clone();
|
|
}
|
|
rg.fn.selectCourse = function ($item, item)
|
|
{
|
|
//sax.debug('selectCourse', $item, item)
|
|
$('table.sax-item-list tbody tr', rg.$pnl.courses).removeClass(rg.class_sel);
|
|
$item.addClass(rg.class_sel);
|
|
setTimeout(function () { rg.fn.refreshMarkers(250); }, 50);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
// Courses burger.
|
|
rg.fn.configureCoursesBurger = function ()
|
|
{
|
|
var $bgr = $('.sax-burger', rg.$pnl.courses).hide();
|
|
var $mnu = $('ul.sax-dropdown-menu', $bgr).empty();
|
|
$mnu.append(rg.fn.getCoursesMenuOption('Cleanse captions', function () { rg.fn.cleanseCourseCaptions(); }, 'sax-process'));
|
|
$bgr.toggle(!!$('.sax-dropdown-item', $mnu).length);
|
|
}
|
|
rg.fn.getCoursesDropdownTemplate = function ()
|
|
{
|
|
return $('.sax-panel-item-template .sax-dropdown-menu.Courses li.sax-dropdown-item', rg.$pnl.courses).clone();
|
|
}
|
|
rg.fn.getCoursesMenuOption = function (lbl, fn, cls)
|
|
{
|
|
return rg.fn.getMenuOption(rg.fn.getCoursesDropdownTemplate(), lbl, fn, cls);
|
|
}
|
|
rg.fn.cleanseCourseCaptions = function ()
|
|
{
|
|
rg.ajax.cleanseCourseCaptions = rg.ajax.cleanseCourseCaptions || { url: sax.url.base + 'Reference/Golf/Ajax/CleanseUsgaCourseCaptions', formId: rg.$frm.courses.prop('id') };
|
|
sax.doAjaxRequest(rg.ajax.cleanseCourseCaptions, 200);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
/* Reference - Golf - Markers. */
|
|
rg.fn.clearMarkers = function ()
|
|
{
|
|
rg.$pnl.markersMsgs.empty();
|
|
rg.$pnl.markersList.find('tbody tr').remove();
|
|
}
|
|
rg.fn.refreshMarkers = function (delay)
|
|
{
|
|
rg.fn.clearMarkers();
|
|
let courseId = rg.$pnl.coursesList.find('tbody tr.' + rg.class_sel).attr(rg.attr_id);
|
|
if (!courseId)
|
|
{
|
|
rg.$pnl.markersMsgs.empty().text('Course must be selected.');
|
|
return;
|
|
}
|
|
$('.FilterCourseId', rg.$frm.markers).val(courseId);
|
|
rg.ajax.golfMarkers = rg.ajax.golfMarkers || { url: sax.url.base + 'Reference/Golf/Ajax/GetMarkers', formId: rg.$frm.markers.prop('id'), callbackFn: rg.fn.doRefreshMarkers };
|
|
sax.doAjaxRequest(rg.ajax.golfMarkers, delay || 50);
|
|
}
|
|
rg.fn.doRefreshMarkers = function (response)
|
|
{
|
|
//sax.debug('doRefreshMarkers', response);
|
|
rg.fn.clearMarkers();
|
|
if (!response.success) return;
|
|
let $list = rg.$pnl.markersList;
|
|
$('tbody tr', $list).remove()
|
|
for (let markerIdx = 0; markerIdx < (response.markers || []).length; markerIdx++)
|
|
$list.append(rg.fn.populateMarker(rg.fn.getMarkerTemplate(), response.markers[markerIdx]));
|
|
}
|
|
rg.fn.populateMarker = function ($item, item)
|
|
{
|
|
$item.attr(rg.attr_id, item.id).on('click', function () { rg.fn.selectMarker($item, item); })
|
|
$('.MarkerCaption', $item).text(item.caption);
|
|
$('.MarkerHoles', $item).text(item.holes);
|
|
$('.MarkerTee', $item).text(item.tee);
|
|
$('.MarkerGender', $item).text(item.gender);
|
|
$('.MarkerSlope', $item).text(item.slopeRating);
|
|
$('.MarkerPar', $item).text(item.par);
|
|
$('.MarkerCourse', $item).text(item.courseRating);
|
|
if (item.bogeyRating) $('.MarkerBogey', $item).text(item.bogeyRating);
|
|
if (item.length) $('.MarkerLength', $item).text(item.length);
|
|
$('.MarkerStatus', $item).append(rg.fn.getStatusIcon(item.statusCode.toLowerCase()));
|
|
return $item;
|
|
}
|
|
rg.fn.getMarkerTemplate = function ()
|
|
{
|
|
return $('.sax-panel-item-template tr.GolfMarker', rg.$pnl.markers).clone();
|
|
}
|
|
rg.fn.selectMarker = function ($item, item)
|
|
{
|
|
//sax.debug('selectMarker', $item, item)
|
|
$('table.sax-item-list tbody tr', rg.$pnl.markers).removeClass(rg.class_sel);
|
|
$item.addClass(rg.class_sel);
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
// Utilities.
|
|
rg.fn.getMenuOption = function ($opt, lbl, fn, cls)
|
|
{
|
|
return $opt.find('div.sax-label').text(lbl).end().on('click', fn).addClass(cls);
|
|
}
|
|
rg.fn.getTickIcon = function ()
|
|
{
|
|
return $('.sax-panel-item-template img.sax-tick', rg.$pnl.golf).clone();
|
|
}
|
|
rg.fn.getCrossIcon = function ()
|
|
{
|
|
return $('.sax-panel-item-template img.sax-cross', rg.$pnl.golf).clone();
|
|
}
|
|
rg.fn.getStatusIcon = function (stat)
|
|
{
|
|
return $('.sax-panel-item-template img.sax-status-' + stat, rg.$pnl.golf).clone();
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
$(function ()
|
|
{
|
|
rg.$pnl.golf = $('.sax-panel.Golf');
|
|
rg.$pnl.filter = $('.sax-panel-filter', rg.$pnl.golf);
|
|
$('.sax-results-refresh', rg.$pnl.filter).on('click', rg.fn.refreshStats);
|
|
rg.$frm.filter = $('#frmRefGolfFilter', rg.$pnl.filter);
|
|
|
|
// Stats.
|
|
rg.$pnl.stats = $('.sax-panel-info.GolfStats', rg.$pnl.golf);
|
|
setTimeout(function () { rg.fn.refreshStats(); }, 250);
|
|
|
|
// Countries.
|
|
rg.$pnl.countries = $('.sax-panel-info.Countries', rg.$pnl.golf);
|
|
rg.$pnl.countriesMsgs = $('.sax-panel-messages', rg.$pnl.countries);
|
|
rg.$pnl.countriesList = $('table.sax-item-list', rg.$pnl.countries);
|
|
rg.$frm.countries = $('#frmCountries', rg.$pnl.golf);
|
|
$('.FilterCountrySearch', rg.$frm.countries).on('input', function () { setTimeout(function () { rg.fn.refreshCountries(500); }, 50); });
|
|
setTimeout(function () { rg.fn.refreshCountries(); }, 1000);
|
|
|
|
// Provinces.
|
|
rg.$pnl.provinces = $('.sax-panel-info.Provinces', rg.$pnl.golf);
|
|
rg.$pnl.provincesMsgs = $('.sax-panel-messages', rg.$pnl.provinces);
|
|
rg.$pnl.provincesList = $('table.sax-item-list', rg.$pnl.provinces);
|
|
rg.$frm.provinces = $('#frmProvinces', rg.$pnl.golf);
|
|
$('.FilterProvinceSearch', rg.$frm.provinces).on('input', function () { setTimeout(function () { rg.fn.refreshProvinces(500); }, 50); });
|
|
|
|
// Courses.
|
|
rg.$pnl.courses = $('.sax-panel-info.Courses', rg.$pnl.golf);
|
|
rg.$pnl.coursesMsgs = $('.sax-panel-messages', rg.$pnl.courses);
|
|
rg.$pnl.coursesList = $('table.sax-item-list', rg.$pnl.courses);
|
|
rg.$frm.courses = $('#frmCourses', rg.$pnl.golf);
|
|
$('.FilterCourseSearch', rg.$frm.courses).on('input', function () { setTimeout(function () { rg.fn.refreshCourses(500); }, 50); });
|
|
//$('.PagingPageNo', rg.$dlg).val(1);
|
|
//$('.PagingPageLength', rg.$dlg).val(16);
|
|
rg.fn.configureCoursesBurger();
|
|
|
|
// Markers.
|
|
rg.$pnl.markers = $('.sax-panel-info.Markers', rg.$pnl.golf);
|
|
rg.$pnl.markersMsgs = $('.sax-panel-messages', rg.$pnl.markers);
|
|
rg.$pnl.markersList = $('table.sax-item-list', rg.$pnl.markers);
|
|
rg.$frm.markers = $('#frmMarkers', rg.$pnl.golf);
|
|
$('.FilterMarkerSearch', rg.$frm.markers).on('input', function () { setTimeout(function () { rg.fn.refreshMarkers(500); }, 50); });
|
|
|
|
var opt = sax.dlgOpts();
|
|
//opt.open = function () { rg.fn.refreshOrganisations(200); };
|
|
//opt.buttons[sax.dlg.btn.ok] = function () { rg.fn.confirmSelection(); };
|
|
opt.buttons[sax.dlg.btn.cancel] = function () { rg.fn.cleanUp(); $(this).dialog('close'); };
|
|
//rg.$dlg = $('#dlgSelectOrganisation').dialog(opt);
|
|
|
|
});
|
|
|
|
//--------------------------------------------------------------
|
|
}(window, window.document));
|
|
|
|
/* The End */ |