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

    File:           mld_kenmerk.asp

    Description:    Aanroep van model_mld_kenmerk voor meldingen EN opdrachten

    Context:        paramater: niveau=M:    melding kenmerken (level = S|D|T)
                               niveau=O:    opdracht kenmerken (level = P|O)
    Notes:
*/
%>
<!-- #include file="../scf/scaffolding.inc" -->
<!-- #include file="../api2/model_mld_kenmerk.inc" -->
<%
var niveau = getQParamSafe("niveau", "");
var kenmerk_key = getQParamInt("id", -1);
var disctype_key = getQParamInt("disciplinetype", -1);
var isclone = getQParamInt("scf_clone", 0);

var isOpdrachtKenmerk = (niveau == "P" || niveau == "O");
var km_level = niveau;
if (kenmerk_key > -1 && mode != "list")
{
    var sql = "SELECT mld_kenmerk_niveau"
            + "  FROM mld_kenmerk"
            + " WHERE mld_kenmerk_key = " + kenmerk_key;
    var oRs = Oracle.Execute(sql);
    if (!oRs.eof)
    {
        km_level = oRs("mld_kenmerk_niveau").Value;
    }
    oRs.Close();
}

var this_model = new model_mld_kenmerk( (isOpdrachtKenmerk ? "O" : "M") );

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

if (mode == "edit")
{
    if (kenmerk_key == -1 || isclone)
    {
      this_model.fields.level.hidden_fld = true;
      this_model.fields.level.defaultvalue = isOpdrachtKenmerk? 'P' : km_level;
    }
}

switch (km_level)
{ // Verwijderen uit de fields lijst.
  // Opdracht.
  case "P":
  case "O": break;
  // Melding.
  case "A": delete this_model.fields.disciplinetype;
            delete this_model.fields.discipline;
            delete this_model.fields.mld_issuetype;
            break;
  case "T": delete this_model.fields.discipline;
            this_model.fields.mld_issuetype.hidden_fld = true;
            this_model.fields.disciplinetype.required = true;
            break;
  case "D": this_model.fields.discipline.required = true;
            break;
  case "S": this_model.fields.mld_issuetype.required = true;
            break;
  case "M": break;
}

function level_LOV()
{
  var v_level = "";
  if (mode == "list" || mode == "search")
  {
    if (isOpdrachtKenmerk)
      v_level = "P;" + L("lcl_mld_opdr_all")
              + ";O;" + L("lcl_mld_typeopdr");
    else
      v_level = "A;" + L("mld_srtdiscipline_m_all")
              + ";T;" + L("lcl_mld_vakgroeptype")
              + ";D;" + L("lcl_mld_vakgroep")
              + ";S;" + L("lcl_complain");
      // In mld_kenmerk.js wordt nog de optie "N"="Alle niveau's" toegevoegd als er een stdmelding_key geselecteerd is.
  }
  else
  {
    switch (km_level)
    {
      case "P": v_level = "P;" + L("lcl_mld_opdr_all"); break;
      case "O": v_level = "O;" + L("lcl_mld_typeopdr"); break;
      case "A": v_level = "A;" + L("mld_srtdiscipline_m_all"); break;
      case "S": v_level = "S;" + L("lcl_complain"); break;
      case "D": v_level = "D;" + L("lcl_mld_vakgroep"); break;
      case "T": v_level = "T;" + L("lcl_mld_vakgroeptype"); break;
      default:  v_level =  "P;" + L("lcl_mld_opdr_all")
                        + ";O;" + L("lcl_mld_typeopdr")
                        + ";A;" + L("mld_srtdiscipline_m_all")
                        + ";T;" + L("lcl_mld_vakgroeptype")
                        + ";D;" + L("lcl_mld_vakgroep")
                        + ";S;" + L("lcl_complain");
    }
  }
  return v_level;
}

var model_params = {
    "search": {
        "autosearch": false, // bewust, dit is de enige, want het zijn er vaak veel en het zoekblok ben je dan steeds kwijt
        "filters": [
            "objectpropertydesc",
            (isOpdrachtKenmerk ? "issuepropertytype" : "issuepropertytypename"),
            (isOpdrachtKenmerk ? "ordertype" : "disciplinetype"),
            "discipline",        // Het veld discipline bestaat niet voor Opdracht en wordt daarom in filter niet getoond!
            "mld_issuetype",     // Het veld mld_issuetype bestaat niet voor Opdracht.
            "attributetype",     // Het veld attributetype bestaat niet voor Opdracht
            (isOpdrachtKenmerk? "filled" : "level") // Niet op level filteren bij Opdracht: Het veld filled bestaat niet voor Opdracht en wordt daarom in filter niet getoond!
        ],
        "transit": [
            "disciplinetype",
            "ordertype",
            "discipline",
            "mld_issuetype",
            "issuepropertytype"
        ],
        "requires": {
            "js": ["./mld_kenmerk.js"]
        }
    },
    "list": { /* wordt voor opdrachten verderop overruled */
      "columns": [
          //"id",
          "disciplinetype",
          "discipline",
          "mld_issuetype",
          "sequence",
          "issuepropertytype",
          "objectpropertydesc",
          "rolecode",
          "attributetype",
          //"group",
          //"required",
          //"level",
          "authorization",
          "code",
          "filled",
          "id"
      ],
      "orderby": [
          "disciplinetype NULLS FIRST",
          "discipline NULLS FIRST",
          "mld_issuetype NULLS FIRST",
          "sequence"
      ]
    },
    "transit": {
        "niveau": niveau
    },
    "print": {},
    "edit": {
        "requires": {
            "js": ["./mld_kenmerk.js"]
        }
    },
    "layout": {
        "block": [
            {
                "blockid": "mldKenmerkAlgemeen",
                "label": L("mgt_kenmerk"),
                "icon": "fa-table-tree",
                "ishtmlsafe": true,
                "hidden": false,
                "buttons": [],
                "fields": [
                    "id",
                    "issuepropertytype",
                    "attributetype",  // wordt schijnbaar niet (altijd) getoond
                    "objectpropertydesc",
                    "level",
                    "disciplinetype",
                    "discipline",
                    "mld_issuetype",
                    "ordertype",
                    "rolecode",
                    "group",
                    "sequence",
                    "default",
                    "hint",
                    "regexp",
                    "code",
                    "treatmentteam"
                ]
            },
            {
                "blockid": "mldKenmerkFormat",
                "label": L("mgt_kenmerk_displayprops"),
                "icon": "fa-face-viewfinder",
                "ishtmlsafe": true,
                "hidden": false,
                "buttons": [],
                "fields": [
                    "required",
                    "requiredstatus",
                    "obligationfill",
                    "authorization",
                    "showexpression",
                    "hltproperty",
                    "clear",
                    "readonly",
                    "inlist"
                ]
            }
        ]
    }
};

if (isOpdrachtKenmerk)
{
    // Andere kolommen voor opdrachten.
    model_params.list = {
        "columns": [
            "ordertype",
            "sequence",
            "issuepropertytype",
            "objectpropertydesc",
            "rolecode",
            "group",
            "required",
            //"attributetype", // bestaan helaas niet voor opdrachtkenmerken (waarom eigenlijk?)
            //"code",
            //"filled",
            "id"
        ],
      "orderby": [
          "ordertype NULLS FIRST",
          "sequence",
          "issuepropertytype NULLS FIRST",
          "objectpropertydesc NULLS FIRST"
      ]
    };
}

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