<?php

namespace PHPMaker2021\rdigital21;

// Page object
$PenilaianAdd = &$Page;
?>
<script>
var currentForm, currentPageID;
var fpenilaianadd;
loadjs.ready("head", function () {
    var $ = jQuery;
    // Form object
    currentPageID = ew.PAGE_ID = "add";
    fpenilaianadd = currentForm = new ew.Form("fpenilaianadd", "add");

    // Add fields
    var currentTable = <?= JsonEncode(GetClientVar("tables", "penilaian")) ?>,
        fields = currentTable.fields;
    if (!ew.vars.tables.penilaian)
        ew.vars.tables.penilaian = currentTable;
    fpenilaianadd.addFields([
        ["kode_tapel", [fields.kode_tapel.visible && fields.kode_tapel.required ? ew.Validators.required(fields.kode_tapel.caption) : null], fields.kode_tapel.isInvalid],
        ["guru_id", [fields.guru_id.visible && fields.guru_id.required ? ew.Validators.required(fields.guru_id.caption) : null], fields.guru_id.isInvalid],
        ["mapel_id", [fields.mapel_id.visible && fields.mapel_id.required ? ew.Validators.required(fields.mapel_id.caption) : null], fields.mapel_id.isInvalid],
        ["kelas", [fields.kelas.visible && fields.kelas.required ? ew.Validators.required(fields.kelas.caption) : null], fields.kelas.isInvalid],
        ["materi", [fields.materi.visible && fields.materi.required ? ew.Validators.required(fields.materi.caption) : null], fields.materi.isInvalid],
        ["tujuan_pembelajaran", [fields.tujuan_pembelajaran.visible && fields.tujuan_pembelajaran.required ? ew.Validators.required(fields.tujuan_pembelajaran.caption) : null], fields.tujuan_pembelajaran.isInvalid],
        ["fase", [fields.fase.visible && fields.fase.required ? ew.Validators.required(fields.fase.caption) : null], fields.fase.isInvalid]
    ]);

    // Set invalid fields
    $(function() {
        var f = fpenilaianadd,
            fobj = f.getForm(),
            $fobj = $(fobj),
            $k = $fobj.find("#" + f.formKeyCountName), // Get key_count
            rowcnt = ($k[0]) ? parseInt($k.val(), 10) : 1,
            startcnt = (rowcnt == 0) ? 0 : 1; // Check rowcnt == 0 => Inline-Add
        for (var i = startcnt; i <= rowcnt; i++) {
            var rowIndex = ($k[0]) ? String(i) : "";
            f.setInvalid(rowIndex);
        }
    });

    // Validate form
    fpenilaianadd.validate = function () {
        if (!this.validateRequired)
            return true; // Ignore validation
        var fobj = this.getForm(),
            $fobj = $(fobj);
        if ($fobj.find("#confirm").val() == "confirm")
            return true;
        var addcnt = 0,
            $k = $fobj.find("#" + this.formKeyCountName), // Get key_count
            rowcnt = ($k[0]) ? parseInt($k.val(), 10) : 1,
            startcnt = (rowcnt == 0) ? 0 : 1, // Check rowcnt == 0 => Inline-Add
            gridinsert = ["insert", "gridinsert"].includes($fobj.find("#action").val()) && $k[0];
        for (var i = startcnt; i <= rowcnt; i++) {
            var rowIndex = ($k[0]) ? String(i) : "";
            $fobj.data("rowindex", rowIndex);

            // Validate fields
            if (!this.validateFields(rowIndex))
                return false;

            // Call Form_CustomValidate event
            if (!this.customValidate(fobj)) {
                this.focus();
                return false;
            }
        }

        // Process detail forms
        var dfs = $fobj.find("input[name='detailpage']").get();
        for (var i = 0; i < dfs.length; i++) {
            var df = dfs[i],
                val = df.value,
                frm = ew.forms.get(val);
            if (val && frm && !frm.validate())
                return false;
        }
        return true;
    }

    // Form_CustomValidate
    fpenilaianadd.customValidate = function(fobj) { // DO NOT CHANGE THIS LINE!
        // Your custom validation code here, return false if invalid.
        return true;
    }

    // Use JavaScript validation or not
    fpenilaianadd.validateRequired = <?= Config("CLIENT_VALIDATE") ? "true" : "false" ?>;

    // Dynamic selection lists
    fpenilaianadd.lists.guru_id = <?= $Page->guru_id->toClientList($Page) ?>;
    fpenilaianadd.lists.mapel_id = <?= $Page->mapel_id->toClientList($Page) ?>;
    fpenilaianadd.lists.kelas = <?= $Page->kelas->toClientList($Page) ?>;
    fpenilaianadd.lists.materi = <?= $Page->materi->toClientList($Page) ?>;
    fpenilaianadd.lists.tujuan_pembelajaran = <?= $Page->tujuan_pembelajaran->toClientList($Page) ?>;
    fpenilaianadd.lists.fase = <?= $Page->fase->toClientList($Page) ?>;
    loadjs.done("fpenilaianadd");
});
</script>
<script>
loadjs.ready("head", function () {
    // Write your table-specific client script here, no need to add script tags.
});
</script>
<?php $Page->showPageHeader(); ?>
<?php
$Page->showMessage();
?>
<form name="fpenilaianadd" id="fpenilaianadd" class="<?= $Page->FormClassName ?>" action="<?= CurrentPageUrl(false) ?>" method="post">
<?php if (Config("CHECK_TOKEN")) { ?>
<input type="hidden" name="<?= $TokenNameKey ?>" value="<?= $TokenName ?>"><!-- CSRF token name -->
<input type="hidden" name="<?= $TokenValueKey ?>" value="<?= $TokenValue ?>"><!-- CSRF token value -->
<?php } ?>
<input type="hidden" name="t" value="penilaian">
<input type="hidden" name="action" id="action" value="insert">
<input type="hidden" name="modal" value="<?= (int)$Page->IsModal ?>">
<input type="hidden" name="<?= $Page->OldKeyName ?>" value="<?= $Page->OldKey ?>">
<div class="ew-add-div"><!-- page* -->
<?php if ($Page->guru_id->Visible) { // guru_id ?>
    <div id="r_guru_id" class="form-group row">
        <label id="elh_penilaian_guru_id" for="x_guru_id" class="<?= $Page->LeftColumnClass ?>"><?= $Page->guru_id->caption() ?><?= $Page->guru_id->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->guru_id->cellAttributes() ?>>
<?php if (!$Security->isAdmin() && $Security->isLoggedIn() && !$Page->userIDAllow("add")) { // Non system admin ?>
<span id="el_penilaian_guru_id">
<span<?= $Page->guru_id->viewAttributes() ?>>
<input type="text" readonly class="form-control-plaintext" value="<?= HtmlEncode(RemoveHtml($Page->guru_id->getDisplayValue($Page->guru_id->EditValue))) ?>"></span>
</span>
<input type="hidden" data-table="penilaian" data-field="x_guru_id" data-hidden="1" name="x_guru_id" id="x_guru_id" value="<?= HtmlEncode($Page->guru_id->CurrentValue) ?>">
<?php } else { ?>
<span id="el_penilaian_guru_id">
    <select
        id="x_guru_id"
        name="x_guru_id"
        class="form-control ew-select<?= $Page->guru_id->isInvalidClass() ?>"
        data-select2-id="penilaian_x_guru_id"
        data-table="penilaian"
        data-field="x_guru_id"
        data-value-separator="<?= $Page->guru_id->displayValueSeparatorAttribute() ?>"
        <?= $Page->guru_id->editAttributes() ?>>
        <?= $Page->guru_id->selectOptionListHtml("x_guru_id") ?>
    </select>
    <?= $Page->guru_id->getCustomMessage() ?>
    <div class="invalid-feedback"><?= $Page->guru_id->getErrorMessage() ?></div>
<?= $Page->guru_id->Lookup->getParamTag($Page, "p_x_guru_id") ?>
<script>
loadjs.ready("head", function() {
    var el = document.querySelector("select[data-select2-id='penilaian_x_guru_id']"),
        options = { name: "x_guru_id", selectId: "penilaian_x_guru_id", language: ew.LANGUAGE_ID, dir: ew.IS_RTL ? "rtl" : "ltr" };
    options.dropdownParent = $(el).closest("#ew-modal-dialog, #ew-add-opt-dialog")[0];
    Object.assign(options, ew.vars.tables.penilaian.fields.guru_id.selectOptions);
    ew.createSelect(options);
});
</script>
</span>
<?php } ?>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->mapel_id->Visible) { // mapel_id ?>
    <div id="r_mapel_id" class="form-group row">
        <label id="elh_penilaian_mapel_id" for="x_mapel_id" class="<?= $Page->LeftColumnClass ?>"><?= $Page->mapel_id->caption() ?><?= $Page->mapel_id->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->mapel_id->cellAttributes() ?>>
<span id="el_penilaian_mapel_id">
<?php $Page->mapel_id->EditAttrs->prepend("onchange", "ew.updateOptions.call(this);"); ?>
    <select
        id="x_mapel_id"
        name="x_mapel_id"
        class="form-control ew-select<?= $Page->mapel_id->isInvalidClass() ?>"
        data-select2-id="penilaian_x_mapel_id"
        data-table="penilaian"
        data-field="x_mapel_id"
        data-value-separator="<?= $Page->mapel_id->displayValueSeparatorAttribute() ?>"
        <?= $Page->mapel_id->editAttributes() ?>>
        <?= $Page->mapel_id->selectOptionListHtml("x_mapel_id") ?>
    </select>
    <?= $Page->mapel_id->getCustomMessage() ?>
    <div class="invalid-feedback"><?= $Page->mapel_id->getErrorMessage() ?></div>
<?= $Page->mapel_id->Lookup->getParamTag($Page, "p_x_mapel_id") ?>
<script>
loadjs.ready("head", function() {
    var el = document.querySelector("select[data-select2-id='penilaian_x_mapel_id']"),
        options = { name: "x_mapel_id", selectId: "penilaian_x_mapel_id", language: ew.LANGUAGE_ID, dir: ew.IS_RTL ? "rtl" : "ltr" };
    options.dropdownParent = $(el).closest("#ew-modal-dialog, #ew-add-opt-dialog")[0];
    Object.assign(options, ew.vars.tables.penilaian.fields.mapel_id.selectOptions);
    ew.createSelect(options);
});
</script>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->kelas->Visible) { // kelas ?>
    <div id="r_kelas" class="form-group row">
        <label id="elh_penilaian_kelas" for="x_kelas" class="<?= $Page->LeftColumnClass ?>"><?= $Page->kelas->caption() ?><?= $Page->kelas->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->kelas->cellAttributes() ?>>
<span id="el_penilaian_kelas">
    <select
        id="x_kelas"
        name="x_kelas"
        class="form-control ew-select<?= $Page->kelas->isInvalidClass() ?>"
        data-select2-id="penilaian_x_kelas"
        data-table="penilaian"
        data-field="x_kelas"
        data-value-separator="<?= $Page->kelas->displayValueSeparatorAttribute() ?>"
        <?= $Page->kelas->editAttributes() ?>>
        <?= $Page->kelas->selectOptionListHtml("x_kelas") ?>
    </select>
    <?= $Page->kelas->getCustomMessage() ?>
    <div class="invalid-feedback"><?= $Page->kelas->getErrorMessage() ?></div>
<?= $Page->kelas->Lookup->getParamTag($Page, "p_x_kelas") ?>
<script>
loadjs.ready("head", function() {
    var el = document.querySelector("select[data-select2-id='penilaian_x_kelas']"),
        options = { name: "x_kelas", selectId: "penilaian_x_kelas", language: ew.LANGUAGE_ID, dir: ew.IS_RTL ? "rtl" : "ltr" };
    options.dropdownParent = $(el).closest("#ew-modal-dialog, #ew-add-opt-dialog")[0];
    Object.assign(options, ew.vars.tables.penilaian.fields.kelas.selectOptions);
    ew.createSelect(options);
});
</script>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->materi->Visible) { // materi ?>
    <div id="r_materi" class="form-group row">
        <label id="elh_penilaian_materi" for="x_materi" class="<?= $Page->LeftColumnClass ?>"><?= $Page->materi->caption() ?><?= $Page->materi->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->materi->cellAttributes() ?>>
<span id="el_penilaian_materi">
<div class="input-group ew-lookup-list" aria-describedby="x_materi_help">
    <div class="form-control ew-lookup-text" tabindex="-1" id="lu_x_materi"><?= EmptyValue(strval($Page->materi->ViewValue)) ? $Language->phrase("PleaseSelect") : $Page->materi->ViewValue ?></div>
    <div class="input-group-append">
        <button type="button" title="<?= HtmlEncode(str_replace("%s", RemoveHtml($Page->materi->caption()), $Language->phrase("LookupLink", true))) ?>" class="ew-lookup-btn btn btn-default"<?= ($Page->materi->ReadOnly || $Page->materi->Disabled) ? " disabled" : "" ?> onclick="ew.modalLookupShow({lnk:this,el:'x_materi[]',m:1,n:10});"><i class="fas fa-search ew-icon"></i></button>
    </div>
</div>
<div class="invalid-feedback"><?= $Page->materi->getErrorMessage() ?></div>
<?= $Page->materi->getCustomMessage() ?>
<?= $Page->materi->Lookup->getParamTag($Page, "p_x_materi") ?>
<input type="hidden" is="selection-list" data-table="penilaian" data-field="x_materi" data-type="text" data-multiple="1" data-lookup="1" data-value-separator="<?= $Page->materi->displayValueSeparatorAttribute() ?>" name="x_materi[]" id="x_materi[]" value="<?= $Page->materi->CurrentValue ?>"<?= $Page->materi->editAttributes() ?>>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->tujuan_pembelajaran->Visible) { // tujuan_pembelajaran ?>
    <div id="r_tujuan_pembelajaran" class="form-group row">
        <label id="elh_penilaian_tujuan_pembelajaran" for="x_tujuan_pembelajaran" class="<?= $Page->LeftColumnClass ?>"><?= $Page->tujuan_pembelajaran->caption() ?><?= $Page->tujuan_pembelajaran->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->tujuan_pembelajaran->cellAttributes() ?>>
<span id="el_penilaian_tujuan_pembelajaran">
<div class="input-group ew-lookup-list" aria-describedby="x_tujuan_pembelajaran_help">
    <div class="form-control ew-lookup-text" tabindex="-1" id="lu_x_tujuan_pembelajaran"><?= EmptyValue(strval($Page->tujuan_pembelajaran->ViewValue)) ? $Language->phrase("PleaseSelect") : $Page->tujuan_pembelajaran->ViewValue ?></div>
    <div class="input-group-append">
        <button type="button" title="<?= HtmlEncode(str_replace("%s", RemoveHtml($Page->tujuan_pembelajaran->caption()), $Language->phrase("LookupLink", true))) ?>" class="ew-lookup-btn btn btn-default"<?= ($Page->tujuan_pembelajaran->ReadOnly || $Page->tujuan_pembelajaran->Disabled) ? " disabled" : "" ?> onclick="ew.modalLookupShow({lnk:this,el:'x_tujuan_pembelajaran[]',m:1,n:10});"><i class="fas fa-search ew-icon"></i></button>
    </div>
</div>
<div class="invalid-feedback"><?= $Page->tujuan_pembelajaran->getErrorMessage() ?></div>
<?= $Page->tujuan_pembelajaran->getCustomMessage() ?>
<?= $Page->tujuan_pembelajaran->Lookup->getParamTag($Page, "p_x_tujuan_pembelajaran") ?>
<input type="hidden" is="selection-list" data-table="penilaian" data-field="x_tujuan_pembelajaran" data-type="text" data-multiple="1" data-lookup="1" data-value-separator="<?= $Page->tujuan_pembelajaran->displayValueSeparatorAttribute() ?>" name="x_tujuan_pembelajaran[]" id="x_tujuan_pembelajaran[]" value="<?= $Page->tujuan_pembelajaran->CurrentValue ?>"<?= $Page->tujuan_pembelajaran->editAttributes() ?>>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->fase->Visible) { // fase ?>
    <div id="r_fase" class="form-group row">
        <label id="elh_penilaian_fase" class="<?= $Page->LeftColumnClass ?>"><?= $Page->fase->caption() ?><?= $Page->fase->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->fase->cellAttributes() ?>>
<span id="el_penilaian_fase">
<template id="tp_x_fase">
    <div class="custom-control custom-radio">
        <input type="radio" class="custom-control-input" data-table="penilaian" data-field="x_fase" name="x_fase" id="x_fase"<?= $Page->fase->editAttributes() ?>>
        <label class="custom-control-label"></label>
    </div>
</template>
<div id="dsl_x_fase" class="ew-item-list"></div>
<input type="hidden"
    is="selection-list"
    id="x_fase"
    name="x_fase"
    value="<?= HtmlEncode($Page->fase->CurrentValue) ?>"
    data-type="select-one"
    data-template="tp_x_fase"
    data-target="dsl_x_fase"
    data-repeatcolumn="5"
    class="form-control<?= $Page->fase->isInvalidClass() ?>"
    data-table="penilaian"
    data-field="x_fase"
    data-value-separator="<?= $Page->fase->displayValueSeparatorAttribute() ?>"
    <?= $Page->fase->editAttributes() ?>>
<?= $Page->fase->getCustomMessage() ?>
<div class="invalid-feedback"><?= $Page->fase->getErrorMessage() ?></div>
</span>
</div></div>
    </div>
<?php } ?>
</div><!-- /page* -->
<?php
    if (in_array("nilai_sumatif", explode(",", $Page->getCurrentDetailTable())) && $nilai_sumatif->DetailAdd) {
?>
<?php if ($Page->getCurrentDetailTable() != "") { ?>
<h4 class="ew-detail-caption"><?= $Language->tablePhrase("nilai_sumatif", "TblCaption") ?></h4>
<?php } ?>
<?php include_once "NilaiSumatifGrid.php" ?>
<?php } ?>
<?php
    if (in_array("nilai_formatif", explode(",", $Page->getCurrentDetailTable())) && $nilai_formatif->DetailAdd) {
?>
<?php if ($Page->getCurrentDetailTable() != "") { ?>
<h4 class="ew-detail-caption"><?= $Language->tablePhrase("nilai_formatif", "TblCaption") ?></h4>
<?php } ?>
<?php include_once "NilaiFormatifGrid.php" ?>
<?php } ?>
<?php if (!$Page->IsModal) { ?>
<div class="form-group row"><!-- buttons .form-group -->
    <div class="<?= $Page->OffsetColumnClass ?>"><!-- buttons offset -->
<button class="btn btn-primary ew-btn" name="btn-action" id="btn-action" type="submit"><?= $Language->phrase("AddBtn") ?></button>
<button class="btn btn-default ew-btn" name="btn-cancel" id="btn-cancel" type="button" data-href="<?= HtmlEncode(GetUrl($Page->getReturnUrl())) ?>"><?= $Language->phrase("CancelBtn") ?></button>
    </div><!-- /buttons offset -->
</div><!-- /buttons .form-group -->
<?php } ?>
</form>
<?php
$Page->showPageFooter();
echo GetDebugMessage();
?>
<script>
// Field event handlers
loadjs.ready("head", function() {
    ew.addEventHandlers("penilaian");
});
</script>
<script>
loadjs.ready("load", function () {
    // Write your table-specific startup script here, no need to add script tags.
});
</script>
