From e8cb002e3c3c9152e28267fa66546db03846a386 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 26 Jul 2021 22:03:37 +1000 Subject: [PATCH] Edit StockLocation --- lib/api_form.dart | 15 +++++++++ lib/widget/location_display.dart | 53 +++++++++++--------------------- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/lib/api_form.dart b/lib/api_form.dart index 947229a2..f9705f9f 100644 --- a/lib/api_form.dart +++ b/lib/api_form.dart @@ -6,6 +6,7 @@ import 'package:dropdown_search/dropdown_search.dart'; import 'package:inventree/api.dart'; import 'package:inventree/app_colors.dart'; import 'package:inventree/inventree/part.dart'; +import 'package:inventree/inventree/stock.dart'; import 'package:inventree/widget/fields.dart'; import 'package:inventree/l10.dart'; @@ -261,6 +262,20 @@ class APIFormField { style: TextStyle(fontWeight: selected ? FontWeight.bold : FontWeight.normal), ) : null, ); + case "stocklocation": + + var loc = InvenTreeStockLocation.fromJson(item); + + return ListTile( + title: Text( + loc.pathstring, + style: TextStyle(fontWeight: selected && extended ? FontWeight.bold : FontWeight.normal) + ), + subtitle: extended ? Text( + loc.description, + style: TextStyle(fontWeight: selected ? FontWeight.bold : FontWeight.normal), + ) : null, + ); default: return ListTile( title: Text( diff --git a/lib/widget/location_display.dart b/lib/widget/location_display.dart index a6313382..b1ffffef 100644 --- a/lib/widget/location_display.dart +++ b/lib/widget/location_display.dart @@ -1,4 +1,5 @@ import 'package:inventree/api.dart'; +import 'package:inventree/api_form.dart'; import 'package:inventree/app_settings.dart'; import 'package:inventree/barcode.dart'; import 'package:inventree/inventree/sentry.dart'; @@ -71,7 +72,7 @@ class _LocationDisplayState extends RefreshableState { IconButton( icon: FaIcon(FontAwesomeIcons.edit), tooltip: L10().edit, - onPressed: _editLocationDialog, + onPressed: () { _editLocationDialog(context); }, ) ); } @@ -79,23 +80,27 @@ class _LocationDisplayState extends RefreshableState { return actions; } - void _editLocation(Map values) async { + void _editLocationDialog(BuildContext context) { - bool result = false; + final _loc = location; - if (location != null) { - result = await location!.update(values: values); - - showSnackIcon( - result ? "Location edited" : "Location editing failed", - success: result - ); + if (_loc == null) { + return; } - refresh(); - } + launchApiForm( + context, + L10().editLocation, + _loc.url, + { + "name": {}, + "description": {}, + "parent": {}, + }, + modelData: _loc.jsondata, + onSuccess: refresh + ); - void _editLocationDialog() { // Values which an be edited var _name; var _description; @@ -103,28 +108,6 @@ class _LocationDisplayState extends RefreshableState { if (location == null) { return; } - - showFormDialog(L10().editLocation, - key: _editLocationKey, - callback: () { - _editLocation({ - "name": _name, - "description": _description - }); - }, - fields: [ - StringField( - label: L10().name, - initial: location?.name ?? '', - onSaved: (value) => _name = value, - ), - StringField( - label: L10().description, - initial: location?.description ?? '', - onSaved: (value) => _description = value, - ) - ] - ); } _LocationDisplayState(this.location);