From 4ff6ce1ca35dd595333d0061ac8e3378253e96ef Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 10 Aug 2021 20:47:36 +1000 Subject: [PATCH] Refactor some more forms --- lib/inventree/company.dart | 13 +++++++++++++ lib/widget/company_detail.dart | 13 +------------ lib/widget/part_notes.dart | 6 ++---- lib/widget/stock_detail.dart | 6 ++---- lib/widget/stock_notes.dart | 22 ++++++++++------------ 5 files changed, 28 insertions(+), 32 deletions(-) diff --git a/lib/inventree/company.dart b/lib/inventree/company.dart index 8a2a3b72..a5d65b25 100644 --- a/lib/inventree/company.dart +++ b/lib/inventree/company.dart @@ -15,6 +15,19 @@ class InvenTreeCompany extends InvenTreeModel { @override String get URL => "company/"; + @override + Map formFields() { + return { + "name": {}, + "description": {}, + "website": {}, + "is_supplier": {}, + "is_manufacturer": {}, + "is_customer": {}, + "currency": {}, + }; + } + InvenTreeCompany() : super(); String get image => jsondata['image'] ?? jsondata['thumbnail'] ?? InvenTreeAPI.staticImage; diff --git a/lib/widget/company_detail.dart b/lib/widget/company_detail.dart index f44ae69d..bc87322e 100644 --- a/lib/widget/company_detail.dart +++ b/lib/widget/company_detail.dart @@ -65,20 +65,9 @@ class _CompanyDetailState extends RefreshableState { void editCompany(BuildContext context) async { - launchApiForm( + company.editForm( context, L10().companyEdit, - company.url, - { - "name": {}, - "description": {}, - "website": {}, - "is_supplier": {}, - "is_manufacturer": {}, - "is_customer": {}, - "currency": {}, - }, - modelData: company.jsondata, onSuccess: (data) async { refresh(); } diff --git a/lib/widget/part_notes.dart b/lib/widget/part_notes.dart index d069b271..5e658e27 100644 --- a/lib/widget/part_notes.dart +++ b/lib/widget/part_notes.dart @@ -46,16 +46,14 @@ class _PartNotesState extends RefreshableState { icon: FaIcon(FontAwesomeIcons.edit), tooltip: L10().edit, onPressed: () { - launchApiForm( + part.editForm( context, L10().editNotes, - part.url, - { + fields: { "notes": { "multiline": true, } }, - modelData: part.jsondata, onSuccess: (data) async { refresh(); } diff --git a/lib/widget/stock_detail.dart b/lib/widget/stock_detail.dart index f0e661b7..053b115e 100644 --- a/lib/widget/stock_detail.dart +++ b/lib/widget/stock_detail.dart @@ -109,17 +109,15 @@ class _StockItemDisplayState extends RefreshableState { void _editStockItem(BuildContext context) async { - launchApiForm( + item.editForm( context, L10().editItem, - item.url, - { + fields: { "status": {}, "batch": {}, "packaging": {}, "link": {}, }, - modelData: item.jsondata, onSuccess: (data) async { refresh(); } diff --git a/lib/widget/stock_notes.dart b/lib/widget/stock_notes.dart index 60214600..c59f5155 100644 --- a/lib/widget/stock_notes.dart +++ b/lib/widget/stock_notes.dart @@ -46,19 +46,17 @@ class _StockNotesState extends RefreshableState { icon: FaIcon(FontAwesomeIcons.edit), tooltip: L10().edit, onPressed: () { - launchApiForm( - context, - L10().editNotes, - item.url, - { - "notes": { - "multiline": true, - } - }, - modelData: item.jsondata, - onSuccess: (data) async { - refresh(); + item.editForm( + context, + L10().editNotes, + fields: { + "notes": { + "multiline": true, } + }, + onSuccess: (data) async { + refresh(); + } ); } )