<%@language="javascript"%>
<% /*
     $Revision$
     $Id$

     File:          message_list.asp, mobile version of fac/fac_user_messages.asp
     Description:   Toont de gebruikersberichten (statusinfo) in een list

    Note:           Komt straks ergens in een submenu te hangen.
                    Een verwijderfunctie zou nog leuk zijn

*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="./resultset_table.inc" -->
<!-- #include file="./mobile.inc" -->
<!-- #include file="./iface.inc" -->
<%
var qrc = getQParamInt("qrc", 0) != 0;
var subject = L("lcl_recent_news");
%>
<html>
  <head>
<% FCLTMHeader.Generate({}); %>
    <script>
      function swipeLeftAction(elem) {
        swipeRightAction(elem);
      }
      function swipeRightAction(elem) {
        if (!(elem.dataset.web_user_message_key > 0)) {
          return;
        }
        var data = { messKey: elem.dataset.web_user_message_key };
        protectRequest.dataToken(data);
        removeCardAnimated(elem);
        $.post(
          "../FAC/fac_user_messages_setReadFlag.asp?messKey=" + data.messKey + "&purge=1",
          data,
          () => {
            [...document.getElementsByClassName("jq-toast-wrap")].forEach(elem => {
              elem.remove();
            });
            jqToast(L("lcl_mobile_message_deleted"));
          },
          "json"
        );
      }
    </script>
  </head>
  <body>
<%
if (user_key != -1)
{
    var sql = "UPDATE web_user_messages"
            + "   SET web_user_mess_action_status = 2"
            + " WHERE prs_perslid_key_receiver = " + user_key
            + "   AND web_user_mess_action_datum > SYSDATE - " + 14;
    Oracle.Execute(sql); // We lezen ze -nu-

    sql = "SELECT m.web_user_mess_dsc"
        + "     , sn.fac_srtnotificatie_url"
        + "     , COALESCE(m.web_user_mess_action_params, ' ') web_user_mess_action_params"
        + "     , m.web_user_mess_action_status"
        + "     , m.web_user_mess_action_datum"
        + "     , m.web_user_message_key"
        + "     , web_user_mess_prioriteit"
        + "     , sn.fac_srtnotificatie_xmlnode"
        + "  FROM web_user_messages m, fac_srtnotificatie sn"
        + " WHERE m.prs_perslid_key_receiver = " + user_key
        + "   AND sn.fac_srtnotificatie_key(+)=m.fac_srtnotificatie_key"
        + "   AND m.web_user_mess_action_datum > SYSDATE - " + 14
        + " ORDER BY m.web_user_mess_action_datum DESC, m.web_user_message_key DESC";

    function fncolLink(oRs)
    {
        var action;
        if (oRs("fac_srtnotificatie_url").Value != null ) {
            //action = oRs("fac_srtnotificatie_url").Value + oRs("web_user_mess_action_params").Value;
            // Hé, dit kan nu via de pseudo-bookmarks!
            action = rooturl + "/default.asp?u=" + oRs("fac_srtnotificatie_xmlnode").Value + "&k=" + oRs("web_user_mess_action_params").Value;
            action = action.replace(/\#/g, "&");
        }
        return action;
    }

    function fnUrgentie(oRs)
    {
      var displ = "";
      switch (oRs("web_user_mess_prioriteit").value) {
        case 1:  displ = I("fa-exclamation-triangle"); break;
        case 3:  displ = I("fa-arrow-circle-down"); break;
      }
      return displ;
    }

    function fncolSubHeader(oRs)
    {
      return  "";
    }

    PAGE_START();
    HEADER({title: subject, back: false, home: !qrc});
    CONTENT_START();

    var rst = new ResultsetTable({sql: sql,
                                   keyColumn: "web_user_message_key",
                                   layout: "card",
                                   linkColumn: fncolLink,
                                   iconColumn: fnUrgentie,
                                   contentColumn: function (oRs) {return "<span class='subject'>" + safe.html(oRs.Fields("web_user_mess_dsc").Value)+ "</span>"+"<div class='text-secondary'>"+toDateTimeString(oRs.Fields("web_user_mess_action_datum").Value, false, false, true)+ "</div>"},
                                   showAll: true,
                                   emptySetString: L("lcl_mobile_no_messages"),
                                   swipeable: true,
                                   data: ["web_user_message_key"]
                                  });

    var cnt = rst.processResultset();

    CONTENT_END();
    FOOTER();
    PAGE_END();
}
PDA_PAGE_END(); %>
	</body>
</html>
<% ASPPAGE_END(); %>
