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

    File:           mld_workflow.asp

    Description:    Beheren van mld_workflowstep
                    Individuele meldingen van een workflowschema

    Context:        start_key is altijd bekend

    Notes:
*/
%>
<!-- #include file="../scf/scaffolding.inc" -->
<!-- #include file="../api2/model_mld_workflowstep.inc" -->
<%

var prevstep = getQParamInt("prevstep", -1);
if (prevstep > 0)
  var mystart_key = Oracle.Get("COALESCE(mld_workflowstep_start_key, mld_workflowstep_key)", "mld_workflowstep", prevstep);
else
{
  var mystart_key = getQParamInt("mystart", -1); // De parameter zit er niet op als we in een include-model zitten
  if (mystart_key == -1)
  { // Dan moet er alleen een id meegegeven zijn. Dan bepalen vanuit de id de start_key.
    var id = getQParam("id");
    var mystart_key = Oracle.Get("COALESCE(mld_workflowstep_start_key, mld_workflowstep_key)", "mld_workflowstep", id);
  }
}


var this_model = new model_mld_workflowstep(mystart_key);

var mode = getQParam("mode", "");
if (mode == 'list')
{
    this_model.REST_POST = false; // Doen we via inline action
}

if ((mode == "edit" || mode == "save") && getQParam("id", -1) < 0) // Toevoegmode.
{
    // Forceer dat ook een 'vorige stap' gekozen wordt
    // Overigens geven we die in mld_workflowstep.js mee als default
    this_model.fields.prevstep = this_model.includes.workflowrules.model.fields.prevstep;
    delete this_model.fields.prevstep.uniquewith;
    this_model.fields.jointype.hidden_fld = true; // deze nog even verbergen
    this_model.fields.issuetype.label = L("mld_workflowrule_step_next");
    this_model.record_title = L("mld_workflowrule_step_next");
    this_model.fields["_hint"] = {
            "dbs": "",
            "label": "",
            "typ": "label",
            "labelvalue": L("mld_workflow_next_in_details")
        }
}

var scf_params =
    {
        "list": {
            "columns": [
                "level",
                "id",
                "issuetype",
                "workflowrules.nextstep_id",
                "workflowrules.nextstep"
            ],
            "requires": {
              js: ["./mld_workflowstep.js"]
            },
            "actionscol": "workflowrules.nextstep",
            "actions":
                [{ action: "add_step", caption: L("lcl_add") }]
        },
        "edit":{
            "addmodal": true
        },
        "layout": {
            "miscellaneous": {
                "icon": "fa-code-commit"
            }
        },
        "transit": {
            "mystart": mystart_key
        },
        "included": {
            "workflowrules": {
                "edit": {
                    "requires": {
                      js: ["./mld_workflowstep.js"]
                    },
                    "buttons": [{ title: L("mld_workflowrule_condition"), action: "build_expression(" + prevstep + ")", icon: "fa-align-left" }]
                },
                "list": {
                    "columns": [
                        "id",
                        "nextstep",
                        "condition"
                    ]
                }
            }
        }

    };
    if (mode != "list" || prevstep > 0)
    {
        // Remove id
        scf_params.list.columns.splice(3, 1);
        scf_params.list.columns.splice(1, 1);
    }

    //xxscf_params.list.orderby = ["level", "issuetype"];

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