Implement a simple form to save custom markdown-enabled content in the

forge's admin area that is displayed instead of the default project list.
Sanitize the URLs that we're using and make a redirect to the listProjects
page when no custom forge page is enabled.
This commit is contained in:
Thomas Keller
2011-12-24 15:50:41 +01:00
parent 17c6ba97d6
commit f4058ddd69
13 changed files with 242 additions and 31 deletions

View File

@@ -32,20 +32,40 @@ Pluf::loadFunction('Pluf_Shortcuts_GetFormForModel');
class IDF_Views_Admin
{
/**
* Home page of the administration.
*
* It should provide an overview of the forge status.
* Start page of the administration.
*/
public $home_precond = array('Pluf_Precondition::staffRequired');
public function home($request, $match)
public $forge_precond = array('Pluf_Precondition::staffRequired');
public function forge($request, $match)
{
$title = __('Forge Management');
return Pluf_Shortcuts_RenderToResponse('idf/gadmin/home.html',
$forge = IDF_Forge::instance();
if ($request->method == 'POST') {
$form = new IDF_Form_Admin_ForgeConf($request->POST);
if ($form->isValid()) {
$forge->setCustomForgePageEnabled($form->cleaned_data['enabled']);
$forge->setCustomForgePageContent($form->cleaned_data['content']);
$request->user->setMessage(__('The forge configuration has been saved.'));
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Admin::forge');
return new Pluf_HTTP_Response_Redirect($url);
}
} else {
$params = array();
$params['enabled'] = $forge->isCustomForgePageEnabled();
if (($content = $forge->getCustomForgePageContent(false)) !== false) {
$params['content'] = $content;
}
if (count($params) == 0) {
$params = null; //Nothing in the db, so new form.
}
$form = new IDF_Form_Admin_ForgeConf($params);
}
return Pluf_Shortcuts_RenderToResponse('idf/gadmin/forge/index.html',
array(
'page_title' => $title,
),
'page_title' => $title,
'form' => $form,
),
$request);
}
}
/**
* Projects overview.