save method

Future<Form?> save()

Implementation

Future<HIVE.Form?> save() async
{
  HIVE.Form? form;

  // Validate the Data
  bool ok = (await validate() == null);

  // Show Success
  if (ok)
  {
    // Serialize the Form
    await serialize(this.element, fields);

    // Serialize Outer Xml
    String xml = framework!.element!.toXmlString(pretty: true);

    // Lookup Form
    HIVE.Form? form = await HIVE.Form.find(framework!.key);

    // Update the Form
    if (form != null)
    {
      Log().info('Updating Form');

      form.complete = completed;
      form.updated  = DateTime.now().millisecondsSinceEpoch;
      form.template = xml;
      form.data     = map;
      await form.update();
    }

    // Insert the Form
    else
    {
      Log().info('Inserting New form');
      form = HIVE.Form(key: framework?.key, parent: framework?.dependency, complete: completed, template: xml, data: map);
      await form.insert();
    }

    // Mark Clean
    clean = true;
  }

  return form;
}