Add "add file" button to display page
authorChristian Weiske <cweiske@cweiske.de>
Mon, 6 Jul 2015 21:10:18 +0000 (23:10 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Mon, 6 Jul 2015 21:10:18 +0000 (23:10 +0200)
data/templates/display-foot.htm
data/templates/edit.htm
src/phorkie/Repository/Post.php
www/edit.php

index 3a53adf1b924caaf65616699bf5012a2835c234c..6324509ab273737d7426cab2963d001ebeead0ae 100644 (file)
@@ -1,5 +1,12 @@
 <div class="row-fluid" style="margin-top: 5ex">
 <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>
   <a class="btn pull-right" href="{{repo.getLink('delete')}}">
    <i class="icon-trash"></i> Delete paste
   </a>
index 870ef23f3c4896e4cf28f0a35528c6e723308799..912a073419941e7a50f6c95e5bcc0b464525a1b1 100644 (file)
@@ -7,7 +7,7 @@
 
 {% block content %}
 <div class="content-padding-fix"></div>
 
 {% 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">
  <div class="control-group">
   <label class="control-label" for="description">Description</label>
   <div class="controls">
   {% endif %}
  {% endfor %}
 
   {% 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">
  {% include 'edit-add.htm' %}
 
   <div class="row-fluid formbuttons">
index a61f2a257e6f78709e49489bce9a1f4dfa063ba5..511a83c569c40cd5d1ff1f6e7c7955f9819ba3e2 100644 (file)
@@ -5,6 +5,16 @@ class Repository_Post
 {
     public $repo;
 
 {
     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;
     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'];
                 }
                     //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
             } else if (!$this->repo->hasFile($orignalName)) {
                 //unknown file
                 //FIXME: Show error message
index 33b22c2afe09031f3fc264c466ac49ef2eeee8ff..e7e6fbcc9422de965b928d162fb18d989f30c6ad 100644 (file)
@@ -11,18 +11,31 @@ $repo->loadFromRequest();
 
 $file = null;
 if (isset($_GET['file'])) {
 
 $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 = '';
 }
 
 $repopo = new Repository_Post($repo);
 if ($repopo->process($_POST, $_SESSION)) {
     $anchor = '';
-    if ($file !== null) {
+    if ($file instanceof File) {
         $anchor = '#' . $file->getAnchorName();
         $anchor = '#' . $file->getAnchorName();
+    } else if ($file === 'newfile' && $repopo->newfileName) {
+        $anchor = '#' . $repo->getFileByName($repopo->newfileName)->getAnchorName();
     }
     redirect($repo->getLink('display', null, true) . $anchor);
 }
 
     }
     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(
 render(
     'edit',
     array(
@@ -30,6 +43,7 @@ render(
         'singlefile' => $file,
         'dh'   => new \Date_HumanDiff(),
         'htmlhelper' => new HtmlHelper(),
         'singlefile' => $file,
         'dh'   => new \Date_HumanDiff(),
         'htmlhelper' => new HtmlHelper(),
+        'formaction' => $repo->getLink('edit', $actionFile)
     )
 );
 ?>
     )
 );
 ?>