Fix load and store remote for mjml grapesjs integration, fix resource finder vie…
…wing, and default json template data
Showing
3 changed files
with
29 additions
and
25 deletions
This diff is collapsed.
Click to expand it.
... | @@ -180,17 +180,25 @@ along with this software (see the LICENSE.md file). If not, see | ... | @@ -180,17 +180,25 @@ along with this software (see the LICENSE.md file). If not, see |
180 | window.onload = () => { | 180 | window.onload = () => { |
181 | window.resourceId = new URLSearchParams(window.location.search).get('resourceId'); | 181 | window.resourceId = new URLSearchParams(window.location.search).get('resourceId'); |
182 | 182 | ||
183 | const request = new XMLHttpRequest(); | ||
184 | request.open("GET", "${baseLinkUrl}/rest/s1/moqui-mjml/mjml?resourceId="+window.resourceId, false); // `false` makes the request synchronous | ||
185 | request.send(null); | ||
186 | |||
187 | let response; | ||
188 | if (request.status === 200) { | ||
189 | response = JSON.parse(request.responseText); | ||
190 | } | ||
191 | // console.log('response ', response) | ||
192 | window.resourceId = response.resourceId; | ||
193 | const url = new URL(window.location.href) | ||
194 | url.searchParams.set('resourceId', window.resourceId); | ||
195 | window.history.pushState({}, '', url) | ||
196 | |||
197 | const projectData = JSON.parse(response.data); | ||
198 | // console.log('window.projectData ', window.projectData) | ||
199 | |||
183 | window.editor = grapesjs.init({ | 200 | window.editor = grapesjs.init({ |
184 | // projectData: { | 201 | projectData: projectData, |
185 | // pages: [ | ||
186 | // { | ||
187 | // component: ` | ||
188 | // <div class="test">Initial content</div> | ||
189 | // <style>.test { color: red }</style> | ||
190 | // ` | ||
191 | // } | ||
192 | // ] | ||
193 | // }, | ||
194 | height: '100%', | 202 | height: '100%', |
195 | noticeOnUnload: false, | 203 | noticeOnUnload: false, |
196 | // Default configurations | 204 | // Default configurations |
... | @@ -203,8 +211,8 @@ along with this software (see the LICENSE.md file). If not, see | ... | @@ -203,8 +211,8 @@ along with this software (see the LICENSE.md file). If not, see |
203 | // Default storage options | 211 | // Default storage options |
204 | options: { | 212 | options: { |
205 | remote: { | 213 | remote: { |
206 | urlLoad: "${baseLinkUrl}/rest/s1/moqui-mjml/mjml?resourceId=" + resourceId, | 214 | urlLoad: "${baseLinkUrl}/rest/s1/moqui-mjml/mjml?resourceId=" + window.resourceId, |
207 | urlStore: "${baseLinkUrl}/rest/s1/moqui-mjml/mjml?resourceId=" + resourceId, | 215 | urlStore: "${baseLinkUrl}/rest/s1/moqui-mjml/mjml?resourceId=" + window.resourceId, |
208 | headers: { | 216 | headers: { |
209 | "X-CSRF-Token": document.getElementById('confMoquiSessionToken').value | 217 | "X-CSRF-Token": document.getElementById('confMoquiSessionToken').value |
210 | }, | 218 | }, |
... | @@ -215,21 +223,16 @@ along with this software (see the LICENSE.md file). If not, see | ... | @@ -215,21 +223,16 @@ along with this software (see the LICENSE.md file). If not, see |
215 | // we have to properly update the body before the store and extract the | 223 | // we have to properly update the body before the store and extract the |
216 | // project data from the response result. | 224 | // project data from the response result. |
217 | onStore: data => { | 225 | onStore: data => { |
218 | console.log('onStore', ({ id: resourceId, data })) | 226 | return { id: window.resourceId, data } |
219 | console.log('onStore resourceId', window.resourceId) | ||
220 | console.log('onStore editor', editor) | ||
221 | console.log('onStore this ', this) | ||
222 | // const url = new URL(window.location.href) | ||
223 | // url.searchParams.set('resourceId', resourceId); | ||
224 | // window.history.pushState({}, '', url) | ||
225 | return { id: resourceId, data } | ||
226 | }, | 227 | }, |
227 | onLoad: result => { | 228 | onLoad: result => { |
229 | if (result.resourceId !== null) { | ||
228 | const url = new URL(window.location.href) | 230 | const url = new URL(window.location.href) |
229 | url.searchParams.set('resourceId', result.resourceId); | 231 | url.searchParams.set('resourceId', result.resourceId); |
230 | window.history.pushState({}, '', url) | 232 | window.history.pushState({}, '', url) |
231 | window.resourceId = result.resourceId; | 233 | window.resourceId = result.resourceId; |
232 | console.log('onLoad ', result) | 234 | } |
235 | // console.log('onLoad ', result) | ||
233 | return result.data | 236 | return result.data |
234 | }, | 237 | }, |
235 | }, | 238 | }, | ... | ... |
... | @@ -32,9 +32,9 @@ along with this software (see the LICENSE.md file). If not, see | ... | @@ -32,9 +32,9 @@ along with this software (see the LICENSE.md file). If not, see |
32 | <then> | 32 | <then> |
33 | <set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs/project')"/> | 33 | <set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs/project')"/> |
34 | <service-call name="create#moqui.resource.DbResource" in-map="[parentResourceId:grapesJsResource.getDbResourceId(),isFile:'Y']" out-map="dbResource"/> | 34 | <service-call name="create#moqui.resource.DbResource" in-map="[parentResourceId:grapesJsResource.getDbResourceId(),isFile:'Y']" out-map="dbResource"/> |
35 | <service-call name="update#moqui.resource.DbResource" in-map="[resourceId:dbResource.resourceId,filename:dbResource.resourceId]" out-map="dbResource"/> | 35 | <service-call name="update#moqui.resource.DbResource" in-map="[resourceId:dbResource.resourceId,filename:dbResource.resourceId+'.json']" out-map="dbResource"/> |
36 | <set field="versionName" value="01"/> | 36 | <set field="versionName" value="01"/> |
37 | <set field="defaultFile" from="ec.resource.getLocationReference('dbresource://grapesjs/template/default')"/> | 37 | <set field="defaultFile" from="ec.resource.getLocationReference('dbresource://grapesjs/template/default.json')"/> |
38 | <set field="data" from="defaultFile.getText()"/> | 38 | <set field="data" from="defaultFile.getText()"/> |
39 | <service-call name="create#moqui.resource.DbResourceFile" in-map="[resourceId: dbResource.resourceId,mimeType: 'text/json',versionName: versionName,rootVersionName: versionName,fileData:data]"/> | 39 | <service-call name="create#moqui.resource.DbResourceFile" in-map="[resourceId: dbResource.resourceId,mimeType: 'text/json',versionName: versionName,rootVersionName: versionName,fileData:data]"/> |
40 | <service-call name="create#moqui.resource.DbResourceFileHistory" in-map="[resourceId: dbResource.resourceId,versionDate: ec.user.nowTimestamp,userId: ec.user.userId,isDiff: 'N']"/> | 40 | <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 | ... | @@ -93,7 +93,8 @@ along with this software (see the LICENSE.md file). If not, see |
93 | <if condition="resourceId == 'null'"><set field="resourceId" from="null"/></if> | 93 | <if condition="resourceId == 'null'"><set field="resourceId" from="null"/></if> |
94 | <!-- <log level="warn" message="resourceId is ${resourceId} resourceId.getClass().getName() ${resourceId.getClass().getName()} resourceId == 'null' ${resourceId == 'null'} resourceId == null ${resourceId == null}"/>--> | 94 | <!-- <log level="warn" message="resourceId is ${resourceId} resourceId.getClass().getName() ${resourceId.getClass().getName()} resourceId == 'null' ${resourceId == 'null'} resourceId == null ${resourceId == null}"/>--> |
95 | <!-- <log level="warn" message="store#GrapeJs ec.web.secureRequestParameters._requestBodyText ${ec.web.secureRequestParameters._requestBodyText}"/>--> | 95 | <!-- <log level="warn" message="store#GrapeJs ec.web.secureRequestParameters._requestBodyText ${ec.web.secureRequestParameters._requestBodyText}"/>--> |
96 | <set field="data" from="new groovy.json.JsonSlurper().parseText(ec.web.secureRequestParameters._requestBodyText).data.toString()"/> | 96 | <set field="data" from="groovy.json.JsonOutput.toJson(new groovy.json.JsonSlurper().parseText(ec.web.secureRequestParameters._requestBodyText).data)"/> |
97 | <!-- <log level="warn" message="store#GrapeJs data ${data}"/>--> | ||
97 | 98 | ||
98 | <!-- <log level="warn" message="store context.toString() ${context.toString()}"/>--> | 99 | <!-- <log level="warn" message="store context.toString() ${context.toString()}"/>--> |
99 | <if condition="!resourceId"> | 100 | <if condition="!resourceId"> |
... | @@ -101,7 +102,7 @@ along with this software (see the LICENSE.md file). If not, see | ... | @@ -101,7 +102,7 @@ along with this software (see the LICENSE.md file). If not, see |
101 | <!-- <log level="warn" message="resourceId is null"/>--> | 102 | <!-- <log level="warn" message="resourceId is null"/>--> |
102 | <set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs/project')"/> | 103 | <set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs/project')"/> |
103 | <service-call name="create#moqui.resource.DbResource" in-map="[parentResourceId:grapesJsResource.getDbResourceId(),isFile:'Y']" out-map="dbResource"/> | 104 | <service-call name="create#moqui.resource.DbResource" in-map="[parentResourceId:grapesJsResource.getDbResourceId(),isFile:'Y']" out-map="dbResource"/> |
104 | <service-call name="update#moqui.resource.DbResource" in-map="[resourceId:dbResource.resourceId,filename:dbResource.resourceId]" out-map="dbResource"/> | 105 | <service-call name="update#moqui.resource.DbResource" in-map="[resourceId:dbResource.resourceId,filename:dbResource.resourceId+'.json']" out-map="dbResource"/> |
105 | <set field="versionName" value="01"/> | 106 | <set field="versionName" value="01"/> |
106 | <service-call name="create#moqui.resource.DbResourceFile" in-map="[resourceId: dbResource.resourceId,mimeType: 'text/json',versionName: versionName,rootVersionName: versionName,fileData:data]"/> | 107 | <service-call name="create#moqui.resource.DbResourceFile" in-map="[resourceId: dbResource.resourceId,mimeType: 'text/json',versionName: versionName,rootVersionName: versionName,fileData:data]"/> |
107 | <service-call name="create#moqui.resource.DbResourceFileHistory" in-map="[resourceId: dbResource.resourceId,versionDate: ec.user.nowTimestamp,userId: ec.user.userId,isDiff: 'N']"/> | 108 | <service-call name="create#moqui.resource.DbResourceFileHistory" in-map="[resourceId: dbResource.resourceId,versionDate: ec.user.nowTimestamp,userId: ec.user.userId,isDiff: 'N']"/> | ... | ... |
-
Please register or sign in to post a comment