Author: bpoussin Date: 2013-07-26 19:24:01 +0200 (Fri, 26 Jul 2013) New Revision: 2915 Url: http://chorem.org/projects/jtimer/repository/revisions/2915 Log: fix bug refresh in add/remove task Modified: branches/ng-jtimer/jtimer-server/src/main/webapp/js/app.js branches/ng-jtimer/jtimer-server/src/main/webapp/js/controllers.js branches/ng-jtimer/jtimer-server/src/main/webapp/js/entities.js branches/ng-jtimer/jtimer-server/src/main/webapp/partials/tasks.html branches/ng-jtimer/jtimer-server/src/main/webapp/webtimer.appcache Modified: branches/ng-jtimer/jtimer-server/src/main/webapp/js/app.js =================================================================== --- branches/ng-jtimer/jtimer-server/src/main/webapp/js/app.js 2013-07-26 17:23:14 UTC (rev 2914) +++ branches/ng-jtimer/jtimer-server/src/main/webapp/js/app.js 2013-07-26 17:24:01 UTC (rev 2915) @@ -134,6 +134,11 @@ update(tree); } }); + isNewElement && childScope.$watch("$node.children.length", function (newValue, oldValue, scope) { + if (newValue !== oldValue) { + update(tree); + } + }); if (!isNewElement) { animate.move(cacheEntry.element, null, lastElement); Modified: branches/ng-jtimer/jtimer-server/src/main/webapp/js/controllers.js =================================================================== --- branches/ng-jtimer/jtimer-server/src/main/webapp/js/controllers.js 2013-07-26 17:23:14 UTC (rev 2914) +++ branches/ng-jtimer/jtimer-server/src/main/webapp/js/controllers.js 2013-07-26 17:24:01 UTC (rev 2915) @@ -115,10 +115,14 @@ * Ajoute une tache root */ $scope.addTask = function() { - $scope.data.tasks.push(new Task($scope.name)); + var newTask = new Task($scope.name); + $scope.data.tasks.push(newTask); $scope.name = ""; save(); - $scope.createTree(); + if (tree) { + tree.addChild($scope.createTreeNode(newTask)); + } +// $scope.createTree(); }; /** @@ -127,28 +131,33 @@ */ $scope.addSubTask = function(node) { var task = node.task; - $scope.data.tasks.push(new Task("New task", task.taskId)); + var newTask = new Task("New task", task.taskId); + $scope.data.tasks.push(newTask); node.$$open = true; save(); - $scope.createTree(); + node.addChild($scope.createTreeNode(newTask)); +// $scope.createTree(); }; /** * Supprime une tache (et ces sous taches recursivement) * @param {type} task */ - $scope.removeTask = function(task) { + $scope.removeTask = function(node) { // methode pour faire la suppression recursivement var removeRecurse = function(tasks) { - angular.forEach(tasks, function() { + angular.forEach(tasks, function(task) { task.remove(); var children = $scope.getChildren(task); removeRecurse(children); }); }; - removeRecurse([task]); + // mark all task as removed + removeRecurse([node.task]); + // remove node in tree + node.remove(); save(); - $scope.createTree(); +// $scope.createTree(); }; /** Modified: branches/ng-jtimer/jtimer-server/src/main/webapp/js/entities.js =================================================================== --- branches/ng-jtimer/jtimer-server/src/main/webapp/js/entities.js 2013-07-26 17:23:14 UTC (rev 2914) +++ branches/ng-jtimer/jtimer-server/src/main/webapp/js/entities.js 2013-07-26 17:24:01 UTC (rev 2915) @@ -150,11 +150,32 @@ this.localTimes = localTimes || []; children = angular.forEach(children, function(child) { child.parent = this; - }); + }, this); this.children = children || []; }; /** + * Ce retire de l'arbre + * @returns {undefined} + */ +TreeNode.prototype.remove = function() { + if (this.parent) { + var brothers = this.parent.children; + var match = brothers.indexOf(this); + + if (match > -1 ) { + brothers.splice(match, 1); + delete this.parent; + } + } +}; + +TreeNode.prototype.addChild = function(node) { + node.parent = this; + this.children.push(node); +}; + +/** * Copie toutes les donnees d'etat d'une noeud * @param {TreeNode} node * @returns {undefined} Modified: branches/ng-jtimer/jtimer-server/src/main/webapp/partials/tasks.html =================================================================== --- branches/ng-jtimer/jtimer-server/src/main/webapp/partials/tasks.html 2013-07-26 17:23:14 UTC (rev 2914) +++ branches/ng-jtimer/jtimer-server/src/main/webapp/partials/tasks.html 2013-07-26 17:24:01 UTC (rev 2915) @@ -20,7 +20,7 @@ <i ng-class="{'icon-play' : ($node.task != currentTask), 'icon-stop' : ($node.task == currentTask)}"></i> </a> <a class="btn btn-mini" href="" ng-click="addSubTask($node)"><i class="icon-plus"></i></a> - <a class="btn btn-mini" href="" ng-click="removeTask($node.task)"><i class="icon-minus"></i></a> + <a class="btn btn-mini" href="" ng-click="removeTask($node)"><i class="icon-minus"></i></a> </span> </div> @@ -67,7 +67,7 @@ </div> <div id="footer"> <span class="left">{{currentDate()}}</span> - <span class="center"><a href="#">WebTimer</a><i class="icon-html5"></i></span> + <span class="center"><i class="icon-html5"></i> <a href="#">WebTimer</a></span> <span class="right">{{tree.getTime().today |time}} | {{tree.getTime().global | time}}</a> </div> Modified: branches/ng-jtimer/jtimer-server/src/main/webapp/webtimer.appcache =================================================================== --- branches/ng-jtimer/jtimer-server/src/main/webapp/webtimer.appcache 2013-07-26 17:23:14 UTC (rev 2914) +++ branches/ng-jtimer/jtimer-server/src/main/webapp/webtimer.appcache 2013-07-26 17:24:01 UTC (rev 2915) @@ -1,5 +1,5 @@ CACHE MANIFEST -# version 11 +# version 12 CACHE: index.html