Merge branch 'feature.wiki-default-page' of projects.ceondo.com:indefero into feature.wiki-default-page

This commit is contained in:
Thomas Keller 2011-11-07 14:34:43 +01:00
commit 2e1369184b
5 changed files with 109 additions and 7 deletions

View File

@ -41,6 +41,7 @@ Phase:Support = Plans for user support and advocacy
Deprecated = Most users should NOT reference this';
const init_one_max = '';
const wiki_default_page = '';
public function initFields($extra=array())
{
@ -59,8 +60,30 @@ Deprecated = Most users should NOT reference this';
'initial' => self::init_one_max,
'widget_attrs' => array('size' => 60),
));
$this->fields['wiki_default_page'] = new Pluf_Form_Field_Varchar(
array('required' => false,
'label' => __('Set a default wiki page instead of the page listing.'),
'initial' => self::wiki_default_page,
'widget_attrs' => array('size' => 60),
));
}
public function clean_wiki_default_page()
{
$pageName = trim($this->cleaned_data['wiki_default_page']);
if (empty($pageName)) {
return '';
}
$sql = new Pluf_SQL('project=%s AND title=%s', array($this->data['projectId'], $pageName));
$pages = Pluf::factory('IDF_WikiPage')->getList(array('filter'=>$sql->gen()));
if ($pages->count() != 1) {
return '';
}
return $pageName;
}
}

View File

@ -418,8 +418,17 @@ class IDF_Views_Project
$title = sprintf(__('%s Documentation Configuration'), (string) $prj);
$conf = new IDF_Conf();
$conf->setProject($prj);
// Get the Wiki list pages
$sql = new Pluf_SQL('project=%s', array($prj->id));
$pages = Pluf::factory('IDF_WikiPage')->getList(array('filter'=>$sql->gen()));
$auto_wiki_page_name = "";
foreach ($pages as $p) {
$auto_wiki_page_name .= '{ name: "' . $p->summary . '", to: "' . $p->title . '" }, ';
}
if ($request->method == 'POST') {
$form = new IDF_Form_WikiConf($request->POST);
$form = new IDF_Form_WikiConf(array_merge($request->POST, array('projectId' => $prj->id)));
if ($form->isValid()) {
foreach ($form->cleaned_data as $key=>$val) {
$conf->setVal($key, $val);
@ -431,7 +440,7 @@ class IDF_Views_Project
}
} else {
$params = array();
$keys = array('labels_wiki_predefined', 'labels_wiki_one_max');
$keys = array('labels_wiki_predefined', 'labels_wiki_one_max', 'wiki_default_page');
foreach ($keys as $key) {
$_val = $conf->getVal($key, false);
if ($_val !== false) {
@ -447,6 +456,7 @@ class IDF_Views_Project
array(
'page_title' => $title,
'form' => $form,
'auto_wiki_page_name' => $auto_wiki_page_name,
),
$request);
}

View File

@ -35,7 +35,43 @@ class IDF_Views_Wiki
* View list of issues for a given project.
*/
public $index_precond = array('IDF_Precondition::accessWiki');
public function index($request, $match, $api=false)
public function index($request, $match)
{
$project = $request->project;
// Search for the default page
$conf = new IDF_Conf();
$conf->setProject($project);
$page = $conf->getVal('wiki_default_page', null);
if ($page === null) {
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::listing',
array($project->shortname));
return new Pluf_HTTP_Response_Redirect($url);
}
// Find the page
$sql = new Pluf_SQL('project=%s AND title=%s',
array($project->id, $page));
$pages = Pluf::factory('IDF_WikiPage')->getList(array('filter'=>$sql->gen()));
if ($pages->count() != 1) {
// The default page have been delete
$conf->setVal('wiki_default_page', null);
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::listing',
array($project->shortname));
return new Pluf_HTTP_Response_Redirect($url);
}
$page = $pages[0];
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::view',
array($project->shortname, $page->title));
return new Pluf_HTTP_Response_Redirect($url);
}
/**
* View list of issues for a given project.
*/
public $listing_precond = array('IDF_Precondition::accessWiki');
public function listing($request, $match, $api=false)
{
$prj = $request->project;
$title = sprintf(__('%s Documentation'), (string) $prj);
@ -82,7 +118,7 @@ class IDF_Views_Wiki
{
$prj = $request->project;
if (!isset($request->REQUEST['q']) or trim($request->REQUEST['q']) == '') {
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::index',
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::listing',
array($prj->shortname));
return new Pluf_HTTP_Response_Redirect($url);
}
@ -182,7 +218,7 @@ class IDF_Views_Wiki
$urlpage = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::view',
array($prj->shortname, $page->title));
$request->user->setMessage(sprintf(__('The page <a href="%s">%s</a> has been created.'), $urlpage, Pluf_esc($page->title)));
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::index',
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::listing',
array($prj->shortname));
return new Pluf_HTTP_Response_Redirect($url);
} elseif (isset($request->POST['preview'])) {
@ -320,7 +356,7 @@ class IDF_Views_Wiki
$urlpage = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::view',
array($prj->shortname, $page->title));
$request->user->setMessage(sprintf(__('The page <a href="%s">%s</a> has been updated.'), $urlpage, Pluf_esc($page->title)));
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::index',
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::listing',
array($prj->shortname));
return new Pluf_HTTP_Response_Redirect($url);
} elseif (isset($request->POST['preview'])) {
@ -358,7 +394,7 @@ class IDF_Views_Wiki
if ($form->isValid()) {
$form->save();
$request->user->setMessage(__('The documentation page has been deleted.'));
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::index',
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::listing',
array($prj->shortname));
return new Pluf_HTTP_Response_Redirect($url);
}

View File

@ -262,6 +262,11 @@ $ctl[] = array('regex' => '#^/p/([\-\w]+)/doc/$#',
'model' => 'IDF_Views_Wiki',
'method' => 'index');
$ctl[] = array('regex' => '#^/p/([\-\w]+)/doc/list/$#',
'base' => $base,
'model' => 'IDF_Views_Wiki',
'method' => 'listing');
$ctl[] = array('regex' => '#^/p/([\-\w]+)/doc/create/$#',
'base' => $base,
'model' => 'IDF_Views_Wiki',

View File

@ -16,6 +16,34 @@
</td>
</tr>
<tr>
<td colspan="2">{$form.f.wiki_default_page.labelTag}:<br />
{if $form.f.wiki_default_page.errors}{$form.f.wiki_default_page.fieldErrors}{/if}
{$form.f.wiki_default_page|unsafe}
</td>
<script type="text/javascript" src="{media '/idf/js/jquery.bgiframe.min.js'}"></script>
<script type="text/javascript" src="{media '/idf/js/jquery.autocomplete.min.js'}"></script>
<script type="text/javascript" charset="utf-8">
{literal}
$(document).ready(function(){
var auto_wiki_page_name = [{/literal}{$auto_wiki_page_name|safe}{literal}];
$("#id_wiki_default_page").autocomplete(auto_wiki_page_name, {
minChars: 0,
width: 310,
matchContains: true,
max: 50,
highlightItem: false,
formatItem: function(row, i, max, term) {
return row.to.replace(new RegExp("(" + term + ")", "gi"), "<strong>$1</strong>") + " <span style='font-size: 80%;'>" + row.name + "</span>";
},
formatResult: function(row) {
return row.to;
}
});
});
{/literal}
</script>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="{trans 'Save Changes'}" name="submit" />
</td>