diff --git a/MVMCoreUI/Atomic/Templates/ListPageTemplateModel.swift b/MVMCoreUI/Atomic/Templates/ListPageTemplateModel.swift index b2b52573..9be4113e 100644 --- a/MVMCoreUI/Atomic/Templates/ListPageTemplateModel.swift +++ b/MVMCoreUI/Atomic/Templates/ListPageTemplateModel.swift @@ -18,6 +18,7 @@ import Foundation } public var molecules: [ListItemModelProtocol & MoleculeModelProtocol]? public var line: LineModel? + public var closeAction: ActionModelProtocol? //-------------------------------------------------- // MARK: - Initializer @@ -36,6 +37,7 @@ import Foundation private enum CodingKeys: String, CodingKey { case molecules case line + case closeAction } //-------------------------------------------------- @@ -46,6 +48,7 @@ import Foundation let typeContainer = try decoder.container(keyedBy: CodingKeys.self) molecules = try typeContainer.decodeModelsIfPresent(codingKey: .molecules) line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) + closeAction = try typeContainer.decodeModelIfPresent(codingKey: .closeAction) try super.init(from: decoder) } @@ -54,6 +57,7 @@ import Foundation var container = encoder.container(keyedBy: CodingKeys.self) try container.encodeModelsIfPresent(molecules, forKey: .molecules) try container.encode(line, forKey: .line) + try container.encodeModelIfPresent(closeAction, forKey: .closeAction) } } diff --git a/MVMCoreUI/Atomic/Templates/ModalMoleculeListTemplate.swift b/MVMCoreUI/Atomic/Templates/ModalMoleculeListTemplate.swift index 2dffb26f..f10abe52 100644 --- a/MVMCoreUI/Atomic/Templates/ModalMoleculeListTemplate.swift +++ b/MVMCoreUI/Atomic/Templates/ModalMoleculeListTemplate.swift @@ -27,11 +27,11 @@ open class ModalMoleculeListTemplate: MoleculeListTemplate { guard let self = self else { return } - guard let actionMap = self.loadObject?.pageJSON?.optionalDictionaryWithChainOfKeysOrIndexes([KeyButtonMap,"CloseButton"]) else { + guard let actionMap = self.templateModel?.closeAction else { MVMCoreActionHandler.shared()?.handleAction(with: ActionBackModel().toJSON(), additionalData: nil, delegateObject: self.delegateObjectIVar) return } - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: nil, delegateObject: self.delegateObjectIVar) + MVMCoreActionHandler.shared()?.handleAction(with: actionMap.toJSON(), additionalData: nil, delegateObject: self.delegateObjectIVar) }) } diff --git a/MVMCoreUI/Atomic/Templates/ModalMoleculeStackTemplate.swift b/MVMCoreUI/Atomic/Templates/ModalMoleculeStackTemplate.swift index 57a58a3c..a4f79e7e 100644 --- a/MVMCoreUI/Atomic/Templates/ModalMoleculeStackTemplate.swift +++ b/MVMCoreUI/Atomic/Templates/ModalMoleculeStackTemplate.swift @@ -13,15 +13,14 @@ open class ModalMoleculeStackTemplate: MoleculeStackTemplate { override open func handleNewData() { super.handleNewData() _ = MVMCoreUICommonViewsUtility.addCloseButton(to: view, action: {[weak self] _ in - guard let self = self else { - return - } - guard let actionMap = self.loadObject?.pageJSON?.optionalDictionaryWithChainOfKeysOrIndexes([KeyButtonMap,"CloseButton"]) else { - MVMCoreActionHandler.shared()?.handleAction(with: ActionBackModel().toJSON(), additionalData: nil, delegateObject: self.delegateObjectIVar) - return - } - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: nil, delegateObject: self.delegateObjectIVar) + guard let self = self else { + return + } + guard let actionMap = self.templateModel?.closeAction else { + MVMCoreActionHandler.shared()?.handleAction(with: ActionBackModel().toJSON(), additionalData: nil, delegateObject: self.delegateObjectIVar) + return + } + MVMCoreActionHandler.shared()?.handleAction(with: actionMap.toJSON(), additionalData: nil, delegateObject: self.delegateObjectIVar) }) } - } diff --git a/MVMCoreUI/Atomic/Templates/StackPageTemplateModel.swift b/MVMCoreUI/Atomic/Templates/StackPageTemplateModel.swift index f21a0421..40d97814 100644 --- a/MVMCoreUI/Atomic/Templates/StackPageTemplateModel.swift +++ b/MVMCoreUI/Atomic/Templates/StackPageTemplateModel.swift @@ -14,6 +14,7 @@ import Foundation return "stack" } public var moleculeStack: StackModel + public var closeAction: ActionModelProtocol? public init(pageType: String, moleculeStack: StackModel) { self.moleculeStack = moleculeStack @@ -22,11 +23,13 @@ import Foundation private enum CodingKeys: String, CodingKey { case stack + case closeAction } required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) moleculeStack = try typeContainer.decode(StackModel.self, forKey: .stack) + closeAction = try typeContainer.decodeModelIfPresent(codingKey: .closeAction) try super.init(from: decoder) } @@ -34,5 +37,6 @@ import Foundation try super.encode(to: encoder) var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeStack, forKey: .stack) + try container.encodeModelIfPresent(closeAction, forKey: .closeAction) } }