fix: scope page

This commit is contained in:
FoskyM 2023-10-01 22:09:21 +08:00
parent bd1c7f36bb
commit 8a23f8ddf0
No known key found for this signature in database
GPG key ID: 42C0ED6994AD7E9C
2 changed files with 11 additions and 10 deletions

View file

@ -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,
});

View file

@ -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');