- Add delete button to remove relationship

- Fix add button in the toolbar.
This commit is contained in:
Paulo Gustavo Veiga 2012-07-16 00:15:59 -03:00
parent 16bbc0a456
commit f449eff9ce
3 changed files with 40 additions and 27 deletions

View File

@ -661,12 +661,30 @@ mindplot.Designer = new Class({
// Build relationship line .... // Build relationship line ....
var result = new mindplot.Relationship(sourceTopic, targetTopic, model); 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)); }.bind(this));
// Append it to the workspace ... // Append it to the workspace ...
dmodel.addRelationship(result); dmodel.addRelationship(result);
return result; return result;
}, },

View File

@ -21,7 +21,7 @@ mindplot.Relationship = new Class({
getStrokeColor:function () { getStrokeColor:function () {
return '#9b74e6'; return '#9b74e6';
}, },
type: "Relationship" type:"Relationship"
}, },
initialize:function (sourceNode, targetNode, model) { initialize:function (sourceNode, targetNode, model) {
$assert(sourceNode, "sourceNode can not be null"); $assert(sourceNode, "sourceNode can not be null");
@ -202,8 +202,7 @@ mindplot.Relationship = new Class({
this._controlPointsController.setVisibility(focus); this._controlPointsController.setVisibility(focus);
this._onFocus = focus; this._onFocus = focus;
console.log("foucus:...."); this.fireEvent(focus ? 'ontfocus' : 'ontblur', this);
} }
}, },
@ -316,5 +315,10 @@ mindplot.Relationship = new Class({
getId:function () { getId:function () {
return this._model.getId(); return this._model.getId();
},
fireEvent:function (type, event) {
var elem = this._line2d;
elem.fireEvent(type, event);
} }
}); });

View File

@ -268,7 +268,7 @@ mindplot.widget.Menu = new Class({
}.bind(this)); }.bind(this));
} }
this._addButton('addTopics', true, false, function () { this._addButton('addTopic', true, false, function () {
designer.createChildForSelectedNode(); designer.createChildForSelectedNode();
}); });
this._registerTooltip('addTopics', $msg('ADD_TOPIC'), "Enter"); this._registerTooltip('addTopics', $msg('ADD_TOPIC'), "Enter");
@ -459,25 +459,14 @@ mindplot.widget.Menu = new Class({
var rels = designer.getModel().filterSelectedRelationships(); var rels = designer.getModel().filterSelectedRelationships();
this._toolbarElems.each(function (button) { this._toolbarElems.each(function (button) {
var buttonId = button.getButtonId(); var isTopicAction = button.isTopicAction();
if (buttonId != "undoEdition" && buttonId != "redoEdition") { var isRelAction = button.isRelAction();
var disable = false; if (isTopicAction || isRelAction) {
if (button.isTopicAction() && button.isRelAction()) { if ((isTopicAction && topics.length != 0) || (isRelAction && rels.length != 0)) {
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 {
button.enable(); button.enable();
} else {
button.disable();
} }
} }
}) })
@ -488,14 +477,16 @@ mindplot.widget.Menu = new Class({
var rels = designer.getModel().filterSelectedRelationships(); var rels = designer.getModel().filterSelectedRelationships();
this._toolbarElems.each(function (button) { this._toolbarElems.each(function (button) {
var buttonId = button.getButtonId(); var isTopicAction = button.isTopicAction();
if (buttonId != "undoEdition" && buttonId != "redoEdition") { var isRelAction = button.isRelAction();
if (button.isTopicAction() && topics.length > 0) { if (isTopicAction || isRelAction) {
if (isTopicAction && topics.length > 0) {
button.enable(); button.enable();
} }
if (button.isRelAction() && rels.length > 0) { if (isRelAction && rels.length > 0) {
button.enable(); button.enable();
} }
} }