From c94d56daffcd0d2f3d024e7fe28e1416d41d2301 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Fri, 27 Feb 2015 09:39:38 -0600 Subject: [PATCH] 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. --- include/ajax.content.php | 22 +++++++++++++------ include/class.page.php | 4 ++-- include/staff/settings-access.inc.php | 15 ++++++++----- .../staff/templates/content-manage.tmpl.php | 13 ++++++++--- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/include/ajax.content.php b/include/ajax.content.php index d7863cb88..eeb5b426c 100644 --- a/include/ajax.content.php +++ b/include/ajax.content.php @@ -136,6 +136,7 @@ class ContentAjaxAPI extends AjaxController { Http::response(403, 'Login Required'); $content = Page::lookup($id, $lang); + $info = $content->getHashtable(); include STAFFINC_DIR . 'templates/content-manage.tmpl.php'; } @@ -146,6 +147,7 @@ class ContentAjaxAPI extends AjaxController { Http::response(403, 'Login Required'); $content = Page::lookup(Page::getIdByType($type, $lang)); + $info = $content->getHashtable(); include STAFFINC_DIR . 'templates/content-manage.tmpl.php'; } @@ -154,19 +156,25 @@ class ContentAjaxAPI extends AjaxController { if (!$thisstaff) Http::response(403, 'Login Required'); - elseif (!$_POST['name'] || !$_POST['body']) - Http::response(422, 'Please submit name and body'); elseif (!($content = Page::lookup($id))) Http::response(404, 'No such content'); + if (!isset($_POST['body'])) + $_POST['body'] = ''; + $vars = array_merge($content->getHashtable(), $_POST); $errors = array(); - if (!$content->save($id, $vars, $errors)) { - if ($errors['err']) - Http::response(422, $errors['err']); - else - Http::response(500, 'Unable to update content: '.print_r($errors, true)); + // Allow empty content for the staff banner + if ($content->save($id, $vars, $errors, + $content->getType() == 'banner-staff') + ) { + 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'; } } ?> diff --git a/include/class.page.php b/include/class.page.php index a6faf5f01..7b1183089 100644 --- a/include/class.page.php +++ b/include/class.page.php @@ -229,7 +229,7 @@ class Page { ? $p : null; } - function save($id, $vars, &$errors) { + function save($id, $vars, &$errors, $allowempty=false) { //Cleanup. $vars['name']=Format::striptags(trim($vars['name'])); @@ -246,7 +246,7 @@ class Page { elseif(($pid=self::getIdByName($vars['name'])) && $pid!=$id) $errors['name'] = __('Name already exists'); - if(!$vars['body']) + if(!$vars['body'] && !$allowempty) $errors['body'] = __('Page body is required'); if($errors) return false; diff --git a/include/staff/settings-access.inc.php b/include/staff/settings-access.inc.php index fa6fc607e..156507f2e 100644 --- a/include/staff/settings-access.inc.php +++ b/include/staff/settings-access.inc.php @@ -170,14 +170,19 @@ $manage_content = function($title, $content) use ($contents) { ?><tr><td colspan="2"> <a href="#ajax.php/content/<?php echo $id; ?>/manage" onclick="javascript: - $.dialog($(this).attr('href').substr(1), 200); - return false;"><i class="icon-file-text pull-left icon-2x" - style="color:#bbb;"></i> <?php + $.dialog($(this).attr('href').substr(1), 201); + return false;" class="pull-left"><i class="icon-file-text icon-2x" + 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/> - <span class="faded" style="display:inline-block;width:90%"><?php + <span class="faded"><?php echo Format::display($notes); ?> <em>(<?php echo sprintf(__('Last Updated %s'), Format::db_datetime($upd)); - ?>)</em></span></td></tr><?php + ?>)</em></span></span></td></tr><?php }; ?> <tr> <th colspan="2"> diff --git a/include/staff/templates/content-manage.tmpl.php b/include/staff/templates/content-manage.tmpl.php index ddf9892ad..7170aeb29 100644 --- a/include/staff/templates/content-manage.tmpl.php +++ b/include/staff/templates/content-manage.tmpl.php @@ -1,12 +1,19 @@ <h3><?php echo __('Manage Content'); ?> — <?php echo Format::htmlchars($content->getName()); ?></h3> <a class="close" href=""><i class="icon-remove-circle"></i></a> <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 - echo Format::htmlchars($content->getName()); ?>" /> + echo Format::htmlchars($info['name']); ?>" /> <div style="margin-top: 5px"> + <div class="error"><?php echo $errors['body']; ?></div> <textarea class="richtext no-bar" name="body"><?php - echo Format::viewableImages($content->getBody()); + echo Format::viewableImages($info['body']); ?></textarea> </div> <div id="msg_info" style="margin-top:7px"><?php -- GitLab