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

    File:               fac_show_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:               Show-mode voor een widget-pagina

*/
%>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="fac_widget.inc" -->
<%
var wgt_page_key = getQParamInt("wgt_page_key");
var this_wgt_page = wgt.func_enabled_wgt_page(wgt_page_key);
var frontpage = getQParamInt("fp", 0) == 1;
user.auth_required_or_abort(this_wgt_page.canRead);
var hasPRSSYS = user.has("WEB_PRSSYS");

var mode = getQParamSafe("mode", "show");

var transitParam = buildTransitParam(["wgt_page_key", "mode"]);

FCLTHeader.Requires({ plugins: ["jQuery"], js: ["./fac_widget_page.js"] });

var widgets = wgt.get_widgets_onpage(wgt_page_key);
%>
<html>
    <head>
<%
        FCLTHeader.Generate();
%>
        <script>
<%      if (!widgets.length && mode !="wrap" && this_wgt_page.canWrite)
        { %>
            if (FcltMgr.startEdit(window))
                window.location.href = "fac_edit_widget_page.asp?1=1<%=transitParam%>";
<%
        }

        if (!this_wgt_page.public || mode == "wrap")
        {
            if (this_wgt_page.canWrite)
            { %>
            function wgt_edit()
            {
                if (FcltMgr.startEdit(window))
                    window.location.href = "fac_edit_widget_page.asp?1=1<%=transitParam%>";
            }

            function wgt_delete_all(key)
            {
                FcltMgr.confirm(L("fac_widget_del_all_txt"), function()
                {
                    $.post("fac_delete_widget_onpage.asp?wgt_page_key=" + key, FcltCallbackRefresh);
                });
            }
<%          }

            if (this_wgt_page.public && (this_wgt_page.readman || user.has("WEB_FACFAC")))
            { %>
            function fac_show_widget_page(key)
            {
                var url = "appl/fac/fac_widget_page.asp?wgt_page_key=" + key;
                FcltMgr.openDetail(url, "<%=safe.jsstring(this_wgt_page.title)%>");
            }
<%              if (hasPRSSYS)
                {
%>
            function fac_set_homepage(key)
            {
                var data = { "mode": "home",
                             "wgt_page_key": key };
                <% protectRequest.dataToken("data"); %>

                FcltMgr.confirm(L("fac_widget_save_homepage"), function ()
                {
                    // Hier wordt $.ajax gebruikt ipv $.post omdat we contentType: json willen verzenden, dat kan niet met $.post
                    $.ajax({ "url": "fac_edit_widget_page_save.asp"
                           , "type": "POST"
                           , "data": JSON.stringify(data)
                           , "dataType": "json"
                           , "contentType": "application/json; charset=utf-8"
                           , "success": FcltCallback
                    });
                });
            }
<%
                }
            }
        } %>

            function menu(evt, item, titel, menu_key)  // Eén menuitem
            {
                if (menu_key > 0)
                {
                    if ($(evt.target).attr("infomsg"))
                    {
                        FcltMgr.alert($(evt.target).attr("infomsg"), {title: "<%=safe.htmlattr(L("lcl_menumessage"))%>"});
                    }
                    item += item.indexOf("?") > -1?"&":"?";
                    item += "from_menu_key=" + menu_key;
                }
                FcltMgr.openDetail(item, titel);
            }

            $(function()
            {
                // voegt onClick toe aan portaal iconen
                $("div.portalmenukop.withimg").children().not("ul").each(function() {
                    $(this).on("click", function() {
                        $(this).siblings("ul").find("li").trigger("click");
                    });
                });

                $(window).on("resize", resizeOnActivate);
            });

        </script>

    </head>
    <body<%=(frontpage ? ' class="mainpage"' : '')%>>
<%
        if ((!this_wgt_page.public || mode == "wrap") && this_wgt_page.canWrite)
        {
            var buttons = [{ title: L("lcl_change"), action:"wgt_edit()", icon: "fa-fclt-edit" }];
            if (this_wgt_page.public && (this_wgt_page.readman || user.has("WEB_FACFAC")))
            {
                buttons.push({ title: L("fac_widget_page_show"), action: "fac_show_widget_page(" + wgt_page_key + ")", icon: "fa-eye" });
                if (hasPRSSYS)
                    buttons.push({ title: L("fac_widget_set_homepage"), tooltip: L("fac_widget_homepage_hint"), action: "fac_set_homepage(" + wgt_page_key + ")", icon: "fa-home" });
            }
            buttons.push({ title: L("lcl_delete"), action:"wgt_delete_all(" + wgt_page_key + ")", icon: "fa-trash-alt" });
            IFRAMER_HEADER("", buttons);
        }
%>
        <div class="widget-row">
<%
    var rowWidth = 0;
    if (!widgets.length) {
        Response.Write(L("lcl_empty_rstable"));
    }
    for (i in widgets)
    {
        widget = widgets[i];
        if (widget.width <= 0) // Widget overslaan
            continue;

        if (rowWidth + widget.width > 12)
        { // Volgende rij
%>
        </div>
        <div class="widget-row">
<%
            rowWidth = 0;
        }

        wgt.renderWidget(widget);

        rowWidth += widget.width;
    }
%>
        </div>
    </body>
</html>