/*
     $Revision$
     $Id$

     File:        mld_list.js
*/
// Resultaat: URL om de data op te halen
function inlineOrdersUrl(row)
{
  var mld_key = row.getAttribute("ROWKEY");
  return "opdr_list.asp?tiny=1&inline=1&urole=" + urole + "&mld_key=" + mld_key;
}

function mld_edit(row)
{
  $(row).addClass('dirty');
  var mld_key = row.getAttribute("ROWKEY");
  url = "appl/mld/mld_melding.asp?urole=" + urole + "&mld_key=" + mld_key;
  FcltMgr.openDetail(url, { reuse: true });
}

function mld_opdr_edit(row)
{
  var mld_key = row.getAttribute("ROWKEY");

  var mldData = eval("(" + row.getAttribute("ROWDATA") + ")");
  if (mldData)
  {
    var opdr_key = mldData.opdr_key;
    var url = "appl/mld/mld_opdr.asp?urole=" + urole + "&opdr_key=" + opdr_key;
    FcltMgr.openDetail(url, { reuse: true });
  }
}

function mld_reject(rowArray, isMulti)
{
  var mldKeyString = getKeyString(rowArray);
  var mldData = eval("(" + rowArray[0].getAttribute("ROWDATA") + ")");

  if (rowArray.length == 1 && mldData && mldData.mldChild) // Niet multi child meldingen kunnen hier al tegengehouden worden.
    return

  // Indien bulk actie dan niet naar dubbele meldingen kijken
  if (rowArray.length == 1 && mldData.mldDoublecheck)
    $.post("../mld/mld_doublecheck.asp",
           { mld_key: mldKeyString,
             multi: (isMulti? 1 : 0),
             urole: urole,
             reject: 1 },
           doublecheckCallback,
           "json");
  else // Geen doublecheck controle dus direct afhandelen
  {
    doublecheckCallback({ maybeDouble: false,
                          multi: (isMulti? 1 : 0),
                          mld_key: mldKeyString,
                          urole: urole,
                          reject: true
                        });
  }
}

function mld_accept(rowArray, isMulti)
{
  var mldKeyString = getKeyString(rowArray);
  var mldData = eval("(" + rowArray[0].getAttribute("ROWDATA") + ")");

  if (rowArray.length == 1 && mldData && mldData.mldChild) // Niet multi child meldingen kunnen hier al tegengehouden worden.
    return

  // Indien bulk actie dan niet naar dubbele meldingen kijken
  if (rowArray.length == 1 && mldData.mldDoublecheck)
    $.post("../mld/mld_doublecheck.asp",
           { mld_key: mldKeyString,
             multi: 0,
             urole: urole },
           doublecheckCallback,
           "json");
  else // Geen doublecheck controle dus direct afhandelen
  {
    doublecheckCallback({ maybeDouble: false,
                          multi: (isMulti? 1 : 0),
                          mld_key: mldKeyString,
                          urole: urole,
                          prefix: mldData.mldPrefix
                        });
  }
}

function mld_continue(row)
{
  var mld_key = row.getAttribute("ROWKEY");
  var mldData = eval("(" + row.getAttribute("ROWDATA") + ")");
  if (mldData && !mldData.mldChild) // Child meldingen kunnen hier al tegengehouden worden.
  {
    var mldPrefix = mldData.mldPrefix;
    var mldUrl = "../mld/mld_continue.asp?urole=" + urole + "&mld_key=" + mld_key
    FcltMgr.openModalDetail( mldUrl
                           , L("lcl_mld_continuation_mld") + mldPrefix + mld_key
                           );
  }
}

function mld_close(rowArray, isMulti)
{
  var mldKeyString = getKeyString(rowArray);
  var mldUrl = "../mld/mld_close_confirm.asp?mld_key=" + mldKeyString;
  FcltMgr.openModalDetail( mldUrl
                         , L("lcl_mld_final_close")
                         , { callback: FcltCallbackRefresh }
                         );
}

function mld_forward(row)
{
  $(row).addClass('dirty');
  var mld_key = row.getAttribute("ROWKEY");
  var mldData = eval("(" + row.getAttribute("ROWDATA") + ")");
  if (mldData && !mldData.mldChild) // Child meldingen kunnen hier al tegengehouden worden.
  {
    var mldPrefix = mldData.mldPrefix;
    var mldUrl = "../mld/mld_forward.asp?mld_key=" + mld_key + "&urole=" + urole;
    FcltMgr.openModalDetail( mldUrl
                           , L("lcl_mld_forward") + " " + mldPrefix + mld_key
                           , { callback: FcltCallbackRefresh }
                           );
  }
}

function mld_forward_empty(row)
{
  $(row).addClass('dirty');
  var mld_key = row.getAttribute("ROWKEY");
  var mldData = eval("(" + row.getAttribute("ROWDATA") + ")");
  if (mldData && !mldData.mldChild) // Child meldingen kunnen hier al tegengehouden worden.
  {
    FcltMgr.alert(L("lcl_shared_validator_missing"));
    // Ga naar het edit meldingen scherm.
    var mldPrefix = mldData.mldPrefix;
    var mldUrl = "appl/mld/mld_edit_melding.asp?urole=" + urole + "&mld_key=" + mld_key + "&embedded=1";
    FcltMgr.openDetail( mldUrl,
                        L("lcl_mld_forward") + " " + mldPrefix + mld_key
                      );
  }
}

function mld_doorzet(rowArray, isMulti)
{
  var mldKeyString = getKeyString(rowArray);
  FcltMgr.confirm(L("lcl_mld_doorzetten_1") + mldKeyString + L("lcl_mld_doorzetten_2"), { autoconfirm: isMulti }, function() {
      var data = {
          mld_key: mldKeyString
      };
      protectRequest.dataToken(data);
      $.post("../mld/mld_doorzet.asp",
          data,
          FcltCallbackRefresh,
          "json");
  });
}

function mld_terugzet(rowArray, isMulti)
{
  var mldKeyString = getKeyString(rowArray);
  FcltMgr.confirm(L("lcl_mld_terugzetten_1") + mldKeyString + L("lcl_mld_terugzetten_2"), { autoconfirm: isMulti }, function() {
      var data = {
          mld_key: mldKeyString,
          terug: 1
      };
      protectRequest.dataToken(data);
      $.post("../mld/mld_doorzet.asp",
          data,
          FcltCallbackRefresh,
          "json");
  });
}

function toggleFlag(evt, mld_key)
{
	FcltMgr.stopPropagation(evt);

  var flagkey = $('#mldflagimg'+mld_key).attr('flagkey');
  var data = { mld_key: mld_key
             , flagkey: flagkey
             };
  protectRequest.dataToken(data);
  $.post("../mld/mld_flag.asp"
        , data
        ,  FcltCallbackAndThen(setFlag)
        , "json"
        );
}

function setFlag(data)
{ // Zet de flag en het volgnummer van de flag.
	var mld_key = data.mld_key;
	var flagkey = data.newflag;
	var flagimg = 'fa fa-circle mldflag'+flagkey;

  $('#mldflagimg'+mld_key).attr('flagkey', flagkey);
  $('#mldflagimg'+mld_key).attr('class', flagimg);
  $('#mldflagimg'+mld_key).parent().attr('title', L("lcl_mld_flag" + flagkey));
  $('#mldflagimg'+mld_key).next().text(flagkey||999); // Hidden span voor sorteren
  $('#complainstable th').removeClass('sorttable_sorted sorttable_sorted_reverse'); // sortable cache't namelijk
}

