<%
/*  $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);

    var key = getQParam("id", -1);

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

    var scf_title = model.record_title;
    %>

    <html>
      <head>
    <%  FCLTHeader.Generate(); %>
        <script type="text/javascript" >
    <%    if (key > 0)
          { %>
            FcltMgr.setTitle("<%=safe.jsstring(scf_title)%>", {hot: false});
    <%    } %>

          function scfClose(params)
          {
    <%      if (key < 0)
            { %>
              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 (!params.keepForm && !params.deleted)
                $("#scfFrame")[0].src = "<%=scf_params.this_fullpath%>?mode=show<%=transit%>&id=<%=key%>";

    <%      } %>
          }
        </script>
      </head>

      <body>
    <%  if (key < 0)
          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;

        IFRAMER("scfFrame", page, { FcltClose: "scfClose" } );

        if (key > 0)
        {
            if (!scf_params.wrap.no_default_frames)
            {
                for (var inc in model.includes)
                {
                    var include = model.includes[inc];
                    if (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;
                        IFRAMER(inc + "Frame", url, { FcltClose: "scfClose" } );
                    }
                }
            }
            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))
                        IFRAMER(frame.id || (fr + "Frame"), frame.url.format(key));
                }
            }
        }
    %>
      </body>
    </html>
<%
}
%>