1
0
mirror of https://github.com/cydrobolt/polr.git synced 2024-11-08 11:12:30 +01:00

delegate button actions to parent & add API active toggle logic

This commit is contained in:
Chaoyi Zha 2015-12-12 12:47:20 -05:00
parent c48bcc491d
commit e58cd81a93
7 changed files with 34 additions and 7 deletions

3
.jshintrc Normal file
View File

@ -0,0 +1,3 @@
{
"esnext": true
}

View File

@ -29,5 +29,24 @@ class AjaxController extends Controller {
if (!$this->currIsAdmin()) {
abort(401, 'User not admin.');
}
$user_to_toggle = $request->input('user_id');
$user = User::where('id', $user_id)
->where('active', 1)
->first();
if (!$user) {
abort(404, 'User not found.');
}
$current_status = $user->api_active;
if ($current_status == 1) {
$new_status = 0;
}
else {
$new_status = 1;
}
$user->api_active = $new_status;
$user->save();
}
}

View File

@ -35,5 +35,5 @@ $app->post('/signup', ['as' => 'psignup', 'uses' => 'UserController@performSignu
$app->post('/shorten', ['as' => 'shorten', 'uses' => 'LinkController@performShorten']);
/* API endpoints */
$app->post('/api/v2/link_avail_check', ['as' => 'link_check', 'uses' => 'AjaxController@checkLinkAvailability']);
$app->post('/api/v2/admin/toggle_api_active', ['as' => 'link_check', 'uses' => 'AjaxController@toggleAPIActive']);
$app->post('/api/v2/link_avail_check', ['as' => 'api_link_check', 'uses' => 'AjaxController@checkLinkAvailability']);
$app->post('/api/v2/admin/toggle_api_active', ['as' => 'api_toggle_api_active', 'uses' => 'AjaxController@toggleAPIActive']);

View File

@ -46,7 +46,7 @@ $(function () {
{{else}}
False
{{/if}}
- <a href='#' data-user-id='{{user_id}}' class='toggle-api-active' class='btn btn-xs btn-success'>Active (click to toggle)</a>
- <a data-user-id='{{user_id}}' class='toggle-api-active btn btn-xs btn-success'>Active (click to toggle)</a>
</p>
<p>
<span>API Key: <code>{{api_key}}</code></span>
@ -62,6 +62,7 @@ $(function () {
api_key: api_key,
api_active: api_active,
api_quota: api_quota,
user_id: user_id,
title: "API Information for " + username,
body: markup
};
@ -74,12 +75,10 @@ $(function () {
$('.activate-edit-modal').click(function () {
// activate modal
});
$('.toggle-api-active').click(function () {
$('body').delegate('.toggle-api-active', 'click', function () {
var toggle_user_id = $(this).data('user-id');
apiCall('admin/toggle_api_active', {
'user_id': toggle_user_id,
});
});
});

View File

@ -1,6 +1,7 @@
function apiCall(path, data) {
var base_api_path = '/api/v2/';
var base_api_path = BASE_API_PATH;
var api_path = base_api_path + path;
console.log('api call');
$.ajax({
url: api_path,
data: data

3
public/js/constants.js Normal file
View File

@ -0,0 +1,3 @@
/* Polr JS Constants */
const BASE_API_PATH = '/api/v2/';

View File

@ -30,6 +30,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<link rel="stylesheet" href="/css/base.css" />
<link href="/css/font-awesome.min.css" rel="stylesheet">
<link rel="shortcut icon" href="favicon.ico" />
<script src='/js/constants.js'></script>
<script src="/js/jquery-1.11.3.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
@yield('css')