You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
3.6 KiB

6 years ago
6 years ago
6 years ago
6 years ago
  1. //
  2. // MessageComposeViewController.swift
  3. // GMERemittance
  4. //
  5. // Created by gme_2 on 02/10/2018.
  6. //Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. class MessageComposeViewController: UIViewController {
  10. // MARK: IBOutlets
  11. @IBOutlet weak var textFieldSubject: UITextField!
  12. @IBOutlet weak var textViewMessage: UITextView!
  13. // MARK: Properties
  14. var type: MailBoxType?
  15. var controlNO: String?
  16. var transactionId: String?
  17. var presenter: MessageComposeModuleInterface?
  18. // MARK: VC's Life cycle
  19. override func viewDidLoad() {
  20. super.viewDidLoad()
  21. self.setup()
  22. }
  23. override func viewWillAppear(_ animated: Bool) {
  24. super.viewWillAppear(animated)
  25. self.setupNormalNavigation()
  26. self.navigationItem.title = "Support"
  27. }
  28. // MARK: IBActions
  29. @IBAction func cancelMessage(_ sender: Any) {
  30. navigationController?.popViewController(animated: true)
  31. dismiss(animated: true, completion: nil)
  32. }
  33. // MARK: Other Functions
  34. private func setup() {
  35. // all setup should be done here
  36. self.textViewMessage.text = "Your request here"
  37. textViewMessage.textColor = UIColor.lightGray
  38. textViewMessage.layer.borderWidth = 0.3
  39. textViewMessage.layer.borderColor = UIColor.lightGray.cgColor
  40. textViewMessage.layer.backgroundColor = UIColor.white.cgColor
  41. textViewMessage.delegate = self
  42. let barbutton = UIBarButtonItem.init(image: #imageLiteral(resourceName: "backIconBlack"), style: .plain, target: self, action: #selector(self.cancelMessage(_:)))
  43. self.navigationItem.leftBarButtonItem = barbutton
  44. setupSubject()
  45. }
  46. private func setupSubject() {
  47. if let _type = self.type {
  48. switch _type {
  49. case .cancel:
  50. self.textFieldSubject.text = "Request For Cancellation"
  51. case .edit:
  52. self.textFieldSubject.text = "Request For Amendment"
  53. }
  54. }
  55. self.textFieldSubject.isUserInteractionEnabled = false
  56. }
  57. @IBAction func submit(_ sender: UIButton) {
  58. let subject = self.textFieldSubject.text!
  59. let body = self.textViewMessage.text ?? ""
  60. let controlNo = self.controlNO ?? ""
  61. let transactionId = self.transactionId ?? ""
  62. if let _type = self.type {
  63. switch _type {
  64. case .cancel:
  65. self.presenter?.cancel(control: controlNo, transId: transactionId, subject: subject, body: body)
  66. case .edit:
  67. self.presenter?.edit(control: controlNo, transId: transactionId, subject: subject, body: body)
  68. }
  69. }
  70. }
  71. }
  72. // MARK: MessageComposeViewInterface
  73. extension MessageComposeViewController: MessageComposeViewInterface {
  74. func show(model: SuccessMessage) {
  75. self.alert(message: model.message, title: "Success") {
  76. self.presenter?.dismiss()
  77. }
  78. }
  79. func show(error: String) {
  80. self.alert(message: error)
  81. }
  82. }
  83. extension MessageComposeViewController: UITextViewDelegate {
  84. func textViewDidBeginEditing(_ textView: UITextView) {
  85. if textView.textColor == UIColor.lightGray {
  86. textView.text = nil
  87. textView.textColor = UIColor.init(hex: "#4a4a4a")
  88. }
  89. }
  90. func textViewDidEndEditing(_ textView: UITextView) {
  91. if textViewMessage.text.isEmpty {
  92. textViewMessage.text = "Your request here"
  93. textViewMessage.textColor = UIColor.lightGray
  94. }
  95. }
  96. }