X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/eebb24ef74a635e06c6bc8f074302996ca5936ec..72dfc92f908add69b4d862e9b6c3107e2a8acd21:/modules/nodeFamilyTree/nodeFamilyTree.js diff --git a/modules/nodeFamilyTree/nodeFamilyTree.js b/modules/nodeFamilyTree/nodeFamilyTree.js index e061277..39ea20f 100644 --- a/modules/nodeFamilyTree/nodeFamilyTree.js +++ b/modules/nodeFamilyTree/nodeFamilyTree.js @@ -1,68 +1,85 @@ -define([ -'libs/jquery-1.9.1.min', -'libs/underscore-min', -'libs/text!./template.html' -], function($, _, templateSrc) { - -'use strict'; - -return function(sandbox) { - - var template = _.template(templateSrc); - - var view = { - dom: $('
' + template({children: null, parent: null}) + '
'), - setup: function() { - this.dom.on('click', 'a', function(e) { - var target = $(e.target); - sandbox.publish('nodeSelected', target.attr('data-id')); - }); - - this.dom.on('mouseenter', 'a', function(e) { - var target = $(e.target); - sandbox.publish('nodeEntered', target.attr('data-id')); - }); - this.dom.on('mouseleave', 'a', function(e) { - var target = $(e.target); - sandbox.publish('nodeLeft', target.attr('data-id')); - }); - }, - setNode: function(node) { - var parentClass = node.parent().attr('wlxml-class'); - var parent = node.parent('[wlxml-tag]').length ? { - repr: node.parent().attr('wlxml-tag') + (parentClass ? ' / ' + parentClass : ''), - id: node.parent().attr('id') - } : undefined; - var children = []; - node.children('[wlxml-tag]').each(function() { - var child = $(this); - var childClass = child.attr('wlxml-class'); - children.push({repr: child.attr('wlxml-tag') + (childClass ? ' / ' + childClass : ''), id: child.attr('id')}); - }); - this.dom.empty(); - this.dom.append($(template({parent: parent, children: children}))); - } - } - - view.setup(); - - return { - start: function() { - sandbox.publish('ready'); - }, - setNode: function(node) { - view.setNode(node); - }, - getView: function() { - return view.dom; - }, - highlightNode: function(id) { - view.dom.find('a[data-id="'+id+'"]').addClass('rng-common-hoveredNode'); - }, - dimNode: function(id) { - view.dom.find('a[data-id="'+id+'"]').removeClass('rng-common-hoveredNode'); - } - }; -}; - +define([ +'libs/jquery-1.9.1.min', +'libs/underscore-min', +'libs/text!./template.html' +], function($, _, templateSrc) { + +'use strict'; + +return function(sandbox) { + + var template = _.template(templateSrc); + + var view = { + dom: $('
' + template({children: null, parent: null}) + '
'), + setup: function() { + var view = this; + this.dom.on('click', 'a', function(e) { + var target = $(e.target); + sandbox.publish('nodeSelected', view.nodes[target.attr('data-id')]); + }); + + this.dom.on('mouseenter', 'a', function(e) { + var target = $(e.target); + sandbox.publish('nodeEntered', view.nodes[target.attr('data-id')]); + }); + this.dom.on('mouseleave', 'a', function(e) { + var target = $(e.target); + sandbox.publish('nodeLeft', view.nodes[target.attr('data-id')]); + }); + }, + setNode: function(node) { + console.log('familyTree sets node'); + var nodes = this.nodes = {}; + this.currentNode = node; + var parentNode = node.parent(); + var parent; + + if(parentNode) { + parent = { + repr: parentNode.getTag() + (parentNode.getClass() ? ' / ' + parentNode.getClass() : ''), + id: parentNode.getId() + }; + this.nodes[parentNode.getId()] = parentNode; + } + + var children = []; + node.children().each(function() { + var child = this; + children.push({repr: child.getTag() + (child.getClass() ? ' / ' + child.getClass() : ''), id: child.getId()}); + nodes[child.getId()] = child; + }); + this.dom.empty(); + this.dom.append($(template({parent: parent, children: children}))); + }, + highlightNode: function(canvasNode) { + this.dom.find('a[data-id="'+canvasNode.getId()+'"]').addClass('rng-common-hoveredNode'); + }, + dimNode: function(canvasNode) { + this.dom.find('a[data-id="'+canvasNode.getId()+'"]').removeClass('rng-common-hoveredNode'); + } + }; + + view.setup(); + + return { + start: function() { + sandbox.publish('ready'); + }, + setNode: function(canvasNode) { + if(!canvasNode.isSame(view.currentNode)) + view.setNode(canvasNode); + }, + getView: function() { + return view.dom; + }, + highlightNode: function(canvasNode) { + view.highlightNode(canvasNode); + }, + dimNode: function(canvasNode) { + view.dimNode(canvasNode); + } + }; +}; + }); \ No newline at end of file