diff options
Diffstat (limited to '_edit/index.php')
-rw-r--r-- | _edit/index.php | 97 |
1 files changed, 68 insertions, 29 deletions
diff --git a/_edit/index.php b/_edit/index.php index c2b72ff..330e8b3 100644 --- a/_edit/index.php +++ b/_edit/index.php @@ -45,20 +45,35 @@ if (isset($id)) { require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/header.php"; require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/navigation.php"; -if (!isset($_PROFILE["requests"][$id])): ?> <form method="post" action="/_edit/save/?id=<?= $id ?>" id="main-form"> <div class="container"> <br><br> + + <img src="/icons/save.svg" alt="" style="position: fixed; z-index: 99999999; opacity: 0; pointer-events: none;"> + <img src="/icons/save.svg?p" alt="" style="position: fixed; z-index: 99999999; opacity: 0; pointer-events: none;"> + <h1 id="btn-area-container" style="display: grid; grid-template-columns: 1fr max-content;"> <?php if ($id !== $_USER): ?> <span><?= getNameFromId($id) ?></span> <?php else: ?> <span><?= $data["nick_name"] ?? $data["first_name"] . " " . $data["last_name"] ?><?php if (isset($data["nick_name"]) && trim($data["nick_name"]) !== ""): ?> <small><small><small>(<?= $data["first_name"] . " " . $data["last_name"] ?>)</small></small></small><?php endif; ?></span> <?php endif; ?> - <span id="btn-area" class="btn-group"><a style="height: 38px;" id="form-btn" title="<?= l("lang_edit_save") ?>" class="btn btn-outline-primary btn-with-img <?= $_PROFILE["blocked"] >= 2 ? "disabled" : "" ?>" data-bs-toggle="tooltip"><img src="/icons/save.svg<?= $_PROFILE["blocked"] >= 2 ? "" : "?p" ?>" style="width: 24px;"></a><a style="height: 38px;" href="/<?= file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/people/" . $id . ".json") ? "people" : "articles" ?>/<?= $id ?>" class="btn btn-outline-dark btn-with-img" title="<?= l("lang_edit_cancel") ?>" data-bs-toggle="tooltip"><img src="/icons/close.svg" style="width: 24px;"></a></span> + <span id="btn-area" class="btn-group"><a style="height: 38px;" id="form-btn" title="<?= l("lang_edit_save") ?>" class="btn btn-outline-primary btn-with-img disabled" data-bs-toggle="tooltip"><img id="save-icon" src="/icons/save.svg" style="width: 24px;"></a><a style="height: 38px;" onclick="preview();" class="btn btn-outline-dark btn-with-img" title="<?= l("lang_edit_preview") ?>" data-bs-toggle="tooltip"><img src="/icons/preview.svg" style="width: 24px;"></a><a style="height: 38px;" href="/<?= file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/people/" . $id . ".json") ? "people" : "articles" ?>/<?= $id ?>" class="btn btn-outline-dark btn-with-img" title="<?= l("lang_edit_cancel") ?>" data-bs-toggle="tooltip"><img src="/icons/close.svg" style="width: 24px;"></a></span> </h1> + <?php if (isset($_PROFILE["requests"][$id])): ?> + <div class="alert alert-secondary"> + <p><b><?= l("lang_edit_alert_title") ?></b></p> + <?php + + $request = json_decode(pf_utf8_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/requests/" . $_PROFILE["requests"][$id] . ".json")), true); + + ?> + <?= str_replace("%1", timeAgo($request["date"]), l("lang_edit_alert_message")) ?> + </div> + <?php endif; ?> + <?php if ($self && $_PROFILE["blocked"] === 1): ?> <div class="alert alert-danger"><p><?= l("lang_blocked_own") ?></p><?= l("lang_blocked_error") ?></div> <?php elseif ($_PROFILE["blocked"] >= 2): ?> @@ -66,12 +81,26 @@ if (!isset($_PROFILE["requests"][$id])): <?php else: ?> <div> <!--suppress HtmlFormInputWithoutLabel --> - <textarea name="contents" id="editor-box" style="display: none;"><?php if (isset($data["contents"]) && trim($data["contents"] !== "")): ?><?= $data["contents"] ?><?php endif; ?></textarea> + <textarea name="contents" id="editor-box" style="display: none;"><?php if (isset($data["contents"]) && trim($data["contents"] !== "")): ?><?= isset($_PROFILE["requests"][$id]) ? json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/requests/" . $_PROFILE["requests"][$id] . ".json"), true)["contents"] : $data["contents"] ?><?php endif; ?></textarea> </div> <?php require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/editor.php"; ?> <script> + let originalContent = document.getElementById("editor-box").innerText; + + window.oneditorchange = (content) => { + if (content !== originalContent) { + document.getElementById("form-btn").classList.remove("disabled"); + document.getElementById("save-icon").src = "/icons/save.svg?p"; + startHook(); + } else { + document.getElementById("form-btn").classList.add("disabled"); + document.getElementById("save-icon").src = "/icons/save.svg"; + stopHook(); + } + } + document.getElementById("form-btn").onclick = (event) => { new bootstrap.Modal(document.getElementById("<?= $id !== $_USER ? "confirm" : "confirm2" ?>")).show() } @@ -94,15 +123,28 @@ if (!isset($_PROFILE["requests"][$id])): <p> <?= l("lang_edit_confirm_summary") ?><br> <!--suppress HtmlFormInputWithoutLabel --> - <textarea class="form-control" name="summary"></textarea> + <textarea class="form-control" name="summary"><?= isset($_PROFILE["requests"][$id]) ? json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/requests/" . $_PROFILE["requests"][$id] . ".json"), true)["summary"] : "" ?></textarea> </p> <p><?= l("lang_edit_confirm_followup") ?></p> - <button class="btn btn-primary"><?= l("lang_edit_confirm_button") ?></button> + <button class="btn btn-primary" onclick="stopHook();"><?= l("lang_edit_confirm_button") ?></button> </div> </div> </div> </div> + <div class="modal fade" id="preview"> + <div class="modal-dialog modal-xl"> + <div class="modal-content"> + <div class="modal-header"> + <h4 class="modal-title"><?= l("lang_edit_preview") ?></h4> + <button type="button" class="btn-close" data-bs-dismiss="modal"></button> + </div> + + <div class="modal-body" id="page-preview"></div> + </div> + </div> + </div> + <div class="modal fade" id="confirm2"> <div class="modal-dialog"> <div class="modal-content"> @@ -119,34 +161,31 @@ if (!isset($_PROFILE["requests"][$id])): </div> </div> </div> -</form> -<?php else: ?> - <div class="container"> - <br><br> - <h1 id="btn-area-container" style="display: grid; grid-template-columns: 1fr max-content;"> - <?php if ($id !== $_USER): ?> - <span><?= getNameFromId($id) ?></span> - <?php else: ?> - <span><?= $data["nick_name"] ?? $data["first_name"] . " " . $data["last_name"] ?><?php if (isset($data["nick_name"]) && trim($data["nick_name"]) !== ""): ?> <small><small><small>(<?= $data["first_name"] . " " . $data["last_name"] ?>)</small></small></small><?php endif; ?></span> - <?php endif; ?> - <span id="btn-area" class="btn-group"><a style="height: 38px;" id="form-btn" title="<?= l("lang_edit_save") ?>" class="btn btn-outline-primary btn-with-img disabled" data-bs-toggle="tooltip"><img src="/icons/save.svg" style="width: 24px;"></a><a style="height: 38px;" href="/<?= file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/people/" . $id . ".json") ? "people" : "articles" ?>/<?= $id ?>" class="btn btn-outline-dark btn-with-img" title="<?= l("lang_edit_cancel") ?>" data-bs-toggle="tooltip"><img src="/icons/close.svg" style="width: 24px;"></a></span> - </h1> - <div class="alert alert-warning"> - <p><b><?= l("lang_edit_alert_title") ?></b></p> - <?php + <script> + let hook = false; - $request = json_decode(pf_utf8_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/requests/" . $_PROFILE["requests"][$id] . ".json")), true); + window.onbeforeunload = function() { + if (hook) { + return ""; + } + } - ?> - <p><?= str_replace("%1", timeAgo($request["date"]), l("lang_edit_alert_message")) ?></p> - <?= l("lang_edit_alert_contents") ?> - </div> + function startHook() { + hook = true; + } - <?= doLinking($request["contents"]) ?> + function stopHook() { + hook = false; + } - <br><br> - </div> -<?php endif; ?> + let _preview = new bootstrap.Modal(document.getElementById("preview")); + + function preview() { + document.getElementById("page-preview").innerHTML = editor.getData(); + _preview.show(); + } + </script> +</form> <?php require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/footer.php"; ?>
\ No newline at end of file |