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

    File:           ins_kenmerk.asp

    Description:    Aanroep van model_ins_kenmerk voor objecten EN taken

    Context:        paramater: niveau=O:    Object kenmerken (level: D=Discipline, G=Objectgroep, S=Objectsoort)
                               niveau=T:    Taak kenmerken (level:  T=Alle taken, C=Periodiek taken, E=Taakcategorie)
    Notes:
*/
%>

<!-- #include file="../scf/scaffolding.inc" -->
<!-- #include file="../api2/model_ins_kenmerk.inc" -->

<%
var niveau = getQParam("niveau", "O");
var kenmerk_key = getQParamInt("id", -1);

if (mode != "save" && mode != "delete" && mode != "api2")
{ %>
  <script>
    var mode = "<%=mode%>";
    var niveau = "<%=niveau%>";
    var kenmerk_key = <%=kenmerk_key%>;
  </script>
<%
}

var isTaakKenmerk = (niveau == "T" || niveau == "E" || niveau == "C");
var km_level = niveau;
if (kenmerk_key > -1 && mode != "list")
{
    var sql = "SELECT ins_kenmerk_niveau"
            + "  FROM ins_kenmerk"
            + " WHERE ins_kenmerk_key = " + kenmerk_key;
    var oRs = Oracle.Execute(sql);
    if (!oRs.eof)
    {
        km_level = oRs("ins_kenmerk_niveau").Value;
    }
    oRs.Close();
}

var this_model = new model_ins_kenmerk( (isTaakKenmerk ? "T" : "O") );

this_model.fields.level.LOV = level_LOV();
this_model.fields.level.filter = "exact";

if (mode == "edit")
{
  if (kenmerk_key == -1)
  {
    this_model.fields.level.LOV = "A;" + L("ins_srtcontrole_m"); // Nieuwe taak, dan is niveau nog niet bekend. Dan maar de algemene term "Taken" weergeven.
    this_model.fields.level.hidden_fld = true;
    this_model.fields.level.defaultvalue = isTaakKenmerk? 'T' : km_level;
  }
}
else
  this_model.fields.level.LOV = level_LOV();

switch (km_level)
{ // Verwijderen uit de fields lijst.
  // Taak.
  case "T":
  case "C":
  case "E": delete this_model.fields.objectdiscipline;
            delete this_model.fields.objectgroup;
            delete this_model.fields.objecttype;
            delete this_model.fields.editlevel;
            delete this_model.fields.measurement;
            this_model.record_title = L("ins_srtcontrole_kenmerk");
            this_model.records_title = L("ins_srtcontrole_kenmerk_m");
            break;
  // Object.
  case "D": delete this_model.fields.requiredstatus;
            delete this_model.fields.taskdiscipline;
            delete this_model.fields.task;
            this_model.fields.objectdiscipline.required = true;
            break;
  case "G": delete this_model.fields.requiredstatus;
            delete this_model.fields.taskdiscipline;
            delete this_model.fields.task;
            this_model.fields.objectgroup.required = true;
            break;
  case "S": delete this_model.fields.requiredstatus;
            delete this_model.fields.taskdiscipline;
            delete this_model.fields.task;
            this_model.fields.objecttype.required = true;
            break;
  case "O": //delete this_model.fields.requiredstatus;
            //delete this_model.fields.taskdiscipline;
            //delete this_model.fields.task;
            //this_model.fields.objecttype.required = true;
            break;
}


