This commit is contained in:
Marcin Kurczewski 2013-10-22 00:17:06 +02:00
parent 823888b0c1
commit eaa8c4897d
8 changed files with 114 additions and 6 deletions

View file

@ -17,7 +17,7 @@ postsPerPage=20
thumbWidth=150
thumbHeight=150
thumbStyle=outside
endlessScrolling=1
endlessScrollingDefault=1
maxSearchTokens=4
[comments]

View file

@ -40,14 +40,20 @@
padding: 0;
}
form.settings label.left,
form.delete label.left,
form.edit label.left {
width: 9em;
}
form.settings .alert,
form.delete .alert,
form.edit .alert {
margin: 1em 0;
}
form.settings input,
form.delete input,
form.edit select,
form.edit input {
width: 16em;

View file

@ -12,7 +12,7 @@ class CommentController
$this->context->stylesheets []= 'comment-list.css';
$this->context->stylesheets []= 'comment-small.css';
$this->context->subTitle = 'comments';
if ($this->config->browsing->endlessScrolling)
if ($this->config->user->hasEnabledEndlessScrolling())
$this->context->scripts []= 'paginator-endless.js';
$page = intval($page);

View file

@ -60,7 +60,7 @@ class PostController
$this->context->stylesheets []= 'post-small.css';
$this->context->stylesheets []= 'post-list.css';
$this->context->stylesheets []= 'paginator.css';
if ($this->config->browsing->endlessScrolling)
if ($this->context->user->hasEnabledEndlessScrolling())
$this->context->scripts []= 'paginator-endless.js';
//redirect requests in form of /posts/?query=... to canonical address

View file

@ -53,7 +53,7 @@ class UserController
{
$this->context->stylesheets []= 'user-list.css';
$this->context->stylesheets []= 'paginator.css';
if ($this->config->browsing->endlessScrolling)
if ($this->context->user->hasEnabledEndlessScrolling())
$this->context->scripts []= 'paginator-endless.js';
$page = intval($page);
@ -217,6 +217,42 @@ class UserController
/**
* @route /user/{name}/settings
* @validate name [^\/]+
*/
public function settingsAction($name)
{
$user = Model_User::locate($name);
PrivilegesHelper::confirmWithException(Privilege::ViewUser, PrivilegesHelper::getIdentitySubPrivilege($user));
$this->context->handleExceptions = true;
$this->context->transport->user = $user;
$this->context->transport->tab = 'settings';
$this->context->viewName = 'user-view';
$this->context->stylesheets []= 'user-view.css';
$this->context->subTitle = $name;
if (InputHelper::get('submit'))
{
$suppliedSafety = InputHelper::get('safety');
if (!is_array($suppliedSafety))
$suppliedSafety = [];
foreach (PostSafety::getAll() as $safety)
$user->enableSafety($safety, in_array($safety, $suppliedSafety));
$user->enableEndlessScrolling(InputHelper::get('endless-scrolling'));
R::store($user);
$this->context->transport->user = $user;
if ($this->context->user->id == $user->id)
$this->context->user = $user;
$this->context->transport->success = true;
}
}
/**
* @route /user/{name}/edit
* @validate name [^\/]+
@ -324,7 +360,7 @@ class UserController
$this->context->stylesheets []= 'post-list.css';
$this->context->stylesheets []= 'post-small.css';
$this->context->stylesheets []= 'paginator.css';
if ($this->config->browsing->endlessScrolling)
if ($this->context->user->hasEnabledEndlessScrolling())
$this->context->scripts []= 'paginator-endless.js';
$this->context->subTitle = $name;

View file

@ -41,6 +41,8 @@ class Model_User extends RedBean_SimpleModel
$this->settings = $settings;
}
public function hasEnabledSafety($safety)
{
return $this->getSetting('safety-' . $safety) !== false;
@ -64,6 +66,21 @@ class Model_User extends RedBean_SimpleModel
}
}
public function hasEnabledEndlessScrolling()
{
$ret = $this->getSetting('endless-scrolling');
if ($ret === null)
$ret = \Chibi\Registry::getConfig()->browsing->endlessScrollingDefault;
return $ret;
}
public function enableEndlessScrolling($enabled)
{
$this->setSetting('endless-scrolling', (bool) $enabled);
}
public static function validateUserName($userName)
{
$userName = trim($userName);

View file

@ -0,0 +1,37 @@
<form action="<?php echo \Chibi\UrlHelper::route('user', 'settings', ['name' => $this->context->transport->user->name]) ?>" method="post" class="settings aligned">
<div class="safety">
<label class="left" for="name">Safety:</label>
<div class="input-wrapper">
<?php foreach (PostSafety::getAll() as $safety): ?>
<?php if (PrivilegesHelper::confirm(Privilege::ListPosts, PostSafety::toString($safety))): ?>
<label><input type="checkbox" name="safety[]" value="<?php echo $safety ?>"<?php if ($this->context->transport->user->hasEnabledSafety($safety)) echo ' checked="checked"' ?>/>
<?php echo TextHelper::camelCaseToHumanCase(PostSafety::toString($safety), true) ?></label>
<?php endif ?>
<?php endforeach ?>
</div>
</div>
<div class="endless-scrolling">
<label class="left" for="name">Endless scrolling:</label>
<div class="input-wrapper">
<label>
<input type="checkbox" name="endless-scrolling" <?php if ($this->context->transport->user->hasEnabledEndlessScrolling()) echo ' checked="checked"' ?>/>
Enabled
</label>
</div>
</div>
<input type="hidden" name="submit" value="1"/>
<?php if ($this->context->transport->success === true): ?>
<p class="alert alert-success">Browsing settings updated!</p>
<?php elseif (isset($this->context->transport->errorMessage)): ?>
<p class="alert alert-error">Error: <?php echo $this->context->transport->errorMessage ?></p>
<?php endif ?>
<div>
<label class="left">&nbsp;</label>
<button type="submit">Update settings</button>
</div>
</form>

View file

@ -121,6 +121,16 @@
</a>
</li>
<?php if ($this->context->transport->tab == 'settings'): ?>
<li class="selected settings">
<?php else: ?>
<li class="settings">
<?php endif ?>
<a href="<?php echo \Chibi\UrlHelper::route('user', 'settings', ['name' => $this->context->transport->user->name]) ?>">
Browsing settings
</a>
</li>
<?php if ($canModifyAnything): ?>
<?php if ($this->context->transport->tab == 'edit'): ?>
<li class="selected edit">
@ -152,7 +162,9 @@
<?php $this->renderFile('post-list') ?>
<?php endif ?>
<?php if ($this->context->transport->tab == 'edit'): ?>
<?php if ($this->context->transport->tab == 'settings'): ?>
<?php $this->renderFile('user-settings') ?>
<?php elseif ($this->context->transport->tab == 'edit'): ?>
<?php $this->renderFile('user-edit') ?>
<?php elseif ($this->context->transport->tab == 'delete'): ?>
<?php $this->renderFile('user-delete') ?>