Add basic create/edit/delete functionality, close #1

master
Skylar Ittner 5 years ago
parent b4ffb8f7ca
commit 407df6e228

3
.gitmodules vendored

@ -1,3 +1,6 @@
[submodule "static/css/material-color"]
path = static/css/material-color
url = https://source.netsyms.com/Netsyms/Material-Color
[submodule "static/easy-markdown-editor"]
path = static/easy-markdown-editor
url = https://source.netsyms.com/Netsyms/easy-markdown-editor.git

@ -7,7 +7,6 @@
/**
* Make things happen when buttons are pressed and forms submitted.
*/
require_once __DIR__ . "/required.php";
if ($VARS['action'] !== "signout") {
@ -35,4 +34,27 @@ switch ($VARS['action']) {
session_destroy();
header('Location: index.php');
die("Logged out.");
case "savenote":
if (empty($VARS['content']) || empty($VARS['noteid'])) {
die($Strings->get("invalid parameters"));
}
http_response_code(204);
$note = Note::loadNote($VARS['noteid']);
if ($note->getOwnerID() != $_SESSION['uid']) {
die($Strings->get("invalid parameters"));
}
$note->setText($VARS['content']);
$note->setColor($VARS['color']);
$note->saveNote();
break;
case "deletenote":
if (empty($VARS['noteid'])) {
die($Strings->get("invalid parameters"));
}
$note = Note::loadNote($VARS['noteid']);
if ($note->getOwnerID() != $_SESSION['uid']) {
die($Strings->get("invalid parameters"));
}
$note->deleteNote();
returnToSender("note_deleted");
}

@ -1,5 +1,8 @@
{
"New": "New",
"New note": "New note",
"Note": "Note",
"Edit": "Edit"
"Edit": "Edit",
"Delete": "Delete",
"Note deleted": "Note deleted"
}

@ -16,5 +16,9 @@ define("MESSAGES", [
"404_error" => [
"string" => "page not found",
"type" => "info"
],
"note_deleted" => [
"string" => "Note deleted",
"type" => "success"
]
]);

@ -73,11 +73,22 @@ class Note {
if ($saveas) {
$database->insert('notes', $data);
return $database->id();
$this->noteid = $database->id();
} else {
$database->update('notes', $data, ['noteid' => $this->noteid]);
return $this->noteid;
}
return $this->noteid;
}
/**
* Delete this note from the database.
* @global type $database
*/
public function deleteNote() {
global $database;
$database->delete('notes', ['noteid' => $this->noteid]);
}
/**

@ -13,5 +13,16 @@ define("PAGES", [
],
"404" => [
"title" => "404 error"
],
"editnote" => [
"title" => "Edit Note",
"styles" => [
"static/easy-markdown-editor/dist/easymde.min.css",
"static/css/editnote.css"
],
"scripts" => [
"static/easy-markdown-editor/dist/easymde.min.js",
"static/js/editnote.js"
]
]
]);

@ -0,0 +1,34 @@
<?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
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
$note = new Note("", "", $_SESSION['uid'], null);
if (!empty($VARS['note'])) {
try {
$note = Note::loadNote($VARS['note']);
} catch (Exception $ex) {
// It's a new note I guess
}
}
// TODO: Check for note sharing
if ($note->getOwnerID() != $_SESSION['uid']) {
header("Location: app.php?msg=no_permission");
die();
}
$note->saveNote();
?>
<form action="action.php" method="POST" id="noteform">
<textarea name="content" id="note_content"><?php echo $note->getText(); ?></textarea>
<input type="hidden" name="noteid" value="<?php echo $note->getID(); ?>" />
<input type="hidden" name="color" value="FFFFFF" />
<input type="hidden" name="action" value="savenote" />
</form>

@ -16,13 +16,17 @@ foreach ($noteids as $n) {
<?php
foreach ($notes as $note) {
echo "#notecard_" . $note->getID() . " {\n"
. " background-color: #" . $note->getColor() . ";\n"
. " border: 1px solid #" . $note->getColor() . ";\n"
. "}\n";
. " background-color: #" . $note->getColor() . ";\n"
. " border: 1px solid #" . $note->getColor() . ";\n"
. "}\n";
}
?>
</style>
<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>
<div class="row">
<?php
@ -35,9 +39,12 @@ foreach ($notes as $note) {
</div>
<div class="card-footer">
<a href="" class="text-body">
<a href="./app.php?page=editnote&note=<?php echo $note->getID(); ?>" class="text-body mr-2">
<i class="fas fa-edit"></i> <?php $Strings->get('Edit'); ?>
</a>
<a href="./action.php?action=deletenote&noteid=<?php echo $note->getID(); ?>" class="text-body text-danger">
<i class="fas fa-trash"></i> <?php $Strings->get('Delete'); ?>
</a>
</div>
</div>
</div>

@ -0,0 +1,13 @@
/*
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
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
.editor-toolbar.fullscreen, .CodeMirror-fullscreen {
margin-top: 60px;
}
.editor-preview-active-side {
margin-top: 10px;
}

@ -0,0 +1 @@
Subproject commit 3551c6c003c5d382ab65d05a873f4c7d665d14a8

@ -0,0 +1,48 @@
/*
* 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
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
var easymde = new EasyMDE({
element: $("#note_content")[0],
autoDownloadFontAwesome: false,
autofocus: true,
forceSync: true,
status: false,
toolbar: [
{
name: "save",
action: function saveNote(editor) {
$("#noteform").submit();
},
className: "fas fa-save",
title: "Save",
},
{
name: "exit",
action: function exit(editor) {
document.location.href = "./app.php";
},
className: "fas fa-times",
title: "Close",
},
"|",
"bold",
"italic",
"heading",
"|",
"quote",
"unordered-list",
"ordered-list",
"horizontal-rule",
"|",
"side-by-side",
"fullscreen"
]
});
var autosaveTimer = setInterval(function () {
$("#noteform").submit();
}, 10 * 1000);
Loading…
Cancel
Save