postCreate not working

postCreate not working

daniloragodanilorago Posts: 20Questions: 5Answers: 0

Dear all,

I really dont know what I'm doing of wrong, but the postCreate isn't working, somebody have a tip for me?
It's not creating, even calling the function.

PHP

<?php
// >>> SESSION (PROJECT ID)
session_start();
$Int__ID__Project = $_SESSION["ID__Project"];
// <<< SESSION (PROJECT ID)

include("DataTables/php/lib/DataTables.php");
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate,
    DataTables\Editor\ValidateOptions;

function Fc__Notification($db, $action, $id, &$values){
    $db->insert('Notification', array(
        'ID__Login'                 => $_SESSION["ID__Login"],
        'Notification__ID'          => $id,
        'Notification__Table'       => 'ERP',
        'Notification__Action'      => '4',
        'Notification__Date'        => date("Y-m-d"),
        'Notification__Title'       => 'New ERP',
        'Notification__Description' => $values['ERP']['ERP__Name'],
        'Notification__Status'      => '1'
    ));
}

Editor::inst($db, 'ERP', 'ID__ERP')
    ->fields(
        Field::inst('ERP.ID__ERP'),
        Field::inst('ERP.ERP__Name')
            ->validator(Validate::notEmpty(ValidateOptions::inst()
                ->message('Error: Fill the Name field!')
            ))
            ->validator(Validate::minLen(3,ValidateOptions::inst()
                ->message('Error: Name must have more than 3 characters!')
            ))
            ->validator(Validate::maxLen(100,ValidateOptions::inst()
                ->message('Error: Name must have less than 100 characters!')
            ))
        ,
        Field::inst('ERP.ERP__Description')
            ->validator(Validate::maxLen(1000,ValidateOptions::inst()
                ->message('Error: Description must have less than 1000 characters!')
            ))
        ,
        Field::inst('ERP.ERP__Date')->setValue(date("Y-m-d")),
        Field::inst('ERP.ID__Login')->setValue($_SESSION['ID__Login'])
            ->options(
                Options::inst()
                    ->table('Login')
                    ->value('ID__Login')
                    ->label('Login__Name')
            )
            ->validator(Validate::notEmpty(ValidateOptions::inst()
                ->message('Error: Fill the Login field!')
            ))
        ,
        Field::inst('Login.Login__Name')
    )
    ->leftJoin('Login', 'Login.ID__Login', '=', 'ERP.ID__Login')
    ->on('postCreate', function($editor, $id, &$values, &$row){
        Fc__Notification($editor->db(), 'create', $id, $values);
    })
    ->process($_POST)
    ->json();

<?php
>
?>


------------------------------------------------------------------------------------------
HTML

<script>
        addEventListener("DOMContentLoaded", function () {
            var editor = new DataTable.Editor( {
                ajax: 'datatables--erp.php',
                table: '#DT__List',
                formOptions: {
                    main: {
                        focus: null,
                        submit: 'changed'
                    }
                },
                fields: [
                    {
                        "label": "ID__ERP:",
                        "name": "ERP.ID__ERP",
                        "type": "readonly",
                        "attr": {
                            "disabled": true
                        }
                    },
                    {
                        "label": "ERP__Name:",
                        "name": "ERP.ERP__Name",
                        "type": "text",
                        "attr": {
                            "maxLength": 100
                        }
                    },
                    {
                        "label": "ERP__Description:",
                        "name": "ERP.ERP__Description",
                        "type": "textarea",
                        "attr": {
                            "maxLength": 1000
                        }
                    },
                    {
                        "label": "ERP__Date:",
                        "name": "ERP.ERP__Date",
                        "type": "readonly",
                        "attr": {
                            "disabled": true
                        }
                    },
                    {
                        "label": "ID__Login:",
                        "name": "ERP.ID__Login",
                        "type": "readonly",
                        "attr": {
                            "disabled": true
                        }
                    }
                ]
            } );

            var table = new DataTable('#DT__List', {
                ajax: 'datatables--erp.php',
                columns: [
                    {
                        "data": "ERP.ID__ERP"
                    },
                    {
                        "data": "ERP.ERP__Name"
                    },
                    {
                        "data": "ERP.ERP__Description"
                    },
                    {
                        "data": "ERP.ERP__Date"
                    },
                    {
                        "data": "Login.Login__Name",
                        "editField": "ERP.ID__Login"
                    }
                ],
                colReorder: true,
                fixedColumns: {
                    start: 1
                },
                fixedHeader: true,
                layout: {
                    topStart: {
                        buttons: [
                            {
                                extend: 'create',
                                text: '<i class="fa fa-plus"></i> Add',
                                className: 'btn btn-outline-primary btn-wave',
                                editor: editor
                            }, {
                                extend: 'edit',
                                text: '<i class="fa fa-edit"></i> Edit',
                                className: 'btn btn-outline-primary btn-wave',
                                editor: editor
                            }, {
                                extend: 'remove',
                                text: '<i class="fa fa-trash"></i> Delete',
                                className: 'btn btn-outline-primary btn-wave',
                                editor: editor
                            }, {
                                extend: 'colvis',
                                text: '<i class="fa fa-search"></i> Columns',
                                className: 'btn btn-outline-primary btn-wave',
                                dropIcon: false,
                                editor: editor
                            }, {
                                extend: 'collection',
                                text: '<i class="fa fa-file-export"></i> Export',
                                className: 'btn btn-outline-primary btn-wave',
                                buttons: ['copy', 'excel', 'csv', 'pdf', 'print'],
                                dropIcon: false
                            }
                        ]
                    }
                },
                order: [[0, 'desc']],
                pageLength: 20,
                paging: true,
                scrollX: true,
                scrollY: 550,
                select: {
                    attr: {
                        className: 'selected-row'
                    },
                    selector: 'td:first-child'
                }
            });
            // >>> ID
            editor.on('open', function(e, mode, action){
                if((action === 'create')||(action === 'edit')){
                    this.hide(['ERP.ID__ERP']);
                    this.hide(['ERP.ERP__Date']);
                    this.hide(['ERP.ID__Login']);
                } else {
                    this.show(['ERP.ID__ERP']);
                    this.show(['ERP.ERP__Date']);
                    this.show(['ERP.ID__Login']);
                }
            })
            editor.on('preOpen', function(e, mode, action) {
                var Str__Field_Name = e.currentTarget.s.includeFields[0];
                if (Str__Field_Name === 'ERP.ERP__Date') {
                    return false;
                }
                if (Str__Field_Name === 'ERP.ID__Login') {
                    return false;
                }
            })
            // >>> LOAD
            editor.on('submitSuccess', () => {
                $('#DT__List').DataTable().ajax.reload();
            });
            // >>> UPDATE
            table.on('click', 'tbody td:not(:first-child)', function (e) {
                editor.inline(this, {
                    onBlur: 'submit'
                });
            });
            // >>> NOTIFICATION
            $('#DT__List').on('click', 'tbody td', function () {
                editor.inline(this, {
                    submit: 'allIfChanged'
                });
            });
        });
        DataTable.Buttons.defaults.dom.button.className = 'btn-group';
        DataTable.ext.buttons.collection.className = 'dropdown-toggle';
        DataTable.ext.buttons.collection.rightAlignClassName = 'dropdown-menu-right';
</script>
Sign In or Register to comment.