<?php

namespace ProjectManagement\prjProjectManagement;

// Page object
$ProjectmemberUpdate = &$Page;
?>
<script>
var currentTable = <?= JsonEncode($Page->toClientVar()) ?>;
ew.deepAssign(ew.vars, { tables: { projectmember: currentTable } });
var currentPageID = ew.PAGE_ID = "update";
var currentForm;
var fprojectmemberupdate;
loadjs.ready(["wrapper", "head"], function () {
    let $ = jQuery;
    let fields = currentTable.fields;

    // Form object
    let form = new ew.FormBuilder()
        .setId("fprojectmemberupdate")
        .setPageId("update")

        // Add fields
        .setFields([
            ["EmployeeID", [fields.EmployeeID.visible && fields.EmployeeID.required ? ew.Validators.required(fields.EmployeeID.caption) : null], fields.EmployeeID.isInvalid],
            ["RoleID", [fields.RoleID.visible && fields.RoleID.required ? ew.Validators.required(fields.RoleID.caption) : null], fields.RoleID.isInvalid],
            ["_ProjectID", [fields._ProjectID.visible && fields._ProjectID.required ? ew.Validators.required(fields._ProjectID.caption) : null], fields._ProjectID.isInvalid],
            ["Created_Date", [fields.Created_Date.visible && fields.Created_Date.required ? ew.Validators.required(fields.Created_Date.caption) : null], fields.Created_Date.isInvalid],
            ["Created_By", [fields.Created_By.visible && fields.Created_By.required ? ew.Validators.required(fields.Created_By.caption) : null], fields.Created_By.isInvalid],
            ["Last_Updated_Date", [fields.Last_Updated_Date.visible && fields.Last_Updated_Date.required ? ew.Validators.required(fields.Last_Updated_Date.caption) : null], fields.Last_Updated_Date.isInvalid],
            ["Last_Updated_By", [fields.Last_Updated_By.visible && fields.Last_Updated_By.required ? ew.Validators.required(fields.Last_Updated_By.caption) : null], fields.Last_Updated_By.isInvalid]
        ])

        // Form_CustomValidate
        .setCustomValidate(
            function (fobj) { // DO NOT CHANGE THIS LINE! (except for adding "async" keyword)!
                    // Your custom validation code here, return false if invalid.
                    return true;
                }
        )

        // Use JavaScript validation or not
        .setValidateRequired(ew.CLIENT_VALIDATE)

        // Dynamic selection lists
        .setLists({
            "EmployeeID": <?= $Page->EmployeeID->toClientList($Page) ?>,
            "RoleID": <?= $Page->RoleID->toClientList($Page) ?>,
            "_ProjectID": <?= $Page->_ProjectID->toClientList($Page) ?>,
        })
        .build();
    window[form.id] = form;
    currentForm = form;
    loadjs.done(form.id);
});
</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="fprojectmemberupdate" id="fprojectmemberupdate" class="<?= $Page->FormClassName ?>" action="<?= CurrentPageUrl(false) ?>" method="post" autocomplete="off">
<?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="projectmember">
<input type="hidden" name="action" id="action" value="update">
<input type="hidden" name="modal" value="<?= (int)$Page->IsModal ?>">
<?php foreach ($Page->RecKeys as $key) { ?>
<?php $keyvalue = is_array($key) ? implode(Config("COMPOSITE_KEY_SEPARATOR"), $key) : $key; ?>
<input type="hidden" name="key_m[]" value="<?= HtmlEncode($keyvalue) ?>">
<?php } ?>
<div id="tbl_projectmemberupdate" class="ew-update-div"><!-- page -->
    <?php if (!$Page->isConfirm()) { // Confirm page ?>
    <div class="form-check">
        <input type="checkbox" class="form-check-input" name="u" id="u" data-ew-action="select-all"><label class="form-check-label" for="u"><?= $Language->phrase("SelectAll") ?></label>
    </div>
    <?php } ?>
