diff --git a/src/main/resources/js/management.js b/src/main/resources/js/management.js index 0243aa1e54..01ee553130 100644 --- a/src/main/resources/js/management.js +++ b/src/main/resources/js/management.js @@ -59,22 +59,23 @@ function switchLinkTypes(type, idOfExistingElement, idOfNewElement, linkTypeFunc function updateDecisionKnowledgeElementAsChild(childId, summary, description, type) { console.log("management.js updateDecisionKnowledgeElementAsChild"); var simpleType = getSimpleType(type); - updateDecisionKnowledgeElement(childId, summary, description, simpleType, function() { - conDecAPI.getDecisionKnowledgeElement(childId, function(decisionKnowledgeElement) { - if (decisionKnowledgeElement.type !== type) { - var parentId = findParentId(childId); - switchLinkTypes(type, parentId, childId, function(linkType, parentId, childId) { - deleteLink(parentId, childId, function() { - conDecAPI.linkElements(parentId, childId, linkType, function() { - notify(); - }); - }); - }); - } else { - notify(); - } - }); - }); + conDecAPI.getDecisionKnowledgeElement(childId, function(decisionKnowledgeElement) { + conDecAPI.updateDecisionKnowledgeElement(childId,summary,description,simpleType,function () { + console.log(decisionKnowledgeElement.type +" IN function "+ type); + if (decisionKnowledgeElement.type !== type) { + var parentId = findParentId(childId); + switchLinkTypes(type, parentId, childId, function(linkType, parentId, childId) { + conDecAPI.deleteLink(parentId, childId, function() { + conDecAPI.linkElements(parentId, childId, linkType, function() { + notify(); + }); + }); + }); + } else { + notify(); + } + }); + }); } function getSimpleType(type) { diff --git a/src/main/resources/js/view.context.menu.js b/src/main/resources/js/view.context.menu.js index c1f449958f..c6a1128920 100644 --- a/src/main/resources/js/view.context.menu.js +++ b/src/main/resources/js/view.context.menu.js @@ -29,6 +29,7 @@ var linkKnowledgeElementText = "Link Existing Element"; var deleteLinkToParentText = "Delete Link to Parent"; var editKnowledgeElementText = "Edit Element"; var deleteKnowledgeElementText = "Delete Element"; +var changeKnowledgeTypeText = "Change Element Type"; var contextMenuCreateAction = { // label for Tree Viewer, name for Treant context menu @@ -144,6 +145,24 @@ function setUpCreateOrEditDialog(summary, description, knowledgeType) { AJS.$("#form-select-type").auiSelect2(); } +function setUpTypeChangeDialog(knowledgeType){ + console.log("view.context.menu.js setUpTypeChangeDialog"); + document.getElementById("dialog-content").insertAdjacentHTML( + "afterBegin", + "
"); + for (var index = 0; index < extendedKnowledgeTypes.length; index++) { + var isSelected = ""; + if (isKnowledgeTypeLocatedAtIndex(knowledgeType, index)) { + isSelected = "selected "; + } + $("select[name='form-select-type']")[0].insertAdjacentHTML("beforeend", ""); + } + AJS.$("#form-select-type").auiSelect2(); +} + function isKnowledgeTypeLocatedAtIndex(knowledgeType, index) { console.log("view.context.menu.js isKnowledgeTypeLocatedAtIndex"); return knowledgeType.toLowerCase() === extendedKnowledgeTypes[index].toLowerCase(); @@ -338,6 +357,40 @@ function setUpDialogForDeleteLinkAction(id, parentId) { }; } +var contextMenuChangeTypeAction = { + "label" : changeKnowledgeTypeText, + "name" : changeKnowledgeTypeText, + "action" : function (position) { + var node = getSelectedTreeViewerNode(position); + var id = node.id; + setUpDialogForChangeTypeAction(id); + }, + "callback" : function(key, options) { + var id = getSelectedTreantNodeId(options); + setUpDialogForChangeTypeAction(id); + } +}; + +function setUpDialogForChangeTypeAction(id) { + console.log("view.context.menu.js setUpDialogForChangeTypeAction"); + setUpDialog(); + setHeaderText(changeKnowledgeTypeText); + conDecAPI.getDecisionKnowledgeElement(id, function(decisionKnowledgeElement) { + var summary = decisionKnowledgeElement.summary; + var description = decisionKnowledgeElement.description; + var type = decisionKnowledgeElement.type; + setUpTypeChangeDialog(type); + + var submitButton = document.getElementById("dialog-submit-button"); + submitButton.textContent = editKnowledgeElementText; + submitButton.onclick = function () { + var type = $("select[name='form-select-type']").val(); + updateDecisionKnowledgeElementAsChild(id,summary,description,type); + AJS.dialog2("#dialog").hide(); + }; + }); +} + var contextMenuSetAsRootAction = { // label for Tree Viewer, name for Treant context menu "name" : makeRootText, diff --git a/src/main/resources/js/view.decision.knowledge.page.js b/src/main/resources/js/view.decision.knowledge.page.js index 58e4426fd3..b09d48bdbf 100644 --- a/src/main/resources/js/view.decision.knowledge.page.js +++ b/src/main/resources/js/view.decision.knowledge.page.js @@ -141,6 +141,7 @@ , "deleteLink" : contextMenu.contextMenuDeleteLinkAction , "delete" : contextMenu.contextMenuDeleteAction , "openIssue" : contextMenu.contextMenuOpenJiraIssueAction + , "changeType" : contextMenu.contextMenuChangeTypeAction }; return menu; }; diff --git a/src/main/resources/js/view.issue.module.js b/src/main/resources/js/view.issue.module.js index 2e0cb7c343..bb451d3345 100644 --- a/src/main/resources/js/view.issue.module.js +++ b/src/main/resources/js/view.issue.module.js @@ -88,7 +88,8 @@ "edit" : contextMenu.contextMenuEditAction, "link" : contextMenu.contextMenuLinkAction, "deleteLink" : contextMenu.contextMenuDeleteLinkAction, - "delete" : contextMenu.contextMenuDeleteAction + "delete" : contextMenu.contextMenuDeleteAction, + "changeType" : contextMenu.contextMenuChangeTypeAction }; return menu; }