// ===================================================================
// Class for showing paged list of Parol.
//
// Collection = array of Parol qualifiers

function FirstPageView(aModel, aController)
{
  try {
    this._Model = aModel;
    this._Controller = aController;
    this._ParolBox = null;

    this._curIndexDiv = document.getElementById("FirstCurIndex");
    this._lastIndexDiv = document.getElementById("FirstLastIndex");
    this._curIndex = 0;
  }
  catch (e) {
    alert("FirstPageView: " + e);
  }
}

FirstPageView.prototype =
{
  toString: function()
  {
    return "FirstPageView";
  },

  updateCollection: function(index)
  {
    var len = this._Model.getSeries().length;
    this._lastIndexDiv.innerHTML = len;
    this._curIndex = index || 0;
    this.notifyUpdateIndex(this._curIndex);
  },

  notifyUpdateIndex: function(index)
  {
    this._curIndexDiv.innerHTML = index + 1;
    this._Controller.selectFirst(index);
  },

  getCurParolQual: function()
  {
    var aParol = this.getCurParol();
    return aParol ? aParol.getID() : null;
  },

  getCurIndex: function()
  {
    return this._curIndex;
  },

  getCurParol: function()
  {
    return this._Model.getSeries() && this._Model.getSeries()[this._curIndex];
  },

  navigate: function(dir)
  {
    try {
      var len = this._Model.getSeries().length;

      switch (dir) {
      case "first":
        if (this._curIndex <= 0) {
          return;
        }
        this._curIndex = 0;
        break;
      case "prev":
        if (this._curIndex <= 0) {
          return;
        }
        --this._curIndex;
        break;
      case "next":
        if (this._curIndex >= len - 1) {
          return;
        }
        ++this._curIndex;
        break;
      case "last":
        if (this._curIndex >= len - 1) {
          return;
        }
        this._curIndex = len - 1;
        break;
      default:
        break;
      }

      this.notifyUpdateIndex(this._curIndex);
    }
    catch (e) {
      alert("Fehler beim Navigieren: " + e.name + ": " + e.message + " (FirstPageView)");
    }
  }
}

