From be9273af73fd8e02c59304e4efa1802b38a7824e Mon Sep 17 00:00:00 2001 From: dcore94 Date: Thu, 21 Jul 2022 18:58:14 +0200 Subject: [PATCH] check authorship to exclude editing possibility before starting --- ccp/js/methodeditorcontroller.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/ccp/js/methodeditorcontroller.js b/ccp/js/methodeditorcontroller.js index bc039ac..ded60fb 100644 --- a/ccp/js/methodeditorcontroller.js +++ b/ccp/js/methodeditorcontroller.js @@ -292,6 +292,18 @@ class CCPMethodEditorController extends HTMLElement{ this.render() } + cloneOrEditMethod(method){ + const subject = this.#boot.subject + const matchingauthors = method.metadata ? method.metadata.filter(md=>md.role === "author" && md.href.endsWith("/" + subject)).length : 0 + if(matchingauthors === 0) this.cloneMethod(method.id); + else + if(window.confirm("Do you want to create a new clone?")){ + this.cloneMethod(method.id) + } else { + this.editMethod(method.id) + } + } + cloneMethod(method){ if(this.#locked) return; this.lockRender() @@ -499,15 +511,11 @@ class CCPMethodEditorController extends HTMLElement{ this.#rootdoc.addEventListener("drop", ev=>{ if(ev.dataTransfer && ev.dataTransfer.getData('text/plain+ccpmethod')){ - const id = ev.dataTransfer.getData('text/plain+ccpmethod') + const method = JSON.parse(ev.dataTransfer.getData('application/json+ccpmethod')) ev.stopImmediatePropagation() ev.preventDefault() ev.stopPropagation() - if(window.confirm("Do you want to create a new clone?")){ - this.cloneMethod(id) - } else { - this.editMethod(id) - } + this.cloneOrEditMethod(method) } })