From f449eff9cea9c109792bcb22bc92e068c07f8db1 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Mon, 16 Jul 2012 00:15:59 -0300 Subject: [PATCH] - Add delete button to remove relationship - Fix add button in the toolbar. --- mindplot/src/main/javascript/Designer.js | 22 ++++++++++-- mindplot/src/main/javascript/Relationship.js | 10 ++++-- mindplot/src/main/javascript/widget/Menu.js | 35 ++++++++------------ 3 files changed, 40 insertions(+), 27 deletions(-) diff --git a/mindplot/src/main/javascript/Designer.js b/mindplot/src/main/javascript/Designer.js index 11431b8e..3e32badc 100644 --- a/mindplot/src/main/javascript/Designer.js +++ b/mindplot/src/main/javascript/Designer.js @@ -661,12 +661,30 @@ mindplot.Designer = new Class({ // Build relationship line .... var result = new mindplot.Relationship(sourceTopic, targetTopic, model); - result.addEvent('onfocus', function (event) { - this.onObjectFocusEvent(result, event); + + result.addEvent('ontblur', function () { + var topics = this.getModel().filterSelectedTopics(); + var rels = this.getModel().filterSelectedRelationships(); + + if (topics.length == 0 || rels.length == 0) { + this.fireEvent('onblur'); + } + }.bind(this)); + + result.addEvent('ontfocus', function () { + var topics = this.getModel().filterSelectedTopics(); + var rels = this.getModel().filterSelectedRelationships(); + + if (topics.length == 1 || rels.length == 1) { + this.fireEvent('onfocus'); + } }.bind(this)); // Append it to the workspace ... dmodel.addRelationship(result); + + + return result; }, diff --git a/mindplot/src/main/javascript/Relationship.js b/mindplot/src/main/javascript/Relationship.js index bf6770e8..690e7b14 100644 --- a/mindplot/src/main/javascript/Relationship.js +++ b/mindplot/src/main/javascript/Relationship.js @@ -21,7 +21,7 @@ mindplot.Relationship = new Class({ getStrokeColor:function () { return '#9b74e6'; }, - type: "Relationship" + type:"Relationship" }, initialize:function (sourceNode, targetNode, model) { $assert(sourceNode, "sourceNode can not be null"); @@ -202,8 +202,7 @@ mindplot.Relationship = new Class({ this._controlPointsController.setVisibility(focus); this._onFocus = focus; - console.log("foucus:...."); - + this.fireEvent(focus ? 'ontfocus' : 'ontblur', this); } }, @@ -316,5 +315,10 @@ mindplot.Relationship = new Class({ getId:function () { return this._model.getId(); + }, + + fireEvent:function (type, event) { + var elem = this._line2d; + elem.fireEvent(type, event); } }); diff --git a/mindplot/src/main/javascript/widget/Menu.js b/mindplot/src/main/javascript/widget/Menu.js index 055719d9..d0ddffb2 100644 --- a/mindplot/src/main/javascript/widget/Menu.js +++ b/mindplot/src/main/javascript/widget/Menu.js @@ -268,7 +268,7 @@ mindplot.widget.Menu = new Class({ }.bind(this)); } - this._addButton('addTopics', true, false, function () { + this._addButton('addTopic', true, false, function () { designer.createChildForSelectedNode(); }); this._registerTooltip('addTopics', $msg('ADD_TOPIC'), "Enter"); @@ -459,25 +459,14 @@ mindplot.widget.Menu = new Class({ var rels = designer.getModel().filterSelectedRelationships(); this._toolbarElems.each(function (button) { - var buttonId = button.getButtonId(); - if (buttonId != "undoEdition" && buttonId != "redoEdition") { + var isTopicAction = button.isTopicAction(); + var isRelAction = button.isRelAction(); - var disable = false; - if (button.isTopicAction() && button.isRelAction()) { - disable = rels.length == 0 && topics.length == 0; - } else if (!button.isTopicAction() && !button.isRelAction()) { - disable = false; - } - else if (button.isTopicAction() && topics.length == 0) { - disable = true; - } else if (button.isRelAction() && rels.length == 0) { - disable = true; - } - - if (disable) { - button.disable(); - } else { + if (isTopicAction || isRelAction) { + if ((isTopicAction && topics.length != 0) || (isRelAction && rels.length != 0)) { button.enable(); + } else { + button.disable(); } } }) @@ -488,14 +477,16 @@ mindplot.widget.Menu = new Class({ var rels = designer.getModel().filterSelectedRelationships(); this._toolbarElems.each(function (button) { - var buttonId = button.getButtonId(); - if (buttonId != "undoEdition" && buttonId != "redoEdition") { + var isTopicAction = button.isTopicAction(); + var isRelAction = button.isRelAction(); - if (button.isTopicAction() && topics.length > 0) { + if (isTopicAction || isRelAction) { + + if (isTopicAction && topics.length > 0) { button.enable(); } - if (button.isRelAction() && rels.length > 0) { + if (isRelAction && rels.length > 0) { button.enable(); } }