function level_LOV()
{
  var v_level = "";
  if (mode == "list" || mode == "search")
  {
    if (isTaakKenmerk)
      v_level =  "A;" + L("mgt_kenmerk_controle_all")
              + ";E;" + L("mgt_kenmerk_ctrdiscipline")
              + ";C;" + L("mgt_kenmerk_srtcontrole");
    else
      v_level = "D;" + L("mgt_srtkenmerk_discipline")
              + ";G;" + L("mgt_srtkenmerk_srtgroep")
              + ";S;" + L("mgt_srtkenmerk_srtdeel");
  }
  else
  {
    switch (km_level)
    {
      case "T": v_level = "T;" + L("mgt_kenmerk_controle_all"); break;
      case "E": v_level = "E;" + L("mgt_kenmerk_ctrdiscipline"); break;
      case "C": v_level = "C;" + L("mgt_kenmerk_srtcontrole"); break;
      case "D": v_level = "D;" + L("mgt_srtkenmerk_discipline"); break;
      case "G": v_level = "G;" + L("mgt_srtkenmerk_srtgroep"); break;
      case "S": v_level = "S;" + L("mgt_srtkenmerk_srtdeel"); break;
      default:  v_level =  "T;" + L("mgt_kenmerk_controle_all")
                        + ";E;" + L("mgt_kenmerk_ctrdiscipline")
                        + ";C;" + L("mgt_kenmerk_srtcontrole")
                        + ";D;" + L("mgt_srtkenmerk_discipline")
                        + ";G;" + L("mgt_srtkenmerk_srtgroep")
                        + ";S;" + L("mgt_srtkenmerk_srtdeel");
    }
  }
  return v_level;
}

var model_params = {
        "search": {
            "autosearch": true,
            "filters": [
                "level",
                "objectpropertydesc",
                "objectpropertytype"
            ],
            "transit": [
                "level",
                "objectdiscipline",
                "objectgroup",
                "objecttype",
                "objectpropertytype"
            ],
            "requires": {
                "js": ["../mgt/srtinstallatieselector.js"]
            }
        },
        "list": {
            "columns": [
                "sequence",
                "objectpropertytype",
                "objectpropertydesc",
                "rolecode",
                "authorization",
                "code",
                "id"
            ],
            "orderby": [
                "objectdiscipline",
                "sequence",
                "objectpropertydesc"
            ]
        },
        "edit": {
            "requires": {
                "js": [
                    "../mgt/srtinstallatieselector.js",
                    "./ins_kenmerk.js"
                ]
            }
        },
        "layout": {
            "block": [
                {
                    "blockid": "insKenmerkAlgemeen",
                    "label": L("mgt_kenmerk"),
                    "icon": "fa-table-tree",
                    "ishtmlsafe": true,
                    "hidden": false,
                    "buttons": [],
                    "fields": [
                        "id",
                        "objectpropertytype",
                        "objectpropertydesc",
                        "objectdiscipline",
                        "objectgroup",
                        "objecttype",
                        "level",
                        "taskdiscipline",
                        "task",
                        "objectkey",
                        "editlevel",
                        "rolecode",
                        "group",
                        "sequence",
                        "propertydefault",
                        "hint",
                        "regexp",
                        "code"
                    ]
                },
                {
                    "blockid": "insKenmerkFormat",
                    "label": L("mgt_kenmerk_displayprops"),
                    "icon": "fa-face-viewfinder",
                    "ishtmlsafe": true,
                    "hidden": false,
                    "buttons": [],
                    "fields": [
                        "required",
                        "requiredstatus",
                        "authorization",
                        "showexpression",
                        "readonly",
                        "inlist",
                        "measurement",
                        "clear"  // voor uitgifte/inname
                    ]
                }
            ]
        },
        "transit": {
            "niveau": niveau
        }
    };

if (isTaakKenmerk)
{ // Kenmerk_niveau: C of E.
  // Toevoegen extra kolom alleen voor taak kenmerken
  model_params.list.columns.splice(0, 0, "task");
  model_params.list.columns.splice(0, 0, "taskdiscipline");
  model_params.list.orderby[0] = "taskdiscipline";

  model_params.search.filters.splice(2, 0, "task");
  model_params.search.filters.splice(2, 0, "taskdiscipline");
}
else
{ // kenmerk_niveau: D | G | S
  // Toevoegen extra kolommen voor niet-taak kenmerken.
  // NB: Standaard in this.list opnemen en bij niveau=C/E verwijderen geeft fout op niet bestaande ins_discipline_key etc.
  model_params.list.columns.splice(0, 0, "objecttype");
  model_params.list.columns.splice(0, 0, "objectgroup");
  model_params.list.columns.splice(0, 0, "objectdiscipline");

  model_params.search.filters.splice(2, 0, "objecttype");
  model_params.search.filters.splice(2, 0, "objectgroup");
  model_params.search.filters.splice(2, 0, "objectdiscipline");
}

scaffolding(this_model, model_params);
%><% ASPPAGE_END(); %>
