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.
This commit is contained in:
sysadminstory 2022-01-22 01:55:57 +01:00
parent 3c4bfb6c78
commit 13d4946e19
5 changed files with 17 additions and 57 deletions

View File

@ -1,35 +0,0 @@
<?php
/**
* ownCloud - Epubreader App
*
* @author Frank de Lange
* @copyright 2014,2018 Frank de Lange
*
* This file is licensed under the Affero General Public License version 3 or
* later.
*/
namespace OCA\Epubreader;
\OC_JSON::callCheck();
\OC_JSON::checkLoggedIn();
$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.'))
)
);
exit();

View File

@ -10,8 +10,6 @@
* later. * later.
*/ */
//$this->create('reader_personal_settings', 'ajax/personal.php')->actionInclude('epubreader/ajax/personal.php');
return ['routes' => [ return ['routes' => [
// Page // Page
['name' => 'page#showReader', 'url' => '/', 'verb' => 'GET'], ['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#get', 'url' => '/preference/{fileId}/{scope}/{name}', 'verb' => 'GET', 'defaults' => ['name' => '']],
['name' => 'preference#set', 'url' => '/preference', 'verb' => 'POST'], ['name' => 'preference#set', 'url' => '/preference', 'verb' => 'POST'],
['name' => 'preference#delete', 'url' => '/preference/{fileId}/{scope}/{name}', 'verb' => 'DELETE'], ['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'],
]]; ]];

View File

@ -9,7 +9,7 @@ window.addEventListener('DOMContentLoaded', function () {
}; };
OC.msg.startSaving('#reader-personal .msg'); 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){ afterSave : function(data){
OC.msg.finishedSaving('#reader-personal .msg', data); OC.msg.finishedSaving('#reader-personal .msg', data);

View File

@ -17,6 +17,7 @@ use OCP\AppFramework\Http;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCA\Epubreader\Service\PreferenceService; use OCA\Epubreader\Service\PreferenceService;
use OCA\Epubreader\Config; use OCA\Epubreader\Config;
use OCP\AppFramework\Http\JSONResponse;
class SettingsController extends Controller { 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 * @NoAdminRequired
* @NoCSRFRequired
* *
* @param string $scope * @param int $EpubEnable
* @param int $fileId * @param int $EpubEnable
* @param string $name if null, return all preferences for $scope + $fileId * @param int $CbxEnable
* *
* @return array|\OCP\AppFramework\Http\JSONResponse * @return array|\OCP\AppFramework\Http\JSONResponse
*/ */
public function setPreference($scope, $fileId, $name) { public function setPreference($EpubEnable, $PdfEnable, $CbxEnable) {
/*\OC_JSON::callCheck();
\OC_JSON::checkLoggedIn();*/
$l = \OC::$server->getL10N('epubreader'); $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('epub_enable', $EpubEnable);
Config::set('pdf_enable', $PdfEnable); Config::set('pdf_enable', $PdfEnable);
Config::set('cbx_enable', $CbxEnable); Config::set('cbx_enable', $CbxEnable);
\OC_JSON::success( $response = array(
array( 'data' => array('message'=> $l->t('Settings updated successfully.')),
'data' => array('message'=> $l->t('Settings updated successfully.')) 'status' => 'success'
) );
);
return new JSONResponse($response);
} }
} }

View File

@ -65,6 +65,6 @@ class PersonalSection implements IIconSection
*/ */
public function getPriority() public function getPriority()
{ {
return 100; return 20;
} }
} }