passforios/pass/Controllers/EditPasswordTableViewController.swift

64 lines
2.7 KiB
Swift
Raw Normal View History

2017-02-13 01:15:42 +08:00
//
// EditPasswordTableViewController.swift
// pass
//
// Created by Mingshen Sun on 12/2/2017.
// Copyright © 2017 Bob Sun. All rights reserved.
//
import UIKit
class EditPasswordTableViewController: PasswordEditorTableViewController {
override func viewDidLoad() {
tableData = [
[[.type: PasswordEditorCellType.textFieldCell, .title: "name", .content: password!.name]],
[[.type: PasswordEditorCellType.fillPasswordCell, .title: "password", .content: password!.password],
[.type: PasswordEditorCellType.passwordLengthCell, .title: "passwordlength"]],
2017-02-13 01:15:42 +08:00
[[.type: PasswordEditorCellType.textViewCell, .title: "additions", .content: password!.getAdditionsPlainText()]],
[[.type: PasswordEditorCellType.scanQRCodeCell],
[.type: PasswordEditorCellType.deletePasswordCell]]
2017-02-13 01:15:42 +08:00
]
super.viewDidLoad()
}
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
if identifier == "saveEditPasswordSegue" {
if let nameCell = tableView.cellForRow(at: IndexPath(row: 0, section: 0)) as? ContentTableViewCell {
if nameCell.getContent() != password?.name {
let alertTitle = "Cannot Save Edit"
let alertMessage = "Editing name is not supported."
Utils.alert(title: alertTitle, message: alertMessage, controller: self) {
nameCell.setContent(content: self.password!.name)
}
return false
2017-02-13 01:15:42 +08:00
}
}
}
return true
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)
2017-02-13 11:42:28 +08:00
if segue.identifier == "saveEditPasswordSegue" {
let cells = tableView.visibleCells
var cellContents = [String: String]()
for cell in cells {
if let indexPath = tableView.indexPath(for: cell),
let contentCell = cell as? ContentTableViewCell,
let cellTitle = tableData[indexPath.section][indexPath.row][.title] as? String,
let cellContent = contentCell.getContent() {
cellContents[cellTitle] = cellContent
2017-03-09 03:19:36 +08:00
}
2017-02-13 11:42:28 +08:00
}
2017-02-15 21:25:26 +08:00
var plainText = ""
if cellContents["additions"]! != "" {
plainText = "\(cellContents["password"]!)\n\(cellContents["additions"]!)"
2017-02-15 21:25:26 +08:00
} else {
plainText = "\(cellContents["password"]!)"
2017-02-15 21:25:26 +08:00
}
password!.updatePassword(name: cellContents["name"]!, plainText: plainText)
2017-02-13 01:15:42 +08:00
}
}
}