Skip to content

Instantly share code, notes, and snippets.

@jhsuZerion
jhsuZerion / iForm-Page-JavaScript-Location.js
Last active July 19, 2016 19:51 — forked from truth3/iForm-Page-JavaScript-Location.js
PREFILL ADDRESS OR STREET USING GOOGLE API
function getStreetNumber(lat, lng) {
var json = getRGeocodeJSON(lat, lng);
var obj = JSON.parse(json);
try { return obj.results[0].address_components[0].short_name; }
catch(e) { return ''; }
}
function getStreetName(lat, lng) {
var json = getRGeocodeJSON(lat, lng);
@jhsuZerion
jhsuZerion / getValueOfBitPosition.js
Created October 17, 2016 18:43
Page-level JavaScript function for working with multi-select elements
/**
* A function to access a value in an option in a multi-select element.
* by converting the value of the multi-select element into a bit and
* @param {integer} i the integer representation from a multi-select element
* @param {position} p the number of the option list value to look-up
* the last option is #1 and increments up
* @return {integer} value of the binary string at the given position
*/
function getValueOfBitPosition(i,p) {
var bit = (i >>> 0).toString(2);
@jhsuZerion
jhsuZerion / getNumSelected.js
Created October 18, 2016 18:24
Function to get the number of options selected in a multi-select element
function getNumSelected(i) {
var bit = (i >>> 0).toString(2);
var count = 0;
for(var i = 0;i<bit.length;i++) {
if(bit[i] == 1) {count ++;}
}
return count;
}
@jhsuZerion
jhsuZerion / multiToKVPs.js
Last active March 15, 2017 20:57
multiToKVPs() - convert a csv list to a set of objects with a value of 1 or 0
/**
* multiToKVPs convert a csv list to a set of objects with a value of 1 or 0
* @param {json_object} obj a JSON object
* @param {string} key the key of the csv list
* @param {array} masterlist the list of possible values in the csv
* @return {json_object} original object with KVPs from masterlist
*/
function multiToKVPs(obj,key,masterlist) {
var multiArray = obj[key].split(',');
@jhsuZerion
jhsuZerion / kvpListToArray.js
Last active May 30, 2017 15:07
kvpListToArray() transforms a dictionary style object to an 'array of objects'
/**
* kvpListToArray transforms a dictionary style object to an 'array of objects'
* @param {object} kvps dictionary style object with key-value-pairs
* @param {type} key_label label for the key in each key-value-pair
* @param {type} value_label label for the value in each key-value-pair
* @return {type} an array of objects
*/
function kvpListToArray(obj,key_label,value_label) {
var array = [];
var tempObj = {};
@jhsuZerion
jhsuZerion / removeIFBMetaData.js
Last active April 29, 2017 02:56
removeIFBMetaData() cleans an IFB/DC record of the 13 metadata fields
/**
* removeIFBMetaData cleans an IFB/DC record of the 13 metadata fields
* @param {json_object} r a record from iFormBuilder or Data Collector
* @return {json_object} original record cleaned of any metadata fields
*/
function removeIFBMetaData(r) {
var metaDataKeys = ["ID", "PARENT_RECORD_ID", "PARENT_PAGE_ID", "PARENT_ELEMENT_ID", "CREATED_DATE", "CREATED_BY", "CREATED_LOCATION", "CREATED_DEVICE_ID", "MODIFIED_DATE", "MODIFIED_BY", "MODIFIED_LOCATION", "MODIFIED_DEVICE_ID", "SERVER_MODIFIED_DATE"];
for (var key in r) {
if (r[key] !== null && Array.isArray(r[key])) {
@jhsuZerion
jhsuZerion / convertStateToFull.js
Created March 15, 2017 03:36
convertStateToFull() transforms a state abbreviation to its full name
/**
* convertStateToFull transforms a state abbreviation to its full name
* @param {string} abbreviation two-letter state abbreviation
* @return {string} full name of the state
*/
function convertStateToFull(abbreviation) {
var states = {
"AL": "Alabama",
"AK": "Alaska",
"AZ": "Arizona",
@jhsuZerion
jhsuZerion / json_webinar.js
Last active April 21, 2017 11:32
Modifying a JSON Object
var record = {
"supervisor": "Ryan Coleman",
"supervisor_email": "rcoleman@zerionsoftware.com",
"team_members": [
{
"member_name": "mnesgoda",
"quarterly_goals": "3",
"motivation": "4",
"communication": "5",
"professionalism": "4"
record = {
"ID": "118",
"PARENT_RECORD_ID": "0",
"PARENT_PAGE_ID": "0",
"PARENT_ELEMENT_ID": "0",
"CREATED_DATE": "2017-04-18 17:06:09",
"CREATED_BY": "Sandbox2",
"CREATED_LOCATION": "",
"CREATED_DEVICE_ID": "8bd823a04e1fd2cb04c6c7d6bff9f08355f44523",
"MODIFIED_DATE": "2017-04-26 12:39:44",
@jhsuZerion
jhsuZerion / list_to_subform.js
Created August 21, 2017 11:55
This function is meant to convert a list of values into an array of records, similar to a subform flattening. Each entry in the list will become the single value in that record. Use this function to flatten list data for tabular entry. The only two required parameters are the record object and the name of the property containing the list. Two op…
/**
* function to flatten a list of values into multiple records
* @param {object} r record with list of values, normally csv
* @param {string} multi_dcn name of property in record
* @param {string} new_dcn custom name to replace property name
* @param {string} delimeter custom delimeter, comma by default
* @return {array} array of records
*/
function list_to_subform(r,multi_dcn,new_dcn,delimeter) {
if(typeof r !== "object" || r.hasOwnProperty(multi_dcn) === false) return r;