diff --git a/fuel/app/classes/controller/rest/browse.php b/fuel/app/classes/controller/rest/browse.php index d520267..84da274 100644 --- a/fuel/app/classes/controller/rest/browse.php +++ b/fuel/app/classes/controller/rest/browse.php @@ -6,7 +6,19 @@ use Fuel\Core\Session; class Controller_Rest_Browse extends Controller_Rest { - public function get_servers() + public function get_server() + { + $servers = Model_Server::find(array( + 'select' => array('id','name', 'url', 'port', 'token'), + 'where' => array( + 'id' => Input::get('server_id'), + ) + )); + + $this->response($servers); + } + + public function get_servers() { $servers = Model_Server::find(array( 'select' => array('id','name'), diff --git a/fuel/app/classes/controller/rest/settings.php b/fuel/app/classes/controller/rest/settings.php index d8f0b20..a07b1ec 100644 --- a/fuel/app/classes/controller/rest/settings.php +++ b/fuel/app/classes/controller/rest/settings.php @@ -18,20 +18,20 @@ class Controller_Rest_Settings extends Controller_Rest public function post_server() { try { + $server_id = Input::post('server_id'); $url = Input::post('url'); - - //@TODO CHECK AND REMOVE HTTP AND HTTPS - $port = Input::post('port'); $token = Input::post('token'); + //@TODO CHECK AND REMOVE HTTP AND HTTPS + $curl = Request::forge('http://' . $url . ($port ? ':' . $port : '') . '/?X-Plex-Token=' . $token, 'curl'); $result = $curl->execute(); if(!$result) throw new FuelException('Can not connect to your server!'); - $server = Model_Server::forge(); + $server = $server_id === null ? Model_Server::forge() : Model_Server::find_by_pk($server_id); $server->set([ 'user_id' => Session::get('user')->id, 'url' => $url, diff --git a/fuel/app/classes/controller/settings.php b/fuel/app/classes/controller/settings.php index 2ef432c..f4cecb8 100644 --- a/fuel/app/classes/controller/settings.php +++ b/fuel/app/classes/controller/settings.php @@ -41,7 +41,6 @@ class Controller_Settings extends Controller_Template $servers = Model_Server::find(function($query) use($user_id) { $query ->where('user_id', $user_id) - ->and_where('disable', 0) ; }); diff --git a/fuel/app/views/modal/modal.php b/fuel/app/views/modal/modal.php index 3fa057d..4b544d0 100755 --- a/fuel/app/views/modal/modal.php +++ b/fuel/app/views/modal/modal.php @@ -8,6 +8,7 @@
+
Plex server information:
diff --git a/fuel/app/views/settings/body.php b/fuel/app/views/settings/body.php index 476edba..c7ee152 100644 --- a/fuel/app/views/settings/body.php +++ b/fuel/app/views/settings/body.php @@ -27,9 +27,13 @@

Settings

diff --git a/fuel/app/views/settings/servers.php b/fuel/app/views/settings/servers.php index 345fbe5..3e3c8a3 100644 --- a/fuel/app/views/settings/servers.php +++ b/fuel/app/views/settings/servers.php @@ -13,22 +13,24 @@
- - - - +

name; ?>

@@ -64,9 +66,10 @@ method: 'get', url: '/rest/settings/add_server.json' }).done(function (data) { - $('body').append(data).delay(100).queue(function() { + $('body').append(data); + setTimeout(function(){ $('.media-server-modal').removeClass('out').addClass('in'); - }); + },100); }); }); $(document).on('click', '.media-server-modal button.close', function () { @@ -89,7 +92,44 @@ setTimeout(function(){location.reload()}, 200); }); }); - $(document).on('click', 'button.remove-device-btn', function () { + $('button.refresh-server-btn').on('click', function () { + var server_id = $(this).data('server-id'); + ajax += 1; + checkAjax(); + $.ajax({ + method: 'get', + url: '/rest/browse/server.json', + data: {server_id: server_id} + }).done(function (data) { + updateServers(data); + ajax -= 1; + alert.toggleClass('transition-out'); + alert_status.html('Browse all your server is GOOD!'); + }); + }); + $('button.edit-server-btn').on('click', function () { + var server_id = $(this).data('server-id'); + $.ajax({ + method: 'get', + url: '/rest/settings/add_server.json' + }).done(function (modal) { + $.ajax({ + method: 'get', + url: '/rest/browse/server.json', + data: {server_id: server_id} + }).done(function (server) { + $('body').append(modal); + setTimeout(function(){ + $('#add-plex #server_id').val(server[0].id); + $('#add-plex #url').val(server[0].url); + $('#add-plex #port').val(server[0].port); + $('#add-plex #token').val(server[0].token); + $('.media-server-modal').removeClass('out').addClass('in'); + },100); + }); + }); + }); + $(document).on('click', 'button.disable-server-btn', function () { var button = this; var server_id = $(this).data('server-id'); $.ajax({ @@ -97,7 +137,7 @@ url: '/rest/settings/server.json', data: {server_id: server_id} }).done(function (data) { - show_alert('success', 'Server delete succesfully!'); + show_alert('success', 'Server disable succesfully!'); $(button).closest('li').get(0).remove(); }).fail(function (data) { data = JSON.parse(data.responseText); @@ -105,7 +145,7 @@ }); }); }); - // UPDATE DATA SERVER AND BROWSING + // UPDATE ALL DATA SERVER AND BROWSING IT var ajax = 0; var alert = $('.alert.alert-status'); var alert_status = $('.alert.alert-status .status');