diff --git a/lib/inventree/model.dart b/lib/inventree/model.dart index 5c9f8f95..da264810 100644 --- a/lib/inventree/model.dart +++ b/lib/inventree/model.dart @@ -9,6 +9,7 @@ import 'package:url_launcher/url_launcher.dart'; import 'package:path/path.dart' as path; import '../l10.dart'; +import '../api_form.dart'; // Paginated response object @@ -64,6 +65,30 @@ class InvenTreeModel { } + // Fields for editing / creating this model + // Override per-model + Map formFields() { + + return {}; + } + + Future editForm(BuildContext context, String title, {Map fields=const {}, Function? onSuccess}) async { + + if (fields.isEmpty) { + fields = formFields(); + } + + launchApiForm( + context, + title, + url, + fields, + modelData: jsondata, + onSuccess: onSuccess + ); + + } + // JSON data which defines this object Map jsondata = {}; diff --git a/lib/inventree/part.dart b/lib/inventree/part.dart index 92b7cbd7..9ed14a78 100644 --- a/lib/inventree/part.dart +++ b/lib/inventree/part.dart @@ -16,6 +16,16 @@ class InvenTreePartCategory extends InvenTreeModel { @override String get URL => "part/category/"; + @override + Map formFields() { + + return { + "name": {}, + "description": {}, + "parent": {} + }; + } + @override Map defaultListFilters() { var filters = new Map(); diff --git a/lib/widget/category_display.dart b/lib/widget/category_display.dart index 3c977da8..9bea0a43 100644 --- a/lib/widget/category_display.dart +++ b/lib/widget/category_display.dart @@ -60,7 +60,6 @@ class _CategoryDisplayState extends RefreshableState { } void _editCategoryDialog(BuildContext context) { - final _cat = category; // Cannot edit top-level category @@ -68,18 +67,7 @@ class _CategoryDisplayState extends RefreshableState { return; } - launchApiForm( - context, - L10().editCategory, - _cat.url, - { - "name": {}, - "description": {}, - "parent": {}, - }, - modelData: _cat.jsondata, - onSuccess: refresh, - ); + _cat.editForm(context, L10().editCategory, onSuccess: refresh); } _CategoryDisplayState(this.category); @@ -227,12 +215,7 @@ class _CategoryDisplayState extends RefreshableState { context, L10().categoryCreate, InvenTreePartCategory().URL, - { - "name": {}, - "description": {}, - "parent": { - } - }, + InvenTreePartCategory().formFields(), modelData: { "parent": (pk > 0) ? pk : null, }