EditContactController.swift 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import UIKit
  2. import DcCore
  3. class EditContactController: NewContactController {
  4. // for editing existing contacts (only
  5. // the name may be edited, therefore disable
  6. // the email field)
  7. init(dcContext: DcContext, contactIdForUpdate: Int) {
  8. super.init(dcContext: dcContext)
  9. title = String.localized("edit_contact")
  10. let contact = DcContact(id: contactIdForUpdate)
  11. nameCell.textField.text = contact.name
  12. emailCell.textField.text = contact.email
  13. emailCell.textField.isEnabled = false
  14. emailCell.contentView.alpha = 0.3
  15. model.name = contact.name
  16. model.email = contact.email
  17. if contactIsValid() {
  18. doneButton?.isEnabled = true
  19. }
  20. }
  21. required init?(coder _: NSCoder) {
  22. fatalError("init(coder:) has not been implemented")
  23. }
  24. @objc override func saveContactButtonPressed() {
  25. _ = dcContext.createContact(name: model.name, email: model.email)
  26. coordinator?.navigateBack()
  27. }
  28. }