// // MessageComposeViewController.swift // GMERemittance // // Created by gme_2 on 02/10/2018. //Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved. // import UIKit class MessageComposeViewController: UIViewController { // MARK: IBOutlets @IBOutlet weak var textFieldSubject: UITextField! @IBOutlet weak var textViewMessage: UITextView! // MARK: Properties var type: MailBoxType? var controlNO: String? var transactionId: String? var presenter: MessageComposeModuleInterface? // MARK: VC's Life cycle override func viewDidLoad() { super.viewDidLoad() self.setup() } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) self.setupNormalNavigation() self.navigationItem.title = "Support" } // MARK: IBActions @IBAction func cancelMessage(_ sender: Any) { navigationController?.popViewController(animated: true) dismiss(animated: true, completion: nil) } // MARK: Other Functions private func setup() { // all setup should be done here self.textViewMessage.text = "Your request here" textViewMessage.textColor = UIColor.lightGray textViewMessage.layer.borderWidth = 0.3 textViewMessage.layer.borderColor = UIColor.lightGray.cgColor textViewMessage.layer.backgroundColor = UIColor.white.cgColor textViewMessage.delegate = self let barbutton = UIBarButtonItem.init(image: #imageLiteral(resourceName: "backIconBlack"), style: .plain, target: self, action: #selector(self.cancelMessage(_:))) self.navigationItem.leftBarButtonItem = barbutton setupSubject() } private func setupSubject() { if let _type = self.type { switch _type { case .cancel: self.textFieldSubject.text = "Request For Cancellation" case .edit: self.textFieldSubject.text = "Request For Amendment" } } self.textFieldSubject.isUserInteractionEnabled = false } @IBAction func submit(_ sender: UIButton) { let subject = self.textFieldSubject.text! let body = self.textViewMessage.text ?? "" let controlNo = self.controlNO ?? "" let transactionId = self.transactionId ?? "" if let _type = self.type { switch _type { case .cancel: self.presenter?.cancel(control: controlNo, transId: transactionId, subject: subject, body: body) case .edit: self.presenter?.edit(control: controlNo, transId: transactionId, subject: subject, body: body) } } } } // MARK: MessageComposeViewInterface extension MessageComposeViewController: MessageComposeViewInterface { func show(model: SuccessMessage) { self.alert(message: model.message, title: "Success") { self.presenter?.dismiss() } } func show(error: String) { self.alert(message: error) } } extension MessageComposeViewController: UITextViewDelegate { func textViewDidBeginEditing(_ textView: UITextView) { if textView.textColor == UIColor.lightGray { textView.text = nil textView.textColor = UIColor.init(hex: "#4a4a4a") } } func textViewDidEndEditing(_ textView: UITextView) { if textViewMessage.text.isEmpty { textViewMessage.text = "Your request here" textViewMessage.textColor = UIColor.lightGray } } }