Skip to content

Commit

Permalink
Changed save behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
DigitalFlow committed Mar 21, 2019
1 parent 5798b39 commit d022208
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions src/web/Xrm.Oss.HtmlTemplating/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,18 @@ export default class EmailTemplating extends React.PureComponent<EditorProps, Ed

registerForm = () => {
if (this.isEntityForm()) {
window.parent.Xrm.Page.data.entity.addOnSave(this.saveForm);
const design = window.parent.Xrm.Page.getAttribute(this.props.jsonField).getValue();

this.Editor.loadDesign((design && JSON.parse(design)) || defaultDesign);

(window as any).unlayer.addEventListener("design:updated", () => {
if (this.isEntityForm()) {
this.Editor.exportHtml(data => {
window.parent.Xrm.Page.getAttribute(this.props.htmlField).setValue(data.html);
window.parent.Xrm.Page.getAttribute(this.props.jsonField).setValue(JSON.stringify(data.design));
});
}
});
}
}

Expand Down Expand Up @@ -81,22 +89,6 @@ export default class EmailTemplating extends React.PureComponent<EditorProps, Ed
window.parent.Xrm.Page.data.entity.save();
}

saveForm = (saveEvent?: Xrm.Events.SaveEventContext) => {
if (this.state.allowSave) {
this.setState({ allowSave: false });
return;
}

saveEvent.getEventArgs().preventDefault();

this.Editor.exportHtml(data => {
window.parent.Xrm.Page.getAttribute(this.props.htmlField).setValue(data.html);
window.parent.Xrm.Page.getAttribute(this.props.jsonField).setValue(JSON.stringify(data.design));

this.setState({ allowSave: true }, this.triggerSave);
});
}

saveSolution = () => {
this.setState({requestPending: true});

Expand Down

0 comments on commit d022208

Please sign in to comment.