The Framework Code

twigs/framework/admin/forms.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 %}

{% set methods = ['PARTIAL', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'] %}

{% block setup %}
    var clicks = [
        ['delb', framework.dodelbean, ''],
        ['editb', framework.goedit],
        ['viewb', framework.goview],
    ]
    var mname = ['PARTIAL', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
{% endblock setup %}

{% block onload %}
    $('#addfform').on('submit', false).parsley()
    $('#addb').on('click', function(e){
        e.preventDefault();
        $(this).attr('disabled', true); // disable submit button
        let data = {}
        const frm = $('#addfform')
        $('input:checked', frm).each(function(index, element){
             data[$(this).attr('name')] = $(this).val();
        })
        $('input:text', frm).each(function(index, element){
             data[$(this).attr('name')] = $(this).val()
        })
        framework.beanCreate('{{constant('Config\\Framework::FORM')}}', data, function(ret){
            $('#addf').modal('hide')
            $('#utab tbody').append('<tr data-id="'+ret+'"><td>' + data.name + '</td>'+
                '<td>' + data.action + '</td>' +
                '<td>' + data.idval + '</td>' +
                '<td>' + mname[data.method] + '</td>' +
                '<td>' + (data.multipart != undefined ? '{{i.check()}}' : '') + '</td>' +
                '<td title="View">{{i.view('viewb')}}</td>' +
                '<td title="Edit">{{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: '{{constant('Config\\FRAMEWORK::FORM')}}', clicks: clicks}, framework.tableClick);
{% endblock onload %}

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

{% block main %}
    <section class="row">
        <article class="ml-auto col-md-10 mr-auto">
            <table class="table table-striped table-hover" id="utab">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Action</th>
                        <th>ID</th>
                        <th>Class</th>
                        <th>Method</th>
                        <th>Multipart</th>
            		<th colspan="3">&nbsp;</th>
                    </tr>
                </thead>
                <tbody>
                    {% for u in siteinfo.forms %}
                    <tr data-id="{{u.id}}">
                        <td>{{u.name}}</td>
                        <td>{{u.action}}</td>
                        <td>{{u.idval}}</td>
                        <td>{{u.class}}</td>
                        <td>{{methods[u.method]}}</td>
                        <td>{{f.tick(u.multipart)}}</td>
                        <td title="View">{{i.view('viewb')}}</td>
                        <td title="Edit">{{i.edit('editb')}}</td>
                        <td title="Delete">{{i.delete('delb')}}</td>
                    </tr>
                    {% else %}
                        <tr><td colspan="4">No forms defined</td></tr>
                    {% endfor %}
                </tbody>
            </table>
            <p><button class="btn btn-primary" data-toggle="modal" data-target="#addf" type="button">Add a Form</button></p>
        </article>
    </section>
    {{m.open({id: 'addf', title: 'Add a Form'})}}
    <div class="modal-body">
        <form id="addfform" action="#" method="post">
            {{f.text({label: 'Form Name', ph: 'Form Name - alphanumeric characters only', name: 'name', required: 1, parsley: {trigger: 'change', type: 'alphanum'} })}}
            {{f.text({label: 'Form Action', ph: 'Form Action URL', name: 'action', parsley: {trigger: 'change', type: 'url'} })}}
            {{f.text({label: 'Form ID', ph: 'Form ID', name: 'idval', parsley: {trigger: 'change', type: 'alphanum'} })}}
            {{f.text({label: 'Form Class', ph: 'Form Class', name: 'class' })}}
            {{f.radio({name: 'method', values:[1, 2, 0], labels: ['GET', 'POST', 'PARTIAL'], check: [TRUE, FALSE, FALSE]})}}
            <br/>
            {{f.checkbox({names: ['multipart'], values:[1], labels: ['Multipart Encoded']})}}
        </form>
    </div>
    {{m.close({action: 'Add', id: 'addb'})}}
{% endblock main %}

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