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

    File:               fac_widget_page.asp
    Description:        Dynamische widget pagina
    Parameters:         wgt_page_key, if omitted the personal widgetpage is used.
                        wellicht iets met edit=1, anders automatisch obv autorisatie
    Context:
    Note:               Aanroep pagina van show/edit-mode van een widget-pagina

*/
%>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="fac_widget.inc" -->
<!-- #include file="fac_nieuws_forum.inc" -->
<%
FCLTHeader.Requires({ plugins: ["suggest", "jQuery"],
                           js: ["jquery-ui.js"] });

var wgt_page_key = getQParamInt("wgt_page_key", -1);
var mode = getQParamSafe("mode", "show");

if (wgt_page_key == -1)
{
    user.auth_required_or_abort(S("fac_usrrap_mode"));
    var sql = "SELECT fac_widget_page_key"
            + "  FROM fac_widget_page"
            + " WHERE prs_perslid_key = " + user_key;
    var oRs = Oracle.Execute(sql);
    if (!oRs.EoF)
    {
        wgt_page_key = oRs("fac_widget_page_key").value;
    }
    oRs.Close();
}

if (wgt_page_key == -1) // Nog steeds, dan is er dus ook geen persoonlijke pagina
    mode = "edit";

var transitParam = buildTransitParam(["wgt_page_key", "mode", "fp"], { "wgt_page_key": wgt_page_key, "mode": mode });

%>
<html>
    <head>
<%
        FCLTHeader.Generate();
%>      <script type="text/javascript">
            var wgt_page_key = <%=wgt_page_key%>;

            function widgetPageClose(params)
            {
                if (params.keepForm) // er is iets fout bij het opslaan
                    return;
<%              if (wgt_page_key == -1)
                { %>
                if (params.cancel || params.close)
                {
                    FcltMgr.closeDetail(window, params);
                    return true;
                }
                if (!params.keepForm)
                    window.location.href = "fac_widget_page.asp?1=1<%=transitParam%>";
<%              }
                else
                { // Bestaande widget_page bewerkt, switch naar show-mode
%>
                if (params.cancel && params.verynew)
                {
                    FcltMgr.closeDetail(window, params);
                }
                if (!params.keepForm)
                {
                    if (params.cancel)
                        $("#widget_page_frame")[0].src = "fac_show_widget_page.asp?1=1<%=transitParam%>";
                    else // Complete refresh
                        window.location.href = "fac_widget_page.asp?1=1<%=transitParam%>";
                }
<%              } %>
            }

            function fcltontabshow()
            {
                var win = $("#widget_page_frame")[0].contentWindow;
                if (FcltMgr._frmaccessible(win) && typeof win.fcltontabshow == "function")
                    win.fcltontabshow();
            }
        </script>
    </head>
    <body>
<%
    if (S("widgetportal") > 0 && getQParamInt("from_menu_key", -1) == -1)
        injectNews();

    if (mode == "edit")
        var page="fac_edit_widget_page.asp";
    else
        var page="fac_show_widget_page.asp";
    page += "?1=1" + transitParam;

    IFRAMER("widget_page_frame", page, { FcltClose: "widgetPageClose" } );
%>
    </body>
</html>