Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
var navigator_current = "top";
var contentViewer_current = "top";
var http_request = false;

var gif_url;
var view_all_contents = true;

// strings containing the names of all active GifDisplays 
var active_displays_l = new Array(); 


//*************************************************************/
//*************************GIF DISPLAYS************************/
//*************************************************************/

// the current displayFrame
var current_display;

// the list of displayFrame objects 
var displays_l = new Array(); 

function displayFrame(name)
{
  this.name = name;
  this.is_viewed = false;
  this.viewed_l = new Array();
}

/*
  This function is called onload. It creates the list of 
  displayFrame objects.
*/

function fillDisplayList()
{
  var iframes_l = document.getElementsByTagName("iframe");
  for (i = 0; i < iframes_l.length; i++)
  {
    displays_l[i] = new displayFrame(iframes_l[i].id);
  }

  // the default current is the first:
  current_display = displays_l[0];
}

function makeCurrent(display_frame_name)
{
  for (i = 0; i < displays_l.length; i++)
  {
    if (displays_l[i].name == display_frame_name)
    {
      break;
    }
  }
  current_display = displays_l[i];
}


//*************************************************************/
//**********************GENERIC FUNCTIONS**********************/
//*************************************************************/

/*
  This function should return the url of the application webpage
  without asking the server...
*/

function getApplicationURL()
{
  var url = window.location.href;

  // remove the cgi request from the end of the string
  var index = url.indexOf("?");
  if (index >= 0)
  {
    url = url.substring(0, index);
  }

  index = url.lastIndexOf("general");
  url = url.substring(0, index);

  // remove the trailing '/' from the end of the string
  index = url.lastIndexOf("/");
  if (index == url.length - 1)
  {
    url = url.substring(0, index);
  }

  return url;
}

function getContextURL()
{
  var app_url = getApplicationURL();
  var index = app_url.lastIndexOf("/");
  return app_url.substring(0, index);
}


/*
  This function submits a generic request in the form of a url
  and calls the receiver_function when the state of the request
  changes.
*/

function makeRequest(url, receiver_function) 
{
  http_request = false;
  if (window.XMLHttpRequest) 
  { 
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType)
    {
      http_request.overrideMimeType('text/xml');
    }
  }
  if (!http_request) 
  {
    alert('Giving up :( Cannot create an XMLHTTP instance');
  }
  http_request.onreadystatechange = receiver_function;
  http_request.open('GET', url, true);
  http_request.send(null);

  return;
}

function dummy()
{
}

//*************************************************************/
//*************************NAVIGATOR***************************/
//*************************************************************/
/* 
  This function returns the URL that should be loaded as
  a result of clicks on the drop down menus of the navigator form.
*/

function getNavigatorRequestURL()
{
  var form = document.getElementById("NavigatorForm");
  var open = form.Open;
  var subscribe   = form.Subscribe;
  var unsubscribe = form.Unsubscribe;

  url = getApplicationURL();

  if (open.value != "")
  {
    url = url + "/Request"
    url = url + "?" + "RequestID=Open";
    url = url + "&" + "Current=" + navigator_current;
    url = url + "&" + "Open=" + open.value;
  }
  else if (subscribe.value != "")
  {
    url = url + "/Request";
    url = url + "?" + "RequestID=Subscribe";
    url = url + "&" + "Current=" + navigator_current;
    url = url + "&" + "SubscribeTo=" + subscribe.value;
  }
  else if (unsubscribe.value != "")
  {
    url = url + "/Request";
    url = url + "?" + "RequestID=Unsubscribe";
    url = url + "&" + "Current=" + navigator_current;
    url = url + "&" + "UnsubscribeFrom=" + unsubscribe.value;
  }
  return url;
}

//*************************************************************/

/*
  This function updates the navigator drop down menus according
  to the xml of the server response.
*/

function updateNavigator()
{
  if (http_request.readyState == 4) 
  {
    if (http_request.status == 200) 
    {
      var xmldoc;
      var subdirs_l;
      var subscribe_l;
      var unsubscribe_l;

      // Load the xml elements on javascript lists:
      if (http_request != false)
      {
        xmldoc = http_request.responseXML;
        navigator_current = xmldoc.getElementsByTagName('current').item(0).firstChild.data;
        subdirs_l = xmldoc.getElementsByTagName('open');
        subscribe_l = xmldoc.getElementsByTagName('subscribe');
        unsubscribe_l = xmldoc.getElementsByTagName('unsubscribe');
      }

      var form = document.getElementById("NavigatorForm");
      var open = form.Open;
      var subscribe   = form.Subscribe;
      var unsubscribe = form.Unsubscribe;

      // Update the Open menu:
      open.options.length = 0;

      open.options[0] = new Option("", "", true, true);
      open.options[1] = new Option("top", "top", false, false);
      for(var i = 0; i < subdirs_l.length; i++)
      {
        var to_open = subdirs_l.item(i).firstChild.data;
        open.options[i + 2] = new Option(to_open, to_open, false, false);
      }
      open.selectedIndex = 0;

      // Update the Subscribe menu:
      subscribe.options.length = 0;
      subscribe.options[0] = new Option("", "", true, true);
      for(var i = 0; i < subscribe_l.length; i++)
      {
        var to_subscribe = subscribe_l.item(i).firstChild.data;
        subscribe.options[i + 1] = new Option(to_subscribe, to_subscribe, false, false);
      }
      subscribe.selectedIndex = 0;

      // Update the Unsubscribe menu:
      unsubscribe.options.length = 0;
      unsubscribe.options[0] = new Option("", "", true, true);
      for(var i = 0; i < unsubscribe_l.length; i++)
      {
        var to_unsubscribe = unsubscribe_l.item(i).firstChild.data;
        unsubscribe.options[i + 1] = new Option(to_unsubscribe, to_unsubscribe, false, false);
      }
      unsubscribe.selectedIndex = 0;
    }
  }
}

