73ae60af by acetousk

Fix load and store remote for mjml grapesjs integration, fix resource finder vie…

…wing, and default json template data
1 parent 4ae7c2ad
......@@ -180,17 +180,25 @@ along with this software (see the LICENSE.md file). If not, see
window.onload = () => {
window.resourceId = new URLSearchParams(window.location.search).get('resourceId');
const request = new XMLHttpRequest();
request.open("GET", "${baseLinkUrl}/rest/s1/moqui-mjml/mjml?resourceId="+window.resourceId, false); // `false` makes the request synchronous
request.send(null);
let response;
if (request.status === 200) {
response = JSON.parse(request.responseText);
}
// console.log('response ', response)
window.resourceId = response.resourceId;
const url = new URL(window.location.href)
url.searchParams.set('resourceId', window.resourceId);
window.history.pushState({}, '', url)
const projectData = JSON.parse(response.data);
// console.log('window.projectData ', window.projectData)
window.editor = grapesjs.init({
// projectData: {
// pages: [
// {
// component: `
// <div class="test">Initial content</div>
// <style>.test { color: red }</style>
// `
// }
// ]
// },
projectData: projectData,
height: '100%',
noticeOnUnload: false,
// Default configurations
......@@ -203,8 +211,8 @@ along with this software (see the LICENSE.md file). If not, see
// Default storage options
options: {
remote: {
urlLoad: "${baseLinkUrl}/rest/s1/moqui-mjml/mjml?resourceId=" + resourceId,
urlStore: "${baseLinkUrl}/rest/s1/moqui-mjml/mjml?resourceId=" + resourceId,
urlLoad: "${baseLinkUrl}/rest/s1/moqui-mjml/mjml?resourceId=" + window.resourceId,
urlStore: "${baseLinkUrl}/rest/s1/moqui-mjml/mjml?resourceId=" + window.resourceId,
headers: {
"X-CSRF-Token": document.getElementById('confMoquiSessionToken').value
},
......@@ -215,21 +223,16 @@ along with this software (see the LICENSE.md file). If not, see
// we have to properly update the body before the store and extract the
// project data from the response result.
onStore: data => {
console.log('onStore', ({ id: resourceId, data }))
console.log('onStore resourceId', window.resourceId)
console.log('onStore editor', editor)
console.log('onStore this ', this)
// const url = new URL(window.location.href)
// url.searchParams.set('resourceId', resourceId);
// window.history.pushState({}, '', url)
return { id: resourceId, data }
return { id: window.resourceId, data }
},
onLoad: result => {
if (result.resourceId !== null) {
const url = new URL(window.location.href)
url.searchParams.set('resourceId', result.resourceId);
window.history.pushState({}, '', url)
window.resourceId = result.resourceId;
console.log('onLoad ', result)
}
// console.log('onLoad ', result)
return result.data
},
},
......
......@@ -32,9 +32,9 @@ along with this software (see the LICENSE.md file). If not, see
<then>
<set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs/project')"/>
<service-call name="create#moqui.resource.DbResource" in-map="[parentResourceId:grapesJsResource.getDbResourceId(),isFile:'Y']" out-map="dbResource"/>
<service-call name="update#moqui.resource.DbResource" in-map="[resourceId:dbResource.resourceId,filename:dbResource.resourceId]" out-map="dbResource"/>
<service-call name="update#moqui.resource.DbResource" in-map="[resourceId:dbResource.resourceId,filename:dbResource.resourceId+'.json']" out-map="dbResource"/>
<set field="versionName" value="01"/>
<set field="defaultFile" from="ec.resource.getLocationReference('dbresource://grapesjs/template/default')"/>
<set field="defaultFile" from="ec.resource.getLocationReference('dbresource://grapesjs/template/default.json')"/>
<set field="data" from="defaultFile.getText()"/>
<service-call name="create#moqui.resource.DbResourceFile" in-map="[resourceId: dbResource.resourceId,mimeType: 'text/json',versionName: versionName,rootVersionName: versionName,fileData:data]"/>
<service-call name="create#moqui.resource.DbResourceFileHistory" in-map="[resourceId: dbResource.resourceId,versionDate: ec.user.nowTimestamp,userId: ec.user.userId,isDiff: 'N']"/>
......@@ -93,7 +93,8 @@ along with this software (see the LICENSE.md file). If not, see
<if condition="resourceId == 'null'"><set field="resourceId" from="null"/></if>
<!-- <log level="warn" message="resourceId is ${resourceId} resourceId.getClass().getName() ${resourceId.getClass().getName()} resourceId == 'null' ${resourceId == 'null'} resourceId == null ${resourceId == null}"/>-->
<!-- <log level="warn" message="store#GrapeJs ec.web.secureRequestParameters._requestBodyText ${ec.web.secureRequestParameters._requestBodyText}"/>-->
<set field="data" from="new groovy.json.JsonSlurper().parseText(ec.web.secureRequestParameters._requestBodyText).data.toString()"/>
<set field="data" from="groovy.json.JsonOutput.toJson(new groovy.json.JsonSlurper().parseText(ec.web.secureRequestParameters._requestBodyText).data)"/>
<!-- <log level="warn" message="store#GrapeJs data ${data}"/>-->
<!-- <log level="warn" message="store context.toString() ${context.toString()}"/>-->
<if condition="!resourceId">
......@@ -101,7 +102,7 @@ along with this software (see the LICENSE.md file). If not, see
<!-- <log level="warn" message="resourceId is null"/>-->
<set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs/project')"/>
<service-call name="create#moqui.resource.DbResource" in-map="[parentResourceId:grapesJsResource.getDbResourceId(),isFile:'Y']" out-map="dbResource"/>
<service-call name="update#moqui.resource.DbResource" in-map="[resourceId:dbResource.resourceId,filename:dbResource.resourceId]" out-map="dbResource"/>
<service-call name="update#moqui.resource.DbResource" in-map="[resourceId:dbResource.resourceId,filename:dbResource.resourceId+'.json']" out-map="dbResource"/>
<set field="versionName" value="01"/>
<service-call name="create#moqui.resource.DbResourceFile" in-map="[resourceId: dbResource.resourceId,mimeType: 'text/json',versionName: versionName,rootVersionName: versionName,fileData:data]"/>
<service-call name="create#moqui.resource.DbResourceFileHistory" in-map="[resourceId: dbResource.resourceId,versionDate: ec.user.nowTimestamp,userId: ec.user.userId,isDiff: 'N']"/>
......