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

     File:          fac_like.asp
     Description:   Beoordelen van een (eigen) afgehandelde melding etc
     Parameters:    key
                    xmlnode
     Context:       vanuit de lijst van eigen afgemelde zaken
                    of een deeplink vanuit een bon

*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/rater.inc" -->
<!-- #include file="./fac_like.inc" -->
<%
FCLTHeader.Requires({ plugins: ["jQuery"] });

var key = getQParamInt("key");
var node = getQParam("node");

var oordeel = getQParamInt("oordeel", null);

var this_like = like.func_enabled_like(key, node);
user.auth_required_or_abort(this_like.canChange);

var transitParam = buildTransitParam(["key", "node"]);

var ANON = false;
if (Session("login_by_fallback")) {
    // Vanuit bookmark ingelogd
    Session.Abandon();
    user_key = -1; // We hebben deze niet meer nodig, en hij zou de protectQS in de weg zitten
    ANON = true;
}

%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
  </head>

  <script type="text/javascript">
<%  if (!ANON) { %>
    function fac_cancel()
    {
      FcltMgr.closeDetail(window, { cancel: true } );
    }
<%  } %>
    function fac_submit_callback(json) {
      json.close = true;
      FcltMgr.closeDetail(window, json);
      // Als we standalone zijn, zijn we nog niet gesloten en passen we de pagina clientside aan om feedback weer te geven
      $("#buttons").remove();
      if (json.result) {
        $(".card-body").text(json.result);
      }
    }

    function fac_submit()
    {
      if (!$("[name=flike_oordeel]:checked").val()) {
        FcltMgr.alert("<%=L('lcl_fac_like_geenoordeel')%>");
        return false;
      }
<%    if (ANON) { %>
      var url = "<%=protectQS.create("fac_like_save_anon.asp?x=x" + transitParam)%>";
<%    } else { %>
      var url = $("form[name=flike]")[0].action;
<%    } %>

      $.post(url, $("[name=flike]").serialize(), FcltCallbackAndThen(fac_submit_callback), "json");
      return true; // disable button
    }

    function togglerPressed()
    {
      $("#flike_opmerk").show();
      FcltMgr.resized(window);
    }
  </script>

  <body class="fclt-modal" id="fac_like">
    <% MODAL_START(); %>
    <form id="flike" name="flike" action="fac_like_save.asp?x=x<%=transitParam%>" method="post">
<%
      MODAL_BLOCK_START("facLike", L("lcl_fac_like_block"), { icon: "fa-star" });
      var table = "";
      var txt= "??";
      switch (node) {
         case "melding"    : table = "mld_melding";
                             var sql = "SELECT isd.ins_srtdiscipline_prefix || TO_CHAR (m.mld_melding_key) item"
                                     + "  FROM mld_melding m"
                                     + "     , ins_srtdiscipline isd"
                                     + "     , ins_tab_discipline id"
                                     + "     , mld_stdmelding sm"
                                     + " WHERE m.mld_stdmelding_key = sm.mld_stdmelding_key"
                                     + "   AND sm.mld_ins_discipline_key = id.ins_discipline_key"
                                     + "   AND id.ins_srtdiscipline_key = isd.ins_srtdiscipline_key"
                                     + "   AND m.mld_melding_key = " + key;
                             oRs = Oracle.Execute(sql);
                             txt = L("lcl_complain").toLowerCase() + " " + oRs("item").Value;  break;
                             oRs.Close();
         case "reservering": table = "res_rsv_ruimte";
                             var sql = "SELECT TO_CHAR(res_reservering_key) || '/' || TO_CHAR(res_rsv_ruimte_volgnr) item"
                                     + "  FROM res_rsv_ruimte"
                                     + " WHERE res_rsv_ruimte_key = " + key;
                             oRs = Oracle.Execute(sql);
                             txt = L("lcl_reservation").toLowerCase() + " R" + oRs("item").Value; break;
                             oRs.Close();
         case "bestelling" : table = "bes_bestelling";
                             txt = L("lcl_bes_bestelling").toLowerCase() + " B" + key;  break;
      }
      var sql = "SELECT " + table + "_satisfaction"
              + ", "      + table + "_satisfaction_op"
              + "  FROM " + table
              + " WHERE " + table + "_key = " + key;
      var oRs = Oracle.Execute(sql);
      oordeel = oordeel || oRs(0).value;
      var opmerking = oRs(1).value;
      oRs.Close();

%>
      <div class="flikehead"><%=L("lcl_fac_like_oordeel").format(txt)%></div>
      <ul class="flikeopts">
<%      if (S("fac_like_excellent") > 0)
        { %>
          <li>
           <label for="flike_oordeel5">
            <input type="radio" id="flike_oordeel5" name="flike_oordeel" value="<%=S('fac_like_excellent')%>"<%=(oordeel==S("fac_like_excellent")? " checked" : "")%>>
            <%=rating.stars(S("fac_like_excellent"), {rating: {note: L("lcl_faclike_statisf5")}})%><%=L("lcl_faclike_statisf5")%>
           </label>
          </li>
<%      }
        if (S("fac_like_good") > 0)
        { %>
          <li>
           <label for="flike_oordeel4">
            <input type="radio" id="flike_oordeel4" name="flike_oordeel" value="<%=S('fac_like_good')%>"<%=(oordeel==S("fac_like_good")? " checked" : "")%>>
            <%=rating.stars(S("fac_like_good"), {rating: {note: L("lcl_faclike_statisf4")}})%><%=L("lcl_faclike_statisf4")%>
           </label>
          </li>
<%      }
        if (S("fac_like_normal") > 0)
        { %>
          <li>
           <label for="flike_oordeel3">
            <input type="radio" id="flike_oordeel3" name="flike_oordeel" value="<%=S('fac_like_normal')%>"<%=(oordeel==S("fac_like_normal")? " checked" : "")%>>
            <%=rating.stars(S("fac_like_normal"), {rating: {note: L("lcl_faclike_statisf3")}})%><%=L("lcl_faclike_statisf3")%>
           </label>
          </li>
<%      }
        if (S("fac_like_poor") > 0)
        { %>
          <li>
           <label for="flike_oordeel2">
            <input type="radio" id="flike_oordeel2" name="flike_oordeel" value="<%=S('fac_like_poor')%>"<%=(oordeel==S("fac_like_poor")? " checked" : "")%>>
            <%=rating.stars(S("fac_like_poor"), {rating: {note: L("lcl_faclike_statisf2")}})%><%=L("lcl_faclike_statisf2")%>
           </label>
          </li>
<%      }
        if (S("fac_like_bad") > 0)
        { %>
          <li>
           <label for="flike_oordeel1">
            <input type="radio" id="flike_oordeel1" name="flike_oordeel" value="<%=S('fac_like_bad')%>"<%=(oordeel==S("fac_like_bad")? " checked" : "")%>>
            <%=rating.stars(S("fac_like_bad"), {rating: {note: L("lcl_faclike_statisf1")}})%><%=L("lcl_faclike_statisf1")%>
           </label>
          </li>
<%      } %>
      </ul>

      <div id="flike_op">
        <span onClick="togglerPressed()"><%=I("fa-chevron-down")%>
          <label onClick="togglerPressed()" for="flike_opmerk"><%=L("lcl_fac_like_remark")%></label>
        </span>
      </div>
      <textarea class="fldtxt" rows="3" maxlength="2000" id="flike_opmerk" name="flike_opmerk"
                    style="<%=(opmerking ? null : "display:none")%>"><%=safe.textarea(opmerking)%></textarea>

      <div class="flikefoot"><%=L("lcl_fac_help_improve")%></div>
<%
      MODAL_BLOCK_END();
      buttons = [];
      buttons.push({title: L("lcl_fac_like_submit"), icon: "fa-fclt-save", action: "fac_submit()", importance: 1 });
      if (!ANON) {
        buttons.push({title: L("lcl_fac_like_cancel"), icon: "fa-fclt-cancel", action: "fac_cancel()", importance: 3 });
      }
      SIMPLE_BLOCK_START();
        CreateButtons(buttons, {showIcons: true});
      SIMPLE_BLOCK_END();
      IFACE.FORM_END();
%>
    </form>
    <% MODAL_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
