view showajax.js.php @ 1120:b2bca5f6d0ff default tip

Cosmetic cleanup: remove trailing whitespace.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 13 Dec 2020 13:47:13 +0200
parents 76e11ae923a7
children
line wrap: on
line source

<?php
//
// FAPWeb - Simple Web-based Demoparty Management System
// Party main screen viewer
// (C) Copyright 2012-2017 Tecnic Software productions (TNSP)
//
header("Content-Type: application/javascript");
require_once "mconfig.inc.php";
require_once "msite.inc.php";
require_once "msession.inc.php";

stCommonAJAX("showajax.php", "show.php");
?>

var failCount = 0;
var lastUpdate = 0;
var errorView = false;


function updateView(txt)
{
  var view = document.getElementById("mainView");
  if (view && txt != false && txt != "")
    view.innerHTML = txt;
}


function displayError()
{
  // Increase failure count
  if (++failCount >= 3 && !errorView)
  {
    errorView = true;
    updateView("<div class=\"slideHeader\"><div class=\"slideHeaderDiv\"></div></div><div class=\"slideText\"><div class=\"guru\">Software Failure.&nbsp;&nbsp;&nbsp;Press left mouse button to continue.<br />Guru Meditation #00000004.0000AAC0</div></div>");
  }
}


//
// Update view when triggered by main tick
//
function viewChanged()
{
  var msuccess2 = function(txt)
  {
    // Successfully fetched new data, initiate view update
    updateView(txt);
  }

  var msuccess1 = function(txt)
  {
    lastUpdate = txt;
    jsSendPOSTRequest("action=get&type=slide", msuccess2, displayError);
  }

  jsSendPOSTRequest("action=get&type=update", msuccess1, displayError);
}


function setTickUpdate(qtime)
{
  if (!timeOutSet)
  {
    timeOutSet = true;
    setTimeout(function() { tickMain(); }, qtime);
  }
}


//
// Main tick function, check for updates from server
//
function tickMain()
{
  timeOutSet = false;

  var msuccess = function(txt)
  {
    failCount = 0;
    if (txt == "changed")
    {
      viewChanged();
      setTickUpdate(250);
    }
    else
    if (txt == "reload")
    {
      location.reload();
    }
    else
    {
      setTickUpdate(500);
    }
  }

  var mfail = function(txt)
  {
    displayError();
    setTickUpdate(5000);
  }

  jsSendPOSTRequest("action=check&lastUpdate="+lastUpdate, msuccess, mfail);
}

var timeOutSet = false;

document.addEventListener("DOMContentLoaded",
function ()
{
  setTickUpdate(100);
  viewChanged();
});