From 8a23f8ddf0678a53a589127b2283af77a7aecd0b Mon Sep 17 00:00:00 2001 From: FoskyM Date: Sun, 1 Oct 2023 22:09:21 +0800 Subject: [PATCH] fix: scope page --- js/src/admin/pages/ScopesPage.js | 17 +++++++++-------- js/src/common/models/Scope.js | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/js/src/admin/pages/ScopesPage.js b/js/src/admin/pages/ScopesPage.js index 3a137bb..2bf51c7 100644 --- a/js/src/admin/pages/ScopesPage.js +++ b/js/src/admin/pages/ScopesPage.js @@ -2,7 +2,7 @@ import app from 'flarum/admin/app'; import Page from 'flarum/common/components/Page'; import Button from 'flarum/common/components/Button'; import Select from 'flarum/common/components/Select'; -import CheckBox from 'flarum/common/components/Checkbox'; +import Checkbox from 'flarum/common/components/Checkbox'; export default class ScopesPage extends Page { translationPrefix = 'foskym-oauth-center.admin.scopes.'; @@ -50,18 +50,20 @@ export default class ScopesPage extends Page { 'PATCH': 'PATCH', }, value: scope[key]() || 'GET', - onchange: (event) => { - this.saveScopeInfo(index, key, event.target.value); + onchange: (value) => { + this.saveScopeInfo(index, key, value); }, - }) : key === 'is_default' ? CheckBox.component({ - state: scope[key]() || false, - onchange: (event) => { - this.saveScopeInfo(index, key, event.target.checked ? 1 : 0); + }) : key === 'is_default' ? Checkbox.component({ + state: scope[key]() === 1 || false, + onchange: (checked) => { + this.scopes[index].is_default((this.scopes[index].is_default() + 1) % 2) + this.saveScopeInfo(index, key, checked ? 1 : 0); }, }) : m('input.FormControl', { type: 'text', value: scope[key]() || '', onchange: (event) => { + this.saveScopeInfo(index, key, event.target.value); }, })) @@ -106,7 +108,6 @@ export default class ScopesPage extends Page { return str; } saveScopeInfo(index, key, value) { - console.log(index, key, value); this.scopes[index].save({ [key]: value, }); diff --git a/js/src/common/models/Scope.js b/js/src/common/models/Scope.js index 97810b7..2b89440 100644 --- a/js/src/common/models/Scope.js +++ b/js/src/common/models/Scope.js @@ -1,10 +1,10 @@ import Model from 'flarum/common/Model'; -export default class Client extends Model { +export default class Scope extends Model { scope = Model.attribute('scope'); resource_path = Model.attribute('resource_path'); method = Model.attribute('method'); - is_default = Model.attribute('is_default', value => value === 1); + is_default = Model.attribute('is_default'); scope_name = Model.attribute('scope_name'); scope_icon = Model.attribute('scope_icon'); scope_desc = Model.attribute('scope_desc');