BMLT Root Server
bmlt.js
Go to the documentation of this file.
3 
4 var bmltClientInit = function (host, recurse) {
5  this.bmltbaseURL = host + "/client_interface/jsonp/?switcher=";
6  this.recurseServiceBodies = recurse == null ? false : recurse;
7 };
8 
9 var getDayOfWeek = function (dayint) {
10  return ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][dayint];
11 };
12 
13 var getTodayDayOfWeek = function () {
14  return (new Date()).getDay() + 1;
15 };
16 
17 var militaryToStandard = function (value) {
18  if (value !== null && value !== undefined) { //If value is passed in
19  if (value.indexOf('AM') > -1 || value.indexOf('PM') > -1) { //If time is already in standard time then don't format.
20  return value;
21  } else {
22  if (value.length === 8) { //If value is the expected length for military time then process to standard time.
23  var valueconv = value.split(':'); // convert to array
24  // fetch
25  var hours = Number(valueconv[0]);
26 
27  // calculate
28  var timeValue;
29  if (hours > 0 && hours <= 12) { // If hour is less than or equal to 12 then convert to standard 12 hour format
30  timeValue= "" + hours;
31  } else if (hours > 12) { //If hour is greater than 12 then convert to standard 12 hour format
32  timeValue= "" + (hours - 12);
33  } else if (hours === 0) { //If hour is 0 then set to 12 for standard time 12 AM
34  timeValue= "12";
35  }
36 
37  timeValue += ":" + valueconv[1]; // get minutes
38  timeValue += (hours >= 12) ? " PM" : " AM"; // get AM/PM
39  // show
40  return timeValue;
41  } else { //If value is not the expected length than just return the value as is
42  return valueconv;
43  }
44  }
45  }
46 };
47 
48 var getMeetingsByCity = function (city, callback) {
49  getJSON(bmltbaseURL + "GetSearchResults&meeting_key=location_municipality&meeting_key_value=" + city + "&callback=?", callback);
50 };
51 
52 var getMeetingsByServiceBodyId = function (serviceBodyId, callback) {
53  getJSON(bmltbaseURL + "GetSearchResults" + getServiceBodyIdQueryString(serviceBodyId) + "&callback=?", callback);
54 };
55 
56 var getMeetingsByServiceBodyIdAndWeekdayId = function (serviceBodyId, weekdayId, callback) {
57  getJSON(bmltbaseURL + "GetSearchResults" + getServiceBodyIdQueryString(serviceBodyId) + "&weekdays=" + weekdayId + "&callback=?", callback);
58 };
59 
60 var getMeetingsByServiceBodyIdAndCity = function (serviceBodyId, city, callback) {
61  getJSON(bmltbaseURL + "GetSearchResults" + getServiceBodyIdQueryString(serviceBodyId) + "&meeting_key=location_municipality&meeting_key_value=" + city + "&callback=?", callback);
62 };
63 
64 var getMeetingsByLocation = function (day, geoWidth, position, callback) {
65  getJSON(bmltbaseURL + "GetSearchResults&weekdays=" + day + "&geo_width=" + geoWidth + "&long_val=" + position.longitude + "&lat_val=" + position.latitude + "&callback=?", callback);
66 };
67 
68 var getFormats = function (callback) {
69  getJSON(bmltbaseURL + "GetFormats&callback=?", callback);
70 };
71 
72 var getUniqueValuesByServiceBody = function (serviceBodyId, field, callback) {
73  getMeetingsByServiceBodyId(serviceBodyId, function (data) {
74  var valuesArray = [];
75  for (i = 0; i < data.length; i++) {
76  valuesArray.push(data[i][field]);
77  }
78 
79  callback(valuesArray.unique())
80  });
81 };
82 
83 var getServiceBodyIdQueryString = function (serviceBodyIds) {
84  var serviceBodyIdString = "";
85  if (Array.isArray(serviceBodyIds)) {
86  for (var i = 0; i < serviceBodyIds.length; i++) {
87  serviceBodyIdString += "&services[]=" + serviceBodyIds[i];
88  }
89  } else {
90  serviceBodyIdString = "&services=" + serviceBodyIds;
91  }
92 
93  return serviceBodyIdString;
94 };
95 
96 var getJSON = function (url, callback) {
97  var random = Math.floor(Math.random() * 999999);
98  var callbackFunctionName = "cb_" + random;
99  if (this.recurseServiceBodies) {
100  url += "&recursive=1";
101  }
102  url = url.replace("callback=?", "callback=" + callbackFunctionName);
103 
104  window[callbackFunctionName] = function (data) {
105  callback(data);
106  };
107 
108  var scriptItem = document.createElement('script');
109  scriptItem.setAttribute('src', url);
110  document.body.appendChild(scriptItem);
111 };
112 
113 Array.prototype.unique = function () {
114  var o = {}, a = [];
115  for (var i = 0; i < this.length; i++) {
116  o[this[i]] = 1
117  for (var e in o) {
118  a.push(e)
119  return a
120  }
121  }
122 };
var getMeetingsByServiceBodyIdAndCity
Definition: bmlt.js:60
var getServiceBodyIdQueryString
Definition: bmlt.js:83
var getMeetingsByServiceBodyId
Definition: bmlt.js:52
undefined
var getMeetingsByCity
Definition: bmlt.js:48
var getMeetingsByLocation
Definition: bmlt.js:64
var a
var getJSON
Definition: bmlt.js:96
var bmltbaseURL
Definition: bmlt.js:1
var getFormats
Definition: bmlt.js:68
var o
var getDayOfWeek
Definition: bmlt.js:9
var getUniqueValuesByServiceBody
Definition: bmlt.js:72
var getTodayDayOfWeek
Definition: bmlt.js:13
var militaryToStandard
Definition: bmlt.js:17
function e
var i
var recurseServiceBodies
Definition: bmlt.js:2
var getMeetingsByServiceBodyIdAndWeekdayId
Definition: bmlt.js:56
var bmltClientInit
Definition: bmlt.js:4