Improve behavior without JavaScript

master
Skylar Ittner 6 years ago
parent 258b6163df
commit 3d0129b647

@ -38,7 +38,6 @@ switch ($VARS['action']) {
if (!isset($VARS['content']) || empty($VARS['noteid'])) {
die($Strings->get("invalid parameters", false));
}
http_response_code(204);
$note = Note::loadNote($VARS['noteid']);
if (!$note->hasWriteAccess(new User($_SESSION['uid']))) {
die($Strings->get("invalid parameters", false));
@ -46,6 +45,11 @@ switch ($VARS['action']) {
$note->setText($VARS['content']);
$note->setColor($VARS['color']);
$note->saveNote();
if (isset($VARS['reload'])) {
returnToSender("", "&note=" . $note->getID());
} else {
http_response_code(204);
}
break;
case "deletenote":
if (empty($VARS['noteid'])) {

@ -8,6 +8,8 @@
"Note deleted": "Note deleted",
"Favorite": "Favorite",
"Set color": "Set color",
"Note color": "Note color",
"Cancel": "Cancel",
"Save": "Save"
"Save": "Save",
"Close": "Close"
}

@ -134,6 +134,7 @@ class Note {
* @return string
*/
public function getColor(): string {
$this->setColor($this->color);
return $this->color;
}
@ -240,6 +241,7 @@ class Note {
*/
public function setColor(string $color) {
$color = strtoupper($color);
$color = str_replace("#", "", $color);
// Make sure we have a valid RRGGBB hex
if (!preg_match("/[A-F0-9]{6}/", $color)) {
$color = "FFFFFF";

@ -1,5 +1,4 @@
<?php
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
@ -23,12 +22,25 @@ if ($note->getOwnerID() != $_SESSION['uid']) {
}
$note->saveNote();
?>
<form action="action.php" method="POST" id="noteform">
<textarea name="content" id="note_content"><?php echo $note->getText(); ?></textarea>
<textarea name="content" id="note_content" rows="10" class="form-control text-body"><?php echo $note->getText(); ?></textarea>
<input type="hidden" name="noteid" value="<?php echo $note->getID(); ?>" />
<input type="hidden" name="source" value="editnote" />
<input type="hidden" name="color" value="<?php echo $note->getColor(); ?>" />
<input type="hidden" name="action" value="savenote" />
<noscript>
<br />
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text"><?php $Strings->get("Note color"); ?></span>
</div>
<input class="form-control" type="color" name="color" value="#<?php echo $note->getColor(); ?>" />
</div>
<button type="submit" class="btn btn-success"><?php $Strings->get("Save"); ?></button>
<a href="./app.php?page=home" class="btn btn-default"><?php $Strings->get("Close"); ?></a>
<!-- Actually reload the page, otherwise Links gives an error -->
<input type="hidden" name="reload" value="1" />
</noscript>
</form>

@ -56,39 +56,6 @@ foreach ($colors as $c) {
?>
</style>
<div class="modal fade" tabindex="-1" role="dialog" id="colormodal">
<div class="modal-dialog" role="document">
<form class="modal-content" action="action.php" method="POST">
<input type="hidden" name="action" value="setcolor" />
<input type="hidden" name="source" value="home" />
<input type="hidden" name="noteid" value="" />
<input type="hidden" name="color" value="FFFFFF" />
<div class="modal-header">
<h5 class="modal-title"><?php $Strings->get("Set color"); ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="d-flex flex-wrap justify-content-center">
<?php
foreach ($colors as $c) {
?>
<button type="submit" name="color" value="<?php echo $c; ?>" class="btn bg_<?php echo $c; ?> m-1">
&nbsp;
</button>
<?php
}
?>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal"><?php $Strings->get("Cancel"); ?></button>
</div>
</form>
</div>
</div>
<div class="btn-group mb-4">
<a href="app.php?page=editnote" class="btn btn-success"><i class="fas fa-plus"></i> <?php $Strings->get("New note"); ?></a>
</div>
@ -133,4 +100,37 @@ foreach ($colors as $c) {
<div class="col-1 sizer-element"></div>
</div>
<div class="modal fade" tabindex="-1" role="dialog" id="colormodal">
<div class="modal-dialog" role="document">
<form class="modal-content" action="action.php" method="POST">
<input type="hidden" name="action" value="setcolor" />
<input type="hidden" name="source" value="home" />
<input type="hidden" name="noteid" value="" />
<input type="hidden" name="color" value="FFFFFF" />
<div class="modal-header">
<h5 class="modal-title"><?php $Strings->get("Set color"); ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="d-flex flex-wrap justify-content-center">
<?php
foreach ($colors as $c) {
?>
<button type="submit" name="color" value="<?php echo $c; ?>" class="btn bg_<?php echo $c; ?> m-1">
&nbsp;
</button>
<?php
}
?>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal"><?php $Strings->get("Cancel"); ?></button>
</div>
</form>
</div>
</div>
Loading…
Cancel
Save