Added user view placeholder templates

This commit is contained in:
Marcin Kurczewski 2014-09-04 19:07:57 +02:00
parent c5881d1c0d
commit 03fbe0990a
6 changed files with 194 additions and 14 deletions

View file

@ -1,19 +1,50 @@
var App = App || {}; var App = App || {};
App.Presenters = App.Presenters || {}; App.Presenters = App.Presenters || {};
App.Presenters.UserPresenter = function(jQuery, topNavigationPresenter, appState) { App.Presenters.UserPresenter = function(
jQuery,
util,
promise,
api,
appState,
topNavigationPresenter,
messagePresenter) {
var $el = jQuery('#content'); var $el = jQuery('#content');
var $messages = $el;
var template;
var accountSettingsTemplate;
var browsingSettingsTemplate;
var user;
var userName; var userName;
function init(args) { function init(args) {
userName = args.userName; userName = args.userName;
topNavigationPresenter.select(appState.get('loggedIn') && appState.get('loggedInUser').name == userName ? 'my-account' : 'users'); topNavigationPresenter.select(appState.get('loggedIn') && appState.get('loggedInUser').name == userName ? 'my-account' : 'users');
render();
promise.waitAll(
util.promiseTemplate('user'),
util.promiseTemplate('account-settings'),
util.promiseTemplate('browsing-settings'),
api.get('/users/' + userName))
.then(function(userHtml, accountSettingsHtml, browsingSettingsHtml, response) {
template = _.template(userHtml);
accountSettingsTemplate = _.template(accountSettingsHtml);
browsingSettingsTemplate = _.template(browsingSettingsHtml);
user = response.json;
render();
}).fail(function(response) {
$el.empty();
messagePresenter.showError($messages, response.json && response.json.error || response);
});
} }
function render() { function render() {
$el.html('Viewing user: ' + userName); $el.html(template({user: user}));
$el.find('.browsing-settings').html(browsingSettingsTemplate({user: user}));
$el.find('.account-settings').html(accountSettingsTemplate({user: user}));
$messages = $el.find('.messages');
}; };
return { return {

View file

@ -0,0 +1,74 @@
<form class="account-settings">
<div class="form-row">
<label class="form-label">User picture:</label>
<div class="form-input">
<label for="account-settings-avatar-gravatar">
<input type="radio" name="avatar-style" id="account-settings-avatar-gravatar" class="avatar-style" value="gravatar"/>
Gravatar
</label>
<label for="account-settings-avatar-manual">
<input type="radio" name="avatar-style" id="account-settings-avatar-manual" class="avatar-style" value="manual"/>
Custom
</label>
<label for="account-settings-avatar-none">
<input type="radio" name="avatar-style" id="account-settings-avatar-none" class="avatar-style" value="none"/>
None
</label>
</div>
</div>
<div class="form-row">
<label class="form-label" for="account-settings-avatar-content"></label>
<div class="form-input">
<input class="avatar-content" type="file" name="avatar-content" id="account-settings-avatar-content"/>
</div>
</div>
<div class="form-row">
<label class="form-label" for="account-settings-name">Name:</label>
<div class="form-input">
<input type="text" name="name" id="account-settings-name" placeholder="New name&hellip;" value=""/>
</div>
</div>
<div class="form-row">
<label class="form-label" for="account-settings-email">E-mail:</label>
<div class="form-input">
<input type="text" name="email" id="account-settings-email" placeholder="New e-mail&hellip;" value=""/>
</div>
</div>
<div class="form-row">
<label class="form-label" for="account-settings-password1">New password:</label>
<div class="form-input">
<input type="password" name="password1" id="account-settings-password1" placeholder="New password&hellip;" value=""/>
</div>
</div>
<div class="form-row">
<label class="form-label" for="account-settings-password2"></label>
<div class="form-input">
<input type="password" name="password2" id="account-settings-password2" placeholder="New password&hellip; (repeat)" value=""/>
</div>
</div>
<div class="form-row">
<label class="form-label" for="account-settings-access-rank">Access rank:</label>
<div class="form-input">
<select name="access-rank" id="account-settings-access-rank">
<option value="anonymous">anonymous</option>
<option value="regular-user">registered</option>
<option value="power-user">power user</option>
<option value="moderator">moderator</option>
<option value="administrator" selected="selected">admin</option>
</select>
</div>
</div>
<div class="form-row">
<label class="form-label"></label>
<div class="form-input">
<button class="submit" type="submit">Update settings</button>
</div>
</div>
</form>

View file

@ -0,0 +1,55 @@
<form class="browsing-settings">
<div class="form-row">
<label class="form-label">Safety:</label>
<div class="form-input">
<input type="hidden" name="safety[]" value=""/>
<label for="browsing-settings-safety-safe">
<input type="checkbox" id="browsing-settings-safety-safe" name="safety[]" value="1"/>
Safe
</label>
<input type="hidden" name="safety[]" value=""/>
<label for="browsing-settings-safety-sketchy">
<input type="checkbox" id="browsing-settings-safety-sketchy" name="safety[]" value="2"/>
Sketchy
</label>
<input type="hidden" name="safety[]" value=""/>
<label for="browsing-settings-safety-unsafe">
<input type="checkbox" id="browsing-settings-safety-unsafe" name="safety[]" value="3"/>
Unsafe
</label>
</div>
</div>
<div class="form-row">
<label class="form-label" for="browsing-settings-endless-scrolling">Endless scrolling:</label>
<div class="form-input">
<input type="hidden" name="endless-scrolling" value="0"/>
<label for="browsing-settings-endless-scrolling">
<input type="checkbox" id="browsing-settings-endless-scrolling" name="endless-scrolling" value="1"/>
Enabled
</label>
</div>
</div>
<div class="form-row">
<label class="form-label" for="browsing-settings-hide-disliked-posts">Hide down-voted:</label>
<div class="form-input">
<input type="hidden" name="hide-disliked-posts" value="0"/>
<label for="browsing-settings-hide-disliked-posts">
<input type="checkbox" id="browsing-settings-hide-disliked-posts" name="hide-disliked-posts" value="1"/>
Enabled
</label>
</div>
</div>
<div class="form-row">
<label class="form-label"></label>
<div class="form-input">
<button class="submit" type="submit">Update settings</button>
</div>
</div>
</form>

View file

@ -0,0 +1,13 @@
<div id="user-view">
<div class="messages"></div>
<%= user.name %>
<h2>Browsing settings</h2>
<div class="browsing-settings"></div>
<h2>Account settings</h2>
<div class="account-settings"></div>
</div>

View file

@ -18,13 +18,14 @@ final class UserController extends AbstractController
{ {
$router->post('/api/users', [$this, 'register']); $router->post('/api/users', [$this, 'register']);
$router->get('/api/users', [$this, 'getFiltered']); $router->get('/api/users', [$this, 'getFiltered']);
$router->get('/api/users/:id', [$this, 'getById']); $router->get('/api/users/:name', [$this, 'getByName']);
$router->put('/api/users/:id', [$this, 'update']); $router->put('/api/users/:name', [$this, 'update']);
$router->delete('/api/users/:id', [$this, 'delete']); $router->delete('/api/users/:name', [$this, 'delete']);
} }
public function getFiltered() public function getFiltered()
{ {
//todo: privilege checking
//todo: move this to form data constructor //todo: move this to form data constructor
$searchFormData = new \Szurubooru\FormData\SearchFormData; $searchFormData = new \Szurubooru\FormData\SearchFormData;
$searchFormData->query = $this->inputReader->query; $searchFormData->query = $this->inputReader->query;
@ -38,30 +39,33 @@ final class UserController extends AbstractController
'totalRecords' => $searchResult->totalRecords]; 'totalRecords' => $searchResult->totalRecords];
} }
public function getById($id) public function getByName($name)
{ {
throw new \BadMethodCallException('Not implemented'); //todo: privilege checking
$user = $this->userService->getByName($name);
if (!$user)
throw new \DomainException('User with name "' . $name . '" was not found.');
return new \Szurubooru\ViewProxies\User($user);
} }
public function register() public function register()
{ {
//todo: privilege checking
$input = new \Szurubooru\FormData\RegistrationFormData; $input = new \Szurubooru\FormData\RegistrationFormData;
//todo: move this to form data constructor //todo: move this to form data constructor
$input->name = $this->inputReader->userName; $input->name = $this->inputReader->userName;
$input->password = $this->inputReader->password; $input->password = $this->inputReader->password;
$input->email = $this->inputReader->email; $input->email = $this->inputReader->email;
$user = $this->userService->register($input); $user = $this->userService->register($input);
return new \Szurubooru\ViewProxies\User($user); return new \Szurubooru\ViewProxies\User($user);
} }
public function update($id) public function update($name)
{ {
throw new \BadMethodCallException('Not implemented'); throw new \BadMethodCallException('Not implemented');
} }
public function delete($id) public function delete($name)
{ {
throw new \BadMethodCallException('Not implemented'); throw new \BadMethodCallException('Not implemented');
} }

View file

@ -29,6 +29,11 @@ class UserService
$this->timeService = $timeService; $this->timeService = $timeService;
} }
public function getByName($name)
{
return $this->userDao->getByName($name);
}
public function getFiltered(\Szurubooru\FormData\SearchFormData $formData) public function getFiltered(\Szurubooru\FormData\SearchFormData $formData)
{ {
$pageSize = intval($this->config->users->usersPerPage); $pageSize = intval($this->config->users->usersPerPage);
@ -46,8 +51,6 @@ class UserService
if ($this->userDao->getByName($formData->name)) if ($this->userDao->getByName($formData->name))
throw new \DomainException('User with this name already exists.'); throw new \DomainException('User with this name already exists.');
//todo: privilege checking
$user = new \Szurubooru\Entities\User(); $user = new \Szurubooru\Entities\User();
$user->name = $formData->name; $user->name = $formData->name;
$user->email = $formData->email; $user->email = $formData->email;