display success flash message after forking
authorChristian Weiske <cweiske@cweiske.de>
Thu, 8 May 2014 20:29:09 +0000 (22:29 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Thu, 8 May 2014 20:29:09 +0000 (22:29 +0200)
data/templates/display-head.htm
data/templates/flashmessages.htm [new file with mode: 0644]
src/phorkie/FlashMessage.php [new file with mode: 0644]
www/display.php
www/fork-remote.php
www/fork.php

index ba1f467..f610f84 100644 (file)
@@ -1,9 +1,4 @@
-{% if forksuccess %}
-<div class="alert alert-success">
- <a href="#" class="close" data-dismiss="alert">×</a>
- Paste has been successfully forked.
-</div>
-{% endif %}
+{% include 'flashmessages.htm' %}
 
 <h1>{{repo.getTitle}}</h1>
 <div class="row repo-info">
diff --git a/data/templates/flashmessages.htm b/data/templates/flashmessages.htm
new file mode 100644 (file)
index 0000000..3ea654a
--- /dev/null
@@ -0,0 +1,6 @@
+{% for msgdata in flashmessages %}
+<div class="alert alert-{{msgdata.type}}">
+ <a href="#" class="close" data-dismiss="alert">×</a>
+ {{msgdata.msg}}
+</div>
+{% endfor %}
\ No newline at end of file
diff --git a/src/phorkie/FlashMessage.php b/src/phorkie/FlashMessage.php
new file mode 100644 (file)
index 0000000..80b8824
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+namespace phorkie;
+
+class FlashMessage
+{
+    public static function save($msg, $type = 'success')
+    {
+        $_SESSION['flashmessages'][] = array(
+            'msg'  => $msg,
+            'type' => $type
+        );
+    }
+
+    public static function getAll()
+    {
+        if (!isset($_SESSION['flashmessages'])
+            || !is_array($_SESSION['flashmessages'])
+        ) {
+            return array();
+        }
+
+        $msgs = $_SESSION['flashmessages'];
+        unset($_SESSION['flashmessages']);
+        return $msgs;
+    }
+}
+?>
index a41f4a8..be79e4b 100644 (file)
@@ -21,6 +21,7 @@ render(
         'repo' => $repo,
         'dh'   => new \Date_HumanDiff(),
         'htmlhelper' => new HtmlHelper(),
+        'flashmessages' => FlashMessage::getAll(),
     )
 );
 ?>
index f41f981..096f432 100644 (file)
@@ -26,6 +26,7 @@ if (isset($_REQUEST['remote_url'])) {
             $new = $forker->forkRemote(
                 $gitUrl['url'], $fr->getUrl(), $gitUrl['title']
             );
+            FlashMessage::save('Remote paste has been forked');
             redirect($new->getLink('display', null, true));
         } catch (\Exception $e) {
             $error = $e->getMessage();
index 352f8bc..cddf2bb 100644 (file)
@@ -16,6 +16,6 @@ $repo->loadFromRequest();
 $forker = new Forker();
 $new    = $forker->forkLocal($repo);
 
-//FIXME: where to put fork source link?
+FlashMessage::save('Paste has been forked');
 redirect($new->getLink('display', null, true));
 ?>