diff --git a/src/content/mytinytodo.js b/src/content/mytinytodo.js index 606fa2b..6b8a422 100644 --- a/src/content/mytinytodo.js +++ b/src/content/mytinytodo.js @@ -2876,6 +2876,10 @@ function extensionSettingsAction(actionString, ext, formData) window.location.assign(json.redirect); return; } + if (json.html) { + $('#page_ajax .mtt-settings-table').html(json.html); //FIXME: maybe whole page? + return; + } const callback = function() { if (json.msg) flashInfo(json.msg, json.details); if (json.reload) { diff --git a/src/includes/api/ListsController.php b/src/includes/api/ListsController.php index 7f4720a..012737f 100644 --- a/src/includes/api/ListsController.php +++ b/src/includes/api/ListsController.php @@ -2,7 +2,7 @@ /* This file is a part of myTinyTodo. - (C) Copyright 2022 Max Pozdeev + (C) Copyright 2022-2023 Max Pozdeev Licensed under the GNU GPL version 2 or any later. See file COPYRIGHT for details. */ @@ -47,19 +47,9 @@ class ListsController extends ApiController { function post() { checkWriteAccess(); + $id = DBCore::default()->createListWithName($this->req->jsonBody['name'] ?? ''); $db = DBConnection::instance(); $t = array(); - $t['total'] = 0; - $name = str_replace( - array('"',"'",'<','>','&'), - '', - trim( $this->req->jsonBody['name'] ?? '' ) - ); - $ow = 1 + (int)$db->sq("SELECT MAX(ow) FROM {$db->prefix}lists"); - $time = time(); - $db->dq("INSERT INTO {$db->prefix}lists (uuid,name,ow,d_created,d_edited,taskview) VALUES (?,?,?,?,?,?)", - array(generateUUID(), $name, $ow, $time, $time, 1) ); - $id = $db->lastInsertId(); $t['total'] = 1; $r = $db->sqa("SELECT * FROM {$db->prefix}lists WHERE id=$id"); $oo = $this->prepareList($r, true); diff --git a/src/includes/class.dbcore.php b/src/includes/class.dbcore.php index 12139e6..2191188 100644 --- a/src/includes/class.dbcore.php +++ b/src/includes/class.dbcore.php @@ -2,7 +2,7 @@ /* This file is a part of myTinyTodo. - (C) Copyright 2022 Max Pozdeev + (C) Copyright 2022-2023 Max Pozdeev Licensed under the GNU GPL version 2 or any later. See file COPYRIGHT for details. */ @@ -169,5 +169,34 @@ class DBCore } return $data; } + + function createListWithName(string $name): int + { + $db = DBConnection::instance(); + $name = str_replace( ['"',"'",'<','>','&'], '', trim($name) ); + $ow = 1 + (int)$db->sq("SELECT MAX(ow) FROM {$db->prefix}lists"); + $time = time(); + $db->dq("INSERT INTO {$db->prefix}lists (uuid,name,ow,d_created,d_edited,taskview) VALUES (?,?,?,?,?,?)", + array(generateUUID(), $name, $ow, $time, $time, 1) ); + $id = $db->lastInsertId(); + return (int)$id; + } + + /** + * Finds all variations of tag by its "normalized" name. Return array of id. + * @param string $name + * @return int[] + * @throws Exception + */ + function getTagIdsByName(string $name): array + { + $db = DBConnection::instance(); + $q = $db->dq("SELECT id FROM {$db->prefix}tags WHERE ". $db->like('name', '%s', $name)); + $a = []; + while ($r = $q->fetchAssoc()) { + $a[] = (int) $r['id']; + } + return $a; + } } diff --git a/src/includes/classes.php b/src/includes/classes.php index 388f43d..f6cbdd1 100644 --- a/src/includes/classes.php +++ b/src/includes/classes.php @@ -2,7 +2,7 @@ /* This file is a part of myTinyTodo. - (C) Copyright 2022 Max Pozdeev + (C) Copyright 2022-2023 Max Pozdeev Licensed under the GNU GPL version 2 or any later. See file COPYRIGHT for details. */ @@ -89,9 +89,10 @@ abstract class ApiController abstract class MTTExtension { - const bundleId = ''; + const bundleId = ''; //abstract - abstract function init(); + function init() { + } public static function extMetaInfo(string $ext): ?array { @@ -114,9 +115,18 @@ abstract class MTTExtension return null; } - public function httpApiUrlPrefix() + public static function extApiActionUrl(string $action, ?string $params = null) { - return get_unsafe_mttinfo('api_url'). 'ext/'. $this::bundleId; + $url = get_unsafe_mttinfo('api_url'). 'ext/'. static::bundleId. "/$action"; + if (!is_null($params)) { + if (false !== strpos($url, '?')) { + $url .= '&'. $params; + } + else { + $url .= '?'. $params; + } + } + return $url; } }