<?php if ($Page->EmployeeID->Visible && (!$Page->isConfirm() || $Page->EmployeeID->multiUpdateSelected())) { // EmployeeID ?>
    <div id="r_EmployeeID"<?= $Page->EmployeeID->rowAttributes() ?>>
        <label for="x_EmployeeID" class="<?= $Page->LeftColumnClass ?>">
            <div class="form-check">
                <input type="checkbox" name="u_EmployeeID" id="u_EmployeeID" class="form-check-input ew-multi-select" value="1"<?= $Page->EmployeeID->multiUpdateSelected() ? " checked" : "" ?>>
                <label class="form-check-label" for="u_EmployeeID"><?= $Page->EmployeeID->caption() ?></label>
            </div>
        </label>
        <div class="<?= $Page->RightColumnClass ?>">
            <div<?= $Page->EmployeeID->cellAttributes() ?>>
                <span id="el_projectmember_EmployeeID">
                    <select
                        id="x_EmployeeID"
                        name="x_EmployeeID"
                        class="form-select ew-select<?= $Page->EmployeeID->isInvalidClass() ?>"
                        <?php if (!$Page->EmployeeID->IsNativeSelect) { ?>
                        data-select2-id="fprojectmemberupdate_x_EmployeeID"
                        <?php } ?>
                        data-table="projectmember"
                        data-field="x_EmployeeID"
                        data-value-separator="<?= $Page->EmployeeID->displayValueSeparatorAttribute() ?>"
                        data-placeholder="<?= HtmlEncode($Page->EmployeeID->getPlaceHolder()) ?>"
                        <?= $Page->EmployeeID->editAttributes() ?>>
                        <?= $Page->EmployeeID->selectOptionListHtml("x_EmployeeID") ?>
                    </select>
                    <?= $Page->EmployeeID->getCustomMessage() ?>
                    <div class="invalid-feedback"><?= $Page->EmployeeID->getErrorMessage() ?></div>
                <?= $Page->EmployeeID->Lookup->getParamTag($Page, "p_x_EmployeeID") ?>
                <?php if (!$Page->EmployeeID->IsNativeSelect) { ?>
                <script>
                loadjs.ready("fprojectmemberupdate", function() {
                    var options = { name: "x_EmployeeID", selectId: "fprojectmemberupdate_x_EmployeeID" },
                        el = document.querySelector("select[data-select2-id='" + options.selectId + "']");
                    if (!el)
                        return;
                    options.closeOnSelect = !options.multiple;
                    options.dropdownParent = el.closest("#ew-modal-dialog, #ew-add-opt-dialog");
                    if (fprojectmemberupdate.lists.EmployeeID?.lookupOptions.length) {
                        options.data = { id: "x_EmployeeID", form: "fprojectmemberupdate" };
                    } else {
                        options.ajax = { id: "x_EmployeeID", form: "fprojectmemberupdate", limit: ew.LOOKUP_PAGE_SIZE };
                    }
                    options.minimumInputLength = ew.selectMinimumInputLength;
                    options = Object.assign({}, ew.selectOptions, options, ew.vars.tables.projectmember.fields.EmployeeID.selectOptions);
                    ew.createSelect(options);
                });
                </script>
                <?php } ?>
                </span>
            </div>
        </div>
    </div>
<?php } ?>
<?php if ($Page->RoleID->Visible && (!$Page->isConfirm() || $Page->RoleID->multiUpdateSelected())) { // RoleID ?>
    <div id="r_RoleID"<?= $Page->RoleID->rowAttributes() ?>>
        <label for="x_RoleID" class="<?= $Page->LeftColumnClass ?>">
            <div class="form-check">
                <input type="checkbox" name="u_RoleID" id="u_RoleID" class="form-check-input ew-multi-select" value="1"<?= $Page->RoleID->multiUpdateSelected() ? " checked" : "" ?>>
                <label class="form-check-label" for="u_RoleID"><?= $Page->RoleID->caption() ?></label>
            </div>
        </label>
        <div class="<?= $Page->RightColumnClass ?>">
            <div<?= $Page->RoleID->cellAttributes() ?>>
                <span id="el_projectmember_RoleID">
                    <select
                        id="x_RoleID"
                        name="x_RoleID"
                        class="form-select ew-select<?= $Page->RoleID->isInvalidClass() ?>"
                        <?php if (!$Page->RoleID->IsNativeSelect) { ?>
                        data-select2-id="fprojectmemberupdate_x_RoleID"
                        <?php } ?>
                        data-table="projectmember"
                        data-field="x_RoleID"
                        data-value-separator="<?= $Page->RoleID->displayValueSeparatorAttribute() ?>"
                        data-placeholder="<?= HtmlEncode($Page->RoleID->getPlaceHolder()) ?>"
                        <?= $Page->RoleID->editAttributes() ?>>
                        <?= $Page->RoleID->selectOptionListHtml("x_RoleID") ?>
                    </select>
                    <?= $Page->RoleID->getCustomMessage() ?>
                    <div class="invalid-feedback"><?= $Page->RoleID->getErrorMessage() ?></div>
                <?= $Page->RoleID->Lookup->getParamTag($Page, "p_x_RoleID") ?>
                <?php if (!$Page->RoleID->IsNativeSelect) { ?>
                <script>
                loadjs.ready("fprojectmemberupdate", function() {
                    var options = { name: "x_RoleID", selectId: "fprojectmemberupdate_x_RoleID" },
                        el = document.querySelector("select[data-select2-id='" + options.selectId + "']");
                    if (!el)
                        return;
                    options.closeOnSelect = !options.multiple;
                    options.dropdownParent = el.closest("#ew-modal-dialog, #ew-add-opt-dialog");
                    if (fprojectmemberupdate.lists.RoleID?.lookupOptions.length) {
                        options.data = { id: "x_RoleID", form: "fprojectmemberupdate" };
                    } else {
                        options.ajax = { id: "x_RoleID", form: "fprojectmemberupdate", limit: ew.LOOKUP_PAGE_SIZE };
                    }
                    options.minimumInputLength = ew.selectMinimumInputLength;
                    options = Object.assign({}, ew.selectOptions, options, ew.vars.tables.projectmember.fields.RoleID.selectOptions);
                    ew.createSelect(options);
                });
                </script>
                <?php } ?>
                </span>
            </div>
        </div>
    </div>
<?php } ?>
<?php if ($Page->_ProjectID->Visible && (!$Page->isConfirm() || $Page->_ProjectID->multiUpdateSelected())) { // ProjectID ?>
    <div id="r__ProjectID"<?= $Page->_ProjectID->rowAttributes() ?>>
        <label for="x__ProjectID" class="<?= $Page->LeftColumnClass ?>">
            <div class="form-check">
                <input type="checkbox" name="u__ProjectID" id="u__ProjectID" class="form-check-input ew-multi-select" value="1"<?= $Page->_ProjectID->multiUpdateSelected() ? " checked" : "" ?>>
                <label class="form-check-label" for="u__ProjectID"><?= $Page->_ProjectID->caption() ?></label>
            </div>
        </label>
        <div class="<?= $Page->RightColumnClass ?>">
            <div<?= $Page->_ProjectID->cellAttributes() ?>>
                <?php if ($Page->_ProjectID->getSessionValue() != "") { ?>
                <span<?= $Page->_ProjectID->viewAttributes() ?>>
                <span class="form-control-plaintext"><?= $Page->_ProjectID->getDisplayValue($Page->_ProjectID->ViewValue) ?></span></span>
                <input type="hidden" id="x__ProjectID" name="x__ProjectID" value="<?= HtmlEncode($Page->_ProjectID->CurrentValue) ?>" data-hidden="1">
                <?php } else { ?>
                <span id="el_projectmember__ProjectID">
                    <select
                        id="x__ProjectID"
                        name="x__ProjectID"
                        class="form-select ew-select<?= $Page->_ProjectID->isInvalidClass() ?>"
                        <?php if (!$Page->_ProjectID->IsNativeSelect) { ?>
                        data-select2-id="fprojectmemberupdate_x__ProjectID"
                        <?php } ?>
                        data-table="projectmember"
                        data-field="x__ProjectID"
                        data-value-separator="<?= $Page->_ProjectID->displayValueSeparatorAttribute() ?>"
                        data-placeholder="<?= HtmlEncode($Page->_ProjectID->getPlaceHolder()) ?>"
                        <?= $Page->_ProjectID->editAttributes() ?>>
                        <?= $Page->_ProjectID->selectOptionListHtml("x__ProjectID") ?>
                    </select>
                    <?= $Page->_ProjectID->getCustomMessage() ?>
                    <div class="invalid-feedback"><?= $Page->_ProjectID->getErrorMessage() ?></div>
                <?= $Page->_ProjectID->Lookup->getParamTag($Page, "p_x__ProjectID") ?>
                <?php if (!$Page->_ProjectID->IsNativeSelect) { ?>
                <script>
                loadjs.ready("fprojectmemberupdate", function() {
                    var options = { name: "x__ProjectID", selectId: "fprojectmemberupdate_x__ProjectID" },
                        el = document.querySelector("select[data-select2-id='" + options.selectId + "']");
                    if (!el)
                        return;
                    options.closeOnSelect = !options.multiple;
                    options.dropdownParent = el.closest("#ew-modal-dialog, #ew-add-opt-dialog");
                    if (fprojectmemberupdate.lists._ProjectID?.lookupOptions.length) {
                        options.data = { id: "x__ProjectID", form: "fprojectmemberupdate" };
                    } else {
                        options.ajax = { id: "x__ProjectID", form: "fprojectmemberupdate", limit: ew.LOOKUP_PAGE_SIZE };
                    }
                    options.minimumInputLength = ew.selectMinimumInputLength;
                    options = Object.assign({}, ew.selectOptions, options, ew.vars.tables.projectmember.fields._ProjectID.selectOptions);
                    ew.createSelect(options);
                });
                </script>
                <?php } ?>
                </span>
                <?php } ?>
            </div>
        </div>
    </div>
<?php } ?>
</div><!-- /page -->
<?= $Page->IsModal ? '<template class="ew-modal-buttons">' : '<div class="row ew-buttons">' ?><!-- buttons .row -->
    <div class="<?= $Page->OffsetColumnClass ?>"><!-- buttons offset -->
<button class="btn btn-primary ew-btn" name="btn-action" id="btn-action" type="submit" form="fprojectmemberupdate"><?= $Language->phrase("UpdateBtn") ?></button>
<button class="btn btn-default ew-btn" name="btn-cancel" id="btn-cancel" type="button" form="fprojectmemberupdate" data-href="<?= HtmlEncode(GetUrl($Page->getReturnUrl())) ?>"><?= $Language->phrase("CancelBtn") ?></button>
    </div><!-- /buttons offset -->
<?= $Page->IsModal ? "</template>" : "</div>" ?><!-- /buttons .row -->
</form>
<?php
$Page->showPageFooter();
echo GetDebugMessage();
?>
<script>
// Field event handlers
loadjs.ready("head", function() {
    ew.addEventHandlers("projectmember");
});
</script>
<script>
loadjs.ready("load", function () {
    // Write your table-specific startup script here, no need to add script tags.
});
</script>
