aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2015-07-06 23:10:18 +0200
committerChristian Weiske <cweiske@cweiske.de>2015-07-06 23:10:18 +0200
commit69e4391bfb53ce2d7a3a42f69e37bbf136d3ee09 (patch)
treedbb36cdd1bec92858baa91b557a43790e744a778
parenta1e6e4c154727f30aaa2e406eb5afb3810d4b398 (diff)
downloadphorkie-69e4391bfb53ce2d7a3a42f69e37bbf136d3ee09.tar.gz
phorkie-69e4391bfb53ce2d7a3a42f69e37bbf136d3ee09.zip
Add "add file" button to display page
-rw-r--r--data/templates/display-foot.htm9
-rw-r--r--data/templates/edit.htm6
-rw-r--r--src/phorkie/Repository/Post.php11
-rw-r--r--www/edit.php18
4 files changed, 40 insertions, 4 deletions
diff --git a/data/templates/display-foot.htm b/data/templates/display-foot.htm
index 3a53adf..6324509 100644
--- a/data/templates/display-foot.htm
+++ b/data/templates/display-foot.htm
@@ -1,5 +1,12 @@
<div class="row-fluid" style="margin-top: 5ex">
- <div class="span12">
+ <div class="span4"></div>
+ <div class="span4" style="text-align: center">
+ <a class="btn" href="{{repo.getLink('edit', 'newfile')}}" id="add-button">
+ <i class="icon-plus"></i>
+ Add file
+ </a>
+ </div>
+ <div class="span4">
<a class="btn pull-right" href="{{repo.getLink('delete')}}">
<i class="icon-trash"></i> Delete paste
</a>
diff --git a/data/templates/edit.htm b/data/templates/edit.htm
index 870ef23..912a073 100644
--- a/data/templates/edit.htm
+++ b/data/templates/edit.htm
@@ -7,7 +7,7 @@
{% block content %}
<div class="content-padding-fix"></div>
-<form method="post" action="{{repo.getLink('edit', singlefile.getFilename)}}" enctype="multipart/form-data" class="form-horizontal">
+<form method="post" action="{{formaction}}" enctype="multipart/form-data" class="form-horizontal">
<div class="control-group">
<label class="control-label" for="description">Description</label>
<div class="controls">
@@ -21,6 +21,10 @@
{% endif %}
{% endfor %}
+ {% if singlefile == "newfile" %}
+ {% include 'edit-file.htm' with {'file': null, 'fileid': 'newfile', 'newfile': true} %}
+ {% endif %}
+
{% include 'edit-add.htm' %}
<div class="row-fluid formbuttons">
diff --git a/src/phorkie/Repository/Post.php b/src/phorkie/Repository/Post.php
index a61f2a2..511a83c 100644
--- a/src/phorkie/Repository/Post.php
+++ b/src/phorkie/Repository/Post.php
@@ -5,6 +5,16 @@ class Repository_Post
{
public $repo;
+ /**
+ * When a new file is created during processing, its name
+ * is stored here for later use.
+ *
+ * @var string
+ */
+ public $newfileName;
+
+
+
public function __construct(Repository $repo = null)
{
$this->repo = $repo;
@@ -76,6 +86,7 @@ class Repository_Post
//automatically append file extension if none is there
$name .= '.' . $arFile['type'];
}
+ $this->newfileName = $name;
} else if (!$this->repo->hasFile($orignalName)) {
//unknown file
//FIXME: Show error message
diff --git a/www/edit.php b/www/edit.php
index 33b22c2..e7e6fbc 100644
--- a/www/edit.php
+++ b/www/edit.php
@@ -11,18 +11,31 @@ $repo->loadFromRequest();
$file = null;
if (isset($_GET['file'])) {
- $file = $repo->getFileByName($_GET['file']);
+ if ($_GET['file'] == 'newfile') {
+ $file = 'newfile';
+ } else {
+ $file = $repo->getFileByName($_GET['file']);
+ }
}
$repopo = new Repository_Post($repo);
if ($repopo->process($_POST, $_SESSION)) {
$anchor = '';
- if ($file !== null) {
+ if ($file instanceof File) {
$anchor = '#' . $file->getAnchorName();
+ } else if ($file === 'newfile' && $repopo->newfileName) {
+ $anchor = '#' . $repo->getFileByName($repopo->newfileName)->getAnchorName();
}
redirect($repo->getLink('display', null, true) . $anchor);
}
+$actionFile = null;
+if ($file instanceof File) {
+ $actionFile = $file->getFilename();
+} else if ($file === 'newfile') {
+ $actionFile = 'newfile';
+}
+
render(
'edit',
array(
@@ -30,6 +43,7 @@ render(
'singlefile' => $file,
'dh' => new \Date_HumanDiff(),
'htmlhelper' => new HtmlHelper(),
+ 'formaction' => $repo->getLink('edit', $actionFile)
)
);
?>