Add basic create/edit/delete functionality, close #1
This commit is contained in:
parent
b4ffb8f7ca
commit
407df6e228
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +1,6 @@
|
|||||||
[submodule "static/css/material-color"]
|
[submodule "static/css/material-color"]
|
||||||
path = static/css/material-color
|
path = static/css/material-color
|
||||||
url = https://source.netsyms.com/Netsyms/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
|
||||||
|
24
action.php
24
action.php
@ -7,7 +7,6 @@
|
|||||||
/**
|
/**
|
||||||
* Make things happen when buttons are pressed and forms submitted.
|
* Make things happen when buttons are pressed and forms submitted.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once __DIR__ . "/required.php";
|
require_once __DIR__ . "/required.php";
|
||||||
|
|
||||||
if ($VARS['action'] !== "signout") {
|
if ($VARS['action'] !== "signout") {
|
||||||
@ -35,4 +34,27 @@ switch ($VARS['action']) {
|
|||||||
session_destroy();
|
session_destroy();
|
||||||
header('Location: index.php');
|
header('Location: index.php');
|
||||||
die("Logged out.");
|
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": "New",
|
||||||
|
"New note": "New note",
|
||||||
"Note": "Note",
|
"Note": "Note",
|
||||||
"Edit": "Edit"
|
"Edit": "Edit",
|
||||||
|
"Delete": "Delete",
|
||||||
|
"Note deleted": "Note deleted"
|
||||||
}
|
}
|
||||||
|
@ -16,5 +16,9 @@ define("MESSAGES", [
|
|||||||
"404_error" => [
|
"404_error" => [
|
||||||
"string" => "page not found",
|
"string" => "page not found",
|
||||||
"type" => "info"
|
"type" => "info"
|
||||||
|
],
|
||||||
|
"note_deleted" => [
|
||||||
|
"string" => "Note deleted",
|
||||||
|
"type" => "success"
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
@ -73,11 +73,22 @@ class Note {
|
|||||||
|
|
||||||
if ($saveas) {
|
if ($saveas) {
|
||||||
$database->insert('notes', $data);
|
$database->insert('notes', $data);
|
||||||
return $database->id();
|
$this->noteid = $database->id();
|
||||||
} else {
|
} else {
|
||||||
$database->update('notes', $data, ['noteid' => $this->noteid]);
|
$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]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
11
pages.php
11
pages.php
@ -13,5 +13,16 @@ define("PAGES", [
|
|||||||
],
|
],
|
||||||
"404" => [
|
"404" => [
|
||||||
"title" => "404 error"
|
"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"
|
||||||
|
]
|
||||||
]
|
]
|
||||||
]);
|
]);
|
34
pages/editnote.php
Normal file
34
pages/editnote.php
Normal file
@ -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
|
<?php
|
||||||
foreach ($notes as $note) {
|
foreach ($notes as $note) {
|
||||||
echo "#notecard_" . $note->getID() . " {\n"
|
echo "#notecard_" . $note->getID() . " {\n"
|
||||||
. " background-color: #" . $note->getColor() . ";\n"
|
. " background-color: #" . $note->getColor() . ";\n"
|
||||||
. " border: 1px solid #" . $note->getColor() . ";\n"
|
. " border: 1px solid #" . $note->getColor() . ";\n"
|
||||||
. "}\n";
|
. "}\n";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</style>
|
</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">
|
<div class="row">
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
@ -35,9 +39,12 @@ foreach ($notes as $note) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
<a href="" class="text-body">
|
<a href="./app.php?page=editnote¬e=<?php echo $note->getID(); ?>" class="text-body mr-2">
|
||||||
<i class="fas fa-edit"></i> <?php $Strings->get('Edit'); ?>
|
<i class="fas fa-edit"></i> <?php $Strings->get('Edit'); ?>
|
||||||
</a>
|
</a>
|
||||||
|
<a href="./action.php?action=deletenote¬eid=<?php echo $note->getID(); ?>" class="text-body text-danger">
|
||||||
|
<i class="fas fa-trash"></i> <?php $Strings->get('Delete'); ?>
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
13
static/css/editnote.css
Normal file
13
static/css/editnote.css
Normal file
@ -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;
|
||||||
|
}
|
1
static/easy-markdown-editor
Submodule
1
static/easy-markdown-editor
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 3551c6c003c5d382ab65d05a873f4c7d665d14a8
|
48
static/js/editnote.js
Normal file
48
static/js/editnote.js
Normal file
@ -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…
x
Reference in New Issue
Block a user