Permalink
Browse files

add flash_success and add_flash_successes(), like errors and notices

make notices print blue by default now, and successes in green
  • Loading branch information...
1 parent 565979c commit 5c6c07a3c8f40df795370a4e172c04808d89cbfd @jcs committed Nov 13, 2011
View
@@ -147,6 +147,16 @@ public function add_flash_notice($string) {
array_push($_SESSION["flash_notices"], $string);
}
+ /* store a success message in the session to be printed on the next view
+ * with the flash_success() helper */
+ public function add_flash_success($string) {
+ if (!isset($_SESSION["flash_successes"]) ||
+ !is_array($_SESSION["flash_successes"]))
+ $_SESSION["flash_successes"] = array();
+
+ array_push($_SESSION["flash_successes"], $string);
+ }
+
/* cancel all buffered output, send a location: header and stop processing */
public function redirect_to($obj_or_url) {
$link = HTMLHelper::link_from_obj_or_string($obj_or_url);
@@ -108,6 +108,25 @@ public function flash_notices() {
return $html;
}
+ /* print the successes stored in the session and then reset the array */
+ public function flash_successes() {
+ $html = "";
+
+ if (isset($_SESSION["flash_successes"]) &&
+ count((array)$_SESSION["flash_successes"])) {
+ $html = "<div class=\"flash-success\">"
+ . implode("<br />\n", array_map(function($e) {
+ return raw_or_h($e); },
+ (array)$_SESSION["flash_successes"]))
+ . "</div>";
+
+ /* clear out for the next view */
+ $_SESSION["flash_successes"] = array();
+ }
+
+ return $html;
+ }
+
/* create a link to a javascript file, appending its modification time to
* force clients to reload it when it's modified */
public function javascript_include_tag($files) {
View
@@ -143,9 +143,16 @@ static function strcasecmp_or_preg_match($check, $string) {
/* when passed a closure containing print/<?=?> code, execute it, capture the
* output, and return it as a string */
- static function to_s($obj, $closure) {
+ static function to_s($obj, $closure, $bind = null) {
ob_start();
+
+ if (version_compare(PHP_VERSION, "5.4.0") >= 0)
+ /* setup $this */
+ if (!empty($bind))
+ $closure->bindTo($bind);
+
$closure($obj);
+
$str = ob_get_contents();
ob_end_clean();
@@ -1,28 +1,37 @@
/* application css */
-/* for flash_notices() and flash_errors() */
-div.flash-notice, div.flash-error {
+/* for flash_errors(), flash_notices() and flash_successes() */
+div.flash-error,
+div.flash-notice,
+div.flash-success {
border: 2px solid;
margin: 5px 5px 10px 5px;
padding: 5px 10px;
}
-div.flash-notice {
+div.flash-error {
+ background-color: #ffe7e7;
+ border-color: red;
+}
+
+div.flash-success {
background-color: #e8ffe7;
border-color: green;
}
-div.flash-error {
- background-color: #ffe7e7;
- border-color: red;
+div.flash-success {
+ background-color: #e0e2fc;
+ border-color: blue;
}
/* for error_messages_for() */
div.fieldWithErrors {
display: inline;
}
-div.fieldWithErrors input, div.fieldWithErrors select {
+div.fieldWithErrors input,
+div.fieldWithErrors select,
+div.fieldWithErrors textarea {
border: 2px solid red;
padding: 2px;
}
@@ -9,6 +9,7 @@
</head>
<body>
<?php echo $html->flash_errors(); ?>
+ <?php echo $html->flash_successes(); ?>
<?php echo $html->flash_notices(); ?>
<?php echo $content_for_layout; ?>

0 comments on commit 5c6c07a

Please sign in to comment.