Skip to content

Commit

Permalink
add func for inspection back button, add validation on tap
Browse files Browse the repository at this point in the history
  • Loading branch information
davidclaveau committed Jan 16, 2024
1 parent 18fd043 commit c592513
Showing 1 changed file with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public enum WatercraftFromSection: Int, CaseIterable {
extension String {
var readableSection: String {
let sectionTitles: [String: String] = [
"basicInformation": "--- BASIC INFORMATION ---",
"watercraftDetails": "--- WATERCRAFT DETAILS ---",
"journeyDetails": "--- JOURNEY DETAILS ---",
"inspectionDetails": "--- INSPECTION DETAILS ---",
"inspectionOutcomes": "--- INSPECTION OUTCOMES ---"
"basicInformation": "- BASIC INFORMATION -",
"watercraftDetails": "- WATERCRAFT DETAILS -",
"journeyDetails": "- JOURNEY DETAILS -",
"inspectionDetails": "- INSPECTION DETAILS -",
"inspectionOutcomes": "- INSPECTION OUTCOMES -"
]
return sectionTitles[self] ?? self.capitalized
}
Expand Down Expand Up @@ -185,9 +185,27 @@ class WatercraftInspectionViewController: BaseViewController {
setGradiantBackground(navigationBar: navigation.navigationBar)
if let model = self.model, model.getStatus() == .Draft {
setRightNavButtons()
setLeftNavButtons()
}
}

private func setLeftNavButtons() {
// Create a UIButton to hold the back icon and text
let backButton = UIButton(type: .custom)
backButton.setTitle(" Shift Overview", for: .normal)
backButton.setTitleColor(UIColor.white, for: .normal)
backButton.setImage(UIImage(systemName: "chevron.backward"), for: .normal)
backButton.addTarget(self, action: #selector(didTapBackButton(sender:)), for: .touchUpInside)
backButton.contentHorizontalAlignment = .left
backButton.semanticContentAttribute = .forceLeftToRight

backButton.sizeToFit()

let backBarButtonItem = UIBarButtonItem(customView: backButton)

navigationItem.leftBarButtonItem = backBarButtonItem
}

private func setRightNavButtons() {
let deleteIcon = UIImage(systemName: "trash")
let deleteButton = UIBarButtonItem(image: deleteIcon, style: .plain, target: self, action: #selector(self.didTapDeleteButton(sender:)))
Expand All @@ -198,6 +216,16 @@ class WatercraftInspectionViewController: BaseViewController {
navigationItem.rightBarButtonItems = [saveButton, deleteButton]
}

@objc func didTapBackButton(sender: UIBarButtonItem) {
self.dismissKeyboard()

if canSubmit() {
self.navigationController?.popViewController(animated: true)
} else {
Alert.show(title: "Incomplete", message: validationMessage())
}
}

// Navigation bar right button action
@objc func didTapDeleteButton(sender: UIBarButtonItem) {
guard let model = self.model else {return}
Expand Down

0 comments on commit c592513

Please sign in to comment.