<%
/*  $Revision$
    $Id$

    File:           scaffolding_wrap.asp
    Status:
    Description:    wrapper voor scaffolding show / edit en iframes voor de includes

    Parameters:     id

    Context:
    Note:

*/ %>
<%
function scaffolding_wrap(model, scf_params)
{
    scf_params.wrap = scf_params.wrap || {};

    var transit = scf_transit2url(scf_params);
    if (scf_params.incsetting)
        transit += "&" + scf_params.incsetting.joinfield + "=" + getQParamInt(scf_params.incsetting.joinfield);

    var key = getQParamInt("id", -1);
    var cloning = getQParamInt("scf_clone", 0) == 1;

    FCLTHeader.Requires({plugins:["jQuery", "suggest"], js: ["jquery-ui.js"]})

    var scf_title = model.record_title;
%>

    <html>
      <head>
<%      FCLTHeader.Generate(); %>
        <script>
<%        if (key > 0)
          { %>
            FcltMgr.setTitle("<%=(cloning?safe.jsstring(L("lcl_scf_clonettl")) + " ":"") + safe.jsstring(scf_title)%>", {hot: false});
<%        }
          if (key < 0 || cloning)
          {
%>           FcltMgr.startEdit(window);
<%        } %>

          function scfClose(params)
          {
<%          if (key < 0 || cloning)
            { %>
              if (params.cancel)
              {
                FcltMgr.closeDetail(window, params);
                return true;
              }
              if (!params.keepForm)
                window.location.href = "<%=scf_params.this_fullpath%>?mode=wrap<%=transit%>&verynew=1&id=" + params.key;
<%          }
            else
            { /* Bestaand object bewerkt, switch naar show-mode */ %>
              if ("reload" in params && params.reload)
              {
                window.location.href = "<%=scf_params.this_fullpath%>?mode=wrap<%=transit%>&id=<%=key%>";
              }
              else if (params.deleted)
              {
                FcltMgr.closeDetail(window, params);
                return true;
              }
              else if (!params.keepForm)
                $("#scfFrame")[0].src = "<%=scf_params.this_fullpath%>?mode=show<%=transit%>&id=<%=key%>";

<%          } %>
          }
<%        if ("layout" in scf_params && typeof scf_params.layout === "object" && "active_tab" in scf_params.layout)
          { %>
            $(function() {
              $("#frametabs").tabs({ "active": "<%=scf_params.layout.active_tab%>" });
            })
<%        } %>
        </script>
      </head>

      <body>
    <%  if (key < 0 || cloning)
          var page = scf_params.this_fullpath + "?mode=edit" + transit; // Maak een nieuw
        else
          var page = scf_params.this_fullpath + "?mode=show" + transit;
        page += "&id=" + key;
        if (cloning)
            page += "&scf_clone=1"
        PAGE_START();
        IFRAMER("scfFrame", page, { FcltClose: "scfClose", title: model.record_title } );

        if (key > 0 && !cloning)
        {
            if (!scf_params.wrap.no_default_frames)
            {
                for (var inc in model.includes)
                {
                    var include = model.includes[inc];
                    if (!include.no_autowrap && include.joinfield && !include.joinfunction && !include.prefunc) // die is te ingewikkeld?
                    {
                        var url = scf_params.this_fullpath + "?mode=list" + transit + "&model=" + inc;
                        // Vanuit fac_reportx heeft fullpath geen id in zich verwerkt. Daarom nog maar een keer in de url
                        url +=  "&" + include.joinfield + "=" + key;
                        var iframerParams = {
                          FcltClose: "scfClose",
                          title: include.label || include.model.records_title,
                          icon: include.icon || "fa-list",
                          refreshOnActivate: include.refreshOnActivate
                        };
                        IFRAMER(inc + "Frame", url, iframerParams);
                    }
                }
            }
            if (scf_params.wrap.frames)
            {
                for (var fr in scf_params.wrap.frames)
                {
                    var frame = scf_params.wrap.frames[fr];
                    if (!frame.autfunction || user.has(frame.autfunction)) {
                        var iframerParams = {
                          title: frame.title,
                          icon: frame.icon || "fa-list",
                          refreshOnActivate: frame.refreshOnActivate
                        };
                        IFRAMER(frame.id || (fr + "Frame"), frame.url.format(key), iframerParams);
                    }
                }
            }
        }
        PAGE_END();
    %>
      </body>
    </html>
<%
}
%>