' : '>
');
text1 +=
'
' +
'
' + dataObs[readingKey] +
'' + displayUnit + '' +
'
' +
'
' + typeLabel + '
' +
'
' +
'
' +
'
';
text1 += '';
if(hasAlert) {
if (!disabled && !alertTrig) {
if ( typeKey !== "wet" )
text1 += 'Alert range ' + ((alertMin && alertMin != "-100") ? "Min: " + alertMin + " " : '') + ( (alertMax && alertMax != "-100") ? "Max: " + alertMax : '');
else
text1 += 'Alert type: ' + ( (alertMax && alertMax == "1" ) ? "Wet" : "Dry");
} else if ( alertTrig ) {
text1 += "Alert Triggered";
} else
text1 += 'Alert Value: (Alert is disabled)';
} else
if (alertable)
text1 += 'No alerts set';
text1 += '';
if ( hasAlert ) {
$("#del-" + typeKey + "-alert-" + deviceInfo["device_id"]).show();
$("#ca-" + typeKey + "-" + deviceInfo["device_id"]).text("Update Alert");
$("#alert-" + typeKey + "-" + deviceInfo["device_id"] + " #high" + typeKey + "-" + deviceInfo["device_id"]).val(valMax);
$("#alert-" + typeKey + "-" + deviceInfo["device_id"] + " #low" + typeKey + "-" + deviceInfo["device_id"]).val(valMin);
$("#textEmailAlert-" + typeKey + "-" + deviceInfo["device_id"]).val(alertMethod);
} else {
$("#del-" + typeKey + "-alert-" + deviceInfo["device_id"]).hide();
$("#ca-" + typeKey + "-" + deviceInfo["device_id"]).text("Create Alert");
}
// the above and this below are hacks needed to give alerts an id and then generate a page for them off of it and link to it.
hasAlert = false;
if (alertable) {
text1 += '
' +
'
' +
"\n";
} else {
text1 += '\n';
}
firstDone = true;
}
// update dataPanel
$("#dataPanel_" + deviceInfo.device_id ).html(text1);
// update Last seen
$( "#device-" + deviceInfo.device_id + " .notiTime" ).html( dataObs["timestamp"] );
$( "#device-" + deviceInfo.device_id + " .notiLink" ).html( dataObs["linkquality"] + "%" );
$( "#device-" + deviceInfo.device_id + " .notiBattery" ).html( ( dataObs["lowbattery"] ? "Good" : "Replace") );
// Last seen out of date
if(new Date().getTime()/1000 - dataObs["utctime"] > 10800) { //3 hours at 3600 seconds per hour
$( "#device-" + deviceInfo.device_id + " .notiTime" ).parent().addClass("red-danger");
} else {
$( "#device-" + deviceInfo.device_id + " .notiTime" ).parent().removeClass("red-danger");
}
// if device is expired switch this out
if ( deviceInfo.expired == "1" ) {
$(".notExpiredDiv-" + deviceInfo.device_id).hide();
$(".renewAlertDiv-" + deviceInfo.device_id).hide();
$(".isExpiredDiv-" + deviceInfo.device_id).show();
} else if ( deviceInfo.alerts &&
( ( deviceInfo.alerts.temp && deviceInfo.alerts.temp.alert_id == "0" ) || ( deviceInfo.alerts.temp2 && deviceInfo.alerts.temp2.alert_id == "0" ) ||
( deviceInfo.alerts.rh && deviceInfo.alerts.rh.alert_id == "0" ) || ( deviceInfo.alerts.wet && deviceInfo.alerts.wet.alert_id == "0" ) ) &&
deviceInfo.expired == "0" ) {
$(".isExpiredDiv-" + deviceInfo.device_id).hide();
$(".notExpiredDiv-" + deviceInfo.device_id).show();
$(".renewAlertDiv-" + deviceInfo.device_id).show();
} else{
$(".renewAlertDiv-" + deviceInfo.device_id).hide();
$(".isExpiredDiv-" + deviceInfo.device_id).hide();
$(".notExpiredDiv-" + deviceInfo.device_id).show();
}
}
/****
* Class name is the footer element to set active.
* Remove is used if we want to clear other elements
* @param className
*/
function setNavActive( element ) {
$('.mobile-nav .ui-btn').removeClass( "ui-btn-active" );
$( element ).addClass( "ui-btn-active" );
}
/**
* Determine the mobile operating system.
* This function either returns 'iOS', 'Android' or 'unknown'
*
* @returns {String}
*/
function getMobileOS() {
var userAgent = navigator.userAgent || navigator.vendor || window.opera;
if( userAgent.match( /iPad/i ) || userAgent.match( /iPhone/i ) || userAgent.match( /iPod/i ) )
return 'iOS';
else if( userAgent.match( /Android/i ) )
return 'Android';
else
return false;
}
function setIntervalAction ( event ) {
var $this = $(this);
var uId = $this.data("id");
var sInt = $("#sIntValue_" + uId).val();
$("#changeInterval-warning-" + uId).hide();
// If we are start the spinner, and call the service
var dataString = "pkey=" + prodKey + "&ref=" + userSKey +
"&sensor=" + uId + "&action=setsensorinterval" + "&interval=" + sInt;
console.log(dataString);
$.ajax({
type: "GET",
url: serviceURL + "user-api.php?",
data: dataString,
success: function(response) {
// Handling the response -- Need to finish out URL's and more here
if ( response && response.result && response.result === "success") {
$("#changeInterval-warning-" + uId).html( response.result );
$("#changeInterval-warning-" + uId).show();
$("#sensorIntervalSpan_" + uId).html("Current Interval: " + sInt + " mins");
$("#sIntValue_" + uId).val(sInt); //feels redundent and unessecary.
} else if ( response && response.result ) {
$("#changeInterval-warning-" + uId).html( response.result );
$("#changeInterval-warning-" + uId).show();
} else {
$("#changeInterval-warning-" + uId).html( "There was a network error. Please try again." );
$("#changeInterval-warning-" + uId).show();
}
},
error: function () {
$("#changeInterval-warning-" + uId).html( "There was a network error. Please try again." );
$("#changeInterval-warning-" + uId).show();
}
});
event.preventDefault();
}
function syncPWSTimezone ( event ) {
var $this = $(this);
var uId = $this.data("id");
var custTimezone = $("#customTimezone-" + uId).val();
var set = 0;
if ($("#setCustTimezone-" + uId).is(':checked')) {
set = 1;
}
$("#timezoneSync-warning-" + uId).hide();
// If we are start the spinner, and call the service
var dataString = "pkey=" + prodKey + "&ref=" + userSKey +
"&sensor=" + uId + "&timezone=" + custTimezone + "&set=" + set + "&action=syncStationTimezone";
if (set == 0 || (set == 1 && custTimezone != 0)) {
$.ajax({
type: "GET",
url: serviceURL + "user-api.php?",
data: dataString,
success: function(response) {
// Handling the response -- Need to finish out URL's and more here
if ( response && response.result && response.result === true) {
$("#timezoneSync-warning-" + uId).html( "success" );
$("#timezoneSync-warning-" + uId).show();
} else {
$("#timezoneSync-warning-" + uId).html( "There was a network error. Please try again." );
$("#timezoneSync-warning-" + uId).show();
}
},
error: function () {
$("#timezoneSync-warning-" + uId).html( "There was a network error. Please try again." );
$("#timezoneSync-warning-" + uId).show();
}
});
}
event.preventDefault();
}
function updateTimezoneAction( event ) {
// hide any previous errors
$("#changeTimeZone-warning").hide();
var time = $("#iUpdateTime").val();
var syncdevs = 1;
if($("#accountTimezonePWSLimiter").is(":checked")) {
syncdevs = 0;
}
timezone = time;
$("#changeTimeZone.container").css("opacity", ".25");
$("#changeTimeZone").spin('medium');
var dataString = "pkey=" + prodKey + "&time=" + time + "&ref=" + userSKey + "&syncdevs=" + syncdevs + "&action=updatetimezone";
$.ajax({
type: "GET",
url: serviceURL + "user-api.php?",
data: dataString,
success: function(response) {
// Handling the response -- Need to finish out URL's and more here
if ( response && response.result && response.result == "success" ) {
initChart();
$("#changeTimeZone").spin(false);
$("#iProfileTime").html($("#iUpdateTime option[value='" + time + "']").text());
hashLoc="#profile";
$("#timezoneUpdateSuccess").show();
setTimeout( function(){ $("#timezoneUpdateSuccess").hide(); },15000 );
window.location.href = urlLoc + "/v1.2/#profile";
} else if ( response && response.result && response.result == "invalid time" )
spinTakedown( "changeTimeZone" , 'Invalid time entered. Please Try Again');
else
spinTakedown( "changeTimeZone" , 'An error happened. Please try again.');
},
error: function () {
spinTakedown( "changeTimeZone" , 'Our servers are experiencing heavy load. Please try again shortly.');
}
});
event.preventDefault();
}
function updateMetricAction( event ) {
// hide any previous errors
$("#changeMetric-warning").hide();
var metric = $("#iUpdateMetric").val();
$("#changeMetric.container").css("opacity", ".25");
$("#changeMetric").spin('medium');
var dataString = "pkey=" + prodKey + "&metric=" + metric + "&ref=" + userSKey + "&action=updatemetric";
$.ajax({
type: "GET",
url: serviceURL + "user-api.php?",
data: dataString,
success: function(response) {
// Handling the response -- Need to finish out URL's and more here
if ( response && response.result && response.result == "success" ) {
isMetric = metric;
initDataTable(true);
initChart();
$("#changeMetric").spin(false);
$("#iProfileMetric").html($("#iUpdateMetric option[value='" + metric + "']").text());
hashLoc="#profile";
$("#metricUpdateSuccess").show();
setTimeout( function(){ $("#metricUpdateSuccess").hide(); },15000 );
window.location.href = urlLoc + "/v1.2/#profile";
} else if ( response && response.result && response.result == "invalid time" )
spinTakedown( "changeMetric" , 'Invalid time entered. Please Try Again');
else
spinTakedown( "changeMetric" , 'An error happened. Please try again.');
},
error: function () {
spinTakedown( "changeMetric" , 'Our servers are experiencing heavy load. Please try again shortly.');
}
});
event.preventDefault();
}
function updatePasswordAction( event ) {
// hide any previous errors
$("#changePassword-warning").hide();
var updateValue = $("#iUpdatePass").val();
var updateConfVal = $("#iConfUpdatePass").val();
$("#changePassword.container").css("opacity", ".25");
$("#changePassword").spin('medium');
if (updateValue != updateConfVal) {
spinTakedown( "changePassword" , 'The entered passwords do not match');
} else {
subURL = serviceURL + "user-api.php?pkey=" + prodKey + "&ref=" + userSKey + "&action=updatepassword";
passform = $("#formPasswordUpdate");
//subURL = "http" + subURL.substring(4);
rawdata = passform.serialize();
$.post(subURL, rawdata)
.done(function(response){
if ( response && response.result && response.result == "success" ) {
$("#changePassword").spin(false);
$("#passUpdateSuccess").show();
setTimeout( function(){ $("#passUpdateSuccess").hide(); },15000 );
hashLoc="#profile";
$("#iUpdatePass").val("");
window.location.href = urlLoc + "/v1.2/#profile";
} else if ( response && response.result)
spinTakedown( "changePassword" , response.result);
else
spinTakedown( "changePassword" , 'An error happened. Please try again.');
})
.fail(function(){
spinTakedown( "changePassword" , 'Our servers are experiencing heavy load. Please try again shortly.');
});
}
event.preventDefault();
}
function updateWeatherAction( event ) {
var dataString = "q=La%20crosse,wi&callback=test&units=imperial&APPID=d65beeb9214a28a0760faf4d0f2beaed";
var url = "http://api.openweathermap.org/data/2.5/weather?";
$.ajax({
type: "GET",
url: url,
data: dataString,
jsonpCallback: 'test',
contentType: "application/json",
dataType: 'jsonp',
success: function(response) {
$("#humidity").text(response.main.pressure + " hpa");
$("#currLocaleTemp").html( '

' + response.main.temp + " °F");
$("#pressure").text(response.main.humidity + "%");
$("#cloudiness").text(response.weather[0].description);
$("#windInfo").html( Math.ceil(response.wind.speed) + " MPH from " + Math.ceil(response.wind.deg) + "°");
},
error: function ( response ) {
}
});
event.preventDefault();
}
function getProvAction( ) {
//Ajax command to get phone providers, with 2 optional values limitlevel and selectid, limitlevel=1 required here.
//limitlevel=1 means only select id and name, any other limit level assumes one provider only, limitlevel=2&selectid=4
var dataString = "pkey=" + prodKey + "&action=getproviders&limitlevel=1";
$.ajax({
type: "GET",
url: serviceURL + "user-api.php?",
data: dataString,
success: function(response) {
for(var i = 0; i < response.length; i++) {
var val = response[i].id;
var opt = response[i].name;
var el = document.createElement("option");
el.text = opt;
el.value = val;
$(".phone-provider-list").append(el);
}
if(userProviderID){
$(".phone-provider-list").val(userProviderID);
} else {
$(".phone-provider-list").val(0);
}
},
error: function(response) {
alert('Our servers are experiencing heavy load. Some things may not have loaded properly.');
}
});
}
function getPPContentAction() {
var dataString = "pkey=" + prodKey + "&action=getPrivacyPolicy";
console.log('rube');
$.ajax({
type: "GET",
url: serviceURL + "user-api.php?",
data: dataString,
success: function(response) {
$("#pp-content-ajax").html(response['content']);
},
error: function(response) {
alert('Our servers are experiencing heavy load. Some things may not have loaded properly.');
}
});
}
function getTOSContentAction() {
var dataString = "pkey=" + prodKey + "&action=getTOS";
console.log('rube');
$.ajax({
type: "GET",
url: serviceURL + "user-api.php?",
data: dataString,
success: function(response) {
$("#tos-content-ajax").html(response['content']);
},
error: function(response) {
alert('Our servers are experiencing heavy load. Some things may not have loaded properly.');
}
});
}