/*
     $Revision$
     $Id$

     File:        bes_list.js
*/

function besEdit(row)
{
  var bes_key = row.getAttribute("ROWKEY");
  var besData = eval('(' + row.getAttribute("ROWDATA") + ')');
  if (besData)
  {
      url = "appl/bes/bes_bestelling.asp?bes_key=" + bes_key + "&details=1" + "&urole=" + urole;
      FcltMgr.openDetail(url, { reuse: true });
  }
}

function besOpdrShow(row)
{
  var besData = eval('(' + row.getAttribute("ROWDATA") + ')');

  if (besData)
  {
    besOpdrKey = besData.besOpdrKey;
    url = "appl/bes/bes_opdr.asp?ordernr=" + besOpdrKey + "&urole=" + urole;
    FcltMgr.openDetail(url, { reuse: true });
  }
}

function besAccept(rowArray, isMulti)
{
  FcltMgr.confirm(L("lcl_bes_accepteren"), { autoconfirm: isMulti }, function() {
      var besKeyString = getKeyString(rowArray);
      $.post("bes_accept.asp", {
          urole: urole,
          bes_key: besKeyString
      }, FcltCallbackRefresh, "json");
  });
}

function besReject(rowArray, isMulti)
{
  var besKeyString = getKeyString(rowArray);
  url = "../bes/bes_reject.asp?bes_key=" + besKeyString + "&urole=" + urole;
  FcltMgr.openModalDetail(url, L("lcl_bes_reject_order_req"), {callback: FcltCallbackRefresh});
}

function besSubmitCallback(json, textStatus)
{
  if (textStatus == "success")
  {
    if (json.mld_order_autoprint == 1 && json.opdr_key_array.length == 1) // Opdrachtbon printen (Niet bij multi)
    {
      // Bij bulk acties opdrachtbon niet printen. (Meerder tegelijk openen geeft  ook foutmelding)
      // Bulk actie worden ook niet toegestaan als setting mld_order_autoprint is gezet
      url = "bes_opdr_xml.asp?opdr_key=" + json.opdr_key_array[0];
      window.open(url).focus();
    }
    FcltCallbackRefresh(json, textStatus);
  }
  else
    FcltMgr.alert(textStatus);
};

function besSubmit(rowArray, isMulti)
{
  var besKeyString = getKeyString(rowArray);
  isMulti ? $.post("bes_submit.asp", {
      urole: urole,
      bes_key: besKeyString
  }, besSubmitCallback, "json") : FcltMgr.confirm(L("lcl_bes_dosubmit"), function() {
      $.post("bes_submit.asp", {
          urole: urole,
          bes_key: besKeyString
      }, besSubmitCallback, "json")
  });
}
