Commit 3164b113 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Refined match editing

parent 3179a789
...@@ -30,6 +30,10 @@ $ -> ...@@ -30,6 +30,10 @@ $ ->
.append($(@).parent('label').html()) .append($(@).parent('label').html())
$(@).closest('.radio').replaceWith(group) $(@).closest('.radio').replaceWith(group)
$('tr').on 'click', -> if /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
href = $(this).data('href') $('abbr').on 'click', ->
document.location = href if href? alert($(@).attr('title'))
$('tr').on 'click', ->
href = $(this).data('href')
document.location = href if href?
...@@ -43,6 +43,8 @@ $ -> ...@@ -43,6 +43,8 @@ $ ->
match_total.text(sum) match_total.text(sum)
match_avg.text(Math.round(sum / count * 10) / 10) match_avg.text(Math.round(sum / count * 10) / 10)
inputs.filter('[value=""]:first').focus()
$('textarea').on 'keyup', -> $('textarea').on 'keyup', ->
$(@).height(0).height($(@).prop('scrollHeight')) $(@).height(0).height($(@).prop('scrollHeight'))
......
...@@ -84,7 +84,7 @@ function filter_form($matches) { ...@@ -84,7 +84,7 @@ function filter_form($matches) {
return $form; return $form;
} }
function create_match_form() { function create_form() {
global $db, $user; global $db, $user;
$disciplines = array('barebow', 'recurve', 'compound'); $disciplines = array('barebow', 'recurve', 'compound');
...@@ -141,6 +141,25 @@ function create_match_form() { ...@@ -141,6 +141,25 @@ function create_match_form() {
return $form; return $form;
} }
function edit_form($match) {
$form = create_form();
$form->setAction("match/{$match->id}");
$form->addHidden('_METHOD', 'PUT');
$created_at = preg_replace('/^(\d{4}-\d{1,2}-\d{1,2})[T ](\d{1,2}:\d{1,2}):00$/', '\1T\2', $match->created_at);
$form['name']->setDefaultValue($match->name);
$form['created_at']->setDefaultValue($created_at);
$form['distance']->setDefaultValue($match->distance);
$form['discipline']->setDefaultValue($match->discipline);
$form['arrows']->setDefaultValue($match->arrows);
$form['turns']->setDefaultValue($match->turns);
$form['notes']->setDefaultValue($match->notes);
return $form;
}
$app->get('/matches', function ($filter=null) use ($app, $db, $user) { $app->get('/matches', function ($filter=null) use ($app, $db, $user) {
$matches = $db->table('match') $matches = $db->table('match')
...@@ -170,15 +189,14 @@ $app->get('/matches', function ($filter=null) use ($app, $db, $user) { ...@@ -170,15 +189,14 @@ $app->get('/matches', function ($filter=null) use ($app, $db, $user) {
$app->render('match/list', compact('matches', 'filter_form')); $app->render('match/list', compact('matches', 'filter_form'));
}); });
$app->get('/match/:id', render_match_action('view')); $app->get('/match/:id', render_match_action('view'));
$app->get('/match/:id/edit', render_match_action('edit'));
$app->get('/match/:id/scores', render_match_action('scores')); $app->get('/match/:id/scores', render_match_action('scores'));
$app->get('/match/:id/delete', render_match_action('delete')); $app->get('/match/:id/delete', render_match_action('delete'));
$app->get('/match', function () use ($app) { $app->get('/match', function () use ($app) {
$app->render('match/create', array('form' => create_match_form())); $app->render('match/create', array('form' => create_form()));
}); });
$app->post('/match', function () use ($app, $db, $user) { $app->post('/match', function () use ($app, $db, $user) {
$form = create_match_form(); $form = create_form();
$form->validate(); $form->validate();
if (!$form->hasErrors()) { if (!$form->hasErrors()) {
...@@ -202,11 +220,53 @@ $app->post('/match/:id/scores', function ($id) use ($app, $db) { ...@@ -202,11 +220,53 @@ $app->post('/match/:id/scores', function ($id) use ($app, $db) {
$app->redirect(ROOT_URL . '/match/' . $id); $app->redirect(ROOT_URL . '/match/' . $id);
}); });
$app->delete('/match/:id', function ($id) { $app->delete('/match/:id', function ($id) use ($app, $db) {
find_match($id)->delete(); find_match($id)->delete();
$app->redirect(ROOT_URL . '/matches'); $app->redirect(ROOT_URL . '/matches');
}); });
$app->put('/match/:id', function ($id) { $app->get('/match/:id/edit', function ($id) use ($app) {
// TODO $match = find_match($id);
$form = edit_form($match);
$app->render('match/edit', compact('form', 'match'));
});
$app->put('/match/:id', function ($id) use ($app) {
function zeropad($array, $size) {
return array_pad(array_slice($array, 0, $size), $size, 0);
}
$match = find_match($id);
$form = edit_form($match);
$form->validate();
if (!$form->hasErrors()) {
$values = $form->getValues();
$update = array(
'name' => $values->name,
'created_at' => str_replace('T', ' ', $values->created_at) . ':00',
'distance' => $values->distance,
'discipline' => $values->discipline,
'arrows' => $values->arrows,
'turns' => $values->turns,
'notes' => $values->notes
);
if ($values->arrows != $match->arrows || $values->turns != $match->turns) {
$scores = unpack_scores($match->scores);
$turns = array_chunk($scores, $match->arrows);
foreach ($turns as $i => $turn)
$turns[$i] = zeropad($turn, $values->arrows);
$scores = call_user_func_array('array_merge', $turns);
$scores = zeropad($scores, $values->turns * $values->arrows);
$update['scores'] = pack_scores($scores);
}
$match->update($update);
$app->redirect(ROOT_URL . "/match/{$match->id}");
}
$app->render('match/edit', compact('form', 'match'));
}); });
...@@ -51,6 +51,7 @@ $xs-width: 768px ...@@ -51,6 +51,7 @@ $xs-width: 768px
input input
border: none border: none
width: 100% width: 100%
background-color: #fff
.panel textarea .panel textarea
border: none border: none
...@@ -62,8 +63,22 @@ $xs-width: 768px ...@@ -62,8 +63,22 @@ $xs-width: 768px
white-space: normal white-space: normal
.actions .actions
float: right
margin-bottom: 15px margin-bottom: 15px
.btn
.glyphicon
display: none
.text
display: inline-block
@media (max-width: $xs-width - 1)
.actions
float: right
.btn
.glyphicon
display: inline-block
.text
display: none
.tags span .tags span
margin-right: 4px margin-right: 4px
...@@ -10,9 +10,11 @@ ...@@ -10,9 +10,11 @@
<div class="btn-group actions"> <div class="btn-group actions">
<a href="matches" class="btn btn-default" title="Cancel"> <a href="matches" class="btn btn-default" title="Cancel">
<span class="glyphicon glyphicon-remove"></span> <span class="glyphicon glyphicon-remove"></span>
<span class="text">Cancel</span>
</a> </a>
<button type="submit" name="send" class="btn btn-primary" title="Save"> <button type="submit" name="send" class="btn btn-primary" title="Save">
<span class="glyphicon glyphicon-save"></span> <span class="glyphicon glyphicon-save"></span>
<span class="text">Save</span>
</button> </button>
</div> </div>
</div> </div>
......
...@@ -10,13 +10,17 @@ ...@@ -10,13 +10,17 @@
</p> </p>
<form action="match/{$match->id}" method="post"> <form action="match/{$match->id}" method="post">
<div class="btn-group actions">
<a href="match/{$match->id}" class="btn btn-default" title="cancel">
<span class="glyphicon glyphicon-remove"></span>
<span class="text">Cancel</span>
</a>
<button type="submit" class="btn btn-primary">
<span class="glyphicon glyphicon-ok"></span>
<span class="text">Yes, I'm sure</span>
</button>
</div>
<input type="hidden" name="_METHOD" value="DELETE"/> <input type="hidden" name="_METHOD" value="DELETE"/>
<button type="submit" class="btn btn-primary">
Yes, I'm sure
</button>
<a href="match/{$match->id}" class="btn btn-default">
Cancel
</a>
</form> </form>
{/block} {/block}
...@@ -2,4 +2,18 @@ ...@@ -2,4 +2,18 @@
{block content} {block content}
<h2 class="page-header">{$match->name}</h2> <h2 class="page-header">{$match->name}</h2>
{form $form}
{form errors}
{form controls}
<div class="form-group">
<div class="form-actions col-sm-offset-2 col-sm-10">
<div class="btn-group actions">
<button type="submit" name="send" class="btn btn-primary" title="Save">
<span class="glyphicon glyphicon-ok"></span>
<span class="text">Save</span>
</button>
</div>
</div>
</div>
{/form}
{/block} {/block}
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<h2 class="page-header"> <h2 class="page-header">
Matches Matches
<div class="btn-group"> <div class="btn-group">
<a href="match" title="Add new match" class="btn btn-sm btn-default"> <a href="match" class="btn btn-sm btn-default" title="Add new match">
<span class="glyphicon glyphicon-plus"></span> <span class="glyphicon glyphicon-plus"></span>
</a> </a>
<a data-toggle="collapse" href="#filter" title="Filter" <a data-toggle="collapse" href="#filter" title="Filter"
......
...@@ -31,7 +31,8 @@ ...@@ -31,7 +31,8 @@
<th class="separator">{$i + 1}</th> <th class="separator">{$i + 1}</th>
<td n:foreach="$row as $j => $arrow" <td n:foreach="$row as $j => $arrow"
n:class="$j == $match->arrows - 1 ? separator"> n:class="$j == $match->arrows - 1 ? separator">
<input type="number" min="0" max="10" name="scores[]" value="{$arrow ? $arrow}"> <input type="number" min="0" max="10" name="scores[]"
value="{$arrow ? $arrow}">
</td> </td>
<td class="row-total">{$sum = array_sum($row)}</td> <td class="row-total">{$sum = array_sum($row)}</td>
<td class="total">{$total = $total + $sum}</td> <td class="total">{$total = $total + $sum}</td>
...@@ -42,7 +43,9 @@ ...@@ -42,7 +43,9 @@
<th colspan="{$match->arrows + 2}">Total:<br>Average:</th> <th colspan="{$match->arrows + 2}">Total:<br>Average:</th>
<td> <td>
<span class="match-total">{$total}</span><br> <span class="match-total">{$total}</span><br>
<span class="match-avg">{$total / ($match->turns * $match->arrows)|number:1}</span> <span class="match-avg" title="{$total / ($match->turns * $match->arrows)|number:4}">
{$total / ($match->turns * $match->arrows)|number:1}
</span>
</td> </td>
</tr> </tr>
</tbody> </tbody>
...@@ -61,6 +64,7 @@ ...@@ -61,6 +64,7 @@
<div class="actions"> <div class="actions">
<button type="submit" class="btn btn-primary" title="Save"> <button type="submit" class="btn btn-primary" title="Save">
<span class="glyphicon glyphicon-ok"></span> <span class="glyphicon glyphicon-ok"></span>
<span class="text">Save</span>
</button> </button>
</div> </div>
......
...@@ -42,7 +42,9 @@ ...@@ -42,7 +42,9 @@
<tr n:foreach="$rows as $i => $row"> <tr n:foreach="$rows as $i => $row">
<th class="separator">{$i + 1}</th> <th class="separator">{$i + 1}</th>
<td n:foreach="$row as $j => $arrow" <td n:foreach="$row as $j => $arrow"
n:class="$j == $match->arrows - 1 ? separator">{$arrow}</td> n:class="$j == $match->arrows - 1 ? separator">
<input type="text" disabled value="{$arrow}">
</td>
<td>{$sum = array_sum($row)}</td> <td>{$sum = array_sum($row)}</td>
<td>{$total = $total + $sum}</td> <td>{$total = $total + $sum}</td>
</tr> </tr>
...@@ -50,7 +52,12 @@ ...@@ -50,7 +52,12 @@
<tbody> <tbody>
<tr> <tr>
<th colspan="{$match->arrows + 2}">Total:<br>Average:</th> <th colspan="{$match->arrows + 2}">Total:<br>Average:</th>
<td>{$total}<br>{$total / ($match->turns * $match->arrows)|number:1}</td> <td>
{$total}<br>
<abbr title="{$total / ($match->turns * $match->arrows)|number:4}">
{$total / ($match->turns * $match->arrows)|number:1}
</abbr>
</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
...@@ -67,12 +74,15 @@ ...@@ -67,12 +74,15 @@
<div class="btn-group actions"> <div class="btn-group actions">
<a href="match/{$match->id}/edit" class="btn btn-default" title="Edit metadata"> <a href="match/{$match->id}/edit" class="btn btn-default" title="Edit metadata">
<span class="glyphicon glyphicon-cog"></span> <span class="glyphicon glyphicon-cog"></span>
<span class="text">Edit metadata</span>
</a> </a>
<a href="match/{$match->id}/scores" class="btn btn-default" title="Edit scores"> <a href="match/{$match->id}/scores" class="btn btn-default" title="Edit scores">
<span class="glyphicon glyphicon-pencil"></span> <span class="glyphicon glyphicon-pencil"></span>
<span class="text">Edit scores</span>
</a> </a>
<a href="match/{$match->id}/delete" class="btn btn-danger" title="Delete"> <a href="match/{$match->id}/delete" class="btn btn-danger" title="Delete">
<span class="glyphicon glyphicon-trash"></span> <span class="glyphicon glyphicon-trash"></span>
<span class="text">Delete</span>
</a> </a>
</div> </div>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment