<template>

    <index-page 
        :app="app"
        :controller="controller"
    >
        <template #append-breadcrumbs>
        </template>

        <template #prepend>
            <user-form-menu 
                :app="app"
                :form="controller.form"
            />

            <users-filter-menu 
                :app="app"
                :filterform="controller.filterform"
            />
			
        </template>
    </index-page>
    
</template>

<script>


    export default {
        props: {
            app: {require: true},
        },

        computed: {
            controller() {
                return this.app.classes.Users;
            }
        },

        methods: {

            LoadResources() {
                this.app.AddClassesByContext(require.context('./../../Classes', true, /\.class.js$/i));
                this.app.AddDataProvidersByContext(require.context('./../../DataSessions', true, /\.dataprovider.js$/i));
                this.app.AddDatatablesByContext(require.context('./../../Datatables', true, /\.datatable.js$/i));
                this.app.AddFormProvidersByContext(require.context('./../../FormProviders', true, /\.formprovider.js$/i));                
                this.app.AddFormsByContext(require.context('./../../Forms', true, /\.form.js$/i));
                this.app.AddFilterFormsByContext(require.context('./../../Filterforms', true, /\.filterform.js$/i));
                this.app.AddMenusByContext(require.context('./../../Toolbars', true, /\.toolbar.js$/i));
                this.app.AddMenusByContext(require.context('./../../Menus', true, /\.menu.js$/i));
                this.app.AddMenusByContext(require.context('./../../Breadcrumbs', true, /\.breadcrumbs.js$/i));
                this.app.AddRequestsByContext(require.context('./../../Requests', true, /\.request.js$/i));
            },

            InitDatatable() {
                this.controller.DatatableRegisterDataProvider(this.controller.model);
            },

            InitForms() {
                this.controller.FormRegisterFormProvider(this.controller.model);

                this.controller.MakeEditableColumn(this.controller.model, 'last_name-column');

                this.app.forms.Usersstatus.SetFormProvider(this.app.formproviders.Usersstatus);

                let columns = this.app.datatables.Users._columns;
                columns['active-column'].editable.AttachForm(this.app.forms.Usersstatus);
                columns['email-column'].editable.AttachForm(this.app.forms.Users);
                columns['phone-column'].editable.AttachForm(this.app.forms.Users);
                columns['avatar-column'].editable.AttachForm(this.app.forms.Users);
            },

            InitFiltering() {
                /**
                 * formularul de filtrare își inregistreaza dataprovider-ul
                 */
                this.controller.FilterformRegisterDataProvider(this.controller.model);

                let columns = this.app.datatables.Users._columns;
                let controls = this.app.filterForms.Users.controls;

                columns['last_name-column']._header.filterable.AttachFilterControl(controls['last_name']);
                columns['first_name-column']._header.filterable.AttachFilterControl(controls['first_name']);
                columns['email-column']._header.filterable.AttachFilterControl(controls['email']);
                columns['phone-column']._header.filterable.AttachFilterControl(controls['phone']);
                columns['active-column']._header.filterable.AttachFilterControl(controls['status']);
            },

            LoadData() {
                this.app.dataSession.Users.Refresh();
            }
        },

        
        mixins: [
            require('VUEMIX/Index/IndexPage'),
        ],

        name: 'Index',
    }
</script>