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

    File:           job_show_job.asp
    Description:    show detailed information of an object

    Parameters:     job_key

    Context:
    Note:

*/ %>
<!-- #include file="../Shared/common.inc"-->
<!-- #include file="../Shared/iface.inc"-->
<!-- #include file="../Shared/persoonselector.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="./job.inc"-->

<%
var job_key = getQParamInt("job_key");
var this_job = job.func_enabled_job(job_key);
user.auth_required_or_abort(this_job.canReadAny);

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


var sql = "SELECT act.fac_activiteit_eenheid"
        + "     , act.fac_activiteit_periode"
        + "     , act.fac_activiteit_aantal "
        + "     , act.prs_perslid_key "
        + "     , fac_activiteit_eerste "
        + "     , fac_activiteit_einddatum "
        + "     , act.fac_activiteit_status_key "
        + "     , pf.prs_perslid_naam_full naam "
        + "     , fac_activiteit_laatste "
        + "     , fac_activiteit_omschrijving "
        + "     , fac_activiteit_xmlnode "
        + "  FROM fac_activiteit act, prs_v_perslid_fullnames_all pf "
        + " WHERE  act.prs_perslid_key = pf.prs_perslid_key "
        + "   AND  fac_activiteit_key = " + job_key;

var oRs = Oracle.Execute(sql);

var eenheid_key = oRs("fac_activiteit_eenheid").value || -1;
var periode     = oRs("fac_activiteit_periode").value;
var aantal      = oRs("fac_activiteit_aantal").value;
var person      = oRs("prs_perslid_key").value;
var firstdate   = oRs("fac_activiteit_eerste").value;
var enddate     = oRs("fac_activiteit_einddatum").value;
var status      = oRs("fac_activiteit_status_key").value;
var naam        = oRs("naam").value;
var lastdate    = oRs("fac_activiteit_laatste").value;
var act_descr   = oRs("fac_activiteit_omschrijving").value;
var xmlnode     = oRs("fac_activiteit_xmlnode").value;
var isTemplate  = (eenheid_key == 5);

oRs.Close();

var action;
var actiontxt = "";

if (eenheid_key === -1) { // 1-malig
  action = 1;
  actiontxt = L("lcl_job_action_1");
} else if (aantal == "" || aantal == null) { // Tot einddatum
  action = 2;
  actiontxt = L("lcl_job_action_2");
} else if (aantal != "" && aantal != null) { // Aantal keer
  action = 3;
  actiontxt = L("lcl_job_action_3");
}

%>
<html>
<head>
<%
   FCLTHeader.Generate();
%>
<script>
    function job_change()
    {
      if (FcltMgr.startEdit(window))
        window.location.href = "job_edit_job.asp?job_key=<%=job_key%>";
    }
    function job_delete()
    {
      FcltMgr.confirm(L("lcl_job_del_txt_job"), function() {
          var data = {
              key: <%=job_key%>,
              level: "J"
          };
          <% protectRequest.dataToken("data"); %>
          $.post("job_delete.asp",
              data,
              FcltCallbackAndThen(function(json) {
                  json.close = true;
                  FcltMgr.closeDetail(window, json);
              }),
              "json");
      });
    }
</script>

</head>

<body class="showmode">
<%SUBFRAME_START();
var buttons = [];
if (isTemplate  ? this_job.canWriteTemplate : this_job.canWrite) {
  var buttons =  [ {title: L("lcl_change"), action: "job_change()", icon: "fa-fclt-edit" },
                   {title: L("lcl_delete"), action: "job_delete()", icon: "fa-trash-alt" }
                 ];
}

IFRAMER_HEADER(L("lcl_job_frame_algemeen"), buttons);
%>
  <form name="u2">
<%
BLOCK_START("job-info", (isTemplate ? L("lcl_template_algemeen") : L("lcl_job_algemeen")), { icon: "fa-briefcase" });
  ROFIELDTR("fldshort", (isTemplate ? L("lcl_job_template_nr") : L("lcl_job_nr")), job_key);
  ROFIELDTR("fld",
            L("lcl_descr"),
            act_descr,
            { suppressEmpty: true,
              translate: { fld: "fac_activiteit_omschrijving", key : job_key }}
           );

  if (!isTemplate) {
    var statusSql = "       SELECT 1, " + safe.qL("lcl_job_stat_1_inactief") + " FROM DUAL"
                  + " UNION SELECT 2, " + safe.qL("lcl_job_stat_2_actief") + " FROM DUAL"
                  + " UNION SELECT 3, " + safe.qL("lcl_job_stat_3_1xoverslaan") + " FROM DUAL";
    FCLTselector("status",
                  statusSql,
                 { initKey: status,
                   label: L("lcl_job_status"),
                   readonly: true
                 });
  }

  FCLTpersoonselector(
              "person",
              "sgPerson",
            { perslidKey: person,
              label: L("lcl_requestor"),
              fieldNameKey: "person",
              filtercode: "M",
              readonly: true
            });

  if (!isTemplate) {
    ROFIELDTR("fld", L("lcl_job_lastdate"), toDateTimeString(lastdate), {suppressEmpty: true});
  }
BLOCK_END();

if (!isTemplate) {
  BLOCK_START("job-planning", L("lcl_job_planning"), { icon: "fa-calendar" });
    ROFIELDTR("fld", L("lcl_job_action"), actiontxt, {suppressEmpty: true});
    ROFIELDTR("fld", L("lcl_job_firstdate"), toDateTimeString(firstdate));

    sql = "       SELECT -1," + safe.quoted_sql(L("lcl_job_action_1"))             + " FROM DUAL"
        + " UNION SELECT 1, " + safe.quoted_sql(L("lcl_ins_controle_dagelijks"))   + " FROM DUAL"
        + " UNION SELECT 2, " + safe.quoted_sql(L("lcl_ins_controle_wekelijks"))   + " FROM DUAL"
        + " UNION SELECT 3, " + safe.quoted_sql(L("lcl_ins_controle_maandelijks")) + " FROM DUAL"
        + " UNION SELECT 4, " + safe.quoted_sql(L("lcl_ins_controle_jaarlijks"))   + " FROM DUAL";
    FCLTselector("unit",
                 sql,
                 { initKey: eenheid_key,
                   label: L("ins_srtcontrole_eenheid"),
                   readonly: true
                 });
    ROFIELDTR("fld", L("lcl_job_period"), periode, {suppressEmpty: true});
    ROFIELDTR("fld", L("lcl_job_enddate"), toDateTimeString(enddate), {suppressEmpty: true});
    ROFIELDTR("fldshort", L("lcl_job_n_times"), aantal, {suppressEmpty: true});
  BLOCK_END();
}
%>
</form>
<% SUBFRAME_END(); %>
</body>
</html>
<% ASPPAGE_END(); %>
