Last active
July 6, 2020 13:42
-
-
Save vtnerd91/237dd9a61f38b385f107 to your computer and use it in GitHub Desktop.
Lock the selected place either to 3 or your highest available lock level.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
if (!String.plFormat) { | |
String.plFormat = function (format) { | |
var args = Array.prototype.slice.call(arguments, 1); | |
return format.replace(/{(\d+)}/g, function (name, number) { | |
return typeof args[number] != "undefined" ? args[number] : match; | |
}); | |
}; | |
} | |
function toTitleCase(str) { | |
if (!str) { | |
return str; | |
} | |
var allCaps = (str === str.toUpperCase()); | |
return str.replace(/\w[^\s-]*/g, function(txt) { | |
return ((txt == txt.toUpperCase()) && !allCaps) ? txt : txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); | |
}); | |
} | |
function normalizePhone(s, outputFormat) { | |
if (!s) { | |
return s; | |
} | |
// Remove all non digits | |
var s1 = s.replace(/\D/g,''); | |
// 9 or 10 digits? | |
var m = s1.match(/^1?(\d{3})(\d{3})(\d{4})$/); | |
if (!m) { | |
return s; | |
} | |
else { | |
return String.plFormat(outputFormat, m[1], m[2], m[3]); | |
} | |
} | |
function normalizeURL(s) { | |
if (!s) { | |
return s; | |
} | |
var m = s.match(/^https?:\/\/(.*)$/i); | |
if (m) { | |
return m[1]; | |
} | |
else { | |
return s; | |
} | |
} | |
var count = 0; | |
var thisUser = W.loginManager.user; | |
if (thisUser === null) | |
return; | |
var usrRank = thisUser.normalizedLevel; | |
var lockLevel3 = 2; | |
var lockLevel4 = 3; | |
var lockLevel5 = 4; | |
if (lockLevel3 > (usrRank - 1)) { | |
lockLevel3 = (usrRank - 1); | |
} | |
if (lockLevel4 > (usrRank - 1)) { | |
lockLevel4 = (usrRank - 1); | |
} | |
if (lockLevel5 > (usrRank - 1)) { | |
lockLevel5 = (usrRank - 1); | |
} | |
var UpdateObject; | |
if (typeof (require) !== "undefined") { | |
UpdateObject = require("Waze/Action/UpdateObject"); | |
} | |
else { | |
UpdateObject = W.Action.UpdateObject; | |
} | |
//console.log(W); | |
jQuery("#map-search input[name=q]").focus(); | |
for (var ix = 0; ix < W.selectionManager.selectedItems.length; ix++) { | |
var item = W.selectionManager.selectedItems[ix].model; | |
//console.log(item); | |
if (item.type == "venue") { | |
var addr = item.getAddress() | |
//console.log(addr); | |
if (!addr) { | |
alert("Place has no address."); | |
return; | |
} | |
var region; | |
switch (addr.state.name) { | |
case "Kentucky": | |
case "North Carolina": | |
case "South Carolina": | |
case "Tennessee": | |
region = "SAT"; | |
break; | |
case "Alabama": | |
case "Florida": | |
case "Georgia": | |
region = "SE"; | |
break; | |
default: | |
region = "Unknown"; | |
break; | |
} | |
var newUrl = normalizeURL(item.attributes.url); | |
var newName = toTitleCase(item.attributes.name); | |
var outputFormat = "({0}) {1}-{2}"; | |
if (region == "SE") { | |
// Phone customizations for Southeast Region | |
outputFormat = "{0}-{1}-{2}"; | |
} | |
var newPhone = normalizePhone(item.attributes.phone, outputFormat); | |
W.model.actionManager.add(new UpdateObject(item, { name: newName, phone: newPhone, url: newUrl })); | |
var issues = []; | |
if (!item.attributes.name) { | |
issues.push("Place does not have a name."); | |
} | |
if (!addr.street || addr.street.isEmpty) { | |
issues.push("Place does not have a street."); | |
} | |
if (!item.attributes.houseNumber) { | |
issues.push("Place does not have a house number."); | |
} | |
if (issues.length > 0) { | |
alert(issues.join("\n")); | |
return; | |
} | |
var levelToLock = lockLevel3; | |
if (region === "SAT") { | |
var level5Categories = ["HOSPITAL_MEDICAL_CARE","AIRPORT"]; | |
for (var ixCat=0; ixCat<item.attributes.categories.length;ixCat++) { | |
if (level5Categories.indexOf(item.attributes.categories[ixCat]) > -1) { | |
levelToLock = lockLevel5; | |
break; | |
} | |
} | |
} | |
if (item.attributes.lockRank < levelToLock) { | |
W.model.actionManager.add(new UpdateObject(item, { lockRank: levelToLock })); | |
} | |
} | |
} | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){if(!String.plFormat){String.plFormat=function(x){var w=Array.prototype.slice.call(arguments,1);return x.replace(/{(\d+)}/g,function(y,z){return typeof w[z]!="undefined"?w[z]:match})}}function f(x){if(!x){return x}var w=(x===x.toUpperCase());return x.replace(/\w[^\s-]*/g,function(y){return((y==y.toUpperCase())&&!w)?y:y.charAt(0).toUpperCase()+y.substr(1).toLowerCase()})}function v(y,z){if(!y){return y}var x=y.replace(/\D/g,"");var w=x.match(/^1?(\d{3})(\d{3})(\d{4})$/);if(!w){return y}else{return String.plFormat(z,w[1],w[2],w[3])}}function q(x){if(!x){return x}var w=x.match(/^https?:\/\/(.*)$/i);if(w){return w[1]}else{return x}}var l=0;var r=W.loginManager.user;if(r===null){return}var u=r.normalizedLevel;var j=2;var h=3;var e=4;if(j>(u-1)){j=(u-1)}if(h>(u-1)){h=(u-1)}if(e>(u-1)){e=(u-1)}var a;if(typeof(require)!=="undefined"){a=require("Waze/Action/UpdateObject")}else{a=W.Action.UpdateObject}jQuery("#map-search input[name=q]").focus();for(var i=0;i<W.selectionManager.selectedItems.length;i++){var s=W.selectionManager.selectedItems[i].model;if(s.type=="venue"){var n=s.getAddress();if(!n){alert("Place has no address.");return}var g;switch(n.state.name){case"Kentucky":case"North Carolina":case"South Carolina":case"Tennessee":g="SAT";break;case"Alabama":case"Florida":case"Georgia":g="SE";break;default:g="Unknown";break}var b=q(s.attributes.url);var o=f(s.attributes.name);var t="({0}) {1}-{2}";if(g=="SE"){t="{0}-{1}-{2}"}var c=v(s.attributes.phone,t);W.model.actionManager.add(new a(s,{name:o,phone:c,url:b}));var p=[];if(!s.attributes.name){p.push("Place does not have a name.")}if(!n.street||n.street.isEmpty){p.push("Place does not have a street.")}if(!s.attributes.houseNumber){p.push("Place does not have a house number.")}if(p.length>0){alert(p.join("\n"));return}var d=j;if(g==="SAT"){var m=["HOSPITAL_MEDICAL_CARE","AIRPORT"];for(var k=0;k<s.attributes.categories.length;k++){if(m.indexOf(s.attributes.categories[k])>-1){d=e;break}}}if(s.attributes.lockRank<d){W.model.actionManager.add(new a(s,{lockRank:d}))}}}})(); |
dandann00dle would like phone number normalization (###) ###-####
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Title Case for the Place Name please