<?php

namespace ProjectManagement\prjProjectManagement;

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

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

        // Add fields
        .setFields([
            ["ResultID", [fields.ResultID.visible && fields.ResultID.required ? ew.Validators.required(fields.ResultID.caption) : null], fields.ResultID.isInvalid],
            ["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], 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 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 if (IsJsonResponse()) { ?>
<input type="hidden" name="json" value="1">
<?php } ?>
<input type="hidden" name="<?= $Page->OldKeyName ?>" value="<?= $Page->OldKey ?>">
<?php if ($Page->getCurrentMasterTable() == "projecttemplate") { ?>
<input type="hidden" name="<?= Config("TABLE_SHOW_MASTER") ?>" value="projecttemplate">
<input type="hidden" name="fk_ID" value="<?= HtmlEncode($Page->templateid->getSessionValue()) ?>">
<?php } ?>
<div class="ew-edit-div"><!-- page* -->
<?php if ($Page->ResultID->Visible) { // ResultID ?>
    <div id="r_ResultID"<?= $Page->ResultID->rowAttributes() ?>>
        <label id="elh_projecttemplateresult_ResultID" class="<?= $Page->LeftColumnClass ?>"><?= $Page->ResultID->caption() ?><?= $Page->ResultID->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div<?= $Page->ResultID->cellAttributes() ?>>
<span id="el_projecttemplateresult_ResultID">
<span<?= $Page->ResultID->viewAttributes() ?>>
<input type="text" readonly class="form-control-plaintext" value="<?= HtmlEncode(RemoveHtml($Page->ResultID->getDisplayValue($Page->ResultID->EditValue))) ?>"></span>
<input type="hidden" data-table="projecttemplateresult" data-field="x_ResultID" data-hidden="1" name="x_ResultID" id="x_ResultID" value="<?= HtmlEncode($Page->ResultID->CurrentValue) ?>">
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->Activities->Visible) { // Activities ?>
    <div id="r_Activities"<?= $Page->Activities->rowAttributes() ?>>
        <label id="elh_projecttemplateresult_Activities" for="x_Activities" class="<?= $Page->LeftColumnClass ?>"><?= $Page->Activities->caption() ?><?= $Page->Activities->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></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) { // Category ?>
    <div id="r_Category"<?= $Page->Category->rowAttributes() ?>>
        <label id="elh_projecttemplateresult_Category" for="x_Category" class="<?= $Page->LeftColumnClass ?>"><?= $Page->Category->caption() ?><?= $Page->Category->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div<?= $Page->Category->cellAttributes() ?>>
<span id="el_projecttemplateresult_Category">
<div class="input-group flex-nowrap">
    <select
        id="x_Category"
        name="x_Category"
        class="form-select ew-select<?= $Page->Category->isInvalidClass() ?>"
        <?php if (!$Page->Category->IsNativeSelect) { ?>
        data-select2-id="fprojecttemplateresultedit_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>
    <?php if (AllowAdd(CurrentProjectID() . "masterprojectcategory") && !$Page->Category->ReadOnly) { ?>
    <button type="button" class="btn btn-default ew-add-opt-btn" id="aol_x_Category" title="<?= HtmlTitle($Language->phrase("AddLink")) . "&nbsp;" . $Page->Category->caption() ?>" data-title="<?= $Page->Category->caption() ?>" data-ew-action="add-option" data-el="x_Category" data-url="<?= GetUrl("masterprojectcategoryaddopt") ?>"><i class="fa-solid fa-plus ew-icon"></i></button>
    <?php } ?>
</div>
<?= $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("fprojecttemplateresultedit", function() {
    var options = { name: "x_Category", selectId: "fprojecttemplateresultedit_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 (fprojecttemplateresultedit.lists.Category?.lookupOptions.length) {
        options.data = { id: "x_Category", form: "fprojecttemplateresultedit" };
    } else {
        options.ajax = { id: "x_Category", form: "fprojecttemplateresultedit", 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) { // Weight ?>
    <div id="r_Weight"<?= $Page->Weight->rowAttributes() ?>>
        <label id="elh_projecttemplateresult_Weight" for="x_Weight" class="<?= $Page->LeftColumnClass ?>"><?= $Page->Weight->caption() ?><?= $Page->Weight->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></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) { // Description ?>
    <div id="r_Description"<?= $Page->Description->rowAttributes() ?>>
        <label id="elh_projecttemplateresult_Description" class="<?= $Page->LeftColumnClass ?>"><?= $Page->Description->caption() ?><?= $Page->Description->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></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(["fprojecttemplateresultedit", "editor"], function() {
    ew.createEditor("fprojecttemplateresultedit", "x_Description", 35, 4, <?= $Page->Description->ReadOnly || false ? "true" : "false" ?>);
});
</script>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->File->Visible) { // File ?>
    <div id="r_File"<?= $Page->File->rowAttributes() ?>>
        <label id="elh_projecttemplateresult_File" class="<?= $Page->LeftColumnClass ?>"><?= $Page->File->caption() ?><?= $Page->File->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></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) { // templateid ?>
    <div id="r_templateid"<?= $Page->templateid->rowAttributes() ?>>
        <label id="elh_projecttemplateresult_templateid" for="x_templateid" class="<?= $Page->LeftColumnClass ?>"><?= $Page->templateid->caption() ?><?= $Page->templateid->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></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">
<div class="input-group flex-nowrap">
    <select
        id="x_templateid"
        name="x_templateid"
        class="form-select ew-select<?= $Page->templateid->isInvalidClass() ?>"
        <?php if (!$Page->templateid->IsNativeSelect) { ?>
        data-select2-id="fprojecttemplateresultedit_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>
    <?php if (AllowAdd(CurrentProjectID() . "projecttemplate") && !$Page->templateid->ReadOnly) { ?>
    <button type="button" class="btn btn-default ew-add-opt-btn" id="aol_x_templateid" title="<?= HtmlTitle($Language->phrase("AddLink")) . "&nbsp;" . $Page->templateid->caption() ?>" data-title="<?= $Page->templateid->caption() ?>" data-ew-action="add-option" data-el="x_templateid" data-url="<?= GetUrl("projecttemplateaddopt") ?>"><i class="fa-solid fa-plus ew-icon"></i></button>
    <?php } ?>
</div>
<?= $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("fprojecttemplateresultedit", function() {
    var options = { name: "x_templateid", selectId: "fprojecttemplateresultedit_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 (fprojecttemplateresultedit.lists.templateid?.lookupOptions.length) {
        options.data = { id: "x_templateid", form: "fprojecttemplateresultedit" };
    } else {
        options.ajax = { id: "x_templateid", form: "fprojecttemplateresultedit", 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* -->
<span id="el_projecttemplateresult_Created_Date">
<input type="hidden" data-table="projecttemplateresult" 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_projecttemplateresult_Created_By">
<input type="hidden" data-table="projecttemplateresult" 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="fprojecttemplateresultedit"><?= $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="fprojecttemplateresultedit" 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("projecttemplateresult");
});
</script>
<script>
loadjs.ready("load", function () {
    // Write your table-specific startup script here, no need to add script tags.
});
</script>
