The Framework Code

twigs/framework/admin/users.twig

File List

{% set ajax = TRUE %}
{% set fwutils = TRUE %}
{% set parsley = TRUE %}

{% extends '@content/page.twig' %}

{% import '@content/iconmacro.twig' as i %}
{% import '@util/formmacro.twig' as f %}
{% import '@util/modalmacro.twig' as m %}

{% block setup %}
    const clicks = [
        ['delb', framework.dodelbean, ''],
        ['admb', framework.dotoggle, '{{constant('\\Config\\Framework::ADMINROLE')}}'],
        ['confirm', framework.dotoggle, 'confirm'],
        ['active', framework.dotoggle, 'active'],
        ['devb', framework.dotoggle, '{{constant('\\Config\\Framework::DEVELROLE')}}'],
        ['editb', framework.goedit]
    ];
{% endblock setup %}

{% block onload %}
    $('#adduform').on('submit', false).parsley();
    $('#addb').on('click', function(e){
        e.preventDefault();
        $(this).attr('disabled', true);
        let data = {admin : 0, devel : 0};
        const frm = $('#adduform');
        $('input:checked', frm).each(function(index, element){
             data[$(this).attr('name')] = 1;
        });
        $('input:text,input:password,input[type="email"]', frm).each(function(index, element){
             data[$(this).attr('name')] = $(this).val();
        });
        framework.beanCreate('user', data, function(ret){
            $('#addu').modal('hide');
            $('#utab tbody').append('<tr data-id="'+ret+'"><td>'+data.login+'</td>'+
                '<td><a href="mailto:'+data.email+'">'+data.email+'</a></td>'+
                '<td>'+framework.mktoggle('confirm', data.confirm)+'</td>'+
                '<td>'+framework.mktoggle('active', data.active)+'</td>'+
                '<td>'+framework.mktoggle('admb', data.admin)+'</td>'+
                '<td>'+framework.mktoggle('devb', data.devel)+'</td>'+
                '<td>{{i.edit('editb')}}</td>' +
                '<td>{{i.delete('delb')}}</td></tr>'
            );
            framework.doBGFade('#utab tbody:last-child', [245,255,159], [255,255,255], 'transparent', 75, 20, 4);
        }, '#addb');
    });
    $('#utab').on('click', {bean: 'user', clicks: clicks}, framework.tableClick);
{% endblock onload %}

{% if not page is defined %}
    {% set page = 1 %}
    {% set pagesize = 10 %}
{% endif %}

{% set pages = siteinfo.pagecount('user', pagesize) %}

{% block header %}
    <section class="col-md-12 mt-5">
	<h1>Users</h1>
    </section>
{% endblock header %}

{% block main %}
    <section class="row">
        <article class="ml-auto col-md-10 mr-auto">
            {% include '@util/paginate.twig' with { page : page, pagesize: pagesize, pages: pages} %}
            <table class="table table-striped table-hover" id="utab">
                <thead>
                    <tr>
                        <th>Login</th>
                        <th>Email</th>
                        <th>Confirmed</th>
                        <th>Active</th>
                        <th>Admin</th>
                        <th>Developer</th>
                        <th colspan="2">&nbsp;</th>
                    </tr>
                </thead>
                <tbody>
                    {% for u in siteinfo.users(page, pagesize) %}
                        <tr data-id="{{u.id}}">
                            <td>{{u.login}}</td>
                            <td><a href="mailto:{{u.email}}">{{u.email}}</a></td>
                            <td>{{f.tick(u.isconfirmed, 'confirm')}}</td>
                            <td>{{f.tick(u.isactive, 'active')}}</td>
                            <td>{{f.tick(u.isadmin, 'admb')}}</td>
                            <td>{{f.tick(u.isdeveloper, 'devb')}}</td>
                            <td>{{i.edit('editb')}}</td>
                            <td>{{i.delete('delb')}}</td>
                        </tr>
                    {% else %}
                        <tr><td colspan="8">No users defined</td></tr>
                    {% endfor %}
                </tbody>
            </table>
            {% include '@util/paginate.twig' with { page : page, pagesize: pagesize, pages: pages} %}
            <p><button class="btn btn-primary" data-toggle="modal" data-target="#addu" type="button">Add User</button></p>
        </article>
    </section>
    {{m.open({id: 'addu', title: 'Add A New User'})}}
    <div class="modal-body">
        {{f.startform({id: 'adduform', method: 'post'})}}
            {{f.text({label: 'User Name', id: 'un', name: 'login', ph: 'username - alphanumeric characters only', required: TRUE, parsley: {
                trigger: 'change',
                'remote-reverse': 'false',
                remote: base~'/ajax/unique/'~constant('Config\\Framework::USER')~'/login/{value}',
                'remote-message': 'That user name is not available',
                type: 'alphanum'
            } })}}
            {{f.password({label: 'Password', id: 'pw', name: 'password', ph: '************', required: TRUE})}}
            {{f.password({label: 'Repeat Password', id: 'rpw', name: 'repeat', ph: '************', required: TRUE, parsley: {
                trigger: 'change',
                'equal-to': '#pw'
            } })}}
            {{f.email({label: 'Email Address', id: 'em', name: 'email', ph: 'pat@smith.com', parsley: {trigger: 'change'}, required: TRUE})}}
            {{f.checkbox({label: 'Roles', group: TRUE, labels: ['Admin', 'Developer'], values: [1, 1], names: ['admin', 'devel']})}}
        {{f.endform()}}
    </div>
    {{m.close({action: 'Add', id: 'addb'})}}
{% endblock main %}

{% block pagefooter %}
{% endblock pagefooter %}