KMBatesPropertyHomeController.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // KMBatesPropertyHomeController.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2022/12/28.
  6. //
  7. import Cocoa
  8. /// Bates 属性主控制器
  9. class KMBatesPropertyHomeController: KMWatermarkAdjectivePropertyMainController {
  10. override func viewDidLoad() {
  11. super.viewDidLoad()
  12. }
  13. override func gotoHomeController(_ selectedModelID: String) {
  14. let controller = KMBatesPropertyController()
  15. controller.controller.selectedTemplateID = selectedModelID
  16. self.showController(controller)
  17. controller.rightButtonClick = { [weak self] index in
  18. self!.gotoCreateController()
  19. }
  20. controller.menuItemClick = { [weak self] index, model in
  21. if (index == 2) { /// 编辑
  22. self!.gotoEditController(model)
  23. }
  24. }
  25. controller.templateDidSelected = { [weak self] model, selected in
  26. if (selected) { /// 模板已选中,
  27. self!.model = model
  28. } else { /// 模板取消选中
  29. self!.model = nil
  30. }
  31. guard let callback = self!.modelDidChange else {
  32. return
  33. }
  34. callback(self?.model)
  35. }
  36. }
  37. override func gotoCreateController() {
  38. let controller = KMCreateBatesController()
  39. let model: KMBatesModel = KMBatesModel()
  40. model.pageCount = self.pageCount
  41. controller.model = model
  42. self.showController(controller)
  43. controller.backClick = { [weak self] in
  44. self?.gotoHomeController("")
  45. }
  46. controller.rightButtonClick = { [weak self] index in
  47. /// 保存到模板
  48. let createController: KMCreateBatesController = self!.currentController as! KMCreateBatesController
  49. if (createController.model != nil) {
  50. let model: KMBatesModel = createController.model as! KMBatesModel
  51. if (!model.hasVaild) {
  52. let alert = NSAlert()
  53. alert.alertStyle = .warning
  54. alert.messageText = NSLocalizedString("Failure", comment: "")
  55. alert.runModal()
  56. return
  57. }
  58. let result = KMBatesManager.defaultManager.addTemplate(model)
  59. if (result) {
  60. guard let callback = self!.modelDidChange else {
  61. return
  62. }
  63. self?.model = model
  64. callback(self?.model)
  65. self?.gotoHomeController(model.id)
  66. }
  67. }
  68. }
  69. controller.modelDidChange = { [weak self] model in
  70. self?.model = model
  71. guard let callback = self!.modelDidChange else {
  72. return
  73. }
  74. callback(self?.model)
  75. }
  76. }
  77. override func gotoEditController(_ model: KMWatermarkAdjectiveBaseModel) {
  78. let controller = KMCreateBatesController()
  79. controller.isEdit = true
  80. model.pageCount = self.pageCount
  81. controller.model = model
  82. controller.flagModel = model.copy() as AnyObject
  83. self.showController(controller)
  84. controller.backClick = { [weak self] in
  85. let editController: KMCreateBatesController = self!.currentController as! KMCreateBatesController
  86. if (editController.isEdited) {
  87. /// 更新模板
  88. let result = KMBatesManager.defaultManager.updateTemplate(editController.model as! KMBatesModel)
  89. // if (result) {
  90. self!.gotoHomeController("")
  91. // }
  92. } else {
  93. self!.gotoHomeController("")
  94. }
  95. }
  96. controller.rightButtonClick = { [weak self] index in
  97. let editController: KMCreateBatesController = self!.currentController as! KMCreateBatesController
  98. editController.resume()
  99. }
  100. }
  101. }