mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-13 18:55:34 +00:00
Ability to edit Company model
This commit is contained in:
@ -1,7 +1,9 @@
|
||||
|
||||
import 'package:InvenTree/api.dart';
|
||||
import 'package:InvenTree/inventree/company.dart';
|
||||
import 'package:InvenTree/widget/dialogs.dart';
|
||||
import 'package:InvenTree/widget/drawer.dart';
|
||||
import 'package:InvenTree/widget/fields.dart';
|
||||
import 'package:InvenTree/widget/refreshable_state.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -23,6 +25,8 @@ class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
|
||||
|
||||
final InvenTreeCompany company;
|
||||
|
||||
final _editCompanyKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
String getAppBarTitle(BuildContext context) { return "Company"; }
|
||||
|
||||
@ -35,6 +39,72 @@ class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void _saveCompany(Map<String, String> values) async {
|
||||
Navigator.of(context).pop();
|
||||
|
||||
var response = await company.update(context, values: values);
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
void editCompanyDialog() {
|
||||
|
||||
// Values which can be edited
|
||||
var _name;
|
||||
var _description;
|
||||
var _website;
|
||||
|
||||
showFormDialog(context, "Edit Company",
|
||||
key: _editCompanyKey,
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
child: Text("Cancel"),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
FlatButton(
|
||||
child: Text("Save"),
|
||||
onPressed: () {
|
||||
if (_editCompanyKey.currentState.validate()) {
|
||||
_editCompanyKey.currentState.save();
|
||||
|
||||
_saveCompany({
|
||||
"name": _name,
|
||||
"description": _description,
|
||||
"website": _website,
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
fields: <Widget>[
|
||||
StringField(
|
||||
label: "Company Name",
|
||||
initial: company.name,
|
||||
onSaved: (value) {
|
||||
_name = value;
|
||||
},
|
||||
),
|
||||
StringField(
|
||||
label: "Company Description",
|
||||
initial: company.description,
|
||||
onSaved: (value) {
|
||||
_description = value;
|
||||
},
|
||||
),
|
||||
StringField(
|
||||
label: "Website",
|
||||
initial: company.website,
|
||||
allowEmpty: true,
|
||||
onSaved: (value) {
|
||||
_website = value;
|
||||
},
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _companyTiles() {
|
||||
|
||||
var tiles = List<Widget>();
|
||||
@ -51,7 +121,7 @@ class _CompanyDetailState extends RefreshableState<CompanyDetailWidget> {
|
||||
),
|
||||
trailing: IconButton(
|
||||
icon: FaIcon(FontAwesomeIcons.edit),
|
||||
onPressed: null,
|
||||
onPressed: editCompanyDialog,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
Reference in New Issue
Block a user