voidlabs / mosaico

Mosaico - Responsive Email Template Editor
https://mosaico.io
GNU General Public License v3.0
1.69k stars 500 forks source link

Looking for reliable function calls that can call 'save' any time? #590

Closed tjgragg closed 3 years ago

tjgragg commented 3 years ago

Hello, I'm using mosiaco within an iframe, wrapped in a form. I've made it so when I click the "Save" button, it posts a message to the parents, which then updates the form with both the html and the json metadata.

I'm trying to see if there are any functions that get called reliable while modifying a template, so I can take out the manual process of clicking "save" to update the form.

Thanks!

tjgragg commented 3 years ago

I figured out how to do this when adding/moving/deleting/duplicating a block (within the viewModel object itself), but I'm still not sure how to do this when someone updates the contents of a block.

bago commented 3 years ago

Either you repeatedly run an exportHTML and compare it with the previous version and if you detect changes you call save, or you alter mosaico and attach some listener to undoserializer.setListener(). Unfortunately you can't currently get access to undoserializer from the outside of the default Mosaico build, so you'll have to alter mosaico sources at least to expose somehow the undoserializer.

The listener will be called for every action that involve the undomanager, so every change of the model. We have users that built a full record/replay system above this feature or a collaboration system to have multiple users work concurrently on the same template (even if this is not solid enough to deal with concurrency issues and breaks too easily, IMHO).