diff --git a/lib/widget/category_display.dart b/lib/widget/category_display.dart index 2a6c6722..45db9435 100644 --- a/lib/widget/category_display.dart +++ b/lib/widget/category_display.dart @@ -5,6 +5,9 @@ import 'package:InvenTree/preferences.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:InvenTree/widget/fields.dart'; +import 'package:InvenTree/widget/dialogs.dart'; +import 'package:InvenTree/widget/snacks.dart'; import 'package:InvenTree/widget/part_detail.dart'; import 'package:InvenTree/widget/drawer.dart'; import 'package:InvenTree/widget/refreshable_state.dart'; @@ -28,6 +31,8 @@ class CategoryDisplayWidget extends StatefulWidget { class _CategoryDisplayState extends RefreshableState { + final _editCategoryKey = GlobalKey(); + @override String getAppBarTitle(BuildContext context) => I18N.of(context).partCategory; @@ -37,11 +42,54 @@ class _CategoryDisplayState extends RefreshableState { IconButton( icon: FaIcon(FontAwesomeIcons.edit), tooltip: I18N.of(context).edit, - onPressed: null, + onPressed: _editCategoryDialog, ) ]; } + void _editCategory(Map values) async { + + final bool result = await category.update(context, values: values); + + showSnackIcon( + refreshableKey, + result ? "Category edited" : "Category editing failed", + success: result + ); + + refresh(); + } + + void _editCategoryDialog() { + + var _name; + var _description; + + showFormDialog( + context, + I18N.of(context).editCategory, + key: _editCategoryKey, + callback: () { + _editCategory({ + "name": _name, + "description": _description + }); + }, + fields: [ + StringField( + label: I18N.of(context).name, + initial: category.name, + onSaved: (value) => _name = value + ), + StringField( + label: I18N.of(context).description, + initial: category.description, + onSaved: (value) => _description = value + ) + ] + ); + } + _CategoryDisplayState(this.category) {} // The local InvenTreePartCategory object @@ -61,6 +109,9 @@ class _CategoryDisplayState extends RefreshableState { int pk = category?.pk ?? -1; + // Update the category + await category.reload(context); + // Request a list of sub-categories under this one await InvenTreePartCategory().list(context, filters: {"parent": "$pk"}).then((var cats) { _subcategories.clear(); diff --git a/lib/widget/snacks.dart b/lib/widget/snacks.dart index 9b2f3cad..b6aeda23 100644 --- a/lib/widget/snacks.dart +++ b/lib/widget/snacks.dart @@ -14,6 +14,9 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; void showSnackIcon(GlobalKey key, String text, {IconData icon, bool success}) { + // Hide the current snackbar + key.currentState.hideCurrentSnackBar(); + // If icon not specified, use the success status if (icon == null) { icon = (success == true) ? FontAwesomeIcons.checkCircle : FontAwesomeIcons.timesCircle;