<?php

namespace ProjectManagement\prjProjectManagement;

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

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

        // Add fields
        .setFields([
            ["Activities", [fields.Activities.visible && fields.Activities.required ? ew.Validators.required(fields.Activities.caption) : null], fields.Activities.isInvalid],
            ["Category", [fields.Category.visible && fields.Category.required ? ew.Validators.required(fields.Category.caption) : null], fields.Category.isInvalid],
            ["Weight", [fields.Weight.visible && fields.Weight.required ? ew.Validators.required(fields.Weight.caption) : null, ew.Validators.integer, ew.Validators.selected], fields.Weight.isInvalid],
            ["Description", [fields.Description.visible && fields.Description.required ? ew.Validators.required(fields.Description.caption) : null], fields.Description.isInvalid],
            ["File", [fields.File.visible && fields.File.required ? ew.Validators.fileRequired(fields.File.caption) : null], fields.File.isInvalid],
            ["templateid", [fields.templateid.visible && fields.templateid.required ? ew.Validators.required(fields.templateid.caption) : null], fields.templateid.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({
            "Category": <?= $Page->Category->toClientList($Page) ?>,
            "templateid": <?= $Page->templateid->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="fprojecttemplateresultupdate" id="fprojecttemplateresultupdate" 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="projecttemplateresult">
<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_projecttemplateresultupdate" 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->Activities->Visible && (!$Page->isConfirm() || $Page->Activities->multiUpdateSelected())) { // Activities ?>
    <div id="r_Activities"<?= $Page->Activities->rowAttributes() ?>>
        <label for="x_Activities" class="<?= $Page->LeftColumnClass ?>">
            <div class="form-check">
                <input type="checkbox" name="u_Activities" id="u_Activities" class="form-check-input ew-multi-select" value="1"<?= $Page->Activities->multiUpdateSelected() ? " checked" : "" ?>>
                <label class="form-check-label" for="u_Activities"><?= $Page->Activities->caption() ?></label>
            </div>
        </label>
        <div class="<?= $Page->RightColumnClass ?>">
            <div<?= $Page->Activities->cellAttributes() ?>>
                <span id="el_projecttemplateresult_Activities">
                <input type="<?= $Page->Activities->getInputTextType() ?>" name="x_Activities" id="x_Activities" data-table="projecttemplateresult" data-field="x_Activities" value="<?= $Page->Activities->EditValue ?>" maxlength="500" placeholder="<?= HtmlEncode($Page->Activities->getPlaceHolder()) ?>" data-format-pattern="<?= HtmlEncode($Page->Activities->formatPattern()) ?>"<?= $Page->Activities->editAttributes() ?> aria-describedby="x_Activities_help">
                <?= $Page->Activities->getCustomMessage() ?>
                <div class="invalid-feedback"><?= $Page->Activities->getErrorMessage() ?></div>
                </span>
            </div>
        </div>
    </div>
<?php } ?>
<?php if ($Page->Category->Visible && (!$Page->isConfirm() || $Page->Category->multiUpdateSelected())) { // Category ?>
    <div id="r_Category"<?= $Page->Category->rowAttributes() ?>>
        <label for="x_Category" class="<?= $Page->LeftColumnClass ?>">
            <div class="form-check">
                <input type="checkbox" name="u_Category" id="u_Category" class="form-check-input ew-multi-select" value="1"<?= $Page->Category->multiUpdateSelected() ? " checked" : "" ?>>
                <label class="form-check-label" for="u_Category"><?= $Page->Category->caption() ?></label>
            </div>
        </label>
        <div class="<?= $Page->RightColumnClass ?>">
            <div<?= $Page->Category->cellAttributes() ?>>
                <span id="el_projecttemplateresult_Category">
                    <select
                        id="x_Category"
                        name="x_Category"
                        class="form-select ew-select<?= $Page->Category->isInvalidClass() ?>"
                        <?php if (!$Page->Category->IsNativeSelect) { ?>
                        data-select2-id="fprojecttemplateresultupdate_x_Category"
                        <?php } ?>
                        data-table="projecttemplateresult"
                        data-field="x_Category"
                        data-value-separator="<?= $Page->Category->displayValueSeparatorAttribute() ?>"
                        data-placeholder="<?= HtmlEncode($Page->Category->getPlaceHolder()) ?>"
                        <?= $Page->Category->editAttributes() ?>>
                        <?= $Page->Category->selectOptionListHtml("x_Category") ?>
                    </select>
                    <?= $Page->Category->getCustomMessage() ?>
                    <div class="invalid-feedback"><?= $Page->Category->getErrorMessage() ?></div>
                <?= $Page->Category->Lookup->getParamTag($Page, "p_x_Category") ?>
                <?php if (!$Page->Category->IsNativeSelect) { ?>
                <script>
                loadjs.ready("fprojecttemplateresultupdate", function() {
                    var options = { name: "x_Category", selectId: "fprojecttemplateresultupdate_x_Category" },
                        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 (fprojecttemplateresultupdate.lists.Category?.lookupOptions.length) {
                        options.data = { id: "x_Category", form: "fprojecttemplateresultupdate" };
                    } else {
                        options.ajax = { id: "x_Category", form: "fprojecttemplateresultupdate", limit: ew.LOOKUP_PAGE_SIZE };
                    }
                    options.minimumInputLength = ew.selectMinimumInputLength;
                    options = Object.assign({}, ew.selectOptions, options, ew.vars.tables.projecttemplateresult.fields.Category.selectOptions);
                    ew.createSelect(options);
                });
                </script>
                <?php } ?>
                </span>
            </div>
        </div>
    </div>
<?php } ?>
<?php if ($Page->Weight->Visible && (!$Page->isConfirm() || $Page->Weight->multiUpdateSelected())) { // Weight ?>
    <div id="r_Weight"<?= $Page->Weight->rowAttributes() ?>>
        <label for="x_Weight" class="<?= $Page->LeftColumnClass ?>">
            <div class="form-check">
                <input type="checkbox" name="u_Weight" id="u_Weight" class="form-check-input ew-multi-select" value="1"<?= $Page->Weight->multiUpdateSelected() ? " checked" : "" ?>>
                <label class="form-check-label" for="u_Weight"><?= $Page->Weight->caption() ?></label>
            </div>
        </label>
        <div class="<?= $Page->RightColumnClass ?>">
            <div<?= $Page->Weight->cellAttributes() ?>>
                <span id="el_projecttemplateresult_Weight">
                <input type="<?= $Page->Weight->getInputTextType() ?>" name="x_Weight" id="x_Weight" data-table="projecttemplateresult" data-field="x_Weight" value="<?= $Page->Weight->EditValue ?>" size="30" placeholder="<?= HtmlEncode($Page->Weight->getPlaceHolder()) ?>" data-format-pattern="<?= HtmlEncode($Page->Weight->formatPattern()) ?>"<?= $Page->Weight->editAttributes() ?> aria-describedby="x_Weight_help">
                <?= $Page->Weight->getCustomMessage() ?>
                <div class="invalid-feedback"><?= $Page->Weight->getErrorMessage() ?></div>
                </span>
            </div>
        </div>
    </div>
<?php } ?>
<?php if ($Page->Description->Visible && (!$Page->isConfirm() || $Page->Description->multiUpdateSelected())) { // Description ?>
    <div id="r_Description"<?= $Page->Description->rowAttributes() ?>>
        <label class="<?= $Page->LeftColumnClass ?>">
            <div class="form-check">
                <input type="checkbox" name="u_Description" id="u_Description" class="form-check-input ew-multi-select" value="1"<?= $Page->Description->multiUpdateSelected() ? " checked" : "" ?>>
                <label class="form-check-label" for="u_Description"><?= $Page->Description->caption() ?></label>
            </div>
        </label>
        <div class="<?= $Page->RightColumnClass ?>">
            <div<?= $Page->Description->cellAttributes() ?>>
                <span id="el_projecttemplateresult_Description">
                <?php $Page->Description->EditAttrs->appendClass("editor"); ?>
                <textarea data-table="projecttemplateresult" data-field="x_Description" name="x_Description" id="x_Description" cols="35" rows="4" placeholder="<?= HtmlEncode($Page->Description->getPlaceHolder()) ?>"<?= $Page->Description->editAttributes() ?> aria-describedby="x_Description_help"><?= $Page->Description->EditValue ?></textarea>
                <?= $Page->Description->getCustomMessage() ?>
                <div class="invalid-feedback"><?= $Page->Description->getErrorMessage() ?></div>
                <script>
                loadjs.ready(["fprojecttemplateresultupdate", "editor"], function() {
                    ew.createEditor("fprojecttemplateresultupdate", "x_Description", 35, 4, <?= $Page->Description->ReadOnly || false ? "true" : "false" ?>);
                });
                </script>
                </span>
            </div>
        </div>
    </div>
<?php } ?>
<?php if ($Page->File->Visible && (!$Page->isConfirm() || $Page->File->multiUpdateSelected())) { // File ?>
    <div id="r_File"<?= $Page->File->rowAttributes() ?>>
        <label class="<?= $Page->LeftColumnClass ?>">
            <div class="form-check">
                <input type="checkbox" name="u_File" id="u_File" class="form-check-input ew-multi-select" value="1"<?= $Page->File->multiUpdateSelected() ? " checked" : "" ?>>
                <label class="form-check-label" for="u_File"><?= $Page->File->caption() ?></label>
            </div>
        </label>
        <div class="<?= $Page->RightColumnClass ?>">
            <div<?= $Page->File->cellAttributes() ?>>
                <span id="el_projecttemplateresult_File">
                <div id="fd_x_File" class="fileinput-button ew-file-drop-zone">
                    <input
                        type="file"
                        id="x_File"
                        name="x_File"
                        class="form-control ew-file-input"
                        title="<?= $Page->File->title() ?>"
                        lang="<?= CurrentLanguageID() ?>"
                        data-table="projecttemplateresult"
                        data-field="x_File"
                        data-size="500"
                        data-accept-file-types="<?= $Page->File->acceptFileTypes() ?>"
                        data-max-file-size="<?= $Page->File->UploadMaxFileSize ?>"
                        data-max-number-of-files="null"
                        data-disable-image-crop="<?= $Page->File->ImageCropper ? 0 : 1 ?>"
                        aria-describedby="x_File_help"
                        <?= ($Page->File->ReadOnly || $Page->File->Disabled) ? " disabled" : "" ?>
                        <?= $Page->File->editAttributes() ?>
                    >
                    <div class="text-body-secondary ew-file-text"><?= $Language->phrase("ChooseFile") ?></div>
                    <?= $Page->File->getCustomMessage() ?>
                    <div class="invalid-feedback"><?= $Page->File->getErrorMessage() ?></div>
                </div>
                <input type="hidden" name="fn_x_File" id= "fn_x_File" value="<?= $Page->File->Upload->FileName ?>">
                <input type="hidden" name="fa_x_File" id= "fa_x_File" value="<?= (Post("fa_x_File") == "0") ? "0" : "1" ?>">
                <table id="ft_x_File" class="table table-sm float-start ew-upload-table"><tbody class="files"></tbody></table>
                </span>
            </div>
        </div>
    </div>
<?php } ?>
<?php if ($Page->templateid->Visible && (!$Page->isConfirm() || $Page->templateid->multiUpdateSelected())) { // templateid ?>
    <div id="r_templateid"<?= $Page->templateid->rowAttributes() ?>>
        <label for="x_templateid" class="<?= $Page->LeftColumnClass ?>">
            <div class="form-check">
                <input type="checkbox" name="u_templateid" id="u_templateid" class="form-check-input ew-multi-select" value="1"<?= $Page->templateid->multiUpdateSelected() ? " checked" : "" ?>>
                <label class="form-check-label" for="u_templateid"><?= $Page->templateid->caption() ?></label>
            </div>
        </label>
        <div class="<?= $Page->RightColumnClass ?>">
            <div<?= $Page->templateid->cellAttributes() ?>>
                <?php if ($Page->templateid->getSessionValue() != "") { ?>
                <span<?= $Page->templateid->viewAttributes() ?>>
                <span class="form-control-plaintext"><?= $Page->templateid->getDisplayValue($Page->templateid->ViewValue) ?></span></span>
                <input type="hidden" id="x_templateid" name="x_templateid" value="<?= HtmlEncode($Page->templateid->CurrentValue) ?>" data-hidden="1">
                <?php } else { ?>
                <span id="el_projecttemplateresult_templateid">
                    <select
                        id="x_templateid"
                        name="x_templateid"
                        class="form-select ew-select<?= $Page->templateid->isInvalidClass() ?>"
                        <?php if (!$Page->templateid->IsNativeSelect) { ?>
                        data-select2-id="fprojecttemplateresultupdate_x_templateid"
                        <?php } ?>
                        data-table="projecttemplateresult"
                        data-field="x_templateid"
                        data-value-separator="<?= $Page->templateid->displayValueSeparatorAttribute() ?>"
                        data-placeholder="<?= HtmlEncode($Page->templateid->getPlaceHolder()) ?>"
                        <?= $Page->templateid->editAttributes() ?>>
                        <?= $Page->templateid->selectOptionListHtml("x_templateid") ?>
                    </select>
                    <?= $Page->templateid->getCustomMessage() ?>
                    <div class="invalid-feedback"><?= $Page->templateid->getErrorMessage() ?></div>
                <?= $Page->templateid->Lookup->getParamTag($Page, "p_x_templateid") ?>
                <?php if (!$Page->templateid->IsNativeSelect) { ?>
                <script>
                loadjs.ready("fprojecttemplateresultupdate", function() {
                    var options = { name: "x_templateid", selectId: "fprojecttemplateresultupdate_x_templateid" },
                        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 (fprojecttemplateresultupdate.lists.templateid?.lookupOptions.length) {
                        options.data = { id: "x_templateid", form: "fprojecttemplateresultupdate" };
                    } else {
                        options.ajax = { id: "x_templateid", form: "fprojecttemplateresultupdate", limit: ew.LOOKUP_PAGE_SIZE };
                    }
                    options.minimumInputLength = ew.selectMinimumInputLength;
                    options = Object.assign({}, ew.selectOptions, options, ew.vars.tables.projecttemplateresult.fields.templateid.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="fprojecttemplateresultupdate"><?= $Language->phrase("UpdateBtn") ?></button>
<button class="btn btn-default ew-btn" name="btn-cancel" id="btn-cancel" type="button" form="fprojecttemplateresultupdate" 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("projecttemplateresult");
});
</script>
<script>
loadjs.ready("load", function () {
    // Write your table-specific startup script here, no need to add script tags.
});
</script>
