Skip to content
Permalink
Browse files

delegate button actions to parent & add API active toggle logic

  • Loading branch information...
cydrobolt committed Dec 12, 2015
1 parent c48bcc4 commit e58cd81a930d35c0e169eb941e101fb82387dcdb
@@ -0,0 +1,3 @@
{
"esnext": true
}
@@ -29,5 +29,24 @@ public function toggleAPIActive(Request $request) {
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();
}
}
@@ -35,5 +35,5 @@
$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']);
@@ -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,
});
});

});
@@ -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
@@ -0,0 +1,3 @@
/* Polr JS Constants */

const BASE_API_PATH = '/api/v2/';
@@ -30,6 +30,8 @@
<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')

0 comments on commit e58cd81

Please sign in to comment.
You can’t perform that action at this time.