From f81697dd1e3c664372dd73934960c8739410e13a Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Sun, 12 Jan 2025 23:29:16 -0500 Subject: [PATCH] we can do cool stuff now like drag'n'drop instances --- .../mocha-php/scripts/mcx-instancebrowser.js | 50 ++++++++++++++++++- .../src/mocha-php/scripts/mcx-instancekey.js | 2 +- .../src/mocha-php/scripts/mcx-moniker.js | 29 +++++++++-- 3 files changed, 73 insertions(+), 8 deletions(-) diff --git a/mocha-php/src/mocha-php/scripts/mcx-instancebrowser.js b/mocha-php/src/mocha-php/scripts/mcx-instancebrowser.js index aa44917..df888d4 100644 --- a/mocha-php/src/mocha-php/scripts/mcx-instancebrowser.js +++ b/mocha-php/src/mocha-php/scripts/mcx-instancebrowser.js @@ -22,6 +22,32 @@ function McxInstanceBrowser(parentElement) this.NativeObject.setEditing(false); }); + this.ParentElement.addEventListener("dragover", function (e) { + if (System.ClassList.Contains(this, "mcx-editable")) { + e.preventDefault(); + } + + var data = e.dataTransfer.getData("application/x-mocha-instance"); + console.log(e); + console.log(data); + if (data == null) + { + e.preventDefault(); + } + }); + this.ParentElement.addEventListener("drop", function (e) { + e.preventDefault(); + + var data = e.dataTransfer.getData("application/x-mocha-instance"); + if (data == null) return; + + data = JSON.parse(data); + console.log(data); + + var instanceKey = InstanceKey.parse(data.iid); + this.NativeObject.add(instanceKey, data.text, data.url); + }); + this.setEditing = function(value) { if (value) @@ -367,10 +393,30 @@ function McxInstanceBrowser(parentElement) } }); + this.add = function(instanceKey, title, url) + { + var strbps = this.HiddenElement.value; + var strbpa = strbps.split(","); + for (var i = 0; i < strbpa.length; i++) + { + if (strbpa[i] === instanceKey.toString()) + { + Alert.show("The instance you selected has already been added", null, "uwt-alert-mini", 5000); + return; + } + } + + strbpa.push(instanceKey.toString()); + this.HiddenElement.value = strbpa.join(","); + + var p = McxMoniker.create(instanceKey, title, url); + var li = document.createElement("li"); + li.appendChild(p); + this.ListElement.appendChild(li); + }; + this.removeAt = function(index) { - console.log(this.HiddenElement); - var strbps = this.HiddenElement.value; var strbpa = strbps.split(","); var strbpn = [ ]; diff --git a/mocha-php/src/mocha-php/scripts/mcx-instancekey.js b/mocha-php/src/mocha-php/scripts/mcx-instancekey.js index 626b6b2..949fcc4 100644 --- a/mocha-php/src/mocha-php/scripts/mcx-instancekey.js +++ b/mocha-php/src/mocha-php/scripts/mcx-instancekey.js @@ -5,7 +5,7 @@ function InstanceKey() this.toString = function() { - return this.ClassIndex + "$" + this.InstanceIndex; + return this.ClassIndex.toString() + "$" + this.InstanceIndex.toString(); }; } diff --git a/mocha-php/src/mocha-php/scripts/mcx-moniker.js b/mocha-php/src/mocha-php/scripts/mcx-moniker.js index 9f00e56..4238dc7 100644 --- a/mocha-php/src/mocha-php/scripts/mcx-moniker.js +++ b/mocha-php/src/mocha-php/scripts/mcx-moniker.js @@ -34,6 +34,20 @@ function McxMoniker(parentElement) this.PopupElement = this.ParentElement.children[2]; } + this.ParentElement.draggable = true; + this.LabelElement.draggable = false; + this.ButtonElement.draggable = false; + + this.ParentElement.addEventListener("dragstart", function (e) { + console.log(this.McxNativeObject.ParentElement.getAttribute("data-instance-id") + "0" + this.McxNativeObject.LabelElement.innerText); + + e.dataTransfer.setData("application/x-mocha-instance", JSON.stringify({ + "url": this.McxNativeObject.LabelElement.tagName == "A" ? this.McxNativeObject.LabelElement.href : null, + "text": this.McxNativeObject.LabelElement.innerText, + "iid": this.McxNativeObject.ParentElement.getAttribute("data-instance-id") + })); + }); +87 this.ParentElement.addEventListener("contextmenu", function(e) { var cm = new ContextMenu(); @@ -310,8 +324,13 @@ function McxMoniker(parentElement) McxMoniker.create = function(instanceKey, title, viewTask) { + if (typeof (instanceKey) === 'string') + { + instanceKey = InstanceKey.parse(instanceKey); + } + var div = document.createElement("div"); - div.setAttribute("data-instance-id", instanceKey); + div.setAttribute("data-instance-id", instanceKey.toString()); div.className = "mcx-moniker uwt-actionpreviewbutton apb-show-text apb-style-ellipsis"; var img = document.createElement("img"); @@ -320,7 +339,7 @@ McxMoniker.create = function(instanceKey, title, viewTask) { this.style.display="none"; }); - img.src = "/madi/asset/uic-assets/1.1.5/zq/icons/1$" + instanceKey.split("$")[0]; + img.src = "/madi/asset/uic-assets/1.1.5/zq/icons/1$" + instanceKey.ClassIndex; img.setAttribute("alt", ""); div.appendChild(img); @@ -328,7 +347,7 @@ McxMoniker.create = function(instanceKey, title, viewTask) if (viewTask != null) { a.className = "apb-text"; - a.href = System.ExpandRelativePath("~/" + System.TenantName + "/d/inst/" + instanceKey + ".htmld"); + a.href = System.ExpandRelativePath("~/" + System.TenantName + "/d/inst/" + instanceKey.toString() + ".htmld"); } else { @@ -346,7 +365,7 @@ McxMoniker.create = function(instanceKey, title, viewTask) a = document.createElement("a"); a.className = "apb-button"; - a.href = System.ExpandRelativePath("~/" + System.TenantName + "/d/inst/" + instanceKey + "/rel-tasks.htmld"); + a.href = System.ExpandRelativePath("~/" + System.TenantName + "/d/inst/" + instanceKey.toString() + "/rel-tasks.htmld"); a.innerHTML = " "; div.appendChild(a); @@ -383,7 +402,7 @@ McxMoniker.create = function(instanceKey, title, viewTask) var img = document.createElement("img"); img.className = "apb-icon"; - img.src = "/madi/asset/uic-assets/1.1.5/zq/icons/1$" + instanceKey.split("$")[0]; + img.src = "/madi/asset/uic-assets/1.1.5/zq/icons/1$" + instanceKey.ClassIndex; img.setAttribute("alt", ""); h2.appendChild(img);