EditContactController.swift 1010 B

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