mirror of
https://github.com/inventree/inventree-app.git
synced 2025-05-02 15:28:53 +00:00
Adds convenience function for editing model
This commit is contained in:
parent
92a7a73408
commit
67ccbf64b5
@ -9,6 +9,7 @@ import 'package:url_launcher/url_launcher.dart';
|
|||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
|
|
||||||
import '../l10.dart';
|
import '../l10.dart';
|
||||||
|
import '../api_form.dart';
|
||||||
|
|
||||||
|
|
||||||
// Paginated response object
|
// Paginated response object
|
||||||
@ -64,6 +65,30 @@ class InvenTreeModel {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fields for editing / creating this model
|
||||||
|
// Override per-model
|
||||||
|
Map<String, dynamic> formFields() {
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> editForm(BuildContext context, String title, {Map<String, dynamic> 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
|
// JSON data which defines this object
|
||||||
Map<String, dynamic> jsondata = {};
|
Map<String, dynamic> jsondata = {};
|
||||||
|
|
||||||
|
@ -16,6 +16,16 @@ class InvenTreePartCategory extends InvenTreeModel {
|
|||||||
@override
|
@override
|
||||||
String get URL => "part/category/";
|
String get URL => "part/category/";
|
||||||
|
|
||||||
|
@override
|
||||||
|
Map<String, dynamic> formFields() {
|
||||||
|
|
||||||
|
return {
|
||||||
|
"name": {},
|
||||||
|
"description": {},
|
||||||
|
"parent": {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, String> defaultListFilters() {
|
Map<String, String> defaultListFilters() {
|
||||||
var filters = new Map<String, String>();
|
var filters = new Map<String, String>();
|
||||||
|
@ -60,7 +60,6 @@ class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _editCategoryDialog(BuildContext context) {
|
void _editCategoryDialog(BuildContext context) {
|
||||||
|
|
||||||
final _cat = category;
|
final _cat = category;
|
||||||
|
|
||||||
// Cannot edit top-level category
|
// Cannot edit top-level category
|
||||||
@ -68,18 +67,7 @@ class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
launchApiForm(
|
_cat.editForm(context, L10().editCategory, onSuccess: refresh);
|
||||||
context,
|
|
||||||
L10().editCategory,
|
|
||||||
_cat.url,
|
|
||||||
{
|
|
||||||
"name": {},
|
|
||||||
"description": {},
|
|
||||||
"parent": {},
|
|
||||||
},
|
|
||||||
modelData: _cat.jsondata,
|
|
||||||
onSuccess: refresh,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_CategoryDisplayState(this.category);
|
_CategoryDisplayState(this.category);
|
||||||
@ -227,12 +215,7 @@ class _CategoryDisplayState extends RefreshableState<CategoryDisplayWidget> {
|
|||||||
context,
|
context,
|
||||||
L10().categoryCreate,
|
L10().categoryCreate,
|
||||||
InvenTreePartCategory().URL,
|
InvenTreePartCategory().URL,
|
||||||
{
|
InvenTreePartCategory().formFields(),
|
||||||
"name": {},
|
|
||||||
"description": {},
|
|
||||||
"parent": {
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modelData: {
|
modelData: {
|
||||||
"parent": (pk > 0) ? pk : null,
|
"parent": (pk > 0) ? pk : null,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user