Skip to content

Commit bef717b

Browse files
committed
add typeahead support for owner email when adding new server
closes pterodactyl#144 pic: http://s3.pterodactyl.io/UpPSJ.png
1 parent f9f751b commit bef717b

File tree

6 files changed

+55
-0
lines changed

6 files changed

+55
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1010
* Support for filtering servers within Admin CP to narrow down results by name, email, allocation, or defined fields.
1111
* Setup scripts (user, mail, env) now support argument flags for use in containers and other non-terminal environments.
1212
* New API endpoints for individual users to control their servers with at `/api/me/*`.
13+
* Typeahead support for owner email when adding a new server.
1314

1415
### Changed
1516
* Creating a user, server, or node now returns `HTTP/1.1 200` and a JSON element with the user/server/node's ID.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ Socket.io - [license](https://github.com/socketio/socket.io/blob/master/LICENSE)
6363

6464
SweetAlert - [license](https://github.com/t4t5/sweetalert/blob/master/LICENSE) - [homepage](http://t4t5.github.io/sweetalert/)
6565

66+
Typeahead — [license](https://github.com/bassjobsen/Bootstrap-3-Typeahead/blob/master/bootstrap3-typeahead.js)[homepage](https://github.com/bassjobsen/Bootstrap-3-Typeahead)
67+
6668
### Additional License Information
6769
Some Javascript and CSS used within the panel is licensed under a `MIT` or `Apache 2.0`. Please check their respective header files for more information.
6870

app/Http/Controllers/Admin/UserController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,12 @@ public function updateUser(Request $request, $user)
130130
return redirect()->route('admin.users.view', $user);
131131
}
132132

133+
public function getJson(Request $request)
134+
{
135+
foreach(User::select('email')->get() as $user) {
136+
$resp[] = $user->email;
137+
}
138+
return $resp;
139+
}
140+
133141
}

app/Http/Routes/AdminRoutes.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public function map(Router $router) {
7373
'uses' => 'Admin\UserController@getIndex'
7474
]);
7575

76+
$router->get('/accounts.json', [
77+
'as' => 'admin.users.json',
78+
'uses' => 'Admin\UserController@getJson'
79+
]);
80+
7681
// View Specific Account
7782
$router->get('/view/{id}', [
7883
'as' => 'admin.users.view',

public/js/vendor/typeahead/typeahead.min.js

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/views/admin/servers/new.blade.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
Create New Server
2424
@endsection
2525

26+
@section('scripts')
27+
@parent
28+
{!! Theme::js('js/vendor/typeahead/typeahead.min.js') !!}
29+
@endsection
30+
2631
@section('content')
2732
<div class="col-md-12">
2833
<ul class="breadcrumb">
@@ -44,6 +49,8 @@
4449
<div class="form-group col-md-6">
4550
<label for="owner" class="control-label">Owner Email</label>
4651
<div>
52+
{{-- Hacky workaround to prevent Safari and Chrome from trying to suggest emails here --}}
53+
<input id="fake_user_name" name="fake_user[name]" style="position:absolute; top:-10000px;" type="text" value="Autofill Me">
4754
<input type="text" autocomplete="off" name="owner" class="form-control" value="{{ old('owner', Input::get('email')) }}" />
4855
</div>
4956
</div>
@@ -253,6 +260,17 @@
253260
$('input[name="custom_image_name"]').val('').prop('disabled', !($(this).is(':checked')));
254261
});
255262
263+
// Typeahead
264+
$.ajax({
265+
type: 'GET',
266+
url: '{{ route('admin.users.json') }}',
267+
}).done(function (data) {
268+
$('input[name="owner"]').typeahead({ fitToElement: true, source: data });
269+
}).fail(function (jqXHR) {
270+
alert('Could not initialize user email typeahead.')
271+
console.log(jqXHR);
272+
});
273+
256274
var nodeData = null;
257275
var currentLocation = null;
258276
var currentNode = null;

0 commit comments

Comments
 (0)