From 93ef642c25d65519b334fecad56bf6567eeb733b Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 6 Jul 2015 22:42:14 +0200 Subject: [PATCH] single file edit: jump to file after saving --- data/templates/display-file.htm | 2 +- data/templates/edit.htm | 2 +- src/phorkie/File.php | 10 ++++++++++ www/edit.php | 14 +++++++++----- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/data/templates/display-file.htm b/data/templates/display-file.htm index 67a584b..adffbc7 100644 --- a/data/templates/display-file.htm +++ b/data/templates/display-file.htm @@ -5,7 +5,7 @@ {{toolinfo.getTitle}} {% endfor %} -

{{file.getFilename}}

+

{{file.getFilename}}

{{file.getRenderedContent(toolres)|raw}} diff --git a/data/templates/edit.htm b/data/templates/edit.htm index 401ed00..870ef23 100644 --- a/data/templates/edit.htm +++ b/data/templates/edit.htm @@ -7,7 +7,7 @@ {% block content %}
-
+
diff --git a/src/phorkie/File.php b/src/phorkie/File.php index 9eb7fa7..2afda4c 100644 --- a/src/phorkie/File.php +++ b/src/phorkie/File.php @@ -38,6 +38,16 @@ class File return $this->path; } + /** + * Get the filename usable as HTML anchor. + * + * @return string + */ + function getAnchorName() + { + return str_replace(' ', '-', $this->getFilename()); + } + /** * Return the full path to the file * diff --git a/www/edit.php b/www/edit.php index e95ca3f..33b22c2 100644 --- a/www/edit.php +++ b/www/edit.php @@ -9,16 +9,20 @@ require_once 'www-header.php'; $repo = new Repository(); $repo->loadFromRequest(); -$repopo = new Repository_Post($repo); -if ($repopo->process($_POST, $_SESSION)) { - redirect($repo->getLink('display', null, true)); -} - $file = null; if (isset($_GET['file'])) { $file = $repo->getFileByName($_GET['file']); } +$repopo = new Repository_Post($repo); +if ($repopo->process($_POST, $_SESSION)) { + $anchor = ''; + if ($file !== null) { + $anchor = '#' . $file->getAnchorName(); + } + redirect($repo->getLink('display', null, true) . $anchor); +} + render( 'edit', array( -- 2.30.2