<?php

namespace ProjectManagement\prjProjectManagement;

// Page object
$ProjectmemberEdit = &$Page;
?>
<?php $Page->showPageHeader(); ?>
<?php
$Page->showMessage();
?>
<main class="edit">
<form name="fprojectmemberedit" id="fprojectmemberedit" class="<?= $Page->FormClassName ?>" action="<?= CurrentPageUrl(false) ?>" method="post" autocomplete="off">
<script>
var currentTable = <?= JsonEncode($Page->toClientVar()) ?>;
ew.deepAssign(ew.vars, { tables: { projectmember: currentTable } });
var currentPageID = ew.PAGE_ID = "edit";
var currentForm;
var fprojectmemberedit;
loadjs.ready(["wrapper", "head"], function () {
    let $ = jQuery;
    let fields = currentTable.fields;

    // Form object
    let form = new ew.FormBuilder()
        .setId("fprojectmemberedit")
        .setPageId("edit")

        // Add fields
        .setFields([
            ["MemberID", [fields.MemberID.visible && fields.MemberID.required ? ew.Validators.required(fields.MemberID.caption) : null], fields.MemberID.isInvalid],
            ["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 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 if (IsJsonResponse()) { ?>
<input type="hidden" name="json" value="1">
<?php } ?>
<input type="hidden" name="<?= $Page->OldKeyName ?>" value="<?= $Page->OldKey ?>">
<?php if ($Page->getCurrentMasterTable() == "masterproject") { ?>
<input type="hidden" name="<?= Config("TABLE_SHOW_MASTER") ?>" value="masterproject">
<input type="hidden" name="fk__ProjectID" value="<?= HtmlEncode($Page->_ProjectID->getSessionValue()) ?>">
<?php } ?>
<div class="ew-edit-div"><!-- page* -->
<?php if ($Page->MemberID->Visible) { // MemberID ?>
    <div id="r_MemberID"<?= $Page->MemberID->rowAttributes() ?>>
        <label id="elh_projectmember_MemberID" class="<?= $Page->LeftColumnClass ?>"><?= $Page->MemberID->caption() ?><?= $Page->MemberID->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div<?= $Page->MemberID->cellAttributes() ?>>
<span id="el_projectmember_MemberID">
<span<?= $Page->MemberID->viewAttributes() ?>>
<input type="text" readonly class="form-control-plaintext" value="<?= HtmlEncode(RemoveHtml($Page->MemberID->getDisplayValue($Page->MemberID->EditValue))) ?>"></span>
<input type="hidden" data-table="projectmember" data-field="x_MemberID" data-hidden="1" name="x_MemberID" id="x_MemberID" value="<?= HtmlEncode($Page->MemberID->CurrentValue) ?>">
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->EmployeeID->Visible) { // EmployeeID ?>
    <div id="r_EmployeeID"<?= $Page->EmployeeID->rowAttributes() ?>>
        <label id="elh_projectmember_EmployeeID" for="x_EmployeeID" class="<?= $Page->LeftColumnClass ?>"><?= $Page->EmployeeID->caption() ?><?= $Page->EmployeeID->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div<?= $Page->EmployeeID->cellAttributes() ?>>
<span id="el_projectmember_EmployeeID">
<div class="input-group flex-nowrap">
    <select
        id="x_EmployeeID"
        name="x_EmployeeID"
        class="form-select ew-select<?= $Page->EmployeeID->isInvalidClass() ?>"
        <?php if (!$Page->EmployeeID->IsNativeSelect) { ?>
        data-select2-id="fprojectmemberedit_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>
    <?php if (AllowAdd(CurrentProjectID() . "masteruser") && !$Page->EmployeeID->ReadOnly) { ?>
    <button type="button" class="btn btn-default ew-add-opt-btn" id="aol_x_EmployeeID" title="<?= HtmlTitle($Language->phrase("AddLink")) . "&nbsp;" . $Page->EmployeeID->caption() ?>" data-title="<?= $Page->EmployeeID->caption() ?>" data-ew-action="add-option" data-el="x_EmployeeID" data-url="<?= GetUrl("masteruseraddopt") ?>"><i class="fa-solid fa-plus ew-icon"></i></button>
    <?php } ?>
</div>
<?= $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("fprojectmemberedit", function() {
    var options = { name: "x_EmployeeID", selectId: "fprojectmemberedit_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 (fprojectmemberedit.lists.EmployeeID?.lookupOptions.length) {
        options.data = { id: "x_EmployeeID", form: "fprojectmemberedit" };
    } else {
        options.ajax = { id: "x_EmployeeID", form: "fprojectmemberedit", 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) { // RoleID ?>
    <div id="r_RoleID"<?= $Page->RoleID->rowAttributes() ?>>
        <label id="elh_projectmember_RoleID" for="x_RoleID" class="<?= $Page->LeftColumnClass ?>"><?= $Page->RoleID->caption() ?><?= $Page->RoleID->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div<?= $Page->RoleID->cellAttributes() ?>>
<span id="el_projectmember_RoleID">
<div class="input-group flex-nowrap">
    <select
        id="x_RoleID"
        name="x_RoleID"
        class="form-select ew-select<?= $Page->RoleID->isInvalidClass() ?>"
        <?php if (!$Page->RoleID->IsNativeSelect) { ?>
        data-select2-id="fprojectmemberedit_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>
    <?php if (AllowAdd(CurrentProjectID() . "masterrole") && !$Page->RoleID->ReadOnly) { ?>
    <button type="button" class="btn btn-default ew-add-opt-btn" id="aol_x_RoleID" title="<?= HtmlTitle($Language->phrase("AddLink")) . "&nbsp;" . $Page->RoleID->caption() ?>" data-title="<?= $Page->RoleID->caption() ?>" data-ew-action="add-option" data-el="x_RoleID" data-url="<?= GetUrl("masterroleaddopt") ?>"><i class="fa-solid fa-plus ew-icon"></i></button>
    <?php } ?>
</div>
<?= $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("fprojectmemberedit", function() {
    var options = { name: "x_RoleID", selectId: "fprojectmemberedit_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 (fprojectmemberedit.lists.RoleID?.lookupOptions.length) {
        options.data = { id: "x_RoleID", form: "fprojectmemberedit" };
    } else {
        options.ajax = { id: "x_RoleID", form: "fprojectmemberedit", 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) { // ProjectID ?>
    <div id="r__ProjectID"<?= $Page->_ProjectID->rowAttributes() ?>>
        <label id="elh_projectmember__ProjectID" for="x__ProjectID" class="<?= $Page->LeftColumnClass ?>"><?= $Page->_ProjectID->caption() ?><?= $Page->_ProjectID->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></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="fprojectmemberedit_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("fprojectmemberedit", function() {
    var options = { name: "x__ProjectID", selectId: "fprojectmemberedit_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 (fprojectmemberedit.lists._ProjectID?.lookupOptions.length) {
        options.data = { id: "x__ProjectID", form: "fprojectmemberedit" };
    } else {
        options.ajax = { id: "x__ProjectID", form: "fprojectmemberedit", 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* -->
<span id="el_projectmember_Created_Date">
<input type="hidden" data-table="projectmember" data-field="x_Created_Date" data-hidden="1" name="x_Created_Date" id="x_Created_Date" value="<?= HtmlEncode($Page->Created_Date->CurrentValue) ?>">
</span>
<span id="el_projectmember_Created_By">
<input type="hidden" data-table="projectmember" data-field="x_Created_By" data-hidden="1" name="x_Created_By" id="x_Created_By" value="<?= HtmlEncode($Page->Created_By->CurrentValue) ?>">
</span>
<?= $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="fprojectmemberedit"><?= $Language->phrase("SaveBtn") ?></button>
<?php if (IsJsonResponse()) { ?>
<button class="btn btn-default ew-btn" name="btn-cancel" id="btn-cancel" type="button" data-bs-dismiss="modal"><?= $Language->phrase("CancelBtn") ?></button>
<?php } else { ?>
<button class="btn btn-default ew-btn" name="btn-cancel" id="btn-cancel" type="button" form="fprojectmemberedit" data-href="<?= HtmlEncode(GetUrl($Page->getReturnUrl())) ?>"><?= $Language->phrase("CancelBtn") ?></button>
<?php } ?>
    </div><!-- /buttons offset -->
<?= $Page->IsModal ? "</template>" : "</div>" ?><!-- /buttons .row -->
</form>
</main>
<?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>
