single file edit: jump to file after saving
authorChristian Weiske <cweiske@cweiske.de>
Mon, 6 Jul 2015 20:42:14 +0000 (22:42 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Mon, 6 Jul 2015 20:42:35 +0000 (22:42 +0200)
data/templates/display-file.htm
data/templates/edit.htm
src/phorkie/File.php
www/edit.php

index 67a584bb0ad858a1c39efb907b7047b9c93f80cd..adffbc70b3837ab3f1024b805ec6076aee4d3332 100644 (file)
@@ -5,7 +5,7 @@
   <a class="btn btn-mini" href="{{toolinfo.getLink(file)}}" style="float: right;">{{toolinfo.getTitle}}</a>
   {% endfor %}
   <a class="btn btn-mini" href="{{repo.getLink('edit', file.getFilename)}}" style="float: right;" title="edit"><i class="icon-edit"></i></a>
-  <h3 id="{{file.getFilename|replace({' ': '-'})}}">{{file.getFilename}}<a class="anchorlink" href="{{repo.getLink('display')}}#{{file.getFilename|replace({' ': '-'})}}"></a></h3>
+  <h3 id="{{file.getAnchorName}}">{{file.getFilename}}<a class="anchorlink" href="{{repo.getLink('display')}}#{{file.getAnchorName}}"></a></h3>
  </div>
   {{file.getRenderedContent(toolres)|raw}}
 </div>
index 401ed00b1c77f929e6c7474c58fefc4711c79d56..870ef23f3c4896e4cf28f0a35528c6e723308799 100644 (file)
@@ -7,7 +7,7 @@
 
 {% block content %}
 <div class="content-padding-fix"></div>
-<form method="post" action="{{repo.getLink('edit')}}" enctype="multipart/form-data" class="form-horizontal">
+<form method="post" action="{{repo.getLink('edit', singlefile.getFilename)}}" enctype="multipart/form-data" class="form-horizontal">
  <div class="control-group">
   <label class="control-label" for="description">Description</label>
   <div class="controls">
index 9eb7fa7002be4463442c1a4c81b596352b5ec895..2afda4c89fc8b2514ebef68a41d5ba3e1bc499aa 100644 (file)
@@ -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
      *
index e95ca3f5ed2dbf5441f79300dc5bfacdd8853308..33b22c2afe09031f3fc264c466ac49ef2eeee8ff 100644 (file)
@@ -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(