<% /*
    $Revision$
    $Id$

    File:           model_fac_notificatie_job.inc

    Description:    Vanuit CodeCharge gegenereerd model voor fac_notificatie_job

    Context:

    Notes:
*/
%>
<%

function model_fac_notificatie_job(params) // J voor Jobs, S voor Scheduled mail
{
    this.records_name = "notificationjobs";
    this.record_name = "notificationjob";
    this.table = "fac_notificatie_job";
    this.primary = "fac_notificatie_job_key";
    this.autfunction = "WEB_PRSSYS";
    this.record_title = L("fac_notificatie_job");
    this.records_title = L("fac_notificatie_job_m");


    this.fields = {
        "id": {
            "dbs": "fac_notificatie_job_key",
            "label": L("lcl_key"),
            "typ": "key",
            "hidden_fld": true,
            "required": true,
            "seq": "fac_s_fac_notificatie_job_key"
        },
        "name": {
            "dbs": "fac_notificatie_job_oms",
            "label": L("fac_notificatie_job_oms"),
            "typ": "varchar",
            "required": true,
            "translate": true
        },
        "view": {
            "dbs": "fac_notificatie_job_view",
            "label": L("fac_notificatie_job_view"),
            "typ": "varchar",
            "required": true
        },
        "flags": {
            "dbs": "fac_notificatie_job_flags",
            "label": L("fac_notificatie_job_flags"),
            "typ": "number",
            "defaultvalue": 0,
            "required": true

        },
        "jobmode": { // Niet hernoemen naar 'mode', dat wordt door scaffolding in de url al gebruikt
            "dbs": "fac_notificatie_job_mode",
            "label": L("fac_notificatie_job_mode"),
            "typ": "number",
            "bits": [
                {
                    "name": "",
                    "label": "",
                    "typ": "check",
                    "mask": 15,
                    "radios": [
                        {
                            "name": "send_status",
                            "label": L("fac_notificatie_job_status"),
                            "mask": 1
                        },
                        {
                            "name": "send_email",
                            "label": L("fac_notificatie_job_email"),
                            "mask": 2
                        },
                        {
                            "name": "send_sms",
                            "label": L("fac_notificatie_job_sms"),
                            "mask": 4
                        },
                        {
                            "name": "send_alert",
                            "label": L("fac_notificatie_job_alert"),
                            "mask": 8
                        }
                    ]
                }
            ]
        },
        "person": {
          "dbs": "prs_perslid_key",
          "label": L("lcl_user"),
          "typ": "key",
          "foreign" : "prs_perslid",
          "readonly": true
       },
        "receiver": {
          "dbs": "prs_perslid_key_receiver",
          "label": L("prs_perslid_key_receiver"),
          "typ": "key",
          "foreign" : "prs_perslid",
          "readonly": true
       },
       "interval": {
            "dbs": "fac_notificatie_job_interval",
            "label": L("fac_notificatie_job_interval"),
            "typ": "number"
        },
/* Alleen sensor updates wat nooit is uitgekristalliseerd
        "seconds": {
            "dbs": "fac_notificatie_job_seconds",
            "label": L("fac_notificatie_job_seconds"),
            "typ": "number"
        },
*/
        "lastrun": {
            "dbs": "fac_notificatie_job_lastrun",
            "label": L("fac_notificatie_job_lastrun"),
            "typ": "datetime",
            "readonly": true
        },
        "nextrun": {
            "dbs": "fac_notificatie_job_nextrun",
            "label": L("fac_notificatie_job_nextrun"),
            "typ": "datetime"
        },
/* Alleen sensor updates wat nooit is uitgekristalliseerd
        "queueid": {
            "dbs": "fac_notificatie_job_queue",
            "label": L("fac_notificatie_job_queue"),
            "typ": "varchar",
            "defaultvalue": "DEFAULT"
        },
*/
        "fac_usrrap_key": {
            dbs: "fac_usrrap_key",
            typ: "key",
            hidden_fld: true
        }
    };

    if (params.niveau == 'S')
    {
        delete this.fields["flags"];
        delete this.fields["jobmode"];
        delete this.fields["seconds"];
        delete this.fields["view"];
        delete this.fields["queueid"];
        this.fields["interval"].LOV = L("fac_notificatie_job_intervalLOV");
        this.fields["interval"].label = L("fac_notificatie_job_interval2");
        var gparams = {
                GET: {
                    wheres: ["prs_perslid_key_receiver IS NOT NULL"]
                }
            };
        if (!user.has("WEB_PRSSYS"))
        {
            gparams.GET.wheres.push("prs_perslid_key_receiver = " + user_key); // alleen van jezelf
            this.autfunction = false;
        }

        this.list = {
            columns: [
                "person",
                "receiver",
                "interval",
                "lastrun",
                "nextrun"
            ]
        };
    }
    else
    {
        delete this.fields["person"];
        delete this.fields["receiver"];
        var gparams = {
                GET: {
                    wheres: ["fac_notificatie_job_view IS NOT NULL"]
                }
            };

        if (user.has("WEB_PRSSYS"))
        {
            this.REST_POST   = generic_REST_POST(this);
        }
    }

    this.REST_GET    = generic_REST_GET(this, gparams);
    this.REST_PUT    = generic_REST_PUT(this);
    this.REST_DELETE = generic_REST_DELETE(this);
}
%>