<?php

namespace PHPMaker2021\rdigital21;

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

    // Add fields
    var currentTable = <?= JsonEncode(GetClientVar("tables", "proyek")) ?>,
        fields = currentTable.fields;
    if (!ew.vars.tables.proyek)
        ew.vars.tables.proyek = currentTable;
    fproyekadd.addFields([
        ["tahun_pelajaran", [fields.tahun_pelajaran.visible && fields.tahun_pelajaran.required ? ew.Validators.required(fields.tahun_pelajaran.caption) : null], fields.tahun_pelajaran.isInvalid],
        ["kelas", [fields.kelas.visible && fields.kelas.required ? ew.Validators.required(fields.kelas.caption) : null], fields.kelas.isInvalid],
        ["project", [fields.project.visible && fields.project.required ? ew.Validators.required(fields.project.caption) : null], fields.project.isInvalid],
        ["nama_proyek", [fields.nama_proyek.visible && fields.nama_proyek.required ? ew.Validators.required(fields.nama_proyek.caption) : null], fields.nama_proyek.isInvalid],
        ["tema", [fields.tema.visible && fields.tema.required ? ew.Validators.required(fields.tema.caption) : null], fields.tema.isInvalid],
        ["dimensi", [fields.dimensi.visible && fields.dimensi.required ? ew.Validators.required(fields.dimensi.caption) : null], fields.dimensi.isInvalid],
        ["deskripsi_proyek", [fields.deskripsi_proyek.visible && fields.deskripsi_proyek.required ? ew.Validators.required(fields.deskripsi_proyek.caption) : null], fields.deskripsi_proyek.isInvalid]
    ]);

    // Set invalid fields
    $(function() {
        var f = fproyekadd,
            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
    fproyekadd.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
    fproyekadd.customValidate = function(fobj) { // DO NOT CHANGE THIS LINE!
        // Your custom validation code here, return false if invalid.
        return true;
    }

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

    // Dynamic selection lists
    fproyekadd.lists.tahun_pelajaran = <?= $Page->tahun_pelajaran->toClientList($Page) ?>;
    fproyekadd.lists.kelas = <?= $Page->kelas->toClientList($Page) ?>;
    fproyekadd.lists.project = <?= $Page->project->toClientList($Page) ?>;
    fproyekadd.lists.tema = <?= $Page->tema->toClientList($Page) ?>;
    fproyekadd.lists.dimensi = <?= $Page->dimensi->toClientList($Page) ?>;
    loadjs.done("fproyekadd");
});
</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="fproyekadd" id="fproyekadd" 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="proyek">
<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->tahun_pelajaran->Visible) { // tahun_pelajaran ?>
    <div id="r_tahun_pelajaran" class="form-group row">
        <label id="elh_proyek_tahun_pelajaran" for="x_tahun_pelajaran" class="<?= $Page->LeftColumnClass ?>"><?= $Page->tahun_pelajaran->caption() ?><?= $Page->tahun_pelajaran->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->tahun_pelajaran->cellAttributes() ?>>
<span id="el_proyek_tahun_pelajaran">
    <select
        id="x_tahun_pelajaran"
        name="x_tahun_pelajaran"
        class="form-control ew-select<?= $Page->tahun_pelajaran->isInvalidClass() ?>"
        data-select2-id="proyek_x_tahun_pelajaran"
        data-table="proyek"
        data-field="x_tahun_pelajaran"
        data-value-separator="<?= $Page->tahun_pelajaran->displayValueSeparatorAttribute() ?>"
        <?= $Page->tahun_pelajaran->editAttributes() ?>>
        <?= $Page->tahun_pelajaran->selectOptionListHtml("x_tahun_pelajaran") ?>
    </select>
    <?= $Page->tahun_pelajaran->getCustomMessage() ?>
    <div class="invalid-feedback"><?= $Page->tahun_pelajaran->getErrorMessage() ?></div>
<?= $Page->tahun_pelajaran->Lookup->getParamTag($Page, "p_x_tahun_pelajaran") ?>
<script>
loadjs.ready("head", function() {
    var el = document.querySelector("select[data-select2-id='proyek_x_tahun_pelajaran']"),
        options = { name: "x_tahun_pelajaran", selectId: "proyek_x_tahun_pelajaran", 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.proyek.fields.tahun_pelajaran.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_proyek_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_proyek_kelas">
    <select
        id="x_kelas"
        name="x_kelas"
        class="form-control ew-select<?= $Page->kelas->isInvalidClass() ?>"
        data-select2-id="proyek_x_kelas"
        data-table="proyek"
        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='proyek_x_kelas']"),
        options = { name: "x_kelas", selectId: "proyek_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.proyek.fields.kelas.selectOptions);
    ew.createSelect(options);
});
</script>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->project->Visible) { // project ?>
    <div id="r_project" class="form-group row">
        <label id="elh_proyek_project" for="x_project" class="<?= $Page->LeftColumnClass ?>"><?= $Page->project->caption() ?><?= $Page->project->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->project->cellAttributes() ?>>
<span id="el_proyek_project">
    <select
        id="x_project"
        name="x_project"
        class="form-control ew-select<?= $Page->project->isInvalidClass() ?>"
        data-select2-id="proyek_x_project"
        data-table="proyek"
        data-field="x_project"
        data-value-separator="<?= $Page->project->displayValueSeparatorAttribute() ?>"
        <?= $Page->project->editAttributes() ?>>
        <?= $Page->project->selectOptionListHtml("x_project") ?>
    </select>
    <?= $Page->project->getCustomMessage() ?>
    <div class="invalid-feedback"><?= $Page->project->getErrorMessage() ?></div>
<script>
loadjs.ready("head", function() {
    var el = document.querySelector("select[data-select2-id='proyek_x_project']"),
        options = { name: "x_project", selectId: "proyek_x_project", language: ew.LANGUAGE_ID, dir: ew.IS_RTL ? "rtl" : "ltr" };
    options.data = ew.vars.tables.proyek.fields.project.lookupOptions;
    options.dropdownParent = $(el).closest("#ew-modal-dialog, #ew-add-opt-dialog")[0];
    Object.assign(options, ew.vars.tables.proyek.fields.project.selectOptions);
    ew.createSelect(options);
});
</script>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->nama_proyek->Visible) { // nama_proyek ?>
    <div id="r_nama_proyek" class="form-group row">
        <label id="elh_proyek_nama_proyek" for="x_nama_proyek" class="<?= $Page->LeftColumnClass ?>"><?= $Page->nama_proyek->caption() ?><?= $Page->nama_proyek->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->nama_proyek->cellAttributes() ?>>
<span id="el_proyek_nama_proyek">
<input type="<?= $Page->nama_proyek->getInputTextType() ?>" data-table="proyek" data-field="x_nama_proyek" name="x_nama_proyek" id="x_nama_proyek" size="30" maxlength="255" value="<?= $Page->nama_proyek->EditValue ?>"<?= $Page->nama_proyek->editAttributes() ?> aria-describedby="x_nama_proyek_help">
<?= $Page->nama_proyek->getCustomMessage() ?>
<div class="invalid-feedback"><?= $Page->nama_proyek->getErrorMessage() ?></div>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->tema->Visible) { // tema ?>
    <div id="r_tema" class="form-group row">
        <label id="elh_proyek_tema" for="x_tema" class="<?= $Page->LeftColumnClass ?>"><?= $Page->tema->caption() ?><?= $Page->tema->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->tema->cellAttributes() ?>>
<span id="el_proyek_tema">
    <select
        id="x_tema"
        name="x_tema"
        class="form-control ew-select<?= $Page->tema->isInvalidClass() ?>"
        data-select2-id="proyek_x_tema"
        data-table="proyek"
        data-field="x_tema"
        data-value-separator="<?= $Page->tema->displayValueSeparatorAttribute() ?>"
        <?= $Page->tema->editAttributes() ?>>
        <?= $Page->tema->selectOptionListHtml("x_tema") ?>
    </select>
    <?= $Page->tema->getCustomMessage() ?>
    <div class="invalid-feedback"><?= $Page->tema->getErrorMessage() ?></div>
<?= $Page->tema->Lookup->getParamTag($Page, "p_x_tema") ?>
<script>
loadjs.ready("head", function() {
    var el = document.querySelector("select[data-select2-id='proyek_x_tema']"),
        options = { name: "x_tema", selectId: "proyek_x_tema", 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.proyek.fields.tema.selectOptions);
    ew.createSelect(options);
});
</script>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->dimensi->Visible) { // dimensi ?>
    <div id="r_dimensi" class="form-group row">
        <label id="elh_proyek_dimensi" for="x_dimensi" class="<?= $Page->LeftColumnClass ?>"><?= $Page->dimensi->caption() ?><?= $Page->dimensi->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->dimensi->cellAttributes() ?>>
<span id="el_proyek_dimensi">
<div class="input-group ew-lookup-list" aria-describedby="x_dimensi_help">
    <div class="form-control ew-lookup-text" tabindex="-1" id="lu_x_dimensi"><?= EmptyValue(strval($Page->dimensi->ViewValue)) ? $Language->phrase("PleaseSelect") : $Page->dimensi->ViewValue ?></div>
    <div class="input-group-append">
        <button type="button" title="<?= HtmlEncode(str_replace("%s", RemoveHtml($Page->dimensi->caption()), $Language->phrase("LookupLink", true))) ?>" class="ew-lookup-btn btn btn-default"<?= ($Page->dimensi->ReadOnly || $Page->dimensi->Disabled) ? " disabled" : "" ?> onclick="ew.modalLookupShow({lnk:this,el:'x_dimensi[]',m:1,n:10});"><i class="fas fa-search ew-icon"></i></button>
    </div>
</div>
<div class="invalid-feedback"><?= $Page->dimensi->getErrorMessage() ?></div>
<?= $Page->dimensi->getCustomMessage() ?>
<?= $Page->dimensi->Lookup->getParamTag($Page, "p_x_dimensi") ?>
<input type="hidden" is="selection-list" data-table="proyek" data-field="x_dimensi" data-type="text" data-multiple="1" data-lookup="1" data-value-separator="<?= $Page->dimensi->displayValueSeparatorAttribute() ?>" name="x_dimensi[]" id="x_dimensi[]" value="<?= $Page->dimensi->CurrentValue ?>"<?= $Page->dimensi->editAttributes() ?>>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->deskripsi_proyek->Visible) { // deskripsi_proyek ?>
    <div id="r_deskripsi_proyek" class="form-group row">
        <label id="elh_proyek_deskripsi_proyek" for="x_deskripsi_proyek" class="<?= $Page->LeftColumnClass ?>"><?= $Page->deskripsi_proyek->caption() ?><?= $Page->deskripsi_proyek->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div <?= $Page->deskripsi_proyek->cellAttributes() ?>>
<span id="el_proyek_deskripsi_proyek">
<textarea data-table="proyek" data-field="x_deskripsi_proyek" name="x_deskripsi_proyek" id="x_deskripsi_proyek" cols="35" rows="4"<?= $Page->deskripsi_proyek->editAttributes() ?> aria-describedby="x_deskripsi_proyek_help"><?= $Page->deskripsi_proyek->EditValue ?></textarea>
<?= $Page->deskripsi_proyek->getCustomMessage() ?>
<div class="invalid-feedback"><?= $Page->deskripsi_proyek->getErrorMessage() ?></div>
</span>
</div></div>
    </div>
<?php } ?>
</div><!-- /page* -->
<?php
    if (in_array("nilai_p5", explode(",", $Page->getCurrentDetailTable())) && $nilai_p5->DetailAdd) {
?>
<?php if ($Page->getCurrentDetailTable() != "") { ?>
<h4 class="ew-detail-caption"><?= $Language->tablePhrase("nilai_p5", "TblCaption") ?></h4>
<?php } ?>
<?php include_once "NilaiP5Grid.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("proyek");
});
</script>
<script>
loadjs.ready("load", function () {
    // Write your table-specific startup script here, no need to add script tags.
});
</script>
