105 lines
3.3 KiB
JavaScript
105 lines
3.3 KiB
JavaScript
/**
|
|
* Common utility functions.
|
|
*/
|
|
(function (context, $) {
|
|
|
|
"use strict";
|
|
|
|
context.JK = context.JK || {};
|
|
var sessionUtils = {};
|
|
var rest = new context.JK.Rest();
|
|
context.JK.SessionUtils = sessionUtils;
|
|
var logger = context.JK.logger;
|
|
|
|
|
|
var LATENCY = {
|
|
ME : {description: "ME", style: "latency-me", min: -1, max: -1},
|
|
GOOD : {description: "GOOD", style: "latency-good", min: 0.0, max: 40.0},
|
|
MEDIUM : {description: "FAIR", style: "latency-fair", min: 40.0, max: 70.0},
|
|
POOR : {description: "POOR", style: "latency-poor", min: 70.0, max: 100},
|
|
UNACCEPTABLE: {description: "UNACCEPTABLE", style: "latency-unacceptable", min: 100, max: 10000000},
|
|
UNKNOWN: {description: "UNKNOWN", style: "latency-unknown", min: -2, max: -2}
|
|
};
|
|
|
|
sessionUtils.createOpenSlot = function($openSlotsTemplate, slot) {
|
|
var inst = context.JK.getInstrumentIcon24(slot.instrument_id);
|
|
|
|
var proficiency_desc = slot.proficiency_desc;
|
|
if(!proficiency_desc) {
|
|
// this is to allow unstructured RSVPs to not specify proficiency_desc
|
|
proficiency_desc = "Any Skill Level";
|
|
}
|
|
|
|
if(!slot.proficiency_desc) {
|
|
proficiency_desc
|
|
}
|
|
var slot = {
|
|
instrument_url: inst,
|
|
instrument: slot.description,
|
|
proficiency: proficiency_desc
|
|
};
|
|
|
|
return context.JK.fillTemplate($openSlotsTemplate.html(), slot);
|
|
}
|
|
|
|
sessionUtils.defaultTimezone = function($timezoneList) {
|
|
var tz = jstz.determine().name();
|
|
// first check if we have this particular timezone
|
|
var found = null;
|
|
if(tz) {
|
|
found = $timezoneList.find('option[data-tz="' + tz +'"]')
|
|
}
|
|
|
|
if(found.length == 0 ) {
|
|
// this is best effort path; it means some reason we couldn't match a timezone by jstz to our dropdown
|
|
var offset = new Date().getTimezoneOffset() * 60; // convert to seconds to match data-utc-offset (seconds)
|
|
found = $timezoneList.find('option[data-utc-offset="' + offset + '"]')
|
|
}
|
|
|
|
if(found.length > 0) {
|
|
var defaultValue = found.attr('value');
|
|
$timezoneList.easyDropDown('select', defaultValue).val(defaultValue);
|
|
}
|
|
}
|
|
|
|
sessionUtils.createLatency = function(user) {
|
|
|
|
var latencyStyle;
|
|
var latencyDescription;
|
|
|
|
if (user.id === context.JK.currentUserId) {
|
|
latencyStyle = LATENCY.ME.style, latencyDescription = LATENCY.ME.description;
|
|
}
|
|
|
|
else {
|
|
var latency = user.full_score;
|
|
|
|
if (!latency) {
|
|
latencyDescription = LATENCY.UNKNOWN.description;
|
|
latencyStyle = LATENCY.UNKNOWN.style;
|
|
}
|
|
else if (latency <= LATENCY.GOOD.max) {
|
|
latencyDescription = LATENCY.GOOD.description;
|
|
latencyStyle = LATENCY.GOOD.style;
|
|
}
|
|
else if (latency > LATENCY.MEDIUM.min && latency <= LATENCY.MEDIUM.max) {
|
|
latencyDescription = LATENCY.MEDIUM.description;
|
|
latencyStyle = LATENCY.MEDIUM.style;
|
|
}
|
|
else if (latency > LATENCY.POOR.min && latency <= LATENCY.UNACCEPTABLE.max) {
|
|
latencyDescription = LATENCY.POOR.description;
|
|
latencyStyle = LATENCY.POOR.style;
|
|
}
|
|
else {
|
|
latencyStyle = LATENCY.UNACCEPTABLE.style
|
|
latencyDescription = LATENCY.UNACCEPTABLE.description
|
|
}
|
|
}
|
|
|
|
return {
|
|
latency_style: latencyStyle,
|
|
latency_text: latencyDescription
|
|
};
|
|
}
|
|
|
|
})(window, jQuery); |