{~
    if(!isset(@page.description))
        @page.description = 'Criar/Editar';

    if(!@breadcrumbs)
        if(isset(@form.table))
            @breadcrumbs = array(@form.table => @page.title, @page.description);
        else
            @breadcrumbs = array(@page.title);

    /*@meta.styles.local.codemirror    = 'codemirror.css';
    @meta.scripts.local.codemirror   = 'codemirror.js';
    @meta.scripts.local.codemirror_xml  = 'codemirror/mode/xml/xml.js';
    @meta.scripts.local.codemirror_css  = 'codemirror/mode/css/css.js';
    @meta.scripts.local.codemirror_js   = 'codemirror/mode/javascript/javascript.js';
    @meta.scripts.local.codemirror_html = 'codemirror/mode/htmlmixed/htmlmixed.js';
    @meta.styles.raw.codemirror      = '.CodeMirror {border: 1px solid #CCC;}';*/
    @meta.styles.local.trumbowyg     = 'trumbowyg.min.css';
    @meta.styles.raw.trumbowyg       = '.trumbowyg { margin: 0 !important; width: 100% !important; }';
    @meta.scripts.local.trumbowyg    = 'trumbowyg.min.js';
    @meta.scripts.local.trumbowyg_pt = 'trumbowyg-pt.min.js';
    @meta.scripts.raw.trumbowyg      = '$(".trumbowyg").trumbowyg({lang: "pt", autogrow: true});';
    @meta.scripts.local.moment       = 'moment.js';
    @meta.scripts.local.inputmask    = 'jquery.inputmask.bundle.min.js';
    @meta.scripts.local.inputmasknum   = 'inputmask/inputmask.numeric.extensions.min.js';
    @meta.scripts.local.inputmaskbind  = 'inputmask/inputmask.binding.js';
    @meta.scripts.local.datetimepicker = 'bootstrap-datetimepicker.min.js';
    @meta.styles.local.datetimepicker  = 'bootstrap-datetimepicker.min.css';
    array_unshift(@meta.scripts.raw, '$(".date").datetimepicker();');

    @meta.styles.local.fileinput     = 'fileinput.min.css';
    @meta.styles.raw.fileinput       = '.kv-fileinput-caption { margin-bottom: 2px !important; }';
    @meta.scripts.local.fileinput    = 'fileinput.min.js';

    @meta.styles.local.select2       = 'select2.min.css';
    @meta.styles.local.select2_bs    = 'select2-bootstrap.min.css';
    @meta.scripts.local.select2      = 'select2/select2.min.js';
    @meta.scripts.local.select2_i18n = 'select2/i18n/pt-BR.js';

    @meta.scripts.raw.form_table     = 'window._appendrow = function(group) {
                                            var $table = $("#table_" + group + " tbody");
                                            var row_count = $table.data("row-count") + 1;
                                            var $row   = $("#row_" + group).clone().removeAttr("id").removeAttr("style").removeClass("dont_post").removeClass("dont-print");
                                            $table.data("row-count", row_count);

                                            $row.find(".order").val(row_count);

                                            $row.find("[name]").each(function(e) {
                                                var $e = $(this);
                                                var name = $e.attr("name").replace(group + "[0]", group + "[" + row_count + "]");

                                                $e.attr("name", name);
                                            });
                                            $row.find(".inputmask, [data-inputmask], [data-inputmask-mask], [data-inputmask-alias]").each(function (ndx, lmnt) {
                                                if (lmnt.inputmask === undefined) {
                                                    Inputmask().mask(lmnt);
                                                }
                                            });

                                            $row.find("select").addClass("select2").css("width", "100%").select2({theme: "bootstrap", minimumResultsForSearch: 5})

                                            $row.find(".date").datetimepicker();

                                            $table.append($row);
                                        }

                                        $("#main_form").submit(function() {
                                            $("input[type=submit]").prop("disabled", true);
                                            $(".dont_post").remove();
                                        }).find("select, input").trigger("change");

                                        $(".select2").css("width", "100%").select2({theme: "bootstrap", minimumResultsForSearch: 5});
                                        ';
    @meta.scripts.raw.sortable_table = 'jQuery(document).ready(function($) {
                                            function reorder($table) {
                                                var rows = $table.find("tr").get();

                                                rows.sort(function(a, b) { return $(a).find(".order").val() - $(b).find(".order").val(); });

                                                for (var i = 0; i < rows.length; i++)
                                                    rows[i].parentNode.appendChild(rows[i]);
                                            }

                                            $("table").on("click", ".order-prior", function(e) {
                                                e.preventDefault();

                                                var $this    = $(this);
                                                var $table   = $this.parents("tbody");
                                                var $current = $this.parents("tr").find(".order");
                                                var $previus = $this.parents("tr").prev("tr:not(.dont_post)").find(".order");

                                                if($previus.length) {
                                                    var old = $current.val();
                                                    $current.val($previus.val());
                                                    $previus.val(old);

                                                    reorder($table);
                                                }

                                                return false;
                                            });

                                            $("table").on("click", ".order-next", function(e) {
                                                e.preventDefault();

                                                var $this    = $(this);
                                                var $table   = $this.parents("tbody");
                                                var $current = $this.parents("tr").find(".order");
                                                var $next = $this.parents("tr").next("tr").find(".order");

                                                if($next.length) {
                                                    var old = $current.val();
                                                    $current.val($next.val());
                                                    $next.val(old);

                                                    reorder($table);
                                                }

                                                return false;
                                            });
                                        });
                                       ';

    @flash = flash('error');
    if(@flash && isset(@form.errors) && !empty(@form.errors))
        @flash = @flash.'<br> verifique os campos para mais detalhes.';
    flash('error', @flash);
~}
<include href="hwapx/admin/admin/header.html" />
<style>
.select2-container--bootstrap .select2-selection {
    border-radius: 0 !important;
}
.only-print {
    display: none;
}
.content {
    overflow: visible;
}
@media print {
    body * {
        visibility: hidden;
    }
    .print, .print * {
        visibility: visible;
    }
    .print {
        position: relative;
        left: 0;
        top: 0;
        right: 0;
        bottom: 0;
    }
    .dont-print, .content-header, .filter-row, .box-header, .box-footer {
        display: none;
    }
    .wrapper, .right-side {
        margin: 0 !important;
    }
    a:link:after, a:visited:after {
        content: "" !important;
    }
    .content, .box-body {
        margin: 0;
    }
    .tab-pane {
        display: block !important;
    }
    .only-print {
        display: block !important;
    }
}
</style>
<div class="row">
    {~
        if(!isset(@form.width))
            @form.width = 10;
    ~}
    <div class="col-lg-{{ @form.width }} col-lg-offset-{{ round((12 - @form.width) / 2) }} col-md-12 col-md-offset-0">
        <!-- Custom tabs (Charts with tabs)-->
        <div class="nav-tabs-custom">
            <!-- Tabs within a box -->
            <ul class="dont-print nav nav-tabs pull-right">
                <check if="{{ isset(@form.groups) }}">
                    {~ @_groups = array_reverse(@form.groups, true); ~}
                    <repeat group="{{ @_groups }}" key="{{ @groupname }}" value="{{ @group }}" counter="{{ @counter }}">
                        <li class="{{ @counter == count(@form.groups) ? 'active' : '' }}"><a href="#group_{{ @groupname }}" data-toggle="tab">{{ @group.legend }}</a></li>
                    </repeat>
                </check>
                <li class="pull-left header"><i class="glyphicon glyphicon-pencil"></i> {{ @form.title }}</li>
            </ul>
            <!-- form start -->
            <form id="main_form" role="form" method="post" action="{{ @URI }}" enctype="multipart/form-data" class="print">
                <div class="box" style="border:none">
                    <div class="box-body">
                        {~ if(!isset(@form.groups)) @form.groups.main = array('legend' => 'main', 'fields' => @form.fields); ~}
                        <div class="tab-content no-padding">
                            <repeat group="{{ @form.groups }}" key="{{ @groupname }}" value="{{ @group }}" counter="{{ @counter }}">
                                <check if="{{ @group.role | role }}">
                                    <div id="group_{{ @groupname }}" class="tab-pane{{ @counter == 1 ? ' active' : '' }}">
                                        <h2 class="only-print" style="margin-top: 0">{{ @group.legend !== 'main' ? @group.legend : @form.name }}</h2>
                                        <div class="row">
                                            <div class="col-lg-12">
                                                <div class="row">
                                                    <check if="{{ isset(@group.fields) }}">
                                                        <repeat group="{{ @group.fields }}" key="{{ @fieldname }}" value="{{ @field }}">
                                                            {~
                                                                @_value = isset(@form.values[@fieldname]) ? @form.values[@fieldname] : (isset(@field.default) ? @field.default : '');
                                                                if(!isset(@field.width))
                                                                    @field.width = in_array(@field.type, array('textarea', 'wysiwyg', 'separator')) ? '12' : '6';
                                                            ~}
                                                            <div class="col-lg-{{ @field.width }} col-md-{{ @field.width }} {{ @field.type == 'hidden' ? 'hidden' : ''}}">
                                                                <div class="form-group{{ isset(@form.errors[@fieldname]) ? ' has-error' : '' }}">
                                                                    <check if="{{ @field.label and @field.type != 'separator' }}">
                                                                        <label>{{ @field.label }}{{ (isset(@field.rules) and in_array('required', @field.rules)) ? ' <span class="text-danger">*</span>' : '' }}</label>
                                                                    </check>
                                                                    <check if="{{ isset(@field.button) }}">
                                                                        <div class="input-group">
                                                                    </check>
                                                                    <switch expr="{{ @field.type }}">
                                                                        <case value="separator">
                                                                            <check if="{{ @field.label }}">
                                                                                <true>
                                                                                    <div style="text-align: center; border-top: lightgray solid 1px; border-bottom: lightgray solid 1px;"><label>{{ @field.label }}</label></div>
                                                                                </true>
                                                                                <false>
                                                                                    <hr>
                                                                                </false>
                                                                            </check>
                                                                        </case>
                                                                        <case value="hidden">
                                                                            <input class="form-control" name="{{ @fieldname }}" type="hidden" value="{{ isset(@form.values[@fieldname]) ? @form.values[@fieldname] : (isset(@field.default) ? @field.default : '') }}" {{ isset(@field.attributes) ? packXMLAttributes(@field.attributes) : '' }} />
                                                                        </case>
                                                                        <case value="static">
                                                                            <input class="form-control" readonly value="{{ isset(@form.values[@fieldname]) ? (isset(@field.options[@form.values[@fieldname]]) ? @field.options[@form.values[@fieldname]] : @form.values[@fieldname]) : (isset(@field.default) ? @field.default : '') }}" {{ isset(@field.attributes) ? packXMLAttributes(@field.attributes) : '' }} />
                                                                        </case>
                                                                        <case value="staticarea">
                                                                            <textarea class="form-control" readonly style="height:200px">{{ isset(@form.values[@fieldname]) ? (isset(@field.options[@form.values[@fieldname]]) ? @field.options[@form.values[@fieldname]] : @form.values[@fieldname]) : (isset(@field.default) ? @field.default : '') }}"</textarea>
                                                                        </case>
                                                                        <case value="statichtml">
                                                                            <div style="height:200px;border: 1px solid #555; background-color: #eee; overflow: scroll;">{{ isset(@form.values[@fieldname]) ? (isset(@field.options[@form.values[@fieldname]]) ? @field.options[@form.values[@fieldname]] : @form.values[@fieldname]) : (isset(@field.default) ? @field.default : '') | raw }}"</div>
                                                                        </case>
                                                                        <case value="placeholder">
                                                                            <div style="height:60px"></div>
                                                                        </case>
                                                                        <case value="wysiwyg">
                                                                            <textarea class="form-control trumbowyg" name="{{ @fieldname }}" style="height:300px;margin: 0;width: 100%;">{{ isset(@form.values[@fieldname]) ? @form.values[@fieldname] : (isset(@field.default) ? @field.default : '') }}</textarea>
                                                                        </case>
                                                                        <case value="code">
                                                                            <textarea class="form-control" id="codemirror_{{ @fieldname }}" name="{{ @fieldname }}" style="height:300px;margin: 0;width: 100%;">{{ isset(@form.values[@fieldname]) ? @form.values[@fieldname] : (isset(@field.default) ? @field.default : '') }}</textarea>
                                                                            {~
                                                                                @meta.scripts.raw['codemirror_'.@fieldname] = 'CodeMirror.fromTextArea(document.getElementById("codemirror_'.@fieldname.'"), '.(isset(@field.options) ? json_encode((object)@field.options) : '{lineNumbers: true}').');';
                                                                            ~}
                                                                            </script>
                                                                        </case>
                                                                        <case value="textarea">
                                                                            <textarea class="form-control" name="{{ @fieldname }}" style="height:200px">{{ isset(@form.values[@fieldname]) ? @form.values[@fieldname] : (isset(@field.default) ? @field.default : '') }}</textarea>
                                                                        </case>
                                                                        <case value="checkbox">
                                                                            <check if="{{ isset(@field.options) }}">
                                                                                <true>
                                                                                    <repeat group="{{ @field.options }}" key="{{ @opt }}" value="{{ @lbl }}">
                                                                                        <div class="checkbox">
                                                                                            <label>
                                                                                                <input class="" value="{{ @opt }}" type="checkbox" name="{{ @fieldname }}[{{ @opt }}]" {{ (isset(@form.values[@fieldname]) and in_array(@opt, (array)@form.values[@fieldname])) ? 'checked' : '' }}/>
                                                                                                {{ @lbl }}
                                                                                            </label>
                                                                                        </div>
                                                                                    </repeat>
                                                                                </true>
                                                                                <false>
                                                                                    <div class="checkbox">
                                                                                        <label>
                                                                                            <input value="{{ @field.value }}" type="checkbox" name="{{ @fieldname }}" {{ (isset(@form.values[@fieldname]) and (@form.values[@fieldname] == @field.value)) ? 'checked' : '' }}/>
                                                                                            Sim/Não
                                                                                        </label>
                                                                                    </div>
                                                                                </false>
                                                                            </check>
                                                                        </case>
                                                                        <case value="radio">
                                                                            <div class="radio">
                                                                                <repeat group="{{ @field.options }}" key="{{ @opt }}" value="{{ @lbl }}">
                                                                                        <label class="radio-inline">
                                                                                            <input class="" value="{{ @opt }}" type="radio" name="{{ @fieldname }}" {{ ((isset(@form.values[@fieldname]) && (@opt == @form.values[@fieldname])) || (!isset(@form.values[@fieldname]) && isset(@field.default) && (@field.default == @opt))) ? 'checked' : '' }}/>
                                                                                            {{ @lbl }}
                                                                                        </label>
                                                                                </repeat>
                                                                                <div style="height: 3px"></div>
                                                                            </div>
                                                                        </case>
                                                                        <case value="dropdown">
                                                                            <select class="form-control select2" name="{{ @fieldname }}" {{ isset(@field.attributes) ? packXMLAttributes(@field.attributes) : '' }}>
                                                                                <repeat group="{{ @field.options }}" key="{{ @key }}" value="{{ @desc }}">
                                                                                    <option value="{{ @key }}"
                                                                                        {{ isset(@desc.attributes) ? packXMLAttributes(@desc.attributes) : '' }}
                                                                                        {{ @key == (isset(@form.values[@fieldname]) ?
                                                                                                   @form.values[@fieldname] : (isset(@field.default) ?
                                                                                                                               @field.default : null)) ? ' selected' : '' }}>
                                                                                        {{ is_array(@desc) ? @desc.label : @desc }}
                                                                                    </option>
                                                                                </repeat>
                                                                            </select>
                                                                        </case>
                                                                        <case value="date">
                                                                            <div class="input-group date">
                                                                                <input class="form-control" value="{{ isset(@form.values[@fieldname]) ? @form.values[@fieldname] : (isset(@field.default) ? @field.default : '') }}" type="text" name="{{ @fieldname }}" data-date-format="{{ @app.date.format2 }}" {{ isset(@field.attributes) ? packXMLAttributes(@field.attributes) : '' }} />
                                                                                <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span>
                                                                            </div>
                                                                        </case>
                                                                        <case value="time">
                                                                            <div class="input-group date">
                                                                                <input class="form-control {{ @field.type }}" value="{{ isset(@form.values[@fieldname]) ? @form.values[@fieldname] : (isset(@field.default) ? @field.default : '') }}" type="text" name="{{ @fieldname }}" data-date-format="{{ @app.time.format2 }}" {{ isset(@field.attributes) ? packXMLAttributes(@field.attributes) : '' }} />
                                                                                <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span>
                                                                            </div>
                                                                        </case>
                                                                        <case value="datetime2">
                                                                            <div class="input-group date">
                                                                                <input class="form-control {{ @field.type }}" value="{{ isset(@form.values[@fieldname]) ? @form.values[@fieldname] : (isset(@field.default) ? @field.default : '') }}" type="text" name="{{ @fieldname }}" data-date-format="{{ @app.datetime.format2 }}" {{ isset(@field.attributes) ? packXMLAttributes(@field.attributes) : '' }} />
                                                                                <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span>
                                                                            </div>
                                                                        </case>
                                                                        <case value="datetime">
                                                                            <div class="input-group date">
                                                                                <input
                                                                                    class="form-control {{ @field.type }}"
                                                                                    value="{{ isset(@form.values[@fieldname]) ? @form.values[@fieldname] : (isset(@field.default) ? @field.default : '') }}"
                                                                                    type="text" name="{{ @fieldname }}"
                                                                                    data-date-format="{{ isset(@field.format) ? @field.format : @app.datetime.format2 }}"
                                                                                    {{ isset(@field.attributes) ? packXMLAttributes(@field.attributes) : '' }} />
                                                                                <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span>
                                                                            </div>
                                                                        </case>
                                                                        <case value="password">
                                                                            {~ @__p = 'password_field_'.time().rand() ~}
                                                                            <button class="btn btn-default form-control"
                                                                                    type="button"
                                                                                    onclick="document.querySelector('.{{ @__p }}').style.display = '';this.style.display = 'none'">
                                                                                Alterar {{ @field.label }}
                                                                            </button>
                                                                            <input style="display:none;" class="form-control {{ @__p }}" type="password" name="{{ @fieldname }}" value="{{ isset(@form.values[@fieldname]) ? '********' : '' }}" />
                                                                        </case>
                                                                        <case value="image">
                                                                            <input class="form-control file_image" value="{{ isset(@form.values[@fieldname]) ? @form.values[@fieldname] : (isset(@field.default) ? @field.default : '') }}" type="file" name="{{ @fieldname }}" {{ (isset(@field.multiple) and @field.multiple) ? 'multiple' : '' }} />
                                                                            {~
                                                                                @__img_tag = isset(@form.values[@fieldname]) && file_exists(@UPLOADS . @form.values[@fieldname]) ? "\"<img src='" . @BASE . "/" . @UPLOADS . @form.values[@fieldname] . "' class='file-preview-image' alt='Imagem'>\"" : "";
                                                                                @meta.scripts.raw['fileinput_'.@fieldname] = 'jQuery(document).ready(function($) {
                                                                                                           $("[name='.@fieldname.']").fileinput({
                                                                                                                 showUpload: false,
                                                                                                                 overwriteInitial: true,
                                                                                                                 initialPreview: [
                                                                                                                    '.@__img_tag.'
                                                                                                                ],
                                                                                                               });
                                                                                                        });';
                                                                            ~}
                                                                        </case>
                                                                        <case value="number">
                                                                            <input
                                                                                class="form-control text-right"
                                                                                value="{{ str_replace($this->f3->get('app.number.thousands'), '', @_value) }}"
                                                                                data-inputmask="'alias': 'numeric', 'groupSeparator': '{{ @app.number.thousands }}', 'radixPoint': '{{ @app.number.radixpoint }}', 'autoGroup': true, 'digits': {{ isset(@field.digits) ? @field.digits : 0 }}, 'digitsOptional': false, 'prefix': '', 'placeholder': '0'"
                                                                                type="text"
                                                                                name="{{ @fieldname }}"
                                                                                {{ isset(@field.attributes) ? packXMLAttributes(@field.attributes) : '' }}
                                                                            />
                                                                        </case>
                                                                        <default>
                                                                            <check if="{{ isset(@field.type) && @field.type == 'text' && isset(@field.options) }}">
                                                                                <datalist id="datalist_{{ @fieldname }}">
                                                                                    <repeat group="{{ @field.options }}" key="{{ @option_value }}" value="{{ @option_text }}">
                                                                                        <option value="{{ @option_text }}">{{ @option_value }}</option>
                                                                                    </repeat>
                                                                                </datalist>
                                                                            </check>
                                                                            <input
                                                                                class="form-control"
                                                                                value="{{ @_value }}"
                                                                                type="{{ isset(@field.type) ? @field.type : 'text' }}"
                                                                                {{ isset(@field.mask) ? 'data-inputmask-clearIncomplete="true" data-inputmask-skip-optional-part-character=" " data-inputmask data-inputmask-mask="'.@field.mask.'"' : '' }}
                                                                                {{ isset(@field.type) && @field.type == 'text' && isset(@field.options) ? 'list="datalist_'.@fieldname.'"' : '' }}
                                                                                {{ isset(@field.attributes) ? packXMLAttributes(@field.attributes) : '' }}
                                                                                name="{{ @fieldname }}" />
                                                                        </default>
                                                                    </switch>
                                                                    <check if="{{ isset(@field.button) }}">
                                                                        <span class="input-group-btn">
                                                                            <button class="btn btn-default" type="button" onclick="{{ @field.button.action }}" id="{{ isset(@field.button.id) ? @field.button.id : @fieldname.'_action' }}" {{ isset(@field.button.attributes) ? packXMLAttributes(@field.button.attributes) : '' }}>
                                                                                <check if="{{ isset(@field.button.icon) }}">
                                                                                <span class="glyphicon glyphicon-{{ @field.button.icon }}"></span>
                                                                                </check>
                                                                                <check if="{{ isset(@field.button.text) }}">
                                                                                {{ @field.button.text }}
                                                                                </check>
                                                                            </button>
                                                                        </span>
                                                                    </div>
                                                                    </check>
                                                                    {*<p class="help-block">{{ isset(@field.help) ? @field.help : '' }}</p>*}
                                                                    <check if="{{ isset(@form.errors[@fieldname]) }}">
                                                                        <true>
                                                                            {*<div class="alert alert-danger" role="alert">
                                                                            {{ implode(@form.errors[@fieldname], '<br>') }}
                                                                            </div>*}
                                                                            <p class="help-block">{{ implode(@form.errors[@fieldname], ', ') }}</p>
                                                                        </true>
                                                                        <false>
                                                                            <check if="{{ isset(@form.errors) }}">
                                                                            <p class="help-block">&nbsp;</p>
                                                                            </check>
                                                                        </false>
                                                                    </check>
                                                                </div>
                                                            </div>
                                                        </repeat>
                                                    </check>
                                                    <check if="{{ isset(@group.table) }}">
                                                        <div class="col-md-12" style="margin-bottom: 10px;">
                                                            {~
                                                                @_groupdata = (boolean)isset(@group.group);
                                                                @_table = array(null);
                                                                if(isset(@form.values[@groupname]))
                                                                    @_table += @form.values[@groupname];
                                                                //@_table[0] = null;
                                                                //array_unshift(@_table, null);
                                                                @_table_row_count = 0;//count(@_table);
                                                                foreach (@_table as @idx =>@_dummy):
                                                                    @_table_row_count = max(@_table_row_count,@$idx);
                                                                endforeach;
                                                                @_showactioncolumn = !isset(@group.allow_insert) || !isset(@group.allow_delete) || @group.allow_insert || @group.allow_delete;
                                                            ~}
                                                            <table class="table table-striped" {{ isset(@group.order) && (!isset(@group.sort) || @group.sort) ? 'data-sortfield="'.@group.order.'"' : '' }} id="table_{{ @groupname }}">
                                                                <thead>
                                                                    <tr>
                                                                        <check if="{{ isset(@group.order) && (!isset(@group.sort) || @group.sort) }}">
                                                                            <th class="dont-print" style="width: 84px;min-width: 84px;max-width: 84px;">
                                                                            Ordem
                                                                            </th>
                                                                        </check>
                                                                        <repeat group="{{ @group.table }}" key="{{ @fieldname }}" value="{{ @field }}">
                                                                            <th data-fieldname="{{ @fieldname }}" class="{{ @field.type == 'hidden' ? 'hidden' : '' }}">{{ @field.label }}{{ (isset(@field.rules) and in_array('required', @field.rules)) ? ' <span class="text-danger">*</span>' : '' }}</th>
                                                                            <check if="{{ isset(@field.type) && @field.type == 'text' && isset(@field.options) }}">
                                                                                <datalist id="datalist_{{ @groupname }}[{{ @fieldname }}]">
                                                                                    <repeat group="{{ @field.options }}" key="{{ @option_value }}" value="{{ @option_text }}">
                                                                                        <option value="{{ @option_text }}">{{ @option_value }}</option>
                                                                                    </repeat>
                                                                                </datalist>
                                                                            </check>
                                                                        </repeat>
                                                                        <check if="{{ @_showactioncolumn }}">
                                                                        <th class="dont-print" style="width: 10px">
                                                                            <check if="{{ !isset(@group.allow_insert) || @group.allow_insert }}">
                                                                                <true>
                                                                                    <a href="javascript:_appendrow('{{ @groupname }}')" class="btn btn-primary btn-md btn-flat"><i class="glyphicon glyphicon-plus"></i></a>
                                                                                </true>
                                                                                <false>
                                                                                    <i class="glyphicon glyphicon-flash"></i>
                                                                                </false>
                                                                            </check>
                                                                        </th>
                                                                        </check>
                                                                    </tr>
                                                                </thead>
                                                                <tbody data-row-count="{{ @_table_row_count }}">
                                                                    <repeat group="{{ @_table }}" key="{{ @c }}" value="{{ @row }}" counter="{{ @ic }}">
                                                                        <check if="{{ @ic != 1 && @_groupdata !== false && @_groupdata !== @row[@group.group] }}">
                                                                            {~ @_groupdata = @row[@group.group] ~}
                                                                            <tr>
                                                                                <th colspan="{{ count(@group.table) + (isset(@group.order) && (!isset(@group.sort) || @group.sort) ? 1 : 0) + (@_showactioncolumn ? 1 : 0) }}">
                                                                                    <h4><strong>{{ @_groupdata }}</strong></h4>
                                                                                </th>
                                                                            </tr>
                                                                        </check>
                                                                        {~ @_dont_post = @ic == 1 ~}
                                                                        <tr {{ @_dont_post ? 'class="dont-print dont_post" style="display:none" id="row_'.@groupname.'"' : '' }}>
                                                                            <td data-fieldname="id" style="display:none;">
                                                                                <input type="hidden" name="{{ @groupname }}[{{ @c }}][id]" value="{{ isset(@row.id) ? @row.id : '' }}">
                                                                            </td>
                                                                            <check if="{{ isset(@group.order) && (!isset(@group.sort) || @group.sort) }}">
                                                                            <td class="dont-print" data-fieldname="{{ @group.order }}">
                                                                                <div style="width: 84px;min-width: 84px;max-width: 84px;">
                                                                                    <check if="{{ ((@ic == 1 || !@row['id']) && (!isset(@group.allow_insert) || @group.allow_insert)) || (!isset(@group.allow_edit) || @group.allow_edit) }}">
                                                                                    <true>
                                                                                        <input type="hidden" name="{{ @groupname }}[{{ @c }}][{{ @group.order }}]" value="{{ isset(@row[@group.order]) ? @row[@group.order] : '' }}" class="order">
                                                                                        <a href="javascript:void(0);" class="btn btn-default btn-flat btn-md order-prior">
                                                                                            <i class="glyphicon glyphicon-chevron-up" style="cursor: pointer;"></i>
                                                                                        </a>
                                                                                        <a href="javascript:void(0);" class="btn btn-default btn-flat btn-md order-next">
                                                                                            <i class="glyphicon glyphicon-chevron-down" style="cursor: pointer;"></i>
                                                                                        </a>
                                                                                    </true>
                                                                                    <false>
                                                                                        <span>{{ @c }}</span>
                                                                                    </false>
                                                                                    </check>
                                                                                </div>
                                                                            </td>
                                                                            </check>
                                                                            <repeat group="{{ @group.table }}" key="{{ @fieldname }}" value="{{ @field }}">
                                                                                {~ @_value = isset(@row[@fieldname]) ? (isset(@field.options[@row[@fieldname]]) ? @field.options[@row[@fieldname]] : @row[@fieldname]) : (isset(@field.default) ? @field.default : '') ~}
                                                                                {~ @_value_raw = isset(@row[@fieldname]) ? @row[@fieldname] : (isset(@field.default) ? @field.default : '') ~}
                                                                                <td data-fieldname="{{ @fieldname }}" style="vertical-align: middle;{{ @field.type == 'hidden' ? 'display:none;' : '' }}">
                                                                                    <div class="{{ isset(@form.errors[@groupname][@c][@fieldname]) ? 'form-group has-error' : '' }}">
                                                                                        <switch expr="{{ ((@ic == 1 || !@row['id']) && (!isset(@group.allow_insert) || @group.allow_insert)) || (!isset(@group.allow_edit) || @group.allow_edit) ? @field.type : 'static' }}">
                                                                                            <case value="static">
                                                                                                <p class="form-control-static">{{ nl2br(@_value) }}</p>
                                                                                                <input
                                                                                                    value="{{ @_value_raw }}"
                                                                                                    type="hidden"
                                                                                                    name="{{ @groupname }}[{{ @c }}][{{ @fieldname }}]"
                                                                                                />
                                                                                            </case>
                                                                                            <case value="wysiwyg">
                                                                                                <textarea class="form-control trumbowyg" name="{{ @groupname }}[{{ @c }}][{{ @fieldname }}]" style="height:300px;margin: 0;width: 100%;">{{ isset(@form.values[@fieldname]) ? @row[@fieldname] : (isset(@field.default) ? @field.default : '') }}</textarea>
                                                                                            </case>
                                                                                            <case value="textarea">
                                                                                                <textarea class="form-control" name="{{ @groupname }}[{{ @c }}][{{ @fieldname }}]" style="height:200px">{{ isset(@row[@fieldname]) ? @row[@fieldname] : (isset(@field.default) ? @field.default : '') }}</textarea>
                                                                                            </case>
                                                                                            <case value="checkbox">
                                                                                                <check if="{{ isset(@field.options) }}">
                                                                                                    <true>
                                                                                                        <repeat group="{{ @field.options }}" key="{{ @opt }}" value="{{ @lbl }}">
                                                                                                            <div class="checkbox">
                                                                                                                <label>
                                                                                                                    <input class="" value="{{ @opt }}" type="checkbox" name="{{ @groupname }}[{{ @c }}][{{ @fieldname }}][{{ @opt }}]" {{ (isset(@row[@fieldname]) and in_array(@opt, @row[@fieldname])) ? 'checked' : '' }}/>
                                                                                                                    {{ @lbl }}
                                                                                                                </label>
                                                                                                            </div>
                                                                                                        </repeat>
                                                                                                    </true>
                                                                                                    <false>
                                                                                                        <div class="checkbox">
                                                                                                            <label>
                                                                                                                <input value="{{ @field.value }}" type="checkbox" name="{{ @groupname }}[{{ @c }}][{{ @fieldname }}]" {{ (isset(@row[@fieldname]) and (@row[@fieldname] == @field.value)) ? 'checked' : '' }}/>
                                                                                                                Sim/Não
                                                                                                            </label>
                                                                                                        </div>
                                                                                                    </false>
                                                                                                </check>
                                                                                            </case>
                                                                                            <case value="radio">
                                                                                                <div class="radio">
                                                                                                    <repeat group="{{ @field.options }}" key="{{ @opt }}" value="{{ @lbl }}">
                                                                                                            <label class="radio-inline">
                                                                                                                <input class="" value="{{ @opt }}" type="radio" name="{{ @groupname }}[{{ @c }}][{{ @fieldname }}]" {{ ((isset(@row[@fieldname]) && (@opt == @row[@fieldname])) || (!isset(@form.values[@fieldname]) && isset(@field.default) && (@field.default == @opt))) ? 'checked' : '' }}/>
                                                                                                                {{ @lbl }}
                                                                                                            </label>
                                                                                                    </repeat>
                                                                                                    <div style="height: 3px"></div>
                                                                                                </div>
                                                                                            </case>
                                                                                            <case value="dropdown">
                                                                                                <select class="form-control{{ @_dont_post ? '' : ' select2' }}" name="{{ @groupname }}[{{ @c }}][{{ @fieldname }}]">
                                                                                                    <repeat group="@field.options" key="{{ @key }}" value="{{ @desc }}">
                                                                                                        <option value="{{ @key }}" {{ @key == (isset(@row[@fieldname]) ?
                                                                                                                                               @row[@fieldname] : (isset(@field.default) ?
                                                                                                                                                                          @field.default : null)) ? ' selected' : '' }}>{{ @desc }}</option>
                                                                                                    </repeat>
                                                                                                </select>
                                                                                            </case>
                                                                                            <case value="date">
                                                                                                <div class="input-group date">
                                                                                                    <input
                                                                                                        class="form-control"
                                                                                                        value="{{ isset(@row[@fieldname]) ? @row[@fieldname] : (isset(@field.default) ? @field.default : '') }}"
                                                                                                        type="text"
                                                                                                        name="{{ @groupname }}[{{ @c }}][{{ @fieldname }}]"
                                                                                                        data-date-format="{{ @app.date.format2 }}"
                                                                                                        {{ isset(@field.attributes) ? packXMLAttributes(@field.attributes) : '' }}>
                                                                                                    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                                                                                                </div>
                                                                                            </case>
                                                                                            <case value="time">
                                                                                                <div class="input-group date">
                                                                                                    <input
                                                                                                        class="form-control"
                                                                                                        value="{{ isset(@row[@fieldname]) ? @row[@fieldname] : (isset(@field.default) ? @field.default : '') }}"
                                                                                                        type="text"
                                                                                                        name="{{ @groupname }}[{{ @c }}][{{ @fieldname }}]"
                                                                                                        data-date-format="{{ @app.time.format2 }}"
                                                                                                        {{ isset(@field.attributes) ? packXMLAttributes(@field.attributes) : '' }}>
                                                                                                    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                                                                                                </div>
                                                                                            </case>
                                                                                            <case value="datetime">
                                                                                                <div class="input-group date">
                                                                                                    <input
                                                                                                        class="form-control"
                                                                                                        value="{{ isset(@row[@fieldname]) ? @row[@fieldname] : (isset(@field.default) ? @field.default : '') }}"
                                                                                                        type="text"
                                                                                                        name="{{ @groupname }}[{{ @c }}][{{ @fieldname }}]"
                                                                                                        data-date-format="{{ isset(@field.format) ? @field.format : @app.datetime.format2 }}"
                                                                                                        {{ isset(@field.attributes) ? packXMLAttributes(@field.attributes) : '' }}>
                                                                                                    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                                                                                                </div>
                                                                                            </case>
                                                                                            <case value="password">
                                                                                                <input class="form-control" type="password" name="{{ @groupname }}[{{ @c }}][{{ @fieldname }}]" value="{{ isset(@row[@fieldname]) ? '********' : '' }}" />
                                                                                            </case>
                                                                                            <case value="image">
                                                                                                <input class="form-control file_image" value="{{ isset(@row[@fieldname]) ? @row[@fieldname] : (isset(@field.default) ? @field.default : '') }}" type="file" name="{{ @groupname }}[{{ @c }}][{{ @fieldname }}]" {{ (isset(@field.multiple) and @field.multiple) ? 'multiple' : '' }} />
                                                                                                {~
                                                                                                    @__img_tag = isset(@row[@fieldname]) && file_exists(@UPLOADS . @row[@fieldname]) ? "\"<img src='/" . @UPLOADS . @row[@fieldname] . "' class='file-preview-image' alt='Imagem'>\"" : "";
                                                                                                    @meta.scripts.raw['fileinput_'.@fieldname] = 'jQuery(document).ready(function($) {
                                                                                                                               $("[name='.@fieldname.']").fileinput({
                                                                                                                                     showUpload: false,
                                                                                                                                     showPreview: false,
                                                                                                                                     overwriteInitial: true,
                                                                                                                                     initialPreview: [
                                                                                                                                        '.@__img_tag.'
                                                                                                                                    ],
                                                                                                                                   });
                                                                                                                            });';
                                                                                                ~}
                                                                                            </case>
                                                                                            <case value="number">
                                                                                                <input
                                                                                                    class="form-control text-right"
                                                                                                    value="{{ str_replace($this->f3->get('app.number.thousands'), '', @_value) }}"
                                                                                                    data-inputmask="'alias': 'numeric', 'groupSeparator': '{{ @app.number.thousands }}', 'radixPoint': '{{ @app.number.radixpoint }}', 'autoGroup': true, 'digits': {{ isset(@field.digits) ? @field.digits : 0 }}, 'digitsOptional': false, 'prefix': '', 'placeholder': '0'"
                                                                                                    type="text"
                                                                                                    name="{{ @groupname }}[{{ @c }}][{{ @fieldname }}]"
                                                                                                />
                                                                                            </case>
                                                                                            <default>
                                                                                                <input
                                                                                                    class="form-control"
                                                                                                    value="{{ @_value }}"
                                                                                                    type="{{ isset(@field.type) ? @field.type : 'text' }}"
                                                                                                    {{ isset(@field.mask) ? 'data-inputmask-clearIncomplete="true" data-inputmask-skipOptionalPartCharacter: " " data-inputmask data-inputmask-mask="'.@field.mask.'"' : '' }}
                                                                                                    {{ isset(@field.attributes) ? packXMLAttributes(@field.attributes) : '' }}
                                                                                                    name="{{ @groupname }}[{{ @c }}][{{ @fieldname }}]"
                                                                                                    {{ isset(@field.type) && @field.type == 'text' && isset(@field.options) ? "list=\"datalist_{@groupname}[@fieldname]\"" : '' }}
                                                                                                />
                                                                                            </default>
                                                                                        </switch>
                                                                                        <check if="{{ isset(@form.errors[@groupname][@c][@fieldname]) }}">
                                                                                            <true>
                                                                                                {*<div class="alert alert-danger" role="alert">
                                                                                                {{ implode(@form.errors[@groupname][@c][@fieldname], '<br>') }}
                                                                                                </div>*}
                                                                                                <p class="help-block">{{ implode(@form.errors[@groupname][@c][@fieldname], ', ') }}</p>
                                                                                            </true>
                                                                                            <false>
                                                                                                <check if="{{ isset(@form.errors[@groupname][@c]) }}">
                                                                                                <p class="help-block">&nbsp;</p>
                                                                                                </check>
                                                                                            </false>
                                                                                        </check>
                                                                                    </div>
                                                                                </td>
                                                                            </repeat>
                                                                            <check if="{{ !isset(@group.allow_delete) || @group.allow_delete }}">
                                                                            <td class="dont-print" style="width: 10px"><a href="javascript:void(0);" onclick="jQuery(this).parent().parent().remove();" class="btn btn-danger btn-md btn-flat"><i class="glyphicon glyphicon-remove"></i></a></td>
                                                                            </check>
                                                                        </tr>
                                                                    </repeat>
                                                                </tbody>
                                                            </table>
                                                        </div>
                                                    </check>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </check>
                            </repeat>
                        </div>
                        <div class="dont-print">
                            <input type="submit" class="btn btn-primary btn-flat" value="Salvar">
                            <!--<input type="reset" class="btn btn-default btn-flat" value="Redefinir" onclick="return confirm('Confima a redefinição dos dados do formulário?');">-->
                            <a href="{{ @BASE }}{{ isset(@form.table) ? F3::alias(@form.table) : F3::alias('admin_dashboard') }}" class="btn btn-warning btn-flat">Cancelar</a>
                            <check if="{{ isset(@form.actions) }}">
                                <div class="pull-right">
                                <repeat group="{{ @form.actions }}" value="{{ @action }}" counter="{{ @counter }}">
                                    <check if="{{ @action.role | role }}">
                                        <true>
                                            <check if="{{ isset(@action.params) }}">
                                                <repeat group="{{ @action.params }}" key="{{ @param }}" value="{{ @field }}">
                                                    {~ F3::set('PARAMS.'.@param, @row[@field]) ~}
                                                </repeat>
                                            </check>
                                            <check if="{{ @counter < @app.table.maxactions or count(@form.actions) <= @app.table.maxactions }}">
                                                <true>
                                                    <a href="{{ isset(@ALIASES[@action.route]) ? @BASE.\F3::alias(@action.route) : @action.route }}" class="btn {{ isset(@action['class']) ? @action['class'] : 'btn-default' }} btn-flat" onclick="{{ (isset(@action.confirm) and @action.confirm) ? 'return confirm(\''.addslashes(is_string(@action.confirm) ? @action.confirm : 'Confirma esta ação?').'\');' : '' }}">{{ @action.description }}</a>
                                                </true>
                                                <false>
                                                    <check if="{{ @counter == @app.table.maxactions }}">
                                                        <div class="btn-group">
                                                            <button type="button" class="btn btn-default btn-flat dropdown-toggle" data-toggle="dropdown">
                                                                Mais Ações
                                                                <span class="caret"></span>
                                                            </button>
                                                            <ul class="dropdown-menu pull-right" role="menu" style="top: auto; bottom: 36px;">
                                                    </check>
                                                        <li>
                                                            <check if="{{ is_array(@action) }}">
                                                                <true>
                                                                    <a href="{{ isset(@ALIASES[@action.route]) ? @BASE.\F3::alias(@action.route) : @action.route }}" onclick="{{ (isset(@action.confirm) and @action.confirm) ? 'return confirm(\''.addslashes(is_string(@action.confirm) ? @action.confirm : 'Confirma esta ação?').'\');' : '' }}">{{ @action.description }}</a>
                                                                </true>
                                                                <false>
                                                                    <li class="divider"></li>
                                                                </false>
                                                            </check>
                                                        </li>
                                                    <check if="{{ @counter == count(@form.actions) }}">
                                                            </ul>
                                                        </div>
                                                    </check>
                                                </false>
                                            </check>
                                        </true>
                                        <false>
                                            {~ @counter-- ~}
                                        </false>
                                    </check>
                                </repeat>
                                </div>
                            </check>
                        </div>
                    </div>
                </div>
            </form>
        </div><!-- /.nav-tabs-custom -->
    </div>
</div>   <!-- /.row -->
<include href="hwapx/admin/admin/footer.html" />
