view showajax.js.php @ 1096:bbc0a3d0b51e

Major renaming / refactor of site messages. Some that were previously modifiable from admin interface are now "hardcoded" in the configuration file. Having these settings made modifiable from there made no sense and just took space in the UI.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 27 Jan 2017 22:15:06 +0200
parents 76e11ae923a7
children b2bca5f6d0ff
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();
});