// // KMBatesPropertyHomeController.swift // PDF Master // // Created by tangchao on 2022/12/28. // import Cocoa /// Bates 属性主控制器 class KMBatesPropertyHomeController: KMWatermarkAdjectivePropertyMainController { override func viewDidLoad() { super.viewDidLoad() } override func gotoHomeController(_ selectedModelID: String) { let controller = KMBatesPropertyController() controller.controller.selectedTemplateID = selectedModelID self.showController(controller) controller.rightButtonClick = { [weak self] index in self!.gotoCreateController() } controller.menuItemClick = { [weak self] index, model in if (index == 2) { /// 编辑 self!.gotoEditController(model) } } controller.templateDidSelected = { [weak self] model, selected in if (selected) { /// 模板已选中, self!.model = model } else { /// 模板取消选中 self!.model = nil } guard let callback = self!.modelDidChange else { return } callback(self?.model) } } override func gotoCreateController() { let controller = KMCreateBatesController() let model: KMBatesModel = KMBatesModel() model.pageCount = self.pageCount controller.model = model self.showController(controller) controller.backClick = { [weak self] in self?.gotoHomeController("") } controller.rightButtonClick = { [weak self] index in /// 保存到模板 let createController: KMCreateBatesController = self!.currentController as! KMCreateBatesController if (createController.model != nil) { let model: KMBatesModel = createController.model as! KMBatesModel if (!model.hasVaild) { let alert = NSAlert() alert.alertStyle = .warning alert.messageText = NSLocalizedString("Failure", comment: "") alert.runModal() return } let result = KMBatesManager.defaultManager.addTemplate(model) if (result) { guard let callback = self!.modelDidChange else { return } self?.model = model callback(self?.model) self?.gotoHomeController(model.id) } } } controller.modelDidChange = { [weak self] model in self?.model = model guard let callback = self!.modelDidChange else { return } callback(self?.model) } } override func gotoEditController(_ model: KMWatermarkAdjectiveBaseModel) { let controller = KMCreateBatesController() controller.isEdit = true model.pageCount = self.pageCount controller.model = model controller.flagModel = model.copy() as AnyObject self.showController(controller) controller.backClick = { [weak self] in let editController: KMCreateBatesController = self!.currentController as! KMCreateBatesController if (editController.isEdited) { /// 更新模板 let result = KMBatesManager.defaultManager.updateTemplate(editController.model as! KMBatesModel) // if (result) { self!.gotoHomeController("") // } } else { self!.gotoHomeController("") } } controller.rightButtonClick = { [weak self] index in let editController: KMCreateBatesController = self!.currentController as! KMCreateBatesController editController.resume() } } }