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

     File:          fac_user_messages.asp (formerly news/news.asp)
     Description:   Toont de gebruikersberichten (statusinfo) in een grid

     Note:          Functioneel is de noodzaak voor deze info veel minder
                    geworden vanwege fac_list die veel meer info toont.

                    Toch maar eens via resulttable
*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/resultset_table_v2.inc" -->
<%
  FCLTHeader.Requires({ plugins: ["jQuery"],
                        js: ["./fac_user_messages.js"] });

  var showall = getQParamInt("showall", 0) == 1;
  var outputmode = getQParamInt("outputmode", 0);
  var collegas = getQParamInt("collegas", 1) == 1;
  var asWidget = getQParamInt("asWidget", 0) == 1;

  function fnrowClass(oRs)
  {
    var lclass = "";
    // zo was het, gewoon overgenomen
    if (oRs("web_user_mess_action_status").Value == 1)
    {
        if (oRs("web_user_mess_prioriteit").value==1)
            lclass = "newstextFreshBold";
        else
            lclass = "newstextFresh";
    }
    else
        lclass = "newstext";

    return lclass;
  }

  function fnrowData(oRs)
  {
    var data = {};
    if (oRs("fac_srtnotificatie_url").Value)
    {
        data.action = oRs("fac_srtnotificatie_url").Value + oRs("web_user_mess_action_params").Value;
        data.action = data.action.replace(/\#/g, "&");
        if (data.action.indexOf("&urole") < 0)
          if (data.action.indexOf("mld_melding.asp") < 0)
              data.action += "&urole=fe";
          else
              data.action += "&urole=xx"; // urole=xx for mld_melding to determine the urole based on rights
    }
    return JSON.stringify(data);
   }
   function fnrowActionEnabler(oRs)
   {
        var data = { eDefault: oRs("fac_srtnotificatie_url").Value != null,
                     eDelete: oRs("prs_perslid_key_receiver").Value == user_key }
        return data;
   }
%>
<html>
  <head>
<%  FCLTHeader.Generate({outputmode:outputmode}) %>
</head>

  <body id="listbody" class="usermessbody<%=asWidget ? ' widgetbody' : ''%>">
<%
var buttons = [];
    buttons.push({title: L("lcl_mark_as_read_all"), icon: "fa-trash-alt", action: "MarkAsReadAll()"});
    buttons.push({title: L("lcl_refresh"), icon: "fa-fclt-refresh", action: "FcltMgr.reload()" });

    if (user_key != -1)
    {
        var prsKeys = (collegas ? user.collegakeylist() : user_key);

        var 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"
                + ",      m.prs_perslid_key_receiver"
                + ",      web_user_mess_prioriteit"
                + ",      pf.prs_perslid_naam_friendly receiver_name"
                + "  FROM web_user_messages m, fac_srtnotificatie sn, prs_v_perslid_fullnames_all pf"
                + " WHERE m.prs_perslid_key_receiver IN (" + prsKeys + ")"
                + "   AND sn.fac_srtnotificatie_key(+)=m.fac_srtnotificatie_key"
                + "   AND m.prs_perslid_key_receiver = pf.prs_perslid_key"
                + " ORDER BY m.web_user_mess_action_datum DESC, m.web_user_message_key DESC";

        // Tweeledig: beperken, maar tevens zorgen dat de sortering goed blijft!
        // Dat is: de nieuwste berichten bovenaan
        sql = "SELECT * FROM (" + sql + ") WHERE ROWNUM < " + S("portalnewsmax");
        var rst = new ResultsetTable({
                                   sql: sql,
                                   keyColumn: "web_user_message_key",
                                   ID: "usermess",
                                   rowData: fnrowData,
                                   rowClass: fnrowClass,
                                   rowActionEnabler: fnrowActionEnabler,
                                   title: L("lcl_recent_news"),
                                   showAll: showall,
                                   outputmode: outputmode,
                                   buttons: buttons,
                                   collapsible: true
                                  });
        if (user.hasCollegas())
            rst.addColumn(new Column({caption: L("lcl_name"), content: "receiver_name", nowrap: true }));
        rst.addColumn(new Column({caption: L("lcl_date"), content: "web_user_mess_action_datum", datatype: "datetime", prettydate: true, nowrap: true }));
        rst.addColumn(new Column({caption: L("lcl_message"), content: "web_user_mess_dsc"}));
        rst.addAction({ action: "DoAction", caption: "", enabler:"eDefault", isDefault: true });
        rst.addAction({ action: "facDelete", caption: L("lcl_mark_as_read"), enabler:"eDelete" });

        var cnt = rst.processResultset();

      }
%>
  </body>
</html>
<% ASPPAGE_END(); %>