App-RPi-EnvUI
view release on metacpan or search on metacpan
public/js/core.js view on Meta::CPAN
$.ajax({
async: false,
type: 'GET',
url: '/logged_in',
success: function(data){
var json = $.parseJSON(data);
logged_in = json.status;
}
});
$('div.ui-page-active #auth').addClass('a');
if (logged_in){
$('div.ui-page-active #auth').text('Logout');
$('div.ui-page-active #auth').attr('href', '/logout');
}
else {
$('div.ui-page-active #auth').text('Login');
$('div.ui-page-active #auth').attr('href', '/login');
}
// aux buttons
for (var i = 1; i < 9; i++){
var aux = 'aux' + i;
if (! logged_in){
$('div.ui-page-active #' + aux).flipswitch("option", "disabled", true);
$('div.ui-page-active #'+aux+'_widget').prop(
'title',
'You must be logged in to make changes.'
);
}
else {
$('div.ui-page-active #'+ aux).flipswitch();
$('div.ui-page-active #'+ aux).flipswitch("option", "onText", "ON");
$('div.ui-page-active #'+ aux).flipswitch("option", "offText", "OFF");
}
// hide all generic auxs if necessary
$.ajax({
async: false,
type: 'GET',
url: '/get_aux/' + aux,
success: function(data){
var json = $.parseJSON(data);
if (parseInt(json.pin) == '-1'){
$('div.ui-page-active #'+aux+'_widget').hide();
}
}
});
}
// button event
$('div.ui-page-active .button').on('change', aux_action);
// main menu
$('div.ui-page-active .myMenu ul li').hover(function() {
$(this).children('ul').stop(true, false, true).slideToggle(300);
});
$.get('/get_config/devel', function(devel){
if (parseInt(devel) == '1'){
$('#time').css({'background-color': 'red'});
}
});
// draggable widgets
var s_positions = localStorage.positions || "{}";
var positions = $.parseJSON(s_positions);
$.each(positions, function (id, pos){
$('div.ui-page-active #'+ id).css(pos);
});
$('div.ui-page-active .drag').draggable({
handle: 'p.widget_handle',
grid: [10, 1],
scroll: false,
opacity: 0.5,
cursor: "move",
drag: function(){
},
stop: function(event, ui){
positions[this.id] = ui.position;
localStorage.positions = JSON.stringify(positions)
}
});
// set limits
$.get('/get_control/temp_limit', function(data){
temp_limit = data;
});
$.get('/get_control/humidity_limit', function(data){
humidity_limit = data;
});
// initialization
event_interval();
display_env();
display_light();
});
$(document).on('pageshow', '#stats', function(){
$('div.ui-page-active .myMenu ul li').hover(function() {
$(this).children('ul').stop(true, false, true).slideToggle(300);
});
$('div.ui-page-active #auth').addClass('a');
if (logged_in){
$('div.ui-page-active #auth').text('Logout');
$('div.ui-page-active #auth').attr('href', '/logout');
}
else {
$('div.ui-page-active #auth').text('Login');
$('div.ui-page-active #auth').attr('href', '/login');
}
graph_interval();
});
// stop the graph timed event when not in stats page
$(document).on('pagebeforehide', '#stats', function(){
clearInterval(graph_event);
});
// external functions
// events
function event_interval(){
$.get('/get_config/event_display_timer', function(interval){
interval = interval * 1000;
setInterval(display_env, interval);
});
}
// core functions
function aux_update(){
display_time();
display_light();
for(var i = 1; i < 9; i++){
var aux = 'aux'+ i;
aux_setup(aux);
}
}
function aux_setup(aux){
$.ajax({
async: true,
type: 'GET',
url: '/get_aux/' + aux,
success: function(data){
var json = $.parseJSON(data);
if (parseInt(json.pin) == '-1'){
return;
}
var onText;
( run in 0.845 second using v1.01-cache-2.11-cpan-39bf76dae61 )