From db4c1388108d658ea53ed9f00c4087ca54ef9eba Mon Sep 17 00:00:00 2001 From: jos Date: Thu, 21 Aug 2014 16:43:48 +0200 Subject: [PATCH] Replaced most alert(...) with throw new Error(...). Added two more entries to labels --- lib/network/Network.js | 1 + lib/network/mixins/HierarchicalLayoutMixin.js | 2 +- lib/network/mixins/ManipulationMixin.js | 16 ++++++++-------- lib/timeline/locales.js | 8 ++++++-- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/network/Network.js b/lib/network/Network.js index ac0476bb..8e9a39c5 100644 --- a/lib/network/Network.js +++ b/lib/network/Network.js @@ -204,6 +204,7 @@ function Network (container, data, options) { editError:"The function for edit does not support two arguments (data, callback).", editBoundError:"No edit function has been bound to this button.", deleteError:"The function for delete does not support two arguments (data, callback).", + createEdgeError:"Cannot link edges to a cluster.", deleteClusterError:"Clusters cannot be deleted." }, tooltip: { diff --git a/lib/network/mixins/HierarchicalLayoutMixin.js b/lib/network/mixins/HierarchicalLayoutMixin.js index b866774d..01f9d25d 100644 --- a/lib/network/mixins/HierarchicalLayoutMixin.js +++ b/lib/network/mixins/HierarchicalLayoutMixin.js @@ -57,7 +57,7 @@ exports._setupHierarchicalLayout = function() { // if the user defined some levels but not all, alert and run without hierarchical layout if (undefinedLevel == true && definedLevel == true) { - alert("To use the hierarchical layout, nodes require either no predefined levels or levels have to be defined for all nodes."); + throw new Error("To use the hierarchical layout, nodes require either no predefined levels or levels have to be defined for all nodes."); this.zoomExtent(true,this.constants.clustering.enabled); if (!this.constants.clustering.enabled) { this.start(); diff --git a/lib/network/mixins/ManipulationMixin.js b/lib/network/mixins/ManipulationMixin.js index 179a8597..b4bebea8 100644 --- a/lib/network/mixins/ManipulationMixin.js +++ b/lib/network/mixins/ManipulationMixin.js @@ -330,7 +330,7 @@ exports._handleConnect = function(pointer) { var node = this._getNodeAt(pointer); if (node != null) { if (node.clusterSize > 1) { - alert("Cannot create edges to a cluster.") + alert(this.constants.labels["createEdgeError"]) } else { this._selectObject(node,false); @@ -386,7 +386,7 @@ exports._finishConnect = function(pointer) { var node = this._getNodeAt(pointer); if (node != null) { if (node.clusterSize > 1) { - alert("Cannot create edges to a cluster.") + alert(this.constants.labels["createEdgeError"]) } else { this._createEdge(connectFromId,node.id); @@ -416,7 +416,7 @@ exports._addNode = function() { }); } else { - alert(this.constants.labels['addError']); + throw new Error(this.constants.labels['addError']); this._createManipulatorBar(); this.moving = true; this.start(); @@ -450,7 +450,7 @@ exports._createEdge = function(sourceNodeId,targetNodeId) { }); } else { - alert(this.constants.labels["linkError"]); + throw new Error(this.constants.labels["linkError"]); this.moving = true; this.start(); } @@ -481,7 +481,7 @@ exports._editEdge = function(sourceNodeId,targetNodeId) { }); } else { - alert(this.constants.labels["linkError"]); + throw new Error(this.constants.labels["linkError"]); this.moving = true; this.start(); } @@ -524,11 +524,11 @@ exports._editNode = function() { }); } else { - alert(this.constants.labels["editError"]); + throw new Error(this.constants.labels["editError"]); } } else { - alert(this.constants.labels["editBoundError"]); + throw new Error(this.constants.labels["editBoundError"]); } }; @@ -558,7 +558,7 @@ exports._deleteSelected = function() { }); } else { - alert(this.constants.labels["deleteError"]) + throw new Error(this.constants.labels["deleteError"]) } } else { diff --git a/lib/timeline/locales.js b/lib/timeline/locales.js index 7150dcc7..b78dca3b 100644 --- a/lib/timeline/locales.js +++ b/lib/timeline/locales.js @@ -14,7 +14,9 @@ exports['en'] = { back: 'Back', addDescription: 'Click in an empty space to place a new node.', linkDescription: 'Click on a node and drag the edge to another node to connect them.', - editEdgeDescription: 'Click on the control points and drag them to a node to connect to it.' + editEdgeDescription: 'Click on the control points and drag them to a node to connect to it.', + createEdgeError:"Cannot link edges to a cluster.", + deleteClusterError:"Clusters cannot be deleted." }; exports['en_EN'] = exports['en']; exports['en_US'] = exports['en']; @@ -35,7 +37,9 @@ exports['nl'] = { back: 'Terug', addDescription: 'Klik op een leeg gebied om een nieuwe node te maken.', linkDescription: 'Klik op een node en sleep de link naar een andere node om ze te verbinden.', - editEdgeDescription: 'Klik op de verbindingspunten en sleep ze naar een node om daarmee te verbinden.' + editEdgeDescription: 'Klik op de verbindingspunten en sleep ze naar een node om daarmee te verbinden.', + createEdgeError:"Cannot link edges to a cluster.", + deleteClusterError:"Clusters cannot be deleted." }; exports['nl_NL'] = exports['nl']; exports['nl_BE'] = exports['nl'];