view show.php @ 144:c030c3cf0d80

More work on display system.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 23 Oct 2013 01:42:21 +0300
parents d2e9285b69ad
children 66b485431cac
line wrap: on
line source

<?
//
// FAPWeb Simple Demoparty System
// Party information display system
// (C) Copyright 2012-2013 Tecnic Software productions (TNSP)
//
require "mconfig.inc.php";
require "msite.inc.php";
require "mcommon.inc.php";
require "majax.php";

stSetupCacheControl();

cmPrintPageHeader("PARTY INFORMATION DISPLAY SYSTEM", "", FALSE);
stCommonAJAX("showajax.php", "show.php", TRUE);
?>

<!-- ========================== -->

<noscript>
  <div class="notice">
    <h1>Javascript required</h1>
    <p>
    The compo system page requires Javascript to be enabled for the AJAX functionality.
    <br />
    <a href="#">Please enable Javascript and reload this page</a>.
    </p>
  </div>
</noscript>

<div class="showView" id="mainView0"></div>
<div class="showView" id="mainView1"></div>

<!-- ========================== -->

<script type="text/javascript">

var failCount = 0;
var prevView = -1, activeView = 0;
var activeSlide = -1, activeSlideMode = -1;
var errorView = false;


function tickAnim()
{
  if (activeView != prevView)
  {
    document.getElementById("mainView0").style.display = (activeView == 0) ? "block" : "none";
    document.getElementById("mainView1").style.display = (activeView == 1) ? "block" : "none";
    prevView = activeView;
  }
}


function updateView(txt)
{
  var view = document.getElementById("mainView"+ activeView);
  if (view)
  {
    view.innerHTML = txt;
  }
}


function displayError()
{
  // Increase failure count
  if (++failCount > 5 && !errorView)
  {
    errorView = true;
    updateView("... error ...");
  }
}


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

  var msuccess2 = function(txt)
  {
    activeSlide = txt;
    sendPOSTRequest("action=get&type=slide", msuccess3, displayError);
  }

  var msuccess1 = function(txt)
  {
    activeSlideMode = txt;
    sendPOSTRequest("action=get&type=activeSlide", msuccess2, displayError);
  }

  sendPOSTRequest("action=get&type=activeSlideMode", msuccess1, displayError);
}


//
// Main tick function, check for updates from server
//
var timeOutSet = false;

function tickMain()
{
  timeOutSet = false;

  var msuccess = function(txt)
  {
    failCount = 0;
    if (txt == "changed")
    {
      viewChanged();
      if (!timeOutSet)
      {
        setTimeout("tickMain();", 500);
        timeOutSet = true;
      }
    }
    else
    {
      if (!timeOutSet)
      {
        setTimeout("tickMain();", 2000);
        timeOutSet = true;
      }
    }
  }
  
  var mfail = function(txt)
  {
    displayError();
    if (!timeOutSet)
    {
      setTimeout("tickMain();", 5000);
      timeOutSet = true;
    }
  }

  sendPOSTRequest("action=check&activeSlide="+activeSlide+"&activeSlideMode="+activeSlideMode, msuccess, mfail);
}

setTimeout("tickMain();", 1000);
setInterval("tickAnim();", 25);
viewChanged();

</script>
<?
cmPrintPageFooter(FALSE);
?>