<?php

namespace ProjectManagement\prjProjectManagement;

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

    // Form object
    let form = new ew.FormBuilder()
        .setId("fprojectdocumentsadd")
        .setPageId("add")

        // Add fields
        .setFields([
            ["DocDate", [fields.DocDate.visible && fields.DocDate.required ? ew.Validators.required(fields.DocDate.caption) : null, ew.Validators.datetime(fields.DocDate.clientFormatPattern)], fields.DocDate.isInvalid],
            ["DocumentTitle", [fields.DocumentTitle.visible && fields.DocumentTitle.required ? ew.Validators.required(fields.DocumentTitle.caption) : null], fields.DocumentTitle.isInvalid],
            ["DocumentFile", [fields.DocumentFile.visible && fields.DocumentFile.required ? ew.Validators.fileRequired(fields.DocumentFile.caption) : null], fields.DocumentFile.isInvalid],
            ["DocumentType", [fields.DocumentType.visible && fields.DocumentType.required ? ew.Validators.required(fields.DocumentType.caption) : null], fields.DocumentType.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({
            "DocumentType": <?= $Page->DocumentType->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="fprojectdocumentsadd" id="fprojectdocumentsadd" 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="projectdocuments">
<input type="hidden" name="action" id="action" value="insert">
<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-add-div"><!-- page* -->
<?php if ($Page->DocDate->Visible) { // DocDate ?>
    <div id="r_DocDate"<?= $Page->DocDate->rowAttributes() ?>>
        <label id="elh_projectdocuments_DocDate" for="x_DocDate" class="<?= $Page->LeftColumnClass ?>"><?= $Page->DocDate->caption() ?><?= $Page->DocDate->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div<?= $Page->DocDate->cellAttributes() ?>>
<span id="el_projectdocuments_DocDate">
<input type="<?= $Page->DocDate->getInputTextType() ?>" name="x_DocDate" id="x_DocDate" data-table="projectdocuments" data-field="x_DocDate" value="<?= $Page->DocDate->EditValue ?>" placeholder="<?= HtmlEncode($Page->DocDate->getPlaceHolder()) ?>" data-format-pattern="<?= HtmlEncode($Page->DocDate->formatPattern()) ?>"<?= $Page->DocDate->editAttributes() ?> aria-describedby="x_DocDate_help">
<?= $Page->DocDate->getCustomMessage() ?>
<div class="invalid-feedback"><?= $Page->DocDate->getErrorMessage() ?></div>
<?php if (!$Page->DocDate->ReadOnly && !$Page->DocDate->Disabled && !isset($Page->DocDate->EditAttrs["readonly"]) && !isset($Page->DocDate->EditAttrs["disabled"])) { ?>
<script>
loadjs.ready(["fprojectdocumentsadd", "datetimepicker"], function () {
    let format = "<?= DateFormat(5) ?>",
        options = {
            localization: {
                locale: ew.LANGUAGE_ID + "-u-nu-" + ew.getNumberingSystem(),
                hourCycle: format.match(/H/) ? "h24" : "h12",
                format,
                ...ew.language.phrase("datetimepicker")
            },
            display: {
                icons: {
                    previous: ew.IS_RTL ? "fa-solid fa-chevron-right" : "fa-solid fa-chevron-left",
                    next: ew.IS_RTL ? "fa-solid fa-chevron-left" : "fa-solid fa-chevron-right"
                },
                components: {
                    hours: !!format.match(/h/i),
                    minutes: !!format.match(/m/),
                    seconds: !!format.match(/s/i)
                },
                theme: ew.getPreferredTheme()
            }
        };
    ew.createDateTimePicker("fprojectdocumentsadd", "x_DocDate", ew.deepAssign({"useCurrent":false,"display":{"sideBySide":false}}, options));
});
</script>
<?php } ?>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->DocumentTitle->Visible) { // DocumentTitle ?>
    <div id="r_DocumentTitle"<?= $Page->DocumentTitle->rowAttributes() ?>>
        <label id="elh_projectdocuments_DocumentTitle" for="x_DocumentTitle" class="<?= $Page->LeftColumnClass ?>"><?= $Page->DocumentTitle->caption() ?><?= $Page->DocumentTitle->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div<?= $Page->DocumentTitle->cellAttributes() ?>>
<span id="el_projectdocuments_DocumentTitle">
<input type="<?= $Page->DocumentTitle->getInputTextType() ?>" name="x_DocumentTitle" id="x_DocumentTitle" data-table="projectdocuments" data-field="x_DocumentTitle" value="<?= $Page->DocumentTitle->EditValue ?>" size="30" maxlength="255" placeholder="<?= HtmlEncode($Page->DocumentTitle->getPlaceHolder()) ?>" data-format-pattern="<?= HtmlEncode($Page->DocumentTitle->formatPattern()) ?>"<?= $Page->DocumentTitle->editAttributes() ?> aria-describedby="x_DocumentTitle_help">
<?= $Page->DocumentTitle->getCustomMessage() ?>
<div class="invalid-feedback"><?= $Page->DocumentTitle->getErrorMessage() ?></div>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->DocumentFile->Visible) { // DocumentFile ?>
    <div id="r_DocumentFile"<?= $Page->DocumentFile->rowAttributes() ?>>
        <label id="elh_projectdocuments_DocumentFile" class="<?= $Page->LeftColumnClass ?>"><?= $Page->DocumentFile->caption() ?><?= $Page->DocumentFile->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div<?= $Page->DocumentFile->cellAttributes() ?>>
<span id="el_projectdocuments_DocumentFile">
<div id="fd_x_DocumentFile" class="fileinput-button ew-file-drop-zone">
    <input
        type="file"
        id="x_DocumentFile"
        name="x_DocumentFile"
        class="form-control ew-file-input"
        title="<?= $Page->DocumentFile->title() ?>"
        lang="<?= CurrentLanguageID() ?>"
        data-table="projectdocuments"
        data-field="x_DocumentFile"
        data-size="500"
        data-accept-file-types="<?= $Page->DocumentFile->acceptFileTypes() ?>"
        data-max-file-size="<?= $Page->DocumentFile->UploadMaxFileSize ?>"
        data-max-number-of-files="null"
        data-disable-image-crop="<?= $Page->DocumentFile->ImageCropper ? 0 : 1 ?>"
        aria-describedby="x_DocumentFile_help"
        <?= ($Page->DocumentFile->ReadOnly || $Page->DocumentFile->Disabled) ? " disabled" : "" ?>
        <?= $Page->DocumentFile->editAttributes() ?>
    >
    <div class="text-body-secondary ew-file-text"><?= $Language->phrase("ChooseFile") ?></div>
    <?= $Page->DocumentFile->getCustomMessage() ?>
    <div class="invalid-feedback"><?= $Page->DocumentFile->getErrorMessage() ?></div>
</div>
<input type="hidden" name="fn_x_DocumentFile" id= "fn_x_DocumentFile" value="<?= $Page->DocumentFile->Upload->FileName ?>">
<input type="hidden" name="fa_x_DocumentFile" id= "fa_x_DocumentFile" value="0">
<table id="ft_x_DocumentFile" class="table table-sm float-start ew-upload-table"><tbody class="files"></tbody></table>
</span>
</div></div>
    </div>
<?php } ?>
<?php if ($Page->DocumentType->Visible) { // DocumentType ?>
    <div id="r_DocumentType"<?= $Page->DocumentType->rowAttributes() ?>>
        <label id="elh_projectdocuments_DocumentType" for="x_DocumentType" class="<?= $Page->LeftColumnClass ?>"><?= $Page->DocumentType->caption() ?><?= $Page->DocumentType->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
        <div class="<?= $Page->RightColumnClass ?>"><div<?= $Page->DocumentType->cellAttributes() ?>>
<span id="el_projectdocuments_DocumentType">
    <select
        id="x_DocumentType"
        name="x_DocumentType"
        class="form-select ew-select<?= $Page->DocumentType->isInvalidClass() ?>"
        <?php if (!$Page->DocumentType->IsNativeSelect) { ?>
        data-select2-id="fprojectdocumentsadd_x_DocumentType"
        <?php } ?>
        data-table="projectdocuments"
        data-field="x_DocumentType"
        data-value-separator="<?= $Page->DocumentType->displayValueSeparatorAttribute() ?>"
        data-placeholder="<?= HtmlEncode($Page->DocumentType->getPlaceHolder()) ?>"
        <?= $Page->DocumentType->editAttributes() ?>>
        <?= $Page->DocumentType->selectOptionListHtml("x_DocumentType") ?>
    </select>
    <?= $Page->DocumentType->getCustomMessage() ?>
    <div class="invalid-feedback"><?= $Page->DocumentType->getErrorMessage() ?></div>
<?php if (!$Page->DocumentType->IsNativeSelect) { ?>
<script>
loadjs.ready("fprojectdocumentsadd", function() {
    var options = { name: "x_DocumentType", selectId: "fprojectdocumentsadd_x_DocumentType" },
        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 (fprojectdocumentsadd.lists.DocumentType?.lookupOptions.length) {
        options.data = { id: "x_DocumentType", form: "fprojectdocumentsadd" };
    } else {
        options.ajax = { id: "x_DocumentType", form: "fprojectdocumentsadd", limit: ew.LOOKUP_PAGE_SIZE };
    }
    options.minimumInputLength = ew.selectMinimumInputLength;
    options = Object.assign({}, ew.selectOptions, options, ew.vars.tables.projectdocuments.fields.DocumentType.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_projectdocuments__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_projectdocuments__ProjectID">
    <select
        id="x__ProjectID"
        name="x__ProjectID"
        class="form-select ew-select<?= $Page->_ProjectID->isInvalidClass() ?>"
        <?php if (!$Page->_ProjectID->IsNativeSelect) { ?>
        data-select2-id="fprojectdocumentsadd_x__ProjectID"
        <?php } ?>
        data-table="projectdocuments"
        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("fprojectdocumentsadd", function() {
    var options = { name: "x__ProjectID", selectId: "fprojectdocumentsadd_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 (fprojectdocumentsadd.lists._ProjectID?.lookupOptions.length) {
        options.data = { id: "x__ProjectID", form: "fprojectdocumentsadd" };
    } else {
        options.ajax = { id: "x__ProjectID", form: "fprojectdocumentsadd", limit: ew.LOOKUP_PAGE_SIZE };
    }
    options.minimumInputLength = ew.selectMinimumInputLength;
    options = Object.assign({}, ew.selectOptions, options, ew.vars.tables.projectdocuments.fields._ProjectID.selectOptions);
    ew.createSelect(options);
});
</script>
<?php } ?>
</span>
<?php } ?>
</div></div>
    </div>
<?php } ?>
    <span id="el_projectdocuments_Created_Date">
    <input type="hidden" data-table="projectdocuments" 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_projectdocuments_Created_By">
    <input type="hidden" data-table="projectdocuments" data-field="x_Created_By" data-hidden="1" name="x_Created_By" id="x_Created_By" value="<?= HtmlEncode($Page->Created_By->CurrentValue) ?>">
    </span>
</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="fprojectdocumentsadd"><?= $Language->phrase("AddBtn") ?></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="fprojectdocumentsadd" data-href="<?= HtmlEncode(GetUrl($Page->getReturnUrl())) ?>"><?= $Language->phrase("CancelBtn") ?></button>
<?php } ?>
    </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("projectdocuments");
});
</script>
<script>
loadjs.ready("load", function () {
    // Write your table-specific startup script here, no need to add script tags.
});
</script>
