diff --git a/customCategory.php b/customCategory.php
new file mode 100644
index 00000000..a9ba9533
--- /dev/null
+++ b/customCategory.php
@@ -0,0 +1,36 @@
+
+
+
+
+
+list($_REQUEST);
+
+ Header("Content-Type: application/json; charset=utf-8");
+ print json_readable_encode($result);
+}
+
+if (isset($_REQUEST['id'])) {
+ $category = $customCategoryRepository->getCategory($_REQUEST['id']);
+ if ($category) {
+ $customCategoryRepository->recordAccess($_REQUEST['id']);
+ }
+
+ Header("Content-Type: application/yaml; charset=utf-8");
+ print $category;
+}
+
+if (isset($_REQUEST['action']) && $_REQUEST['action'] === 'save') {
+ $content = file_get_contents("php://input");
+
+ $id = $customCategoryRepository->saveCategory($content);
+ $customCategoryRepository->recordAccess($id);
+
+ Header("Content-Type: text/plain; charset=utf-8");
+ print $id;
+}
diff --git a/src/customCategory.js b/src/customCategory.js
index b47d6623..64c348af 100644
--- a/src/customCategory.js
+++ b/src/customCategory.js
@@ -26,23 +26,25 @@ class CustomCategoryRepository {
return callback(null, yaml.load(cache[id]))
}
- ajax('customCategory', { id }, (result) => {
- let data
- cache[id] = result
-
- try {
- data = yaml.load(result)
- }
- catch (e) {
- return global.alert(e)
- }
+ fetch('customCategory.php?id=' + id)
+ .then(res => res.text())
+ .then(result => {
+ let data
+ cache[id] = result
+
+ try {
+ data = yaml.load(result)
+ }
+ catch (e) {
+ return global.alert(e)
+ }
- if (Object.is(data) && !('name' in data)) {
- data.name = 'Custom ' + id.substr(0, 6)
- }
+ if (Object.is(data) && !('name' in data)) {
+ data.name = 'Custom ' + id.substr(0, 6)
+ }
- callback(null, data)
- })
+ callback(null, data)
+ })
}
getTemplate (id, options, callback) {
@@ -57,10 +59,27 @@ class CustomCategory {
load (id, callback) {
this.id = id
- ajax('customCategory', { id }, (result) => {
- this.content = result
- callback(null, result)
- })
+
+ fetch('customCategory.php?id=' + id)
+ .then(res => res.text())
+ .then(result => {
+ let data
+ cache[id] = result
+ this.content = result
+
+ try {
+ data = yaml.load(result)
+ }
+ catch (e) {
+ return global.alert(e)
+ }
+
+ if (Object.is(data) && !('name' in data)) {
+ data.name = 'Custom ' + id.substr(0, 6)
+ }
+
+ callback(null, data)
+ })
}
edit () {
@@ -115,7 +134,10 @@ class CustomCategory {
applyContent (content) {
this.content = content
- ajax('customCategory', { action: 'save' }, this.content, () => {})
+ fetch('customCategory.php?action=save', {
+ method: 'POST',
+ body: this.content
+ })
if (this.textarea) {
this.textarea.value = content
@@ -207,33 +229,35 @@ hooks.register('browser-more-categories', (browser, parameters) => {
function customCategoriesList (browser, options) {
browser.dom.innerHTML = ' ' + lang('loading')
- ajax('customCategory', { action: 'list' }, (result) => {
- browser.dom.innerHTML = ''
+ fetch('customCategory.php?action=list')
+ .then(res => res.json())
+ .then(result => {
+ browser.dom.innerHTML = ''
- const ul = document.createElement('ul')
- browser.dom.appendChild(ul)
+ const ul = document.createElement('ul')
+ browser.dom.appendChild(ul)
- result.forEach(cat => {
- const li = document.createElement('li')
+ result.forEach(cat => {
+ const li = document.createElement('li')
- const a = document.createElement('a')
- a.href = '#categories=custom/' + cat.id
- a.appendChild(document.createTextNode(cat.name))
- li.appendChild(a)
+ const a = document.createElement('a')
+ a.href = '#categories=custom/' + cat.id
+ a.appendChild(document.createTextNode(cat.name))
+ li.appendChild(a)
- const edit = document.createElement('a')
- edit.onclick = (e) => {
- editCustomCategory(cat.id)
- e.preventDefault()
- }
- edit.innerHTML = ' '
- li.appendChild(edit)
+ const edit = document.createElement('a')
+ edit.onclick = (e) => {
+ editCustomCategory(cat.id)
+ e.preventDefault()
+ }
+ edit.innerHTML = ' '
+ li.appendChild(edit)
- ul.appendChild(li)
- })
+ ul.appendChild(li)
+ })
- browser.catchLinks()
- })
+ browser.catchLinks()
+ })
}
hooks.register('init', () => {
diff --git a/src/customCategory.php b/src/customCategory.php
index e752a106..b8239a3c 100644
--- a/src/customCategory.php
+++ b/src/customCategory.php
@@ -79,32 +79,3 @@ class CustomCategoryRepository {
}
$customCategoryRepository = new CustomCategoryRepository();
-
-function ajax_customCategory ($param, $content) {
- global $db;
- global $customCategoryRepository;
-
- if (!$db) {
- return null;
- }
-
- if (isset($param['action']) && $param['action'] === 'list') {
- return $customCategoryRepository->list($param);
- }
-
- if (isset($param['id'])) {
- $category = $customCategoryRepository->getCategory($param['id']);
- if ($category) {
- $customCategoryRepository->recordAccess($param['id']);
- }
-
- return $category;
- }
-
- if (isset($param['action']) && $param['action'] === 'save') {
- $id = $customCategoryRepository->saveCategory($content);
- $customCategoryRepository->recordAccess($id);
-
- return $id;
- }
-}