mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 21:46:46 +00:00
Edit part category
This commit is contained in:
parent
3757010599
commit
a62b038faf
@ -5,6 +5,9 @@ import 'package:InvenTree/preferences.dart';
|
|||||||
|
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.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/part_detail.dart';
|
||||||
import 'package:InvenTree/widget/drawer.dart';
|
import 'package:InvenTree/widget/drawer.dart';
|
||||||
import 'package:InvenTree/widget/refreshable_state.dart';
|
import 'package:InvenTree/widget/refreshable_state.dart';
|
||||||
@ -28,6 +31,8 @@ class CategoryDisplayWidget extends StatefulWidget {
|
|||||||
|
|
||||||
class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
||||||
|
|
||||||
|
final _editCategoryKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String getAppBarTitle(BuildContext context) => I18N.of(context).partCategory;
|
String getAppBarTitle(BuildContext context) => I18N.of(context).partCategory;
|
||||||
|
|
||||||
@ -37,11 +42,54 @@ class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
|||||||
IconButton(
|
IconButton(
|
||||||
icon: FaIcon(FontAwesomeIcons.edit),
|
icon: FaIcon(FontAwesomeIcons.edit),
|
||||||
tooltip: I18N.of(context).edit,
|
tooltip: I18N.of(context).edit,
|
||||||
onPressed: null,
|
onPressed: _editCategoryDialog,
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _editCategory(Map<String, String> 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: <Widget>[
|
||||||
|
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) {}
|
_CategoryDisplayState(this.category) {}
|
||||||
|
|
||||||
// The local InvenTreePartCategory object
|
// The local InvenTreePartCategory object
|
||||||
@ -61,6 +109,9 @@ class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
|||||||
|
|
||||||
int pk = category?.pk ?? -1;
|
int pk = category?.pk ?? -1;
|
||||||
|
|
||||||
|
// Update the category
|
||||||
|
await category.reload(context);
|
||||||
|
|
||||||
// Request a list of sub-categories under this one
|
// Request a list of sub-categories under this one
|
||||||
await InvenTreePartCategory().list(context, filters: {"parent": "$pk"}).then((var cats) {
|
await InvenTreePartCategory().list(context, filters: {"parent": "$pk"}).then((var cats) {
|
||||||
_subcategories.clear();
|
_subcategories.clear();
|
||||||
|
@ -14,6 +14,9 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|||||||
|
|
||||||
void showSnackIcon(GlobalKey<ScaffoldState> key, String text, {IconData icon, bool success}) {
|
void showSnackIcon(GlobalKey<ScaffoldState> key, String text, {IconData icon, bool success}) {
|
||||||
|
|
||||||
|
// Hide the current snackbar
|
||||||
|
key.currentState.hideCurrentSnackBar();
|
||||||
|
|
||||||
// If icon not specified, use the success status
|
// If icon not specified, use the success status
|
||||||
if (icon == null) {
|
if (icon == null) {
|
||||||
icon = (success == true) ? FontAwesomeIcons.checkCircle : FontAwesomeIcons.timesCircle;
|
icon = (success == true) ? FontAwesomeIcons.checkCircle : FontAwesomeIcons.timesCircle;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user