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:
parent
c48bcc491d
commit
e58cd81a93
@ -29,5 +29,24 @@ class AjaxController extends Controller {
|
|||||||
if (!$this->currIsAdmin()) {
|
if (!$this->currIsAdmin()) {
|
||||||
abort(401, 'User not admin.');
|
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('/signup', ['as' => 'psignup', 'uses' => 'UserController@performSignu
|
|||||||
$app->post('/shorten', ['as' => 'shorten', 'uses' => 'LinkController@performShorten']);
|
$app->post('/shorten', ['as' => 'shorten', 'uses' => 'LinkController@performShorten']);
|
||||||
|
|
||||||
/* API endpoints */
|
/* API endpoints */
|
||||||
$app->post('/api/v2/link_avail_check', ['as' => 'link_check', 'uses' => 'AjaxController@checkLinkAvailability']);
|
$app->post('/api/v2/link_avail_check', ['as' => 'api_link_check', 'uses' => 'AjaxController@checkLinkAvailability']);
|
||||||
$app->post('/api/v2/admin/toggle_api_active', ['as' => 'link_check', 'uses' => 'AjaxController@toggleAPIActive']);
|
$app->post('/api/v2/admin/toggle_api_active', ['as' => 'api_toggle_api_active', 'uses' => 'AjaxController@toggleAPIActive']);
|
||||||
|
@ -46,7 +46,7 @@ $(function () {
|
|||||||
{{else}}
|
{{else}}
|
||||||
False
|
False
|
||||||
{{/if}}
|
{{/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>
|
||||||
<p>
|
<p>
|
||||||
<span>API Key: <code>{{api_key}}</code></span>
|
<span>API Key: <code>{{api_key}}</code></span>
|
||||||
@ -62,6 +62,7 @@ $(function () {
|
|||||||
api_key: api_key,
|
api_key: api_key,
|
||||||
api_active: api_active,
|
api_active: api_active,
|
||||||
api_quota: api_quota,
|
api_quota: api_quota,
|
||||||
|
user_id: user_id,
|
||||||
title: "API Information for " + username,
|
title: "API Information for " + username,
|
||||||
body: markup
|
body: markup
|
||||||
};
|
};
|
||||||
@ -74,12 +75,10 @@ $(function () {
|
|||||||
$('.activate-edit-modal').click(function () {
|
$('.activate-edit-modal').click(function () {
|
||||||
// activate modal
|
// activate modal
|
||||||
});
|
});
|
||||||
|
$('body').delegate('.toggle-api-active', 'click', function () {
|
||||||
$('.toggle-api-active').click(function () {
|
|
||||||
var toggle_user_id = $(this).data('user-id');
|
var toggle_user_id = $(this).data('user-id');
|
||||||
apiCall('admin/toggle_api_active', {
|
apiCall('admin/toggle_api_active', {
|
||||||
'user_id': toggle_user_id,
|
'user_id': toggle_user_id,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
function apiCall(path, data) {
|
function apiCall(path, data) {
|
||||||
var base_api_path = '/api/v2/';
|
var base_api_path = BASE_API_PATH;
|
||||||
var api_path = base_api_path + path;
|
var api_path = base_api_path + path;
|
||||||
|
console.log('api call');
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: api_path,
|
url: api_path,
|
||||||
data: data
|
data: data
|
||||||
|
3
public/js/constants.js
Normal file
3
public/js/constants.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/* Polr JS Constants */
|
||||||
|
|
||||||
|
const BASE_API_PATH = '/api/v2/';
|
@ -30,6 +30,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
<link rel="stylesheet" href="/css/base.css" />
|
<link rel="stylesheet" href="/css/base.css" />
|
||||||
<link href="/css/font-awesome.min.css" rel="stylesheet">
|
<link href="/css/font-awesome.min.css" rel="stylesheet">
|
||||||
<link rel="shortcut icon" href="favicon.ico" />
|
<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/jquery-1.11.3.min.js"></script>
|
||||||
<script src="/js/bootstrap.min.js"></script>
|
<script src="/js/bootstrap.min.js"></script>
|
||||||
@yield('css')
|
@yield('css')
|
||||||
|
Loading…
Reference in New Issue
Block a user