From 13d4946e19be9c3d047879db7c97001014508fb4 Mon Sep 17 00:00:00 2001 From: sysadminstory Date: Sat, 22 Jan 2022 01:55:57 +0100 Subject: [PATCH] Cleanup old files and update comments Change the settings url to be mor consistant with the others urls of the app. Better feedback if the saving of settings did work or not. Use the Framework to get the settings value, instead of using the $_POST array. --- ajax/personal.php | 35 --------------------------- appinfo/routes.php | 6 ++--- js/settings.js | 2 +- lib/Controller/SettingsController.php | 29 +++++++++------------- lib/Settings/PersonalSection.php | 2 +- 5 files changed, 17 insertions(+), 57 deletions(-) delete mode 100644 ajax/personal.php diff --git a/ajax/personal.php b/ajax/personal.php deleted file mode 100644 index 801090b..0000000 --- a/ajax/personal.php +++ /dev/null @@ -1,35 +0,0 @@ -getL10N('epubreader'); - -$EpubEnable = isset($_POST['EpubEnable']) ? $_POST['EpubEnable'] : 'false'; -$PdfEnable = isset($_POST['PdfEnable']) ? $_POST['PdfEnable'] : 'false'; -$CbxEnable = isset($_POST['CbxEnable']) ? $_POST['CbxEnable'] : 'false'; - -Config::set('epub_enable', $EpubEnable); -Config::set('pdf_enable', $PdfEnable); -Config::set('cbx_enable', $CbxEnable); - -\OC_JSON::success( - array( - 'data' => array('message'=> $l->t('Settings updated successfully.')) - ) -); - -exit(); - diff --git a/appinfo/routes.php b/appinfo/routes.php index eda152f..f70c426 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -10,8 +10,6 @@ * later. */ -//$this->create('reader_personal_settings', 'ajax/personal.php')->actionInclude('epubreader/ajax/personal.php'); - return ['routes' => [ // Page ['name' => 'page#showReader', 'url' => '/', 'verb' => 'GET'], @@ -36,6 +34,8 @@ return ['routes' => [ ['name' => 'preference#get', 'url' => '/preference/{fileId}/{scope}/{name}', 'verb' => 'GET', 'defaults' => ['name' => '']], ['name' => 'preference#set', 'url' => '/preference', 'verb' => 'POST'], ['name' => 'preference#delete', 'url' => '/preference/{fileId}/{scope}/{name}', 'verb' => 'DELETE'], - ['name' => 'settings#setPreference', 'url' => '/ajax/personal.php', 'verb' => 'POST'], + + // User Settings + ['name' => 'settings#setPreference', 'url' => '/settings/set', 'verb' => 'POST'], ]]; diff --git a/js/settings.js b/js/settings.js index c296899..171e675 100644 --- a/js/settings.js +++ b/js/settings.js @@ -9,7 +9,7 @@ window.addEventListener('DOMContentLoaded', function () { }; OC.msg.startSaving('#reader-personal .msg'); - $.post(OC.generateUrl('apps/epubreader/ajax/personal.php'), data, readerSettings.afterSave); + $.post(OC.generateUrl('apps/epubreader/settings/set'), data, readerSettings.afterSave); }, afterSave : function(data){ OC.msg.finishedSaving('#reader-personal .msg', data); diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 9564d3f..acf3520 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -17,6 +17,7 @@ use OCP\AppFramework\Http; use OCP\AppFramework\Controller; use OCA\Epubreader\Service\PreferenceService; use OCA\Epubreader\Config; +use OCP\AppFramework\Http\JSONResponse; class SettingsController extends Controller { @@ -40,35 +41,29 @@ class SettingsController extends Controller { } /** - * @brief return preference for $fileId + * @brief set preference for file type association * * @NoAdminRequired - * @NoCSRFRequired * - * @param string $scope - * @param int $fileId - * @param string $name if null, return all preferences for $scope + $fileId + * @param int $EpubEnable + * @param int $EpubEnable + * @param int $CbxEnable * * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function setPreference($scope, $fileId, $name) { - /*\OC_JSON::callCheck(); - \OC_JSON::checkLoggedIn();*/ + public function setPreference($EpubEnable, $PdfEnable, $CbxEnable) { $l = \OC::$server->getL10N('epubreader'); - $EpubEnable = isset($_POST['EpubEnable']) ? $_POST['EpubEnable'] : 'false'; - $PdfEnable = isset($_POST['PdfEnable']) ? $_POST['PdfEnable'] : 'false'; - $CbxEnable = isset($_POST['CbxEnable']) ? $_POST['CbxEnable'] : 'false'; - Config::set('epub_enable', $EpubEnable); Config::set('pdf_enable', $PdfEnable); Config::set('cbx_enable', $CbxEnable); - \OC_JSON::success( - array( - 'data' => array('message'=> $l->t('Settings updated successfully.')) - ) - ); + $response = array( + 'data' => array('message'=> $l->t('Settings updated successfully.')), + 'status' => 'success' + ); + + return new JSONResponse($response); } } \ No newline at end of file diff --git a/lib/Settings/PersonalSection.php b/lib/Settings/PersonalSection.php index 0ce26e9..17d8d64 100644 --- a/lib/Settings/PersonalSection.php +++ b/lib/Settings/PersonalSection.php @@ -65,6 +65,6 @@ class PersonalSection implements IIconSection */ public function getPriority() { - return 100; + return 20; } } \ No newline at end of file