mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-14 03:05:32 +00:00
API form for editing PartCategory
- Custom related field renderer function - Grab related field data from the server
This commit is contained in:
@ -22,6 +22,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
||||
|
||||
import '../api_form.dart';
|
||||
|
||||
class CategoryDisplayWidget extends StatefulWidget {
|
||||
|
||||
CategoryDisplayWidget(this.category, {Key? key}) : super(key: key);
|
||||
@ -35,7 +37,6 @@ class CategoryDisplayWidget extends StatefulWidget {
|
||||
|
||||
class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
||||
|
||||
final _editCategoryKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
String getAppBarTitle(BuildContext context) => L10().partCategory;
|
||||
@ -71,7 +72,9 @@ class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
||||
IconButton(
|
||||
icon: FaIcon(FontAwesomeIcons.edit),
|
||||
tooltip: L10().edit,
|
||||
onPressed: _editCategoryDialog,
|
||||
onPressed: () {
|
||||
_editCategoryDialog(context);
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -80,49 +83,26 @@ class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
||||
|
||||
}
|
||||
|
||||
void _editCategory(Map<String, String> values) async {
|
||||
void _editCategoryDialog(BuildContext context) {
|
||||
|
||||
final bool result = await category!.update(values: values);
|
||||
|
||||
showSnackIcon(
|
||||
result ? "Category edited" : "Category editing failed",
|
||||
success: result
|
||||
);
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
void _editCategoryDialog() {
|
||||
final _cat = category;
|
||||
|
||||
// Cannot edit top-level category
|
||||
if (category == null) {
|
||||
if (_cat == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var _name;
|
||||
var _description;
|
||||
|
||||
showFormDialog(
|
||||
launchApiForm(
|
||||
context,
|
||||
L10().editCategory,
|
||||
key: _editCategoryKey,
|
||||
callback: () {
|
||||
_editCategory({
|
||||
"name": _name,
|
||||
"description": _description
|
||||
});
|
||||
_cat.url,
|
||||
{
|
||||
"name": {},
|
||||
"description": {},
|
||||
"parent": {},
|
||||
},
|
||||
fields: <Widget>[
|
||||
StringField(
|
||||
label: L10().name,
|
||||
initial: category?.name,
|
||||
onSaved: (value) => _name = value
|
||||
),
|
||||
StringField(
|
||||
label: L10().description,
|
||||
initial: category?.description,
|
||||
onSaved: (value) => _description = value
|
||||
)
|
||||
]
|
||||
modelData: _cat.jsondata,
|
||||
onSuccess: refresh,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -188,8 +188,6 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
"link": {},
|
||||
|
||||
"category": {
|
||||
"filters": {
|
||||
}
|
||||
},
|
||||
|
||||
// Checkbox fields
|
||||
|
Reference in New Issue
Block a user