Holger Knublauch

Tree selection working

This diff is collapsed. Click to expand it.
...@@ -339,6 +339,73 @@ function appReloadForm(resourceURI, queryGraphURI, linkElementId) { ...@@ -339,6 +339,73 @@ function appReloadForm(resourceURI, queryGraphURI, linkElementId) {
339 339
340 340
341 /** 341 /**
342 + * Selects a given node in a given tree.
343 + * Will expand if necessary, using a server-side shortest path algorithm.
344 + * @param treeId the id of the tree
345 + * @param nodeURI the URI of the resource to select
346 + */
347 +function appSelectTreeNode(treeId, nodeURI) {
348 +
349 + // TODO: Currently this only works on the Tree that was created last
350 + // but not if multiple trees are on a page
351 +
352 + var tree = $('#' + treeId);
353 + var dataProviderURI = tree.attr('treedataprovider');
354 + if(!dataProviderURI) {
355 + alert('Error: Element with id ' + treeId + ' does not have treedataprovider attribute');
356 + return;
357 + }
358 +
359 + var rootURI = tree.attr('treeroot');
360 +
361 + // Do nothing if it's already selected
362 + var sel = tree.jstree('get_selected');
363 + if(sel) {
364 + if(sel.attr('resource') == nodeURI) {
365 + return;
366 + }
367 + }
368 +
369 + // Load path to root from the server and then call helper function
370 + var data = {
371 + _format: 'json',
372 + _viewClass: 'app:TreeShortestPathCallback',
373 + dataProvider: '<' + dataProviderURI + '>',
374 + node: '<' + nodeURI + '>'
375 + };
376 + if(rootURI) {
377 + data.root = '<' + rootURI + '>';
378 + }
379 + $.get(uispinServlet, data, function(path) {
380 + appSelectTreeNodeHelper(tree, tree, path, 0);
381 + });
382 +}
383 +
384 +
385 +// Private helper function - walks an array, expanding nodes along the way
386 +function appSelectTreeNodeHelper(tree, node, path, index) {
387 +
388 + var next = path[index];
389 +
390 + node.children("ul").children("li").each(function(i, o) {
391 + var child = $(o);
392 + if(child.attr('resource') == next) {
393 + if(index == path.length - 1) {
394 + // End reached: select this node
395 + tree.jstree('select_node', child, true);
396 + child[0].scrollIntoView();
397 + }
398 + else {
399 + tree.jstree('open_node', child, function() {
400 + appSelectTreeNodeHelper(tree, child, path, index + 1);
401 + });
402 + }
403 + }
404 + });
405 +}
406 +
407 +
408 +/**
342 * Submits a form and switches it to viewing mode when done. 409 * Submits a form and switches it to viewing mode when done.
343 * @param form the id of the form 410 * @param form the id of the form
344 * @param servlet the optional name of the servlet 411 * @param servlet the optional name of the servlet
......
...@@ -5,8 +5,7 @@ ...@@ -5,8 +5,7 @@
5 ui:view="{= ?dataProvider }" 5 ui:view="{= ?dataProvider }"
6 arg:root="{= ?root }"> 6 arg:root="{= ?root }">
7 7
8 - <!-- The div that will be turned into a jsTree below --> 8 + <div id="{= ?id }" treedataprovider="{= ?dataProvider }" treeroot="{= ?root }"/>
9 - <div id="{= ?id }" />
10 9
11 <script type="text/javascript"> 10 <script type="text/javascript">
12 $(function () { 11 $(function () {
...@@ -15,12 +14,7 @@ ...@@ -15,12 +14,7 @@
15 "plugins" : [ 14 "plugins" : [
16 "themes", 15 "themes",
17 "json_data", 16 "json_data",
18 - "ui", 17 + "ui" ],
19 - "crrm",
20 - "cookies",
21 - "search",
22 - "types",
23 - "hotkeys" ],
24 18
25 "json_data" : { 19 "json_data" : {
26 "ajax" : { 20 "ajax" : {
...@@ -40,6 +34,10 @@ ...@@ -40,6 +34,10 @@
40 34
41 "themes" : { 35 "themes" : {
42 "theme" : "classic" 36 "theme" : "classic"
37 + },
38 +
39 + "ui": {
40 + "select_limit": 1
43 } 41 }
44 }); 42 });
45 }); 43 });
......