whitespace, get rid of redundant ajax startup

This commit is contained in:
Isaac Connor 2018-10-16 17:20:10 -04:00
parent c2af380e29
commit b0078fb1d9
1 changed files with 112 additions and 113 deletions

View File

@ -1,4 +1,7 @@
var requestQueue = new Request.Queue( { concurrent: monitorData.length, stopOnFailure: false } );
var requestQueue = new Request.Queue({
concurrent: monitorData.length,
stopOnFailure: false
});
function Monitor(monitorData) {
this.id = monitorData.id;
@ -21,7 +24,6 @@ function Monitor( monitorData ) {
console.log("No streamCmdQuery");
};
this.setStateClass = function(element, stateClass) {
if ( !element.hasClass(stateClass) ) {
if ( stateClass != 'alarm' )
@ -37,7 +39,7 @@ function Monitor( monitorData ) {
this.onError = function(text, error) {
console.log('onerror: ' + text + ' error:'+error);
// Requeue, but want to wait a while.
var streamCmdTimeout = 1000*statusRefreshTimeout;
var streamCmdTimeout = 10*statusRefreshTimeout;
this.streamCmdTimer = this.streamCmdQuery.delay(streamCmdTimeout, this);
};
this.onFailure = function(xhr) {
@ -132,7 +134,9 @@ function Monitor( monitorData ) {
}
} // end if Ok or not
var streamCmdTimeout = statusRefreshTimeout;
// The idea here is if we are alarmed, do updates faster. However, there is a timeout in the php side which isn't getting modified, so this may cause a problem. Also the server may only be able to update so fast.
// The idea here is if we are alarmed, do updates faster.
// However, there is a timeout in the php side which isn't getting modified,
// so this may cause a problem. Also the server may only be able to update so fast.
//if ( this.alarmState == STATE_ALARM || this.alarmState == STATE_ALERT ) {
//streamCmdTimeout = streamCmdTimeout/5;
//}
@ -142,7 +146,7 @@ function Monitor( monitorData ) {
this.streamCmdQuery = function(resent) {
if ( resent ) {
console.log( this.connKey+": Resending" );
console.log(this.connKey+": timeout: Resending");
this.streamCmdReq.cancel();
}
//console.log("Starting CmdQuery for " + this.connKey );
@ -155,18 +159,17 @@ function Monitor( monitorData ) {
this.streamCmdReq = new Request.JSON( {
url: this.url,
method: 'get',
timeout: 1000+AJAX_TIMEOUT,
timeout: AJAX_TIMEOUT,
onSuccess: this.getStreamCmdResponse.bind(this),
onTimeout: this.streamCmdQuery.bind(this, true),
onError: this.onError.bind(this),
onFailure: this.onFailure.bind(this),
link: 'cancel'
} );
console.log("queueing for " + this.id + " " + this.connKey );
console.log("queueing for " + this.id + " " + this.connKey + " timeout is: " + AJAX_TIMEOUT);
requestQueue.addRequest("cmdReq"+this.id, this.streamCmdReq);
}
}
} // end function Monitor
function selectLayout(element) {
layout = $j(element).val();
@ -175,7 +178,7 @@ function selectLayout( element ) {
layout = layouts[layout];
console.log(layout);
for ( var i = 0; i < monitors.length; i++ ) {
for ( var i = 0, length = monitors.length; i < length; i++ ) {
monitor = monitors[i];
// Need to clear the current positioning, and apply the new
@ -214,9 +217,8 @@ function selectLayout( element ) {
Cookie.write( 'zmMontageScale', '', { duration: 10*365 } );
$('scale').set('value', '');
$('width').set('value', '');
if ( 1 ) {
for ( var x = 0; x < monitors.length; x++ ) {
var monitor = monitors[x];
for ( var i = 0, length = monitors.length; i < length; i++ ) {
var monitor = monitors[i];
var streamImg = $('liveStream'+monitor.id);
if ( streamImg ) {
if ( streamImg.nodeName == 'IMG' ) {
@ -237,15 +239,14 @@ if ( 1 ) {
}
} // end foreach monitor
}
}
}
} // end function selectLayout(element)
function changeSize() {
var width = $('width').get('value');
var height = $('height').get('value');
for ( var x = 0; x < monitors.length; x++ ) {
var monitor = monitors[x];
for ( var i = 0, length = monitors.length; i < length; i++ ) {
var monitor = monitors[i];
// Scale the frame
monitor_frame = $j('#monitorFrame'+monitor.id);
@ -253,8 +254,11 @@ function changeSize() {
console.log("Error finding frame for " + monitor.id);
continue;
}
monitor_frame.css('width',width?width+'px':'');
monitor_frame.css('height',height?height+'px':'');
if ( width )
monitor_frame.css('width', width+'px');
if ( height )
monitor_frame.css('height', height+'px');
/*Stream could be an applet so can't use moo tools*/
var streamImg = $('liveStream'+monitor.id);
if ( streamImg ) {
@ -294,10 +298,10 @@ function changeScale() {
selectLayout('#zmMontageLayout');
return;
}
for ( var x = 0; x < monitors.length; x++ ) {
var monitor = monitors[x];
var newWidth = ( monitorData[x].width * scale ) / SCALE_BASE;
var newHeight = ( monitorData[x].height * scale ) / SCALE_BASE;
for ( var i = 0, length = monitors.length; i < length; i++ ) {
var monitor = monitors[i];
var newWidth = ( monitorData[i].width * scale ) / SCALE_BASE;
var newHeight = ( monitorData[i].height * scale ) / SCALE_BASE;
// Scale the frame
monitor_frame = $j('#monitorFrame'+monitor.id);
@ -342,10 +346,10 @@ function edit_layout(button) {
// Turn off the onclick on the image.
for ( var i = 0; i < monitors.length; i++ ) {
for ( var i = 0, length = monitors.length; i < length; i++ ) {
var monitor = monitors[i];
monitor_feed = $j('#imageFeed'+monitor.id)[0];
monitor_feed.click('');
monitor_feed.onclick = '';
};
$j('#monitors .monitorFrame').draggable({
@ -360,7 +364,7 @@ function save_layout(button) {
var form = button.form;
// In fixed positioning, order doesn't matter. In floating positioning, it does.
var Positions = {};
for ( var i = 0; i < monitors.length; i++ ) {
for ( var i = 0, length = monitors.length; i < lenth; i++ ) {
var monitor = monitors[i];
monitor_frame = $j('#monitorFrame'+monitor.id);
@ -377,11 +381,12 @@ function save_layout(button) {
} // end foreach monitor
form.Positions.value = JSON.stringify(Positions);
form.submit();
}
} // end function save_layout
function cancel_layout(button) {
$j('#SaveLayout').hide();
$j('#EditLayout').show();
for ( var i = 0; i < monitors.length; i++ ) {
for ( var i = 0, length = monitors.length; i < length; i++ ) {
var monitor = monitors[i];
monitor_feed = $j('#imageFeed'+monitor.id);
monitor_feed.click(monitor.onclick);
@ -409,25 +414,19 @@ function initPage() {
jQuery("#hdrbutton").toggleClass('glyphicon-menu-down').toggleClass('glyphicon-menu-up');
}
for ( var i = 0; i < monitorData.length; i++ ) {
for ( var i = 0, length = monitorData.length; i < length; i++ ) {
monitors[i] = new Monitor(monitorData[i]);
// Start the fps and status updates. give a random delay so that we don't assault the server
var delay = Math.round( (Math.random()+0.5)*statusRefreshTimeout );
var interval = monitors[i].refresh;
monitors[i].start(delay);
var interval = monitors[i].refresh;
if ( monitors[i].type == 'WebSite' && interval > 0 ) {
setInterval(reloadWebSite, interval*1000, i);
}
}
selectLayout('#zmMontageLayout');
for ( var i = 0; i < monitorData.length; i++ ) {
if ( monitors[i].type == 'WebSite' )
continue;
var delay = Math.round( (Math.random()+0.75)*statusRefreshTimeout );
console.log("Delay for monitor " + monitorData[i].id + " is " + delay );
monitors[i].streamCmdQuery.delay( delay, monitors[i] );
//monitors[i].zm_startup(delay);
}
}
// Kick everything off
window.addEvent('domready', initPage);