Fix icon removal. Notes pending.

- Update icon size
This commit is contained in:
Paulo Veiga 2011-09-02 13:59:08 -03:00
parent d43eb930d9
commit ba1a724df6
4 changed files with 52 additions and 70 deletions

View File

@ -26,7 +26,7 @@ mindplot.IconGroup = new Class({
this._removeTip = new mindplot.IconGroup.RemoveTip(this._group, topicId); this._removeTip = new mindplot.IconGroup.RemoveTip(this._group, topicId);
this.seIconSize(iconSize, iconSize); this.seIconSize(iconSize, iconSize);
this.registerListeners(); this._registerListeners();
}, },
@ -42,10 +42,6 @@ mindplot.IconGroup = new Class({
return this._group; return this._group;
}, },
setSize : function(width, height) {
this._group.setSize(width, height);
},
getSize : function() { getSize : function() {
return this._group.getSize(); return this._group.getSize();
}, },
@ -57,38 +53,22 @@ mindplot.IconGroup = new Class({
addIcon : function(icon) { addIcon : function(icon) {
$defined(icon, "icon is not defined"); $defined(icon, "icon is not defined");
icon.setGroup(this); icon.setGroup(this);
this._icons.push(icon);
// Adjust group and position ...
this._resize(this._icons.length);
this._positionIcon(icon, this._icons.length - 1);
var imageShape = icon.getImage(); var imageShape = icon.getImage();
var groupShape = this._group; this._group.appendChild(imageShape);
var iconsLength = this._icons.length;
imageShape.setPosition(mindplot.Icon.HEIGHT * iconsLength, 0);
groupShape.setSize((iconsLength + 1) * this._iconSize.width, this._iconSize.height);
groupShape.setCoordSize((iconsLength + 1 ) * mindplot.Icon.HEIGHT, mindplot.Icon.HEIGHT);
groupShape.appendChild(imageShape);
this._icons.push(icon);
// Register event for the group .. // Register event for the group ..
this._removeTip.decorate(this._topicId, icon); this._removeTip.decorate(this._topicId, icon);
}, },
getIcons : function() { _findIconFromUrl : function(url) {
return this._icons;
},
removeIcon : function(url) {
this._removeIcon(this.getIcon(url));
},
removeImageIcon : function(icon) {
var imgIcon = this.getImageIcon(icon);
this._removeIcon(imgIcon);
},
getIcon : function(url) {
var result = null; var result = null;
this._icons.each(function(el) { this._icons.each(function(el) {
var nativeImage = el.getImage(); var nativeImage = el.getImage();
@ -99,17 +79,7 @@ mindplot.IconGroup = new Class({
return result; return result;
}, },
getImageIcon : function(icon) { _findIconFromModel : function(iconModel) {
var result = null;
this._icons.each(function(el) {
if (result == null && $defined(el.getModel().isIconModel) && el.getId() == icon.getId() && el.getUiId() == icon.getUiId()) {
result = el;
}
}, this);
return result;
},
findIconFromModel : function(iconModel) {
var result = null; var result = null;
this._icons.each(function(el) { this._icons.each(function(el) {
var elModel = el.getModel(); var elModel = el.getModel();
@ -125,17 +95,30 @@ mindplot.IconGroup = new Class({
return result; return result;
}, },
_removeIcon : function(icon) { removeIconByUrl : function(url) {
var icon = this._findIconFromUrl(url);
this._removeIcon(icon);
},
// remove from model... removeIcon : function(iconModel) {
this._icons.forEach(function(icon) { $assert(iconModel, "iconModel can not be null");
var icon = this._findIconFromModel(iconModel);
this._removeIcon(icon);
},
_removeIcon : function(icon) {
$assert(icon, "icon can not be null");
this._removeTip.close(0);
this._group.removeChild(icon.getImage()); this._group.removeChild(icon.getImage());
}.bind(this));
this._icons.erase(icon); this._icons.erase(icon);
this._resize(this._icons.length);
// Add all again ... // Add all again ...
this._icons.forEach(function(icon) { this._icons.forEach(function(elem, i) {
this.addIcon(icon); this._positionIcon(elem, i);
}.bind(this)); }.bind(this));
}, },
@ -143,7 +126,7 @@ mindplot.IconGroup = new Class({
this._group.moveToFront(); this._group.moveToFront();
}, },
registerListeners : function() { _registerListeners : function() {
this._group.addEvent('click', function(event) { this._group.addEvent('click', function(event) {
// Avoid node creation ... // Avoid node creation ...
event.stopPropagation(); event.stopPropagation();
@ -154,6 +137,15 @@ mindplot.IconGroup = new Class({
event.stopPropagation(); event.stopPropagation();
}); });
},
_resize : function(iconsLength) {
this._group.setSize(iconsLength * this._iconSize.width, this._iconSize.height);
this._group.setCoordSize(iconsLength * mindplot.Icon.HEIGHT, mindplot.Icon.HEIGHT);
},
_positionIcon : function(icon, order) {
icon.getImage().setPosition(mindplot.Icon.HEIGHT * order, 0);
} }
}); });
@ -177,7 +169,6 @@ mindplot.IconGroup.RemoveTip = new Class({
// Now, let move the position the icon... // Now, let move the position the icon...
var pos = icon.getPosition(); var pos = icon.getPosition();
// icon.setSize(15, 15);
// Register events ... // Register events ...
var widget = this._buildWeb2d(); var widget = this._buildWeb2d();
@ -221,9 +212,7 @@ mindplot.IconGroup.RemoveTip = new Class({
var widget = this._widget; var widget = this._widget;
var close = function() { var close = function() {
// icon.setSize(12, 12);
this._activeIcon = null; this._activeIcon = null;
this._container.removeChild(widget); this._container.removeChild(widget);
this._widget = null; this._widget = null;
@ -302,7 +291,7 @@ mindplot.IconGroup.RemoveTip = new Class({
icon.addEvent('mouseout', function() { icon.addEvent('mouseout', function() {
this.hide(); this.hide();
}.bind(this)) }.bind(this));
icon.__remove = true; icon.__remove = true;
} }
} }

View File

@ -329,18 +329,12 @@ mindplot.Topic = new Class({
//Removing the icon from MODEL //Removing the icon from MODEL
var model = this.getModel(); var model = this.getModel();
model._removeIcon(iconModel); model.removeIcon(iconModel);
//Removing the icon from UI //Removing the icon from UI
var iconGroup = this.getIconGroup(); var iconGroup = this.getIconGroup();
if ($defined(iconGroup)) { if ($defined(iconGroup)) {
var imgIcon = iconGroup.findIconFromModel(iconModel); iconGroup.removeIcon(iconModel);
iconGroup.removeImageIcon(imgIcon);
if (iconGroup.getIcons().length == 0) {
this.get2DElement().removeChild(iconGroup.getNativeElement());
this._iconsGroup = null;
}
this._adjustShapes();
} }
}, },
@ -362,16 +356,15 @@ mindplot.Topic = new Class({
}, },
removeNote : function() { removeNote : function() {
// Update model ...
var model = this.getModel(); var model = this.getModel();
var notes = model.getNotes(); var notes = model.getNotes();
model._removeNote(notes[0]); model.removeNote(notes[0]);
// Remove UI ...
var iconGroup = this.getIconGroup(); var iconGroup = this.getIconGroup();
if ($defined(iconGroup)) { if ($defined(iconGroup)) {
iconGroup.removeIcon(mindplot.Note.IMAGE_URL); iconGroup.removeIconByUrl(mindplot.Note.IMAGE_URL);
if (iconGroup.getIcons().length == 0) {
this.get2DElement().removeChild(iconGroup.getNativeElement());
this._iconsGroup = null;
}
} }
this._adjustShapes(); this._adjustShapes();

View File

@ -179,7 +179,7 @@ mindplot.collaboration.frameworks.brix.model.NodeModel = new Class({
this._notes.push(note); this._notes.push(note);
}, },
_removeNote : function(note) { removeNote : function(note) {
$assert(note && note.isNoteModel(), 'Only NoteModel can be appended to Mindmap object as links'); $assert(note && note.isNoteModel(), 'Only NoteModel can be appended to Mindmap object as links');
this._notes.erase(note); this._notes.erase(note);
}, },
@ -194,7 +194,7 @@ mindplot.collaboration.frameworks.brix.model.NodeModel = new Class({
this._icons.push(icon); this._icons.push(icon);
}, },
_removeIcon : function(icon) { removeIcon : function(icon) {
$assert(icon && icon.isIconModel(), 'Only IconModel can be appended to Mindmap object as icons'); $assert(icon && icon.isIconModel(), 'Only IconModel can be appended to Mindmap object as icons');
this._icons.erase(icon); this._icons.erase(icon);
}, },

View File

@ -146,7 +146,7 @@ mindplot.model.NodeModel = new Class({
this._notes.push(note); this._notes.push(note);
}, },
_removeNote : function(note) { removeNote : function(note) {
$assert(note && note.isNoteModel(), 'Only NoteModel can be appended to Mindmap object as links'); $assert(note && note.isNoteModel(), 'Only NoteModel can be appended to Mindmap object as links');
this._notes.erase(note); this._notes.erase(note);
}, },
@ -161,7 +161,7 @@ mindplot.model.NodeModel = new Class({
this._icons.push(icon); this._icons.push(icon);
}, },
_removeIcon : function(icon) { removeIcon : function(icon) {
$assert(icon && icon.isIconModel(), 'Only IconModel can be appended to Mindmap object as icons'); $assert(icon && icon.isIconModel(), 'Only IconModel can be appended to Mindmap object as icons');
this._icons.erase(icon); this._icons.erase(icon);
}, },