Menu refactor cont. toolbar.jsp -> toolbar.jsf

This commit is contained in:
Gonzalo Bellver 2011-11-30 20:07:50 -03:00
parent 5ffce2bbc3
commit 6d81803047
5 changed files with 67 additions and 59 deletions

View File

@ -17,6 +17,7 @@
*/ */
mindplot.widget.IMenu = new Class({ mindplot.widget.IMenu = new Class({
initialize : function(designer, containerId, mapId) { initialize : function(designer, containerId, mapId) {
$assert(designer, "designer can not be null"); $assert(designer, "designer can not be null");
$assert(containerId, "containerId can not be null"); $assert(containerId, "containerId can not be null");
@ -27,67 +28,13 @@ mindplot.widget.IMenu = new Class({
this._mapId = mapId; this._mapId = mapId;
}, },
_registerEvents : function(designer) {
// Register on close events ...
this._toolbarElems.forEach(function(elem) {
elem.addEvent('show', function() {
this.clear()
}.bind(this));
}.bind(this));
designer.addEvent('onblur', function() {
var topics = designer.getModel().filterSelectedTopics();
var rels = designer.getModel().filterSelectedRelations();
this._toolbarElems.forEach(function(button) {
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 {
button.enable();
}
})
}.bind(this));
designer.addEvent('onfocus', function() {
var topics = designer.getModel().filterSelectedTopics();
var rels = designer.getModel().filterSelectedRelations();
this._toolbarElems.forEach(function(button) {
if (button.isTopicAction() && topics.length > 0) {
button.enable();
}
if (button.isRelAction() && rels.length > 0) {
button.enable();
}
})
}.bind(this));
},
clear : function() { clear : function() {
this._toolbarElems.forEach(function(item) { this._toolbarElems.forEach(function(item) {
item.hide(); item.hide();
}); });
}, },
_save:function (saveElem, designer, saveHistory) { save:function (saveElem, designer, saveHistory) {
console.log("save!!!!"); //TODO(gb): Remove trace!!!
// Load map content ... // Load map content ...
var mindmap = designer.getMindmap(); var mindmap = designer.getMindmap();
var mindmapProp = designer.getMindmapProperties(); var mindmapProp = designer.getMindmapProperties();

View File

@ -242,21 +242,21 @@ mindplot.widget.Menu = new Class({
var saveElem = $('save'); var saveElem = $('save');
if (saveElem) { if (saveElem) {
this._addButton('save', false, false, function() { this._addButton('save', false, false, function() {
this._save(saveElem, designer, true); this.save(saveElem, designer, true);
}.bind(this)); }.bind(this));
if (!readOnly) { if (!readOnly) {
// To prevent the user from leaving the page with changes ... // To prevent the user from leaving the page with changes ...
$(window).addEvent('beforeunload', function () { $(window).addEvent('beforeunload', function () {
if (designer.needsSave()) { if (designer.needsSave()) {
this._save(saveElem, designer, false); this.save(saveElem, designer, false);
} }
}.bind(this)); }.bind(this));
// Autosave on a fixed period of time ... // Autosave on a fixed period of time ...
(function() { (function() {
if (designer.needsSave()) { if (designer.needsSave()) {
this._save(saveElem, designer, false); this.save(saveElem, designer, false);
} }
}.bind(this)).periodical(30000); }.bind(this)).periodical(30000);
} }
@ -350,6 +350,58 @@ mindplot.widget.Menu = new Class({
this._registerEvents(designer); this._registerEvents(designer);
}, },
_registerEvents : function(designer) {
// Register on close events ...
this._toolbarElems.forEach(function(elem) {
elem.addEvent('show', function() {
this.clear()
}.bind(this));
}.bind(this));
designer.addEvent('onblur', function() {
var topics = designer.getModel().filterSelectedTopics();
var rels = designer.getModel().filterSelectedRelations();
this._toolbarElems.forEach(function(button) {
var disable = false;
if (button.isTopicAction() && button.isRelAction()) {
disable = rels.length == 0 && topics.length == 0;
console.log(disable);
} 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();
}
})
}.bind(this));
designer.addEvent('onfocus', function() {
var topics = designer.getModel().filterSelectedTopics();
var rels = designer.getModel().filterSelectedRelations();
this._toolbarElems.forEach(function(button) {
if (button.isTopicAction() && topics.length > 0) {
button.enable();
}
if (button.isRelAction() && rels.length > 0) {
button.enable();
}
})
}.bind(this));
},
_addButton:function (buttonId, topic, rel, fn) { _addButton:function (buttonId, topic, rel, fn) {
// Register Events ... // Register Events ...
var button = new mindplot.widget.ToolbarItem(buttonId, function(event) { var button = new mindplot.widget.ToolbarItem(buttonId, function(event) {

View File

@ -114,6 +114,15 @@ mindplot.widget.ThinkmappingMenu = new Class({
this._registerEvents(designer); this._registerEvents(designer);
}, },
_registerEvents : function(designer) {
// Register on close events ...
this._toolbarElems.forEach(function(elem) {
elem.addEvent('show', function() {
this.clear()
}.bind(this));
}.bind(this));
},
_addButton:function (buttonId, fn) { _addButton:function (buttonId, fn) {
// Register Events ... // Register Events ...
var button = new mindplot.widget.ToolbarItem(buttonId, function(event) { var button = new mindplot.widget.ToolbarItem(buttonId, function(event) {

View File

@ -133,7 +133,7 @@
<div id="headerMapTitle">Title: <span>${mindmap.title}</span></div> <div id="headerMapTitle">Title: <span>${mindmap.title}</span></div>
</div> </div>
<%@ include file="/jsp/toolbar.jsp" %> <%@ include file="/jsp/toolbar.jsf" %>
</div> </div>
<div id="mindplot"></div> <div id="mindplot"></div>