2018-03-28 09:36:01 +08:00
|
|
|
import bundleService from "./bundle.js";
|
|
|
|
import server from "./server.js";
|
|
|
|
import noteDetailService from "./note_detail.js";
|
|
|
|
|
|
|
|
const $noteDetailRender = $('#note-detail-render');
|
2018-08-29 02:55:21 +08:00
|
|
|
const $noteDetailRenderHelp = $('#note-detail-render-help');
|
|
|
|
const $noteDetailRenderContent = $('#note-detail-render-content');
|
2018-05-27 07:27:47 +08:00
|
|
|
const $renderButton = $('#render-button');
|
|
|
|
|
2018-08-29 02:55:21 +08:00
|
|
|
async function render() {
|
|
|
|
const attributes = await noteDetailService.getAttributes();
|
|
|
|
const renderNotes = attributes.filter(attr =>
|
|
|
|
attr.type === 'relation'
|
|
|
|
&& attr.name === 'renderNote'
|
|
|
|
&& !!attr.value);
|
2018-03-28 09:36:01 +08:00
|
|
|
|
2018-08-29 02:55:21 +08:00
|
|
|
$noteDetailRender.show();
|
2018-05-27 07:27:47 +08:00
|
|
|
|
2018-08-29 02:55:21 +08:00
|
|
|
$noteDetailRenderContent.empty();
|
|
|
|
$noteDetailRenderContent.toggle(renderNotes.length > 0);
|
|
|
|
$noteDetailRenderHelp.toggle(renderNotes.length === 0);
|
2018-03-28 09:36:01 +08:00
|
|
|
|
2018-08-29 02:55:21 +08:00
|
|
|
for (const renderNote of renderNotes) {
|
|
|
|
const bundle = await server.get('script/bundle/' + renderNote.value);
|
2018-05-27 07:27:47 +08:00
|
|
|
|
2018-08-29 02:55:21 +08:00
|
|
|
$noteDetailRenderContent.append(bundle.html);
|
2018-05-27 07:58:08 +08:00
|
|
|
|
2018-08-29 05:08:56 +08:00
|
|
|
await bundleService.executeBundle(bundle, noteDetailService.getCurrentNote());
|
2018-05-27 07:27:47 +08:00
|
|
|
}
|
2018-05-27 07:58:08 +08:00
|
|
|
}
|
|
|
|
|
2018-05-27 07:27:47 +08:00
|
|
|
$renderButton.click(render);
|
|
|
|
|
2018-03-28 09:36:01 +08:00
|
|
|
export default {
|
2018-08-29 02:55:21 +08:00
|
|
|
show: render,
|
|
|
|
getContent: () => "",
|
2018-03-28 09:36:01 +08:00
|
|
|
focus: () => null
|
|
|
|
}
|