Skip to content

Commit

Permalink
Misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
WoWTech committed Jul 26, 2017
1 parent 0e14fd6 commit d7b32d0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
4 changes: 3 additions & 1 deletion app/Http/Controllers/AccountsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public function store()
'password' => 'required|string|min:6|confirmed',
]);

Account::create(request()->all());
$account = Account::create(request()->all());

$account->attachRole('user');

return redirect()->route('admin.accounts.index');
}
Expand Down
18 changes: 9 additions & 9 deletions public/js/admin/main.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
let timer;
let timerInterval = 100;
let username_input = $('#username');
let username_autocomplete = $('#username-autocomplete');

username_input.keyup(function(){
username_autocomplete.keyup(function(){
clearTimeout(timer);
timer = setTimeout(getUsers, timerInterval);
});

username_input.keydown(function(){
username_autocomplete.keydown(function(){
clearTimeout(timer);
});

$("body").on('click', 'ul#ajax-users-list li', (e) => {
$("#acc").val($(e.target).data('id'));
$("#username").val($(e.target).data('username'));
$("#username-autocomplete").val($(e.target).data('username'));
$('ul#ajax-users-list').remove();
});

$("#username").blur(() => {
username_autocomplete.blur(() => {
setTimeout(() => {$('ul#ajax-users-list').hide()}, 200);
});

$("#username").focus(() => {
username_autocomplete.focus(() => {
$('ul#ajax-users-list').show();
});

Expand All @@ -35,17 +35,17 @@ let showUsers = data =>
});
list += "</ul>";

username_input.after(list);
username_autocomplete.after(list);
}

let getUsers = () =>
{
if (username_input.val().length < 3)
if (username_autocomplete.val().length < 3)
return;

$.post("/admin/getusers",
{
username: username_input.val(),
username: username_autocomplete.val(),
_token: $("meta[name='_token']").attr('content')
}, showUsers);
}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/admin/accounts/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<div class="roles-array">
@foreach ($roles as $role)
<div class="role-block">
<input type="checkbox" name="roles[]" value="{{ $role->id }}" {{ !Auth::user()->hasRole($role->name) ?: 'checked' }}>
<input type="checkbox" name="roles[]" value="{{ $role->id }}" {{ !$account->hasRole($role->name) ?: 'checked' }}>
<span class="role-caption">{{ $role->display_name }}</span>
</div>
@endforeach
Expand Down
4 changes: 2 additions & 2 deletions resources/views/admin/posts/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<form action="{{ route('admin.posts.update', $post) }}" method="POST">

@include('layouts.input_errors')

{{ csrf_field() }}
{{ method_field('PATCH') }}
<div class="input-group">
Expand All @@ -22,7 +22,7 @@
</div>
<div class="input-group">
<label for="author">Post author</label>
<input id="username" type="text" name="username" value="{{ $post->account->username }}" required>
<input id="username-autocomplete" type="text" name="username" value="{{ $post->account->username }}" required>
<input id="acc" type="hidden" name="account_id" value="{{ $post->account->id }}" required>
</div>
<div class="input-group">
Expand Down
2 changes: 1 addition & 1 deletion resources/views/admin/posts/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<td>{{ $post->account->username }}</td>
<td>{{ $post->created_at->toFormattedDateString() }}</td>
<td>
@permission('edit-post')
@permission('update-post')
<a href="{{ route('admin.posts.edit', $post) }}">Edit</a>
@endpermission
@permission('delete-post')
Expand Down

0 comments on commit d7b32d0

Please sign in to comment.