TrShuttleProxy._orderTopBottomList = function()

in trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Shuttle.js [1101:1260]


TrShuttleProxy._orderTopBottomList = function(
  down,
  list,
  formName
  )
{
  //get the formname if needed
  if(formName == (void 0))
  {
    formName = TrShuttleProxy._findFormNameContaining(list);
  }

  //get the actual list
  var colList = document.forms[formName].elements[list];

  //get all the indexes of the items selected in the list
  var selItems = TrShuttleProxy._getSelectedIndexes(formName, list);

  //if no items are selected, return with alert.
  if(selItems.length == 0)
  {
    if (_shuttle_no_items_selected.length > 0)
      alert(_shuttle_no_items_selected);

    return;
  }

  var descArray = TrShuttleProxy._getDescArray(list);
  var moveDescArray = new Array();
  var selDescArray = new Array();

  var moveItemsText = new Array();
  var moveItemsValue = new Array();
  var moveItemsIndex = 0;
  if(down == 0)
  {
    //get an array of all the items we will have to displace in order
    var selItemsIndex = 0;
    var moveItemsIndex = 0;
    for(var colListIndex=0;
        colListIndex < selItems[selItems.length - 1];
        colListIndex++)
    {
      if(colListIndex != selItems[selItemsIndex])
      {
        moveItemsText[moveItemsIndex] = colList.options[colListIndex].text;
        moveItemsValue[moveItemsIndex] = colList.options[colListIndex].value;

        if (  descArray != (void 0) )
          moveDescArray[moveItemsIndex] = descArray[colListIndex];

        moveItemsIndex++
      }
      else
      {

        if ( descArray != (void 0) )
          selDescArray[selItemsIndex] = descArray[colListIndex];

        selItemsIndex++;

      }
    }

    if ( descArray != (void 0) )
      selDescArray[selItemsIndex] = descArray[colListIndex];


    //place items to move toward top of col
    for(var i = 0; i < selItems.length; i++)
    {
      colList.options[i].text = colList.options[selItems[i]].text;
      colList.options[i].value = colList.options[selItems[i]].value;
      colList.options[i].selected = true;

      if ( descArray != (void 0) )
        descArray[i] = selDescArray[i];
    }

    //place displaced items below
    for(var j = 0; j < moveItemsText.length; j++)
    {
      colList.options[i].text = moveItemsText[j];
      colList.options[i].value = moveItemsValue[j];
      colList.options[i].selected = false;

      if ( descArray != (void 0) )
        descArray[i] = moveDescArray[j];
      i++
    }



  }
  else
  {
    //get an array of all the items we will have to displace in order
    var selItemsIndex = 1;
    var moveItemsIndex = 0;

    if ( descArray != (void 0) )
      selDescArray[0] = descArray[selItems[0]];

    for(var colItemsIndex=selItems[0]+1;
        colItemsIndex <= colList.length-2;
        colItemsIndex++)
    {
      if((selItemsIndex == selItems.length) ||
         (colItemsIndex != selItems[selItemsIndex]))
      {
        moveItemsText[moveItemsIndex] = colList.options[colItemsIndex].text;
        moveItemsValue[moveItemsIndex] = colList.options[colItemsIndex].value;

        if ( descArray != (void 0) )
          moveDescArray[moveItemsIndex] = descArray[colItemsIndex];

        moveItemsIndex++;
      }
      else
      {
        if ( descArray != (void 0) )
          selDescArray[selItemsIndex] = descArray[colItemsIndex];

        selItemsIndex++;
      }
    }


    //place items to move toward bottom of col
    var j = colList.length - 2;
    for(var i = selItems.length-1; i >= 0; i--)
    {
      colList.options[j].text = colList.options[selItems[i]].text;
      colList.options[j].value = colList.options[selItems[i]].value;
      colList.options[j].selected = true;

      if ( descArray != (void 0) )
        descArray[j] = selDescArray[i];
      j--;
    }


    //place displaced items above
    for(var i = moveItemsText.length-1; i >= 0; i--)
    {
      colList.options[j].text = moveItemsText[i];
      colList.options[j].value = moveItemsValue[i];
      colList.options[j].selected = false;

      if ( descArray != (void 0) )
        descArray[j] = moveDescArray[i];
      j--
    }
  }

  TrShuttleProxy._displayDesc( list, formName );

  //make the list for submission
  TrShuttleProxy._makeList(formName, list);
}