/*************************************************************/

function makeNavigatorRequest()
{
  url = getNavigatorRequestURL();

  // pass a reference to the updateNavigator function:
  makeRequest(url, updateNavigator); 
}


//*************************************************************/
//************************CONFIG BOX***************************/
//*************************************************************/

function submitConfigure(url, myform)
{
  navigator_form = false;
  url = url + "/Request";
  url = url + "?" + "RequestID=Configure";
  url = url + "&" + "Hostname=" + myform.Hostname.value;
  url = url + "&" + "Port=" + myform.Port.value;
  url = url + "&" + "Clientname=" + myform.Name.value;

  var funct = alertContents;
  makeRequest(url, funct);
}

//*************************************************************/

function alertContents() 
{
  if (http_request.readyState == 4) 
  {
    if (http_request.status == 200) 
    {
      alert("Configuration Submitted");
    }
    else 
    {
      alert('There was a problem with the request.');
    }
  }
}


//*************************************************************/
//***********************GIF DISPLAY***************************/
//*************************************************************/

/*
  Returns true if the display frame provided as an argument 
  is currently being viewed.
*/

function isViewed(display_frame_name)
{
  for (i = 0; i < active_displays_l.length; i++)
  { 
    if (active_displays_l[i] == display_frame_name) 
    {
      return true; 
    }
  }
  return false;
}

//*************************************************************/

/*
  These functions get called if the user clicks on the "start viewing"
  or "stop viewing" buttons of a display frame. They set the is_viewed
  field of the displayFrame object.
*/

function getDisplayFrame(display_frame_name)
{
  for (i = 0; i < displays_l.length; i++)
  {
    if (displays_l[i].name == display_frame_name)
    return displays_l[i];
  }
}

function startViewing(display_frame_name)
{
  var display = getDisplayFrame(display_frame_name);

  if (display.is_viewed) 
  {
    alert('This GifViewer is already active');
    return;
  }

  display.is_viewed = true;
  updateDisplay(display_frame_name);
}

function stopViewing(display_frame_name)
{
  var display = getDisplayFrame(display_frame_name);
  display.is_viewed = false;
}

//*************************************************************/

/*
  This function is initially called when the "start viewing" button
  of a display frame is pressed and keeps calling itself every 
  [interval] msec, refreshing the frame until it becomes inactive. 
*/

function updateDisplay(display_frame_name)
{
  var interval = 5000;
  var display_frame = getDisplayFrame(display_frame_name);

  if (display_frame.is_viewed == true)
  {  
    makeDisplayRequest(display_frame_name);
    if (display_frame.viewed_l.length != 0)
    {
      window.frames[display_frame_name].location.href = getGifURL(display_frame_name);
    }
  }
  var this_function_call = "updateDisplay('" + display_frame_name + "')";
  setTimeout(this_function_call, interval);
}

//*************************************************************/

function getGifURL(display_frame_name)
{
  var url = getContextURL();
  url = url + "/temporary/" + display_frame_name + ".gif";
  return url;
}

//*************************************************************/

function getDisplayRequestURL(display_frame_name)  
{
  url = getApplicationURL();
  url = url + "/Request"
  url = url + "?" + "RequestID=Draw"
  url = url + "&" + "Current=" + contentViewer_current;
  url = url + "&" + "DisplayFrameName=" + display_frame_name;

  var display_frame = getDisplayFrame(display_frame_name);
  for (i = 0; i < display_frame.viewed_l.length; i++)
  {
    url = url + "&" + "View=" + display_frame.viewed_l[i];
  }
  return url;
}

//*************************************************************/

function makeDisplayRequest(display_frame_name)
{
  url = getDisplayRequestURL(display_frame_name);
  // pass a reference to the updateGifURL function:
  makeRequest(url, updateGifURL); 
}

//*************************************************************/

function updateGifURL()
{
  if (http_request.readyState == 4) 
  {
    if (http_request.status == 200) 
    {
      var xmldoc;

       // Load the xml elements on javascript lists:
      if (http_request != false)
      {
        xmldoc  = http_request.responseXML;
        gif_url = xmldoc.getElementsByTagName('fileURL').item(0).firstChild.data;
      }
    }
  }
}


