diff --git a/application/controllers/api/frontend/v1/Phrasen.php b/application/controllers/api/frontend/v1/Phrasen.php index e8d99f472..6005b2c9c 100644 --- a/application/controllers/api/frontend/v1/Phrasen.php +++ b/application/controllers/api/frontend/v1/Phrasen.php @@ -5,8 +5,12 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); /** * */ -class Phrasen extends FHC_Controller +class Phrasen extends FHCAPI_Controller { + public function __construct() + { + parent::__construct(['loadModule' => [self::PERM_ANONYMOUS]]); + } //------------------------------------------------------------------------------------------------------------------ // Public methods @@ -17,11 +21,6 @@ class Phrasen extends FHC_Controller public function loadModule($module) { $this->load->library('PhrasesLib', [$module], 'pj'); - $this->outputJson([ - 'data' => json_decode($this->pj->getJSON()), - 'meta' => [ - 'status' => FHCAPI_Controller::STATUS_SUCCESS - ] - ]); + $this->terminateWithSuccess(json_decode($this->pj->getJSON())); } } diff --git a/public/js/plugin/Phrasen.js b/public/js/plugin/Phrasen.js index 7dc9c71c7..9365fa5f3 100644 --- a/public/js/plugin/Phrasen.js +++ b/public/js/plugin/Phrasen.js @@ -1,3 +1,5 @@ +import FhcApi from './FhcApi.js'; + const categories = Vue.reactive({}); const loadingModules = {}; @@ -23,13 +25,11 @@ const phrasen = { if (Array.isArray(category)) return Promise.all(category.map(cat => this.loadCategory(cat))); if (!loadingModules[category]) - loadingModules[category] = axios - .get(FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/api/frontend/v1/phrasen/loadModule/' + category) + loadingModules[category] = this.config.globalProperties.$fhcApi + .get('/api/frontend/v1/phrasen/loadModule/' + category) + .then(res => res?.data ? extractCategory(res.data, category) : {}) .then(res => { - if (res?.data?.data) - categories[category] = extractCategory(res.data.data, category); - else - categories[category] = {}; + categories[category] = res; }); return loadingModules[category]; }, @@ -62,6 +62,11 @@ const phrasen = { export default { install(app, options) { - app.config.globalProperties.$p = phrasen; + app.use(FhcApi); + app.config.globalProperties.$p = { + t: phrasen.t, + loadCategory: cat => phrasen.loadCategory.call(app, cat), + t_ref: phrasen.t_ref + }; } }