mirror of
https://github.com/inventree/inventree-app.git
synced 2025-05-05 08:48:55 +00:00
Ability to edit Company model
This commit is contained in:
parent
16cdae42ed
commit
75725c2cb9
@ -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,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
@ -1,6 +1,36 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
|
||||
class StringField extends TextFormField {
|
||||
|
||||
StringField({String label, String hint, String initial, Function onSaved, Function validator, bool allowEmpty = false}) :
|
||||
super(
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
hintText: hint
|
||||
),
|
||||
initialValue: initial,
|
||||
onSaved: onSaved,
|
||||
validator: (value) {
|
||||
print("Value: ${value}");
|
||||
if (!allowEmpty && value.isEmpty) {
|
||||
return "Value cannot be empty";
|
||||
}
|
||||
|
||||
if (validator != null) {
|
||||
return validator(value);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Helper class for quantity values
|
||||
*/
|
||||
class QuantityField extends TextFormField {
|
||||
|
||||
QuantityField({String label = "", String hint = "", String initial = "", double max = null, TextEditingController controller}) :
|
||||
|
Loading…
x
Reference in New Issue
Block a user