From 128342b8e86a36c52aaf18b9732307ea541b618a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Thu, 23 Jun 2011 21:09:56 +0200 Subject: [PATCH] Reimplement moving dependencies when moving task It wasn't working most of the time. Instead of fixing it, reimplement using simpler approach. FEA: ItEr75S08MigrationZK5 --- .../java/org/zkoss/ganttz/TaskComponent.java | 1 - .../main/resources/web/js/common/Common.js | 19 ++++++++++++++-- .../web/js/ganttz/DependencyComponent.js | 2 -- .../resources/web/js/ganttz/TaskComponent.js | 22 ++++++++++--------- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/ganttzk/src/main/java/org/zkoss/ganttz/TaskComponent.java b/ganttzk/src/main/java/org/zkoss/ganttz/TaskComponent.java index 851c3e439..77628a912 100644 --- a/ganttzk/src/main/java/org/zkoss/ganttz/TaskComponent.java +++ b/ganttzk/src/main/java/org/zkoss/ganttz/TaskComponent.java @@ -105,7 +105,6 @@ public class TaskComponent extends Div implements AfterCompose { setContext("idContextMenuTaskAssignment"); this.task = task; setClass(calculateCSSClass()); - setId(UUID.randomUUID().toString()); this.disabilityConfiguration = disabilityConfiguration; taskViolationListener = Constraint diff --git a/ganttzk/src/main/resources/web/js/common/Common.js b/ganttzk/src/main/resources/web/js/common/Common.js index 9ad23e36c..d5a063e5c 100644 --- a/ganttzk/src/main/resources/web/js/common/Common.js +++ b/ganttzk/src/main/resources/web/js/common/Common.js @@ -1,5 +1,20 @@ zk.$package("common"); common.Common = zk.$extends(zk.Widget,{},{ - webAppContextPath : function(){ return window.location.pathname.split( '/' )[1];} -}) \ No newline at end of file + + webAppContextPath : function(){ return window.location.pathname.split( '/' )[1];}, + + memoize: function(timeoutTimeMillis, functionToExecute) { + var lastTimeCalled = null; + var cachedResult = null; + return function() { + var now = Date.now(); + if (lastTimeCalled !== null && ((now - lastTimeCalled) < timeoutTimeMillis)) { + return cachedResult; + } + lastTimeCalled = now; + cachedResult = functionToExecute.apply(null, arguments); + return cachedResult; + }; + } +}); \ No newline at end of file diff --git a/ganttzk/src/main/resources/web/js/ganttz/DependencyComponent.js b/ganttzk/src/main/resources/web/js/ganttz/DependencyComponent.js index 8d631f0d1..cd1d7b42a 100644 --- a/ganttzk/src/main/resources/web/js/ganttz/DependencyComponent.js +++ b/ganttzk/src/main/resources/web/js/ganttz/DependencyComponent.js @@ -222,8 +222,6 @@ ganttz.DependencyComponent = zk.$extends(ganttz.DependencyComponentBase,{ /*maybe move this listener to the $init method*/ YAHOO.util.Event.onDOMReady(this.proxy(function() { this.draw(); - ganttz.TaskComponent.$(this.getIdTaskOrig()).addRelatedDependency(this); - ganttz.TaskComponent.$(this.getIdTaskEnd()).addRelatedDependency(this); })); }, draw : function() { diff --git a/ganttzk/src/main/resources/web/js/ganttz/TaskComponent.js b/ganttzk/src/main/resources/web/js/ganttz/TaskComponent.js index 8a8341aaa..335abb780 100644 --- a/ganttzk/src/main/resources/web/js/ganttz/TaskComponent.js +++ b/ganttzk/src/main/resources/web/js/ganttz/TaskComponent.js @@ -114,23 +114,25 @@ ganttz.TaskComponent = zk.$extends(zul.Widget, { consolidateNewDependency : function(task){ zAu.send(new zk.Event(this, 'onAddDependency', {dependencyId : task.id})); }, - addRelatedDependency : function(dependency){ - if(this._dependencies == undefined) this._dependencies = []; - this._dependencies.push(dependency); - }, _addDragDrop : function(){ var dragdropregion = this._getDragDropRegion(); - + var thisTaskId = this.$n().id; + var relatedDependencies = common.Common.memoize(3000, function() { + return jq('.dependency[idtaskorig='+ thisTaskId + ']') + .add('.dependency[idtaskend='+ thisTaskId + ']') + .get() + .map(function(dep) { + return ganttz.DependencyComponentBase.$(dep); + }); + }); dragdropregion.on('dragEvent', this.proxy(function(ev) { // Slight overload. It could be more efficent to overwrite the YUI // method // that is setting the top property jq(this.$n()).css('top',''); - if (this._dependencies != undefined) { - jq.each(this._dependencies, function(index, dependency){ - dependency.draw(); - }); - } + relatedDependencies().forEach(function(dependency) { + dependency.draw(); + }); }), null, false); // Register the event endDragEvent dragdropregion.on('endDragEvent', this.proxy(function(ev) {