//*************************************************************/
//**********************CONTENT VIEWER*************************/
//*************************************************************/

/* 
  This function updates the ContentViewer "Unview" field
  after the user chooses to view or stop viewing something
*/

function updateContentViewerNoRequest()
{
  var form = document.getElementById("ContentViewerForm");
  var view = form.View;
  var unview = form.Unview;

  // first updated the list of viewed MEs
  updateViewedList();

  // then update the Unview menu, based on the updated list:
  unview.options.length = 0;
  unview.options[0] = new Option("", "", true, true);
  var viewed_from_current = getViewedFromDir(contentViewer_current);
  for (var i = 0; i < viewed_from_current.length; i++)
  {
    unview.options[i + 1] = new Option(viewed_from_current[i], viewed_from_current[i], false, false);
  }
  unview.selectedIndex = 0;

  // clear the lingering selection from the "View" menu
  view.selectedIndex = 0;
}

function updateViewedList()
{
  var form = document.getElementById("ContentViewerForm");
  var view   = form.View;
  var unview = form.Unview;

  if (view.value != "")
  {
    var addition = view.value;
    viewedListAdd(addition);
  }
  else if (unview.value != "")
  {
    var removal = unview.value;
    viewedListRemove(removal);
  }
}

//*************************************************************/

/*
  These functions add/remove something to/from the viewed_l.
*/

function viewedListAdd(addition)
{
  for (i = 0; i < current_display.viewed_l.length; i++)
  { 
    if (addition == current_display.viewed_l[i]) 
    {
      return; 
    }
  }
  current_display.viewed_l[current_display.viewed_l.length] = addition;
}

function viewedListRemove(removal)
{
  for (i = 0; i < current_display.viewed_l.length; i++)
  {
    if (removal == current_display.viewed_l[i])
    {
      current_display.viewed_l.splice(i, 1);
    }
  }
}

//*************************************************************/

function makeContentViewerRequest()
{
  url = getContentViewerRequestURL();
  makeRequest(url, updateContentViewer);
}

//*************************************************************/

function getContentViewerRequestURL()
{
  var form = document.getElementById("ContentViewerForm");
  var open = form.Open;

  url = getApplicationURL();

  if (open.value != "")
  {
    url = url + "/Request";
    url = url + "?RequestID=ContentsOpen";
    url = url + "&" + "Current=" + contentViewer_current;
    url = url + "&" + "Open=" + open.value;
  }

  return url;
}

//*************************************************************/

/*
  This function updates the fields of the content viewer widget
  after an "ContentViewerOpen" request.
*/

function updateContentViewer()
{
  if (http_request.readyState == 4) 
  {
    if (http_request.status == 200) 
    {
      var xmldoc;
      var subdirs_l;
      var view_l;
      var unview_l;

      // Load the xml elements on javascript lists:
      if (http_request != false)
      {
        xmldoc = http_request.responseXML;

        // set the contentViewer_current first:
        contentViewer_current = xmldoc.getElementsByTagName('current').item(0).firstChild.data;

        subdirs_l = xmldoc.getElementsByTagName('open');
        view_l = xmldoc.getElementsByTagName('view');
      }

      // get references to the form elements so that we can update them
      var form = document.getElementById("ContentViewerForm");
      var open = form.Open;
      var view = form.View;
      var unview = form.Unview; 

      // Update the Open menu:
      open.options.length = 0;
      open.options[0] = new Option("", "", true, true);
      open.options[1] = new Option("top", "top", false, false);
      for(var i = 0; i < subdirs_l.length; i++)
      {
        var to_open = subdirs_l.item(i).firstChild.data;
        open.options[i + 2] = new Option(to_open, to_open, false, false);
      }
      open.selectedIndex = 0;

      // Update the View menu:
      view.options.length = 0;
      view.options[0] = new Option("", "", true, true);
      for(var i = 0; i < view_l.length; i++)
      {
        var to_view = view_l.item(i).firstChild.data;
        view.options[i + 1] = new Option(to_view, to_view, false, false);
      }
      view.selectedIndex = 0;

      // Update the Unview menu:
      unview.options.length = 0;
      unview.options[0] = new Option("", "", true, true);
      var viewed_from_current = getViewedFromDir(contentViewer_current);
      for (var i = 0; i < viewed_from_current.length; i++)
      {
        unview.options[i + 1] = new Option(viewed_from_current[i], viewed_from_current[i], false, false);
      }
      unview.selectedIndex = 0;
    }
  }
}

//*************************************************************/

/*
  This function returns an array with all files in viewed_l that
  also reside in the directory dir, supplied as a parameter.
*/

function getViewedFromDir(dir)
{
  var viewed_l = current_display.viewed_l;
  var in_dir_l = new Array();
  for (var i = 0; i < current_display.viewed_l.length; i++)
  {
    var entry = viewed_l[i];
    var index = entry.lastIndexOf("/");
    if (entry.substring(0, index) == dir)
    {
      in_dir_l[in_dir_l.length] = entry;
    }
  }
  return in_dir_l;
}