<%@language = "javascript" %>

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

<%
var bedrijf_key = getQParamInt("company", -1);
var prs_key = getQParamInt("person", -1);
var dienst_key  = getQParamInt("service", -1);
var id  = getQParamInt("id", -1);

var this_model = new model_prs_bedrijfdienstlocatie();

var model_params = {
    "search": {
        "autosearch": true,
        "filters": [
            "service",
            "company"
        ]
    },
    "list": {
        "columns": [],
        "requires": {
            js: ["./prs_bedrijfdienstlocatie.js"]
        }
    },
    "edit": {
        "modal": true,
        "requires": {
            "js": ["./prs_bedrijfdienstlocatie.js"]
        }
    },
    "layout": {
        "miscellaneous":{
            "label": _main_block_title(),
            "icon" : (id > -1 ? "fa-stopwatch" : "fa-concierge-bell")
        }
    },
    "transit": {
        "company": bedrijf_key,
        "person": prs_key,
        "service": dienst_key
    }
};
model_params.list.columns = (bedrijf_key > 0
                            ? ["company", "location", "building", "duration", "autoorder"]
                            : ["service", "forcompany"]);
model_params.list.orderby = (bedrijf_key > 0
                            ? ["service", "location", "building"]
                            : ["service", "forcompany"]);

function _main_block_title()
{
  var sql;
  if (id > -1)
    return L("lcl_prs_dienst_scope_sla");
  if (bedrijf_key > -1)
    sql = "SELECT prs_bedrijf_naam descr FROM prs_bedrijf WHERE prs_bedrijf_key = " + bedrijf_key;
  else if (prs_key > -1)
    sql = "SELECT prs_perslid_naam_friendly descr FROM prs_v_perslid_fullnames WHERE prs_perslid_key = " + prs_key;
  var result = L("lcl_select_dienst");
  if (sql)
  {
    var oRs = Oracle.Execute(sql);
    result = L("lcl_select_dienst_at").format(safe.html(oRs("descr").Value));
    oRs.Close();
  }

  return result;
}

if (mode == "edit")
{
  if (prs_key > 0)
  {
    delete this_model.fields.company;
  }
  else if (bedrijf_key > 0)
  {
    delete this_model.fields.person;
    delete this_model.fields.forcompany;
  }
}

if (mode == "list")
{
  model_params.list.buttons = [];

  if (prs_key > 0)
    // Voeg een knop voor toevoegen van bedrijfdienstlocatie aan bedrijf of persoon toe.
    model_params.list.buttons.push({ icon: "fa-plus", title: L("lcl_add"), action: "scf_add_service(" + bedrijf_key + ", " + prs_key + ")", id: "btn_scf_my_add" });

  if (bedrijf_key > -1)
    // Voeg een knop voor wijzigen van de dienst(-locatie)-scope toe.
    model_params.list.buttons.push({ icon: "fa-map-marker-edit fa-lg", title: L("lcl_prs_dienst_edit_scope"), action: "scf_add_location("+dienst_key+","+bedrijf_key+")", id: "btn_scf_my_add" });

  if (prs_key > 0)
    // modal is true, dus nu hier toevoegen.
    model_params.list.buttons.push({ icon: "fa-brackets-curly", title: L("lcl_scf_paste"), action: "scf_import()", id: "btn_scf_my_imp" });
}

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