" + this.uiModel.components[this.model.getCurrentPCName()].icon +
"
" + this.getLabelForType(this.getPCTypeForName(this.model.getCurrentPCName())) + "
";
}
this.pageModifier.insertComponentAfter(
model.getCurrentInsertPCId(),
model.getCurrentPCId(),
this.model.getCurrentPCName(),
content,
this.model.getCurrentPCName()
);
this.toolSlate.setContentFromComponent(this.model.getCurrentPCName(), "creation_form");
this.initFormButtonsAndSettingsLink();
}
initFormButtonsAndSettingsLink() {
const model = this.model;
document.querySelectorAll("#copg-editor-slate-content [data-copg-ed-type='form-button']").forEach(form_button => {
const dispatch = this.dispatcher;
const action = this.actionFactory;
const act = form_button.dataset.copgEdAction;
const cname = form_button.dataset.copgEdComponent;
if (cname === "Page") {
form_button.addEventListener("click", (event) => {
event.preventDefault();
switch (act) {
case "component.cancel":
dispatch.dispatch(action.page().editor().componentCancel());
break;
case "component.save":
const form = form_button.closest("form");
const form_data = new FormData(form);
//after_pcid, pcid, component, data
dispatch.dispatch(action.page().editor().componentSave(
model.getCurrentInsertPCId(),
model.getCurrentPCId(),
model.getCurrentPCName(),
form_data
));
break;
case "component.update":
const uform = form_button.closest("form");
const uform_data = new FormData(uform);
//after_pcid, pcid, component, data
dispatch.dispatch(action.page().editor().componentUpdate(
model.getCurrentPCId(),
model.getCurrentPCName(),
uform_data
));
break;
}
});
}
});
document.querySelectorAll("#copg-editor-slate-content [data-copg-ed-type='link']").forEach(link => {
const dispatch = this.dispatcher;
const action = this.actionFactory;
const act = link.dataset.copgEdAction;
const cname = link.dataset.copgEdComponent;
if (cname === "Page") {
link.addEventListener("click", (event) => {
event.preventDefault();
switch (act) {
case "component.settings":
//after_pcid, pcid, component, data
dispatch.dispatch(action.page().editor().componentSettings(
model.getCurrentPCName(),
model.getCurrentPCId(),
model.getCurrenntHierId()
));
break;
}
});
}
});
}
removeInsertedComponent(pcid) {
this.pageModifier.removeInsertedComponent(pcid);
}
////
//// Generic editing
////
loadGenericEditingForm(cname, pcid, hierid) {
const loadEditingFormAction = this.actionFactory.page().query().loadEditingForm(cname, pcid, hierid);
this.client.sendQuery(loadEditingFormAction).then(result => {
const p = result.getPayload();
this.toolSlate.setContent(p.editForm);
this.initFormButtonsAndSettingsLink();
});
}
}