
<form class="form-horizontal form-label-left" action="index.php?module=criteria&event=update&id=[% $c.criteria_id %]" method="post" id="hm1">
    <div class="card panel-fcs-border shadow-sm">
        <div class="card-header">
            <div class="row">
                <div class="col-sm-6">
                    <span class="fcs-card-title h2">[% $user->gettext('Kriterium aktualisieren') %]</span>
                </div>
                <div class="col-sm-6 text-end">
                    <a href="javascript:checkForm();" class="btn btn-outline-primary">[% $user->gettext('Speichern') %]</a>
                    [% if $smarty.const.STANDARD_CRITERIA != $c.criteria_id %]
                        <a href="javascript:setAsDefault();" class="btn btn-outline-primary">[% $user->gettext('Als Standard setzen') %]</a>
                    [% else %]
                        <a href="javascript:unsetAsDefault();" class="btn btn-outline-primary">[% $user->gettext('Standard entfernen') %]</a>
                    [% /if %]

                </div>
            </div>
        </div>
        <div class="card-body">
            [% if $errMessage %]
                <div class="alert alert-danger">[%  $errMessage %]</div>
            [% /if %]
            <div class="form-group row mb-3">
                <label class="col-sm-3">
                    [% $user->gettext('Name des Kriteriums') %]
                </label>
                <div class="col-sm-9">
                    <input type="text" value="[% $c.criteria_name %]" class="form-control" name="cName">
                </div>
            </div>
            <div class="form-group row mb-3">
                <label class="col-sm-3">
                    [% $user->gettext('Kommentar') %]
                </label>
                <div class="col-sm-9">
                    <textarea class="form-control"  name="cComment">[% $c.criteria_comment %]</textarea>
                </div>
            </div>

            <div class="form-group row mb-3">
                <label class="col-sm-3">
                    [% $user->gettext('Reihenfolge') %]
                </label>
                <div class="col-sm-9">
                    <input type="number" style="width: 10%;" value="[% $c.criteria_order %]" class="form-control" name="cOrder">
                </div>
            </div>

            <div class="form-group row mb-3">
                <label class="col-sm-3">
                    [% $user->gettext('Aktiv') %]
                </label>
                <div class="col-sm-9">
                    <input type="checkbox" name="active" value="" [% if $c.criteria_active %]checked[% /if %] onchange='setActive([% $c.criteria_id%]);'>
                </div>
            </div>
        </div>
    </div>
</form>

<script>
    function checkForm() {
        $("#hm1").submit();
    }

    function setAsDefault() {
        $.post("index.php?module=settings&event=setStandardCriteria", {id: [% $c.criteria_id %]}, function (data) {
            console.log(data);
            parent.location.reload();
        });
    }

    function unsetAsDefault() {
        $.post("index.php?module=settings&event=unsetStandardCriteria", {id: [% $c.criteria_id %]}, function (data) {
            console.log(data);
            parent.location.reload();
        });
    }
</script>