Skip to content
Snippets Groups Projects
Commit c94d56da authored by Jared Hancock's avatar Jared Hancock
Browse files

access: Allow empty staff banner. Show update errors

Allow the staff banner to be set to empty (which is the default).

Also display the update errors back on the dialog for failed updated.
parent 87f3028b
No related branches found
No related tags found
No related merge requests found
...@@ -136,6 +136,7 @@ class ContentAjaxAPI extends AjaxController { ...@@ -136,6 +136,7 @@ class ContentAjaxAPI extends AjaxController {
Http::response(403, 'Login Required'); Http::response(403, 'Login Required');
$content = Page::lookup($id, $lang); $content = Page::lookup($id, $lang);
$info = $content->getHashtable();
include STAFFINC_DIR . 'templates/content-manage.tmpl.php'; include STAFFINC_DIR . 'templates/content-manage.tmpl.php';
} }
...@@ -146,6 +147,7 @@ class ContentAjaxAPI extends AjaxController { ...@@ -146,6 +147,7 @@ class ContentAjaxAPI extends AjaxController {
Http::response(403, 'Login Required'); Http::response(403, 'Login Required');
$content = Page::lookup(Page::getIdByType($type, $lang)); $content = Page::lookup(Page::getIdByType($type, $lang));
$info = $content->getHashtable();
include STAFFINC_DIR . 'templates/content-manage.tmpl.php'; include STAFFINC_DIR . 'templates/content-manage.tmpl.php';
} }
...@@ -154,19 +156,25 @@ class ContentAjaxAPI extends AjaxController { ...@@ -154,19 +156,25 @@ class ContentAjaxAPI extends AjaxController {
if (!$thisstaff) if (!$thisstaff)
Http::response(403, 'Login Required'); Http::response(403, 'Login Required');
elseif (!$_POST['name'] || !$_POST['body'])
Http::response(422, 'Please submit name and body');
elseif (!($content = Page::lookup($id))) elseif (!($content = Page::lookup($id)))
Http::response(404, 'No such content'); Http::response(404, 'No such content');
if (!isset($_POST['body']))
$_POST['body'] = '';
$vars = array_merge($content->getHashtable(), $_POST); $vars = array_merge($content->getHashtable(), $_POST);
$errors = array(); $errors = array();
if (!$content->save($id, $vars, $errors)) { // Allow empty content for the staff banner
if ($errors['err']) if ($content->save($id, $vars, $errors,
Http::response(422, $errors['err']); $content->getType() == 'banner-staff')
else ) {
Http::response(500, 'Unable to update content: '.print_r($errors, true)); Http::response(201, 'Have a great day!');
} }
if (!$errors['err'])
$errors['err'] = __('Correct the error(s) below and try again!');
$info = $_POST;
$errors = Format::htmlchars($errors);
include STAFFINC_DIR . 'templates/content-manage.tmpl.php';
} }
} }
?> ?>
...@@ -229,7 +229,7 @@ class Page { ...@@ -229,7 +229,7 @@ class Page {
? $p : null; ? $p : null;
} }
function save($id, $vars, &$errors) { function save($id, $vars, &$errors, $allowempty=false) {
//Cleanup. //Cleanup.
$vars['name']=Format::striptags(trim($vars['name'])); $vars['name']=Format::striptags(trim($vars['name']));
...@@ -246,7 +246,7 @@ class Page { ...@@ -246,7 +246,7 @@ class Page {
elseif(($pid=self::getIdByName($vars['name'])) && $pid!=$id) elseif(($pid=self::getIdByName($vars['name'])) && $pid!=$id)
$errors['name'] = __('Name already exists'); $errors['name'] = __('Name already exists');
if(!$vars['body']) if(!$vars['body'] && !$allowempty)
$errors['body'] = __('Page body is required'); $errors['body'] = __('Page body is required');
if($errors) return false; if($errors) return false;
......
...@@ -170,14 +170,19 @@ $manage_content = function($title, $content) use ($contents) { ...@@ -170,14 +170,19 @@ $manage_content = function($title, $content) use ($contents) {
?><tr><td colspan="2"> ?><tr><td colspan="2">
<a href="#ajax.php/content/<?php echo $id; ?>/manage" <a href="#ajax.php/content/<?php echo $id; ?>/manage"
onclick="javascript: onclick="javascript:
$.dialog($(this).attr('href').substr(1), 200); $.dialog($(this).attr('href').substr(1), 201);
return false;"><i class="icon-file-text pull-left icon-2x" return false;" class="pull-left"><i class="icon-file-text icon-2x"
style="color:#bbb;"></i> <?php style="color:#bbb;"></i> </a>
<span style="display:inline-block;width:90%;padding-left:10px;line-height:1.2em">
<a href="#ajax.php/content/<?php echo $id; ?>/manage"
onclick="javascript:
$.dialog($(this).attr('href').substr(1), 201);
return false;"><?php
echo Format::htmlchars($title); ?></a><br/> echo Format::htmlchars($title); ?></a><br/>
<span class="faded" style="display:inline-block;width:90%"><?php <span class="faded"><?php
echo Format::display($notes); ?> echo Format::display($notes); ?>
<em>(<?php echo sprintf(__('Last Updated %s'), Format::db_datetime($upd)); <em>(<?php echo sprintf(__('Last Updated %s'), Format::db_datetime($upd));
?>)</em></span></td></tr><?php ?>)</em></span></span></td></tr><?php
}; ?> }; ?>
<tr> <tr>
<th colspan="2"> <th colspan="2">
......
<h3><?php echo __('Manage Content'); ?> &mdash; <?php echo Format::htmlchars($content->getName()); ?></h3> <h3><?php echo __('Manage Content'); ?> &mdash; <?php echo Format::htmlchars($content->getName()); ?></h3>
<a class="close" href=""><i class="icon-remove-circle"></i></a> <a class="close" href=""><i class="icon-remove-circle"></i></a>
<hr/> <hr/>
<form method="post" action="#content/<?php echo $content->getId(); ?>"> <?php if ($errors['err']) { ?>
<div class="error-banner">
<?php echo $errors['err']; ?>
</div>
<?php } ?>
<form method="post" action="#content/<?php echo $info['id']; ?>">
<div class="error"><?php echo $errors['name']; ?></div>
<input type="text" style="width: 100%; font-size: 14pt" name="name" value="<?php <input type="text" style="width: 100%; font-size: 14pt" name="name" value="<?php
echo Format::htmlchars($content->getName()); ?>" /> echo Format::htmlchars($info['name']); ?>" />
<div style="margin-top: 5px"> <div style="margin-top: 5px">
<div class="error"><?php echo $errors['body']; ?></div>
<textarea class="richtext no-bar" name="body"><?php <textarea class="richtext no-bar" name="body"><?php
echo Format::viewableImages($content->getBody()); echo Format::viewableImages($info['body']);
?></textarea> ?></textarea>
</div> </div>
<div id="msg_info" style="margin-top:7px"><?php <div id="msg_info" style="margin-top:7px"><?php
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment