{
    "type": "Ext.grid.Panel",
    "reference": {
        "name": "items",
        "type": "array"
    },
    "codeClass": null,
    "userConfig": {
        "height": null,
        "id": "gridAsistencia",
        "itemId": "gridAsistencia",
        "designer|userClassName": "gridAsistencia",
        "designer|userAlias": "gridasistencia",
        "title": "",
        "lockedViewConfig": [
            "{ \r",
            "    scroll: false\r",
            "}"
        ],
        "normalGridConfig": [
            " {\r",
            "        scroll: 'both'\r",
            "    }"
        ],
        "columnLines": true,
        "store": null
    },
    "designerId": "5f29ee01-af97-4f63-ba76-81393065b27c",
    "cn": [
        {
            "type": "Ext.grid.View",
            "reference": {
                "name": "viewConfig",
                "type": "object"
            },
            "codeClass": null,
            "designerId": "490cf4f5-9a86-4cc6-9231-1a937c370ac1"
        },
        {
            "type": "Ext.grid.column.Number",
            "reference": {
                "name": "columns",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "hidden": true,
                "dataIndex": "id_vinculo",
                "lockable": true,
                "locked": true,
                "text": "Id_vinculo"
            },
            "designerId": "6285a4e8-a0e1-4b11-a92a-98058c12db3a"
        },
        {
            "type": "Ext.grid.column.Column",
            "reference": {
                "name": "columns",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "minWidth": null,
                "width": 65,
                "dataIndex": "indiv_dni",
                "lockable": true,
                "locked": true,
                "text": "D.N.I.",
                "flex": null
            },
            "designerId": "23709f91-3596-441a-86bb-ea6e26484557"
        },
        {
            "type": "Ext.grid.column.Column",
            "reference": {
                "name": "columns",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "minWidth": 180,
                "width": null,
                "dataIndex": "nombre_persona",
                "lockable": true,
                "locked": true,
                "text": "Apelldos y nombres ",
                "flex": 2
            },
            "designerId": "6bb581f9-7d5a-4960-a50f-5689501e98f3"
        },
        {
            "type": "Ext.grid.column.Column",
            "reference": {
                "name": "columns",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "minWidth": 150,
                "width": null,
                "dataIndex": "cargo",
                "lockable": true,
                "locked": true,
                "text": "Cargo",
                "flex": 1
            },
            "designerId": "109af4d2-b5d0-4bd7-a37a-bb634ef48678"
        },
        {
            "type": "Ext.grid.column.Column",
            "reference": {
                "name": "columns",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "minWidth": 90,
                "width": null,
                "dataIndex": "situacionlaboral",
                "lockable": true,
                "locked": true,
                "text": "Situac. Laboral",
                "flex": 1
            },
            "designerId": "bdab8aa6-264c-4c8c-9954-fa342270a25a"
        },
        {
            "type": "Ext.grid.column.Column",
            "reference": {
                "name": "columns",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "width": 40,
                "dataIndex": "jornada",
                "lockable": true,
                "locked": true,
                "text": "Jorn"
            },
            "designerId": "14848c4f-97ca-4a70-8a74-52b5ad8138c5"
        },
        {
            "type": "Ext.toolbar.Toolbar",
            "reference": {
                "name": "dockedItems",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "dock": "top",
                "height": 35,
                "ui": null
            },
            "designerId": "d3717da4-4de9-49ad-ad8a-c6451071cd59",
            "cn": [
                {
                    "type": "Ext.toolbar.TextItem",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null,
                        "itemId": "txtInstitucion",
                        "text": null
                    },
                    "designerId": "946a5298-535a-41cc-87f7-a70413edcb39"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "50e8b96b-0948-4bad-82f0-6066de25d8a0"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "a277abea-91bb-4e5d-92ab-82890c30adf2"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "9b995ec7-2503-4b33-8fea-c38ccd06f6fb"
                },
                {
                    "type": "Ext.toolbar.TextItem",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null,
                        "itemId": "txtNivel",
                        "text": null
                    },
                    "designerId": "43651d6b-92f5-4056-af13-e019f22b0189"
                },
                {
                    "type": "Ext.toolbar.TextItem",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null,
                        "hidden": true,
                        "itemId": "txtie",
                        "text": null
                    },
                    "designerId": "bb9e716f-a164-45aa-8e72-6eaebab84612"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "d54819a4-4149-4054-94ac-a24447f7147f"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "e077461d-2517-4507-aeff-8a7525f46505"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "daf2db39-7e16-4e69-99d0-59af3c4fa14f"
                },
                {
                    "type": "Ext.form.field.ComboBox",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null,
                        "autoRender": false,
                        "id": "id_meses",
                        "margin": "0 0 0 15",
                        "width": 152,
                        "fieldLabel": "Mes",
                        "labelAlign": "right",
                        "labelWidth": 40,
                        "name": "id_meses",
                        "value": [
                            "new Date().getMonth() + 1 "
                        ],
                        "enableKeyEvents": true,
                        "selectOnFocus": true,
                        "editable": false,
                        "displayField": "nombre_meses",
                        "store": "meses",
                        "typeAhead": true,
                        "valueField": "id_meses"
                    },
                    "designerId": "6b8bcbac-719f-4669-8e68-a200ee79c789",
                    "cn": [
                        {
                            "type": "basiceventbinding",
                            "reference": {
                                "name": "listeners",
                                "type": "array"
                            },
                            "codeClass": null,
                            "userConfig": {
                                "fn": "onMesesAfterRender",
                                "implHandler": [
                                    "var v = new Date().getMonth() + 1; // 1..12\r",
                                    "var s = component.getStore();\r",
                                    "if (!s) return;\r",
                                    "// Si el store no está cargado, espera a que cargue\r",
                                    "if (s.isLoading()) {\r",
                                    "    s.on('load', function(){ component.setValue(v); }, { single:true });\r",
                                    "} else if (s.getCount() === 0 && s.load) {\r",
                                    "    s.load(function(){ component.setValue(v); });\r",
                                    "} else {\r",
                                    "    component.setValue(v);\r",
                                    "}\r",
                                    ""
                                ],
                                "name": "afterrender",
                                "scope": "me"
                            },
                            "designerId": "5429d681-17be-47ce-8d3b-24652c1a088a"
                        }
                    ]
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "2d42f206-c2ed-481c-afed-742fa2346f4a"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "1afedb20-9b11-42a7-b61c-0a1ba2bdd82a"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "2e4c324d-17c7-405c-b95b-15f4ea788396"
                },
                {
                    "type": "Ext.form.field.Number",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null,
                        "id": "anio",
                        "width": 107,
                        "fieldLabel": "Año",
                        "labelAlign": "right",
                        "labelWidth": 40,
                        "submitValue": false,
                        "value": [
                            "new Date().getFullYear()"
                        ],
                        "maxValue": 2030,
                        "minValue": 2025
                    },
                    "designerId": "83c62ba7-ffcf-458c-b2c9-dd0392b7a028"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "c1195c33-03b9-4965-a6b6-b8cbb4690b4c"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "26a57404-4af5-4709-8092-bfff835cd0d6"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "705385bc-ae11-4703-9bc1-f294b80403af"
                },
                {
                    "type": "Ext.form.field.ComboBox",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null,
                        "id": "idtipotrabajador2",
                        "itemId": "idtipotrabajador2",
                        "width": 193,
                        "fieldLabel": "Tip. Trab.",
                        "labelAlign": "right",
                        "labelWidth": 60,
                        "name": "idtipotrabajador",
                        "submitValue": false,
                        "value": [
                            "new Date().getFullYear()"
                        ],
                        "allowBlank": false,
                        "enableKeyEvents": true,
                        "selectOnFocus": true,
                        "editable": false,
                        "displayField": "nombretipotrabajador",
                        "forceSelection": true,
                        "store": "tipotrabajador",
                        "valueField": "idtipotrabajador"
                    },
                    "designerId": "ef9ee69c-070f-416f-8833-6e17042f2d27"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "a70ab2e2-e290-4e79-93c7-00d1fc03b3f3"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "079aa0d2-d492-4a4b-8593-6bed82c2d480"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "b8c0790b-7db6-440e-b319-3bc431fd444f"
                },
                {
                    "type": "Ext.button.Button",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null,
                        "icon": "img/demo16.png",
                        "text": "aceptar"
                    },
                    "designerId": "a1254362-f5c9-46b2-b0b4-0d31aac4fa84",
                    "cn": [
                        {
                            "type": "basicfunction",
                            "reference": {
                                "name": "items",
                                "type": "array"
                            },
                            "codeClass": null,
                            "userConfig": {
                                "fn": "handler",
                                "implHandler": [
                                    "var w     = Ext.ComponentQuery.query('asistencia')[0];\r",
                                    "var codie = '';\r",
                                    "var cmpIe = w.down('#txtie');\r",
                                    "if (cmpIe) {\r",
                                    "    var raw = cmpIe.text || (cmpIe.getEl() && cmpIe.getEl().dom && cmpIe.getEl().dom.textContent) || '';\r",
                                    "    codie = raw.replace(/^CODIE:\\s*/,'').trim();\r",
                                    "}\r",
                                    "var mes  = (Ext.getCmp('id_meses') && Ext.getCmp('id_meses').getValue()) || '';\r",
                                    "var anio = (Ext.getCmp('anio')      && Ext.getCmp('anio').getValue())      || '';\r",
                                    "var idtipotrabajador2 = (Ext.getCmp('idtipotrabajador2')      && Ext.getCmp('idtipotrabajador2').getValue())      || '';\r",
                                    "if (!mes || mes < 1 || mes > 12) {\r",
                                    "    Ext.Msg.alert('Validación', 'Seleccione un mes válido.');\r",
                                    "    return;\r",
                                    "}\r",
                                    "if (!anio || anio < 2020) {\r",
                                    "    Ext.Msg.alert('Validación', 'Ingrese un año válido.');\r",
                                    "    return;\r",
                                    "}\r",
                                    "if (!codie) {\r",
                                    "    Ext.Msg.alert('Validación', 'No se encontró el CODIE.');\r",
                                    "    return;\r",
                                    "}\r",
                                    "Ext.Ajax.request({\r",
                                    "    url: 'controladores/AsistenciaMensualDiaria.php',\r",
                                    "    method: 'POST',\r",
                                    "    params: { codie: codie, mes: mes, anio: anio, idtipotrabajador2: idtipotrabajador2 },\r",
                                    "    success: function(response) {\r",
                                    "        var json = Ext.decode(response.responseText);\r",
                                    "        if (json.success) {\r",
                                    "            var grid = Ext.getCmp('gridAsistencia');\r",
                                    "            var store = Ext.data.StoreManager.lookup('AsistenciaMensualStore');\r",
                                    "            grid.suspendLayouts();\r",
                                    "            // ==============================\r",
                                    "            // 1️⃣  Crear modelo dinámico\r",
                                    "            // ==============================\r",
                                    "            var nuevosCampos = [];\r",
                                    "            Ext.Array.each(json.columnas, function(col){\r",
                                    "                nuevosCampos.push(col.dataIndex);\r",
                                    "            });\r",
                                    "\r",
                                    "            var model = Ext.define('AsistenciaModelDinamico', {\r",
                                    "                extend: 'Ext.data.Model',\r",
                                    "                fields: nuevosCampos\r",
                                    "            });\r",
                                    "            store.model = model;\r",
                                    "\r",
                                    "            // ============================================\r",
                                    "            //  Añadir renderer + resaltar domingos\r",
                                    "            // ============================================\r",
                                    "            var mes = Ext.getCmp('id_meses').getValue();\r",
                                    "            var anio = Ext.getCmp('anio').getValue();\r",
                                    "            Ext.Array.each(json.columnas, function(col) {\r",
                                    "                if (/dia_/.test(col.dataIndex)) {\r",
                                    "                    // Hacer columna editable \r",
                                    "                    col.editor = {\r",
                                    "                        xtype: 'textfield',\r",
                                    "                        maxLength: 6,\r",
                                    "                        validateOnChange: true,\r",
                                    "                        maskRe: /[0-9AIJLPTHY]/i, // solo teclas permitidas\r",
                                    "                    }\r",
                                    "                    col.renderer = function(value) {\r",
                                    "                        var color;\r",
                                    "                        switch (value) {\r",
                                    "                            case 'A': color = '#2ecc71'; break; // verde dia laborado\r",
                                    "                            case 'I': color = '#e74c3c'; break; // rojo Inasstencia Injustificada\r",
                                    "                            case 'J': color = '#e74c3c'; break; // rojo Inasstencia Justificada Lic, perm, vaca,onom\r",
                                    "                            case 'L': color = '#e74c3c'; break; // rojo Licencia sin goce de Remuneraciones\r",
                                    "                            case 'P': color = '#e74c3c'; break; // rojo Permiso sin goce de remuneraciones\r",
                                    "                            case 'T': color = '#f1c40f'; break; // amarillo Tardanza\r",
                                    "                            case 'H': color = '#e74c3c'; break; // rojo Tardanza\r",
                                    "                            default : color = '#ecf0f1'; break; // gris claro\r",
                                    "                        }\r",
                                    "                        return '<div style=\"text-align:center;background-color:' + color +\r",
                                    "                        ';color:#000;padding:3px;border-radius:3px;\">' +\r",
                                    "                        (value || '') + '</div>';\r",
                                    "                    };\r",
                                    "                }\r",
                                    "            });\r",
                                    "\r",
                                    "\r",
                                    "            // ==============================\r",
                                    "            // 3️⃣  Reconfigurar grid\r",
                                    "            // ==============================\r",
                                    "            grid.reconfigure(store, json.columnas);\r",
                                    "\r",
                                    "            // ==============================\r",
                                    "            // 4️⃣  Cargar datos\r",
                                    "            // ==============================\r",
                                    "            store.loadData(json.data, false);\r",
                                    "\r",
                                    "            grid.getView().refresh(true);\r",
                                    "            grid.resumeLayouts(true);\r",
                                    "            grid.updateLayout();\r",
                                    "        } else {\r",
                                    "            Ext.Msg.alert('Error', 'No se pudo cargar la asistencia.');\r",
                                    "        }\r",
                                    "    },\r",
                                    "    failure: function() {\r",
                                    "        Ext.Msg.alert('Error', 'Error de conexión con el servidor.');\r",
                                    "    }\r",
                                    "});\r",
                                    ""
                                ]
                            },
                            "designerId": "cfc03d5f-4827-42aa-bbcb-96b992365056"
                        }
                    ]
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "f7b5ce7f-bd93-4951-9add-9b1fece85022"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "c27f4174-8857-43dd-84ef-e59e0de1b046"
                },
                {
                    "type": "Ext.toolbar.Separator",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "e3083b2b-fc4d-446e-9dbb-8bdc33ca7417"
                },
                {
                    "type": "Ext.toolbar.Fill",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null
                    },
                    "designerId": "826d03e0-89ef-45f4-85b5-cbe72a6c05d1"
                },
                {
                    "type": "Ext.toolbar.TextItem",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null,
                        "itemId": "infoIe",
                        "style": [
                            "{\r",
                            "       'font-weight': 'bold',     // Negrita\r",
                            "        'color': '#0044cc',        // Azul\r",
                            "        'font-size': '13px',       // Tamaño de letra\r",
                            "        'margin-left': '5px'       // Separación del label\r",
                            "    }"
                        ],
                        "text": ""
                    },
                    "designerId": "7b5ee9d6-9d4d-40f1-acd9-544201a893a4"
                },
                {
                    "type": "Ext.button.Button",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null,
                        "icon": "img/exit.png",
                        "text": "Salir"
                    },
                    "designerId": "fb39b9b0-1832-4efb-a75a-188ce50a652d",
                    "cn": [
                        {
                            "type": "basicfunction",
                            "reference": {
                                "name": "items",
                                "type": "array"
                            },
                            "codeClass": null,
                            "userConfig": {
                                "fn": "handler",
                                "designer|params": [
                                    "button"
                                ],
                                "implHandler": [
                                    "var win    = button.up('window');\r",
                                    "win.close();\r",
                                    ""
                                ]
                            },
                            "designerId": "e57cd0f5-97e0-4197-b9c4-1bce1c49367a"
                        }
                    ]
                },
                {
                    "type": "Ext.form.field.Hidden",
                    "reference": {
                        "name": "items",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "layout|flex": null,
                        "itemId": "hidCodie",
                        "fieldLabel": null,
                        "name": "codie"
                    },
                    "designerId": "87bdba2c-3318-4582-949f-4c5107ab8cb9"
                }
            ]
        },
        {
            "type": "basiceventbinding",
            "reference": {
                "name": "listeners",
                "type": "array"
            },
            "codeClass": null,
            "userConfig": {
                "fn": "onGridAsistenciaCellClick",
                "implHandler": [
                    "var w     = Ext.ComponentQuery.query('asistencia')[0];\r",
                    "var codie = '';\r",
                    "var cmpIe = w.down('#txtie');\r",
                    "if (cmpIe) {\r",
                    "    var raw = cmpIe.text || (cmpIe.getEl() && cmpIe.getEl().dom && cmpIe.getEl().dom.textContent) || '';\r",
                    "    codie = raw.replace(/^CODIE:\\s*/,'').trim();\r",
                    "}\r",
                    "var grid    = tableview.up('gridpanel');\r",
                    "var columns = tableview.getGridColumns ? tableview.getGridColumns() : grid.columns;\r",
                    "var column  = columns[cellIndex];\r",
                    "if (!column) {\r",
                    "    return;\r",
                    "}\r",
                    "var dataIndex = column.dataIndex || '';\r",
                    "// ===============================\r",
                    "// 📝 OBSERVACIONES\r",
                    "// ===============================\r",
                    "if (dataIndex === 'observaciones') {\r",
                    "\r",
                    "    // Doble clic → editar\r",
                    "    if (window.gridAsistenciaClickTimer) {\r",
                    "        clearTimeout(window.gridAsistenciaClickTimer);\r",
                    "        window.gridAsistenciaClickTimer = null;\r",
                    "\r",
                    "        // Abrir editor manualmente\r",
                    "        grid.editingPlugin.startEdit(record, column);\r",
                    "        return;\r",
                    "    }\r",
                    "\r",
                    "    // Clic simple → no hace nada\r",
                    "    window.gridAsistenciaClickTimer = Ext.defer(function () {\r",
                    "        window.gridAsistenciaClickTimer = null;\r",
                    "    }, 250);\r",
                    "\r",
                    "    return;\r",
                    "}\r",
                    "\r",
                    "// Solo actuamos en columnas de día (dia_1, dia_2, ...)\r",
                    "if (dataIndex.indexOf('dia_') !== 0) {\r",
                    "    return;\r",
                    "}\r",
                    "\r",
                    "// ──────────────────────────────\r",
                    "// Detectar doble clic\r",
                    "// ──────────────────────────────\r",
                    "if (window.gridAsistenciaClickTimer) {\r",
                    "    // Segundo clic dentro del intervalo → doble clic\r",
                    "    clearTimeout(window.gridAsistenciaClickTimer);\r",
                    "    window.gridAsistenciaClickTimer = null;\r",
                    "    // NO hacemos nada aquí: dejamos que el plugin CellEditing abra el editor\r",
                    "    return;\r",
                    "}\r",
                    "\r",
                    "// Primer clic: esperamos un poco por si viene el segundo\r",
                    "var dia   = dataIndex.split('_')[1];\r",
                    "var mes   = Ext.getCmp('id_meses').getValue();\r",
                    "var anio  = Ext.getCmp('anio').getValue();\r",
                    "var fecha = Ext.String.format('{0}-{1}-{2}',\r",
                    "    anio,\r",
                    "    Ext.String.leftPad(mes, 2, '0'),\r",
                    "    Ext.String.leftPad(dia, 2, '0')\r",
                    "    );\r",
                    "\r",
                    "var usuarioCodigo = record.get('indiv_dni'); // o el campo que corresponda\r",
                    "var institucion   = codie; // tu CODIE\r",
                    "\r",
                    "window.gridAsistenciaClickTimer = Ext.defer(function () {\r",
                    "    // Si llegamos aquí es porque NO hubo doble clic\r",
                    "    window.gridAsistenciaClickTimer = null;\r",
                    "\r",
                    "    // ──────────────────────────────\r",
                    "    // Aquí tu AJAX para mostrar horas\r",
                    "    // ──────────────────────────────\r",
                    "    Ext.Ajax.request({\r",
                    "        url   : 'controladores/HorasDias.php',\r",
                    "        method: 'POST',\r",
                    "        params: {\r",
                    "            usuario_codigo: usuarioCodigo,\r",
                    "            institucion   : institucion,\r",
                    "            fecha         : fecha\r",
                    "        },\r",
                    "        success: function (response) {\r",
                    "            var raw = Ext.String.trim(response.responseText || '');\r",
                    "            if (!raw) {\r",
                    "                Ext.Msg.alert('Horas', 'Sin respuesta del servidor.');\r",
                    "                return;\r",
                    "            }\r",
                    "\r",
                    "            var result;\r",
                    "            try {\r",
                    "                result = Ext.decode(raw);\r",
                    "            } catch (ex) {\r",
                    "                Ext.Msg.alert('Horas', 'Respuesta inválida del servidor.');\r",
                    "                return;\r",
                    "            }\r",
                    "\r",
                    "            if (!result.success) {\r",
                    "                Ext.Msg.alert('Horas', result.error || 'No se pudieron obtener las horas.');\r",
                    "                return;\r",
                    "            }\r",
                    "\r",
                    "            if (!result.horas || !result.horas.length) {\r",
                    "                Ext.Msg.alert('Horas', 'No hay marcados para ' + fecha);\r",
                    "                return;\r",
                    "            }\r",
                    "\r",
                    "            Ext.Msg.alert('Horas del ' + fecha, result.horas.join('<br/>'));\r",
                    "        },\r",
                    "        failure: function () {\r",
                    "            Ext.Msg.alert('Error', 'Error en la comunicación con el servidor.');\r",
                    "        }\r",
                    "    });\r",
                    "\r",
                    "}, 250); // 250 ms para distinguir clic simple de doble clic\r",
                    "\r",
                    ""
                ],
                "name": "cellclick",
                "scope": "me"
            },
            "designerId": "d93efafe-ce00-4187-977d-f1383f59a2d3"
        },
        {
            "type": "Ext.grid.plugin.CellEditing",
            "reference": {
                "name": "plugins",
                "type": "array"
            },
            "codeClass": "Ext.grid.plugin.CellEditing",
            "designerId": "d7a4a753-0a8f-4f01-a88f-6d411b173d9c",
            "cn": [
                {
                    "type": "basiceventbinding",
                    "reference": {
                        "name": "listeners",
                        "type": "array"
                    },
                    "codeClass": null,
                    "userConfig": {
                        "fn": "onCellEditingEdit",
                        "implHandler": [
                            "var w     = Ext.ComponentQuery.query('asistencia')[0];\r",
                            "var codie = '';\r",
                            "var cmpIe = w.down('#txtie');\r",
                            "\r",
                            "if (cmpIe) {\r",
                            "    var raw = cmpIe.text || (cmpIe.getEl() && cmpIe.getEl().dom && cmpIe.getEl().dom.textContent) || '';\r",
                            "    codie = raw.replace(/^CODIE:\\s*/,'').trim();\r",
                            "}\r",
                            "\r",
                            "var idVinculo = e.record.get('id_vinculo');\r",
                            "var mes  = Ext.getCmp('id_meses').getValue();\r",
                            "var anio = Ext.getCmp('anio').getValue();\r",
                            "\r",
                            "/* =========================================================\r",
                            "CASO 1: SE EDITA ASISTENCIA (dia_1, dia_2, ...)\r",
                            "========================================================= */\r",
                            "if (e.field.indexOf('dia_') === 0) {\r",
                            "\r",
                            "    var dia        = e.field.split('_')[1];\r",
                            "    //var nuevoValor = e.value; // A, I, J, etc.\r",
                            "    var nuevoValor = (e.value || '').toString().toUpperCase();\r",
                            "    // actualizar visualmente el grid\r",
                            "    e.record.set(e.field, nuevoValor);\r",
                            "    \r",
                            "    Ext.Ajax.request({\r",
                            "        url    : 'controladores/GuardarAsistenciaDia.php',\r",
                            "        method : 'POST',\r",
                            "        params : {\r",
                            "            id_vinculo     : idVinculo,\r",
                            "            id_institucion : codie,\r",
                            "            anio           : anio,\r",
                            "            mes            : mes,\r",
                            "            dia            : dia,\r",
                            "            valor          : nuevoValor   // SOLO asistencia\r",
                            "        },\r",
                            "        success: function(resp) {\r",
                            "            var r = Ext.decode(resp.responseText);\r",
                            "            if (!r.success) {\r",
                            "                Ext.Msg.alert('Error', r.error || 'No se pudo guardar.');\r",
                            "                e.record.set(e.field, e.originalValue);\r",
                            "            }\r",
                            "        },\r",
                            "        failure: function() {\r",
                            "            Ext.Msg.alert('Error', 'Error al guardar asistencia.');\r",
                            "            e.record.set(e.field, e.originalValue);\r",
                            "        }\r",
                            "    });\r",
                            "\r",
                            "    return;\r",
                            "}\r",
                            "\r",
                            "/* =========================================================\r",
                            "CASO 2: SE EDITA OBSERVACIÓN\r",
                            "========================================================= */\r",
                            "if (e.field === 'observacion') {\r",
                            "\r",
                            "    Ext.Ajax.request({\r",
                            "        url    : 'controladores/GuardarObservacion.php',\r",
                            "        method : 'POST',\r",
                            "        params : {\r",
                            "            id_vinculo  : e.record.get('id_vinculo'),\r",
                            "            anio        : Ext.getCmp('anio').getValue(),\r",
                            "            mes         : Ext.getCmp('id_meses').getValue(),\r",
                            "            observacion : e.value\r",
                            "        },\r",
                            "        success: function(resp){\r",
                            "            var r = Ext.decode(resp.responseText);\r",
                            "            if (!r.success){\r",
                            "                Ext.Msg.alert('Error', r.error);\r",
                            "                e.record.set('observacion', e.originalValue);\r",
                            "            }\r",
                            "        }\r",
                            "    });\r",
                            "}\r",
                            ""
                        ],
                        "name": "edit",
                        "scope": "me"
                    },
                    "designerId": "acb573b6-6653-434b-99d1-36517606932e"
                }
            ]
        }
    ]
}