<%@ LANGUAGE="JavaScript" %>
<% /*
     $Revision$
     $Id$

    File:               Bes/sel_Favourites.asp
    Description:        Kies uit je favorieten lijst
    Parameters:
        srtdeel_key     disc_key  van de discipline
    Context:            Binnen ModalForm.asp als gebruiker knopje 'Favorieten toevoegen'
                        drukt van een bestelling
    Note:

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

   var disc_key = getQParamInt('disc_key');
%>
<html>
<head>
<%
   FCLTHeader.Generate();
%>
</head>
<%
    // Maak het favorietenlijst formulier
%>
<body  class="modal" id="mod_favorites" style='width:500px' onLoad="loadAction();">
    <form name="u2">
    <% BLOCK_START("favInfo", L("lcl_bes_fav_sel_items_fl")); %>

    <script type="text/javascript">

      function doSubmit()
      {
        selItemList = [];
        $("#besfavtable>tbody>tr.selected", workFrame.document.body).each(function ()
            {
                selItemList.push(this.myData.bes_item_info);
            }
        )
        FcltMgr.closeDetail(window, {selItemList: selItemList});
      }

      // Zorgt voor het laden van de juiste favorieten lijst
      function loadFavouritsList() {
        var fav_opt = document.u2.fav.options;
        var fav = "";
        if (fav_opt.selectedIndex != -1)
            fav = fav_opt[fav_opt.selectedIndex].value;
        var recent = $("input[name='which']:checked").val();

        $("#workFrame")[0].src = 'fav_items_list.asp?fav_name=' + escape(fav) + "&prs_key=<%=user_key%>" + "&disc_key=<%=disc_key%>&recent=" + recent;
      }

      function recentChanged() {
        loadFavouritsList();
      }

      function loadAction() {
        document.u2.fav.focus();
        loadFavouritsList();
      }

    </script>

  <tr>
    <td><label><input type="radio" name="which" checked value="0" onClick="recentChanged()"><%=L("lcl_bes_favour_list")%></label></td>
    <td>
<%
        // disciplines waar ik wat voor scope/rechten dan ook voor heb
          sql = "SELECT bf.bes_favoriet_naam"
              + ",     bf.bes_favoriet_naam"
              + " FROM bes_v_aanwezigsrtdeel d"
              + ",     bes_v_aanwezigsrtgroep g"
              + ",     bes_favoriet bf"
              + " WHERE d.bes_srtgroep_key = g.bes_srtgroep_key"
              + "   AND d.bes_srtdeel_key = bf.bes_srtdeel_key"
              + "   AND bf.bes_favoriet_naam IS NULL"
              + "   AND bf.prs_perslid_key = " + user_key
              + "   AND g.ins_discipline_key = " + disc_key
              + " UNION"
              + " SELECT bf.bes_favoriet_naam"
              + ",      bf.bes_favoriet_naam"
              + "  FROM bes_v_aanwezigsrtdeel d"
              + ",      bes_v_aanwezigsrtgroep g"
              + ",      bes_favoriet bf"
              + " WHERE d.bes_srtgroep_key = g.bes_srtgroep_key"
              + "   AND d.bes_srtdeel_key = bf.bes_srtdeel_key"
              + "   AND bf.bes_favoriet_naam IS NOT NULL"
              + "   AND bf.prs_perslid_key = " + user_key
              + "   AND g.ins_discipline_key = " + disc_key
              + " ORDER BY 2, 1";

            FCLTselector("fav", sql, { onChange: "loadFavouritsList()" } );

%>      </td>
    </tr>
    <tr>
        <td colspan="2"><label><input type="radio" name="which" value="1" onClick="recentChanged()"><%=L("lcl_bes_fav_recently")%></label></td>
    </tr>
    <tr><td colspan="2">
            <label><%=L("lcl_bes_fav_items_fl")%>:</label>
            <iframe width="100%" height="400" src="../Shared/empty.asp" name="workFrame" id="workFrame" frameborder="0"
                    scrolling="auto" framespacing='0'
                    xxonload="FcltMgr.iframeLoaded(this)">
            </iframe>
        </td>
    </tr>
<%  BLOCK_END();

  var buttons =  [ {title: L("lcl_submit"), icon:"opslaan.png", action:"doSubmit()" },
                   {title: L("lcl_cancel"), icon: "undo.png", action:"FcltMgr.closeDetail(window, { cancel: true })" } ];
  CreateButtons(buttons);
IFACE.FORM_END();
%>
    </form>
</div>
</body>
</html>
