<% /*
    $Revision$
    $Id$

    File:           model_cad_legendawaarde.inc

    Description:    Vanuit CodeCharge gegenereerd model voor cad_legendawaarde

    Context:

    Notes:
*/
%>
<%

function model_cad_legendawaarde()
{
    this.table = "cad_legendawaarde";
    this.primary = "cad_legendawaarde_key";
    this.records_name = "cad_legendawaardes";
    this.record_name = "cad_legendawaarde";
    this.autfunction = "WEB_CADMGT";
    this.record_title = L("cad_legendawaarde");
    this.records_title = L("cad_legendawaarde_m");


    this.fields = {
        "id": {
            "dbs": "cad_legendawaarde_key",
            "label": "Key",
            "typ": "key",
            "required": true,
            "filter": "exact",
            "seq": "cad_s_cad_legendawaarde_key"
        },
        "legendas": {
            "dbs": "cad_legenda_key",
            "label": L("cad_legenda"),
            "typ": "key",
            "foreign": {
                "tbl": "cad_legenda",
                "key": "cad_legenda_key",
                "desc": "cad_legenda_omschrijving"
            }
        },
        "name": {
            "dbs": "cad_legendawaarde_value",
            "label": L("cad_legendawaarde_value"),
            "typ": "varchar",
            "translate": true
        },
        "description": {
            "dbs": "cad_legendawaarde_omschr",
            "label": L("cad_legendawaarde_omschr"),
            "typ": "varchar",
            "translate": true
        },
        "rgb": {
            "dbs": "cad_legendawaarde_rgb",
            "label": L("cad_legendawaarde_rgb"),
            "typ": "varchar",
            "defaultvalue": "FFFFFF",
            "listfunction": fnshowcolor
        }
    };


    this.list = {
        "columns": [
            "id",
            "legendas",
            "name",
            "description",
            "rgb"
        ]
    };
    this.search = {
        "autosearch": true
    };
    this.edit = {
        "requires": {
            "js": [
                "../localscripts/colorpicker/js/evol.colorpicker.min.js",
                "../mgt/cad_legendawaarde.js"
            ],
            "css": [
            	"../localscripts/colorpicker/css/evol.colorpicker.min.css",
            	"../localscripts/colorpicker/css/colorpicker.css"
            ]
        },
        "modal": true
    };


    function fnshowcolor(oRs)
    {   // Tonen van gekleurde blokjes bij de waarde in de lijst.
        var kleur = (oRs.Fields("rgb").Value).replace(/ /g, "");
        var result = "<span style='width:50px; float:left; display:inline'>"
                   + "<div style='width:20px; background-color:#" + safe.html(kleur) + "'>"
                   + "<div style='padding-left:25px'>" + safe.html(kleur) + "</div></div></span>"
        return result;
    }

    this.hook_pre_edit = function (obj, fld)
    {
        // Niet-model velden toevoegen.
        fld._color = {
            "dbs": "",
            "label": "",
            "typ": "button"
        };
        var color_panel_def = '<div id="color_select"></div><br/>'
                            + '<div class="">'
                            + '<button id="btn_cp_accept">' + L("cad_legendawaarde_accept") + '</button>'
                            + '<button id="btn_cp_hide">' + L("cad_legendawaarde_hide") + '</button>'
                            + '</div>';
        fld.color_panel = {
            "dbs": "",
            "label": "",
            "typ": "div",
            "defaultvalue": color_panel_def,
            "hidden": true
        };

        var rgb = (obj.rgb).replace(/ /g, "");
        var kleur = '<span style="border:1px;width:16px;display: inline-block;background-color:#' + rgb + '">&nbsp;</span>'
                  + '&nbsp;' + L("cad_legendawaarde_select");
        fld._color.defaultvalue = kleur;
    }

    this.REST_GET    = generic_REST_GET(this);
    this.REST_POST   = generic_REST_POST(this);
    this.REST_PUT    = generic_REST_PUT(this);
    this.REST_DELETE = generic_REST_DELETE(this);
}
%>