diff --git a/lib/widget/company_detail.dart b/lib/widget/company_detail.dart index 9c9fdfc9..c96b0e65 100644 --- a/lib/widget/company_detail.dart +++ b/lib/widget/company_detail.dart @@ -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 { final InvenTreeCompany company; + final _editCompanyKey = GlobalKey(); + @override String getAppBarTitle(BuildContext context) { return "Company"; } @@ -35,6 +39,72 @@ class _CompanyDetailState extends RefreshableState { // TODO } + void _saveCompany(Map 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: [ + 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: [ + 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 _companyTiles() { var tiles = List(); @@ -51,7 +121,7 @@ class _CompanyDetailState extends RefreshableState { ), trailing: IconButton( icon: FaIcon(FontAwesomeIcons.edit), - onPressed: null, + onPressed: editCompanyDialog, ), ), )); diff --git a/lib/widget/fields.dart b/lib/widget/fields.dart index 53817659..2f815d86 100644 --- a/lib/widget/fields.dart +++ b/lib/widget/fields.dart @@ -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}) :