|
|
@ -10,6 +10,12 @@ import UIKit |
|
|
|
import RxSwift |
|
|
|
import RxCocoa |
|
|
|
|
|
|
|
enum DynamicFieldRequire: String { |
|
|
|
case mandatory = "M" |
|
|
|
case optional = "O" |
|
|
|
case hidden = "H" |
|
|
|
} |
|
|
|
|
|
|
|
class SetupRecipientViewController: UIViewController { |
|
|
|
// MARK: Properties |
|
|
|
var viewModel: SetupRecipientViewModel! |
|
|
@ -49,6 +55,7 @@ class SetupRecipientViewController: UIViewController { |
|
|
|
@IBOutlet private weak var lastNameLocalTextField: ValidationTextField! |
|
|
|
@IBOutlet private weak var fullNameLocalTextField: ValidationTextField! |
|
|
|
|
|
|
|
@IBOutlet private weak var nativeCountryTextField: ValidationTextField! |
|
|
|
@IBOutlet private weak var mobileTextField: ValidationTextField! |
|
|
|
@IBOutlet private weak var emailTextField: ValidationTextField! |
|
|
|
|
|
|
@ -165,7 +172,8 @@ extension SetupRecipientViewController { |
|
|
|
|
|
|
|
setSelectTextFields(of:[ |
|
|
|
countryTextField, paymentModeTextField, bankTextField, branchTextField, |
|
|
|
idTextField, stateProvinceTextField, districtTextField, relationTextField, reasonTextField |
|
|
|
idTextField, stateProvinceTextField, districtTextField, relationTextField, reasonTextField, |
|
|
|
nativeCountryTextField |
|
|
|
] |
|
|
|
) |
|
|
|
recipientBankInfomationContainerView.isHidden = true |
|
|
@ -200,6 +208,7 @@ extension SetupRecipientViewController { |
|
|
|
"Middle Name in Local": middleNameLocalTextField, |
|
|
|
"Last Name in Local": lastNameLocalTextField, |
|
|
|
"Local Name": fullNameLocalTextField, |
|
|
|
"Native Country": nativeCountryTextField, |
|
|
|
"Id Type": idTextField, |
|
|
|
"ID Number": idNumberTextField, |
|
|
|
"Mobile Number": mobileTextField, |
|
|
@ -249,6 +258,7 @@ extension SetupRecipientViewController { |
|
|
|
openDistrictTrigger: districtTextField.rx.controlEvent(.editingDidBegin).asDriver(), |
|
|
|
openRelationTrigger: relationTextField.rx.controlEvent(.editingDidBegin).asDriver(), |
|
|
|
openReasonTrigger: reasonTextField.rx.controlEvent(.editingDidBegin).asDriver(), |
|
|
|
openNativeCountryTrigger: nativeCountryTextField.rx.controlEvent(.editingDidBegin).asDriver(), |
|
|
|
saveTrigger: saveTrigger |
|
|
|
) |
|
|
|
|
|
|
@ -319,6 +329,24 @@ extension SetupRecipientViewController { |
|
|
|
output.selectedBank.drive(onNext: { |
|
|
|
self.bankTextField.text = $0?.name |
|
|
|
self.bankTextField.sendActions(for: .editingChanged) |
|
|
|
if $0?.branchRequired?.lowercased() == "false" { |
|
|
|
self.branchTextField.isHidden = true |
|
|
|
self.branchTextField.text = "" |
|
|
|
self.branchTextField.valid.onNext(true) |
|
|
|
} else { |
|
|
|
self.branchTextField.isHidden = false |
|
|
|
self.branchTextField.valid.onNext(false) |
|
|
|
} |
|
|
|
|
|
|
|
if $0?.accountRequired?.lowercased() == "false" { |
|
|
|
self.accountTextField.isHidden = true |
|
|
|
self.accountTextField.text = "" |
|
|
|
self.accountTextField.valid.onNext(true) |
|
|
|
} else { |
|
|
|
self.accountTextField.isHidden = false |
|
|
|
self.accountTextField.valid.onNext(false) |
|
|
|
} |
|
|
|
|
|
|
|
}).disposed(by: disposeBag) |
|
|
|
|
|
|
|
output.selectedBranch.drive(onNext: { |
|
|
@ -334,6 +362,16 @@ extension SetupRecipientViewController { |
|
|
|
output.selectedStateProvince.drive(onNext: { |
|
|
|
self.stateProvinceTextField.text = $0?.name |
|
|
|
self.stateProvinceTextField.sendActions(for: .editingChanged) |
|
|
|
|
|
|
|
let count = $0?.districts?.count ?? 0 |
|
|
|
if count == 0 { |
|
|
|
self.districtTextField.isHidden = true |
|
|
|
self.districtTextField.valid.onNext(true) |
|
|
|
} else { |
|
|
|
self.districtTextField.isHidden = false |
|
|
|
self.districtTextField.valid.onNext(false) |
|
|
|
} |
|
|
|
|
|
|
|
}).disposed(by: disposeBag) |
|
|
|
|
|
|
|
output.selectedDistrict.drive(onNext: { |
|
|
@ -351,6 +389,12 @@ extension SetupRecipientViewController { |
|
|
|
self.reasonTextField.sendActions(for: .editingChanged) |
|
|
|
}).disposed(by: disposeBag) |
|
|
|
|
|
|
|
output.selectedNativeCountry.drive(onNext: { |
|
|
|
self.nativeCountryTextField.text = $0?.text |
|
|
|
// self.nativeCountryTextField.setCountry(with: $0?.code, isShowCode: false) |
|
|
|
self.nativeCountryTextField.sendActions(for: .editingChanged) |
|
|
|
}).disposed(by: disposeBag) |
|
|
|
|
|
|
|
output.models.dynamicFieldsModel.drive(onNext: { |
|
|
|
self.setDynamicFields(dynamicFieldInfo: $0) |
|
|
|
self.recipientBankInfomationContainerView.animateHidden(isHidden: false, duration: 0.5) |
|
|
@ -363,42 +407,58 @@ extension SetupRecipientViewController { |
|
|
|
guard |
|
|
|
let key = property.fieldName, |
|
|
|
let textField = self.dynamicFieldDic?[key], |
|
|
|
let isRequire = property.required, |
|
|
|
let isRequire = DynamicFieldRequire(rawValue: property.required ?? ""), |
|
|
|
let min = property.minLength, |
|
|
|
let max = property.maxLength, |
|
|
|
let keyboardType = property.keyBoardType else { return } |
|
|
|
|
|
|
|
textField.isHidden = isRequire == "M" ? false : true |
|
|
|
textField.errorMessage = "general_length_error_text".localized().replacingOccurrences( |
|
|
|
of: "xxx", |
|
|
|
with: "\(min)" |
|
|
|
).replacingOccurrences(of: "ooo", with: "\(max)") |
|
|
|
|
|
|
|
if !textField.isHidden { |
|
|
|
switch isRequire { |
|
|
|
case .mandatory: |
|
|
|
textField.isHidden = false |
|
|
|
if max == min && min == -1 { |
|
|
|
textField.validCondition = { !$0.isEmpty } |
|
|
|
textField.errorMessage = nil |
|
|
|
} else { |
|
|
|
textField.validCondition = { ($0.count >= min && $0.count <= max) && !$0.isEmpty } |
|
|
|
textField.errorMessage = "general_length_error_text".localized().replacingOccurrences( |
|
|
|
of: "xxx", |
|
|
|
with: "\(min)" |
|
|
|
).replacingOccurrences(of: "ooo", with: "\(max)") |
|
|
|
} |
|
|
|
} else { |
|
|
|
case .optional: |
|
|
|
textField.isHidden = false |
|
|
|
if max == min && min == -1 { |
|
|
|
textField.validCondition = nil |
|
|
|
textField.errorMessage = nil |
|
|
|
} else { |
|
|
|
textField.validCondition = { ($0.count >= min && $0.count <= max) } |
|
|
|
} |
|
|
|
|
|
|
|
if !textField.titleText.contains(" (Optional)") { |
|
|
|
textField.titleText += " (Optional)" |
|
|
|
textField.placeholder = "\(textField.placeholder ?? "") (Optional)" |
|
|
|
} |
|
|
|
case .hidden: |
|
|
|
textField.isHidden = true |
|
|
|
textField.text = "" |
|
|
|
} |
|
|
|
|
|
|
|
if key.contains("Local") { |
|
|
|
textField.keyboardType = .default |
|
|
|
} else { |
|
|
|
switch keyboardType { |
|
|
|
case "N": textField.keyboardType = .numberPad |
|
|
|
let keyType = GMEKeyboardType(rawValue: keyboardType) ?? GMEKeyboardType.alphabetNumbericSpecial |
|
|
|
|
|
|
|
switch keyType { |
|
|
|
case .numberic: textField.keyboardType = .numberPad |
|
|
|
default: textField.keyboardType = .asciiCapable |
|
|
|
} |
|
|
|
|
|
|
|
textField.rx.controlEvent(.editingChanged).asDriver() |
|
|
|
.drive(onNext: { _ in |
|
|
|
switch keyboardType { |
|
|
|
case "AN": textField.setKeyboardType(type: .an, isSendAction: false) |
|
|
|
case "ANS": textField.setKeyboardType(type: .ans, isSendAction: false) |
|
|
|
default: textField.setKeyboardType(type: .ans, isSendAction: false) |
|
|
|
switch keyType { |
|
|
|
case .numberic: textField.fitlerBy(type: .alphabetNumberic, isSendAction: false) |
|
|
|
default: textField.fitlerBy(type: keyType, isSendAction: false) |
|
|
|
} |
|
|
|
}).disposed(by: disposeBag) |
|
|
|
} |
|
|
|