From 03c5ddfcb7f20447f1e4677a14ea37d76d2fd724 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 4 Apr 2012 14:14:30 +0200 Subject: [PATCH] More skills tree fixes --- main/css/base.css | 1 + main/inc/lib/javascript/skills.js | 31 ++++++++++++++-------- main/template/default/skill/skill_tree.tpl | 31 +++++++++++++++------- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/main/css/base.css b/main/css/base.css index 8af9b63b89..948cbbf686 100644 --- a/main/css/base.css +++ b/main/css/base.css @@ -2924,6 +2924,7 @@ form .formw .freeze { position:relative; } + .done_window { background-color: #73982C; } diff --git a/main/inc/lib/javascript/skills.js b/main/inc/lib/javascript/skills.js index 80cf6ebd97..9877beaeff 100644 --- a/main/inc/lib/javascript/skills.js +++ b/main/inc/lib/javascript/skills.js @@ -27,7 +27,7 @@ var editEndpointOptions = { isTarget:true, maxConnections:100, endpoint:"Rectangle", - paintStyle:{ fillStyle:"yellow" }, + paintStyle:{ fillStyle:"yellow" } }; @@ -88,6 +88,11 @@ function open_parent(parent_id, id) { load_parent(numeric_parent_id, numeric_id); } + +function open_block_student(id) { + open_block(id, 1) +} + /* * * When clicking a children block @@ -104,7 +109,8 @@ function open_block(id, load_user_data) { //Remove everything except parents if (jQuery.inArray(skills[i].element, parents) == -1) { if (debug) console.log('deleting this skill '+ skills[i].element + " id: " + i); - jsPlumb.removeEveryEndpoint(skills[i].endp); + jsPlumb.detachAllConnections(skills[i].element); + jsPlumb.removeAllEndpoints(skills[i].element); $("#"+skills[i].element).remove(); } } @@ -125,12 +131,11 @@ function open_block(id, load_user_data) { pos_parent = $('#'+parents[0]).position(); jsPlumb.animate(parents[0], { left: center_x, top:offset_y }, { duration:duration_value }); top_value = 2*space_between_blocks_y +offset_y ; */ + load_children(numeric_id, 0, load_user_data); + } -function open_block_student(id) { - open_block(id, 1) -} function load_children(my_id, top_value, load_user_data) { if (debug) console.log("load_children : my_id " + my_id + ", top_value:" + top_value +", load_user_data: "+load_user_data); @@ -138,7 +143,9 @@ function load_children(my_id, top_value, load_user_data) { //Loading children var ix = 0; - $('#skill_tree').append('
Root
'); + if (my_id == 1) { + + $('#skill_tree').append('
Root
'); // jsPlumb.animate('block_'+my_id, { left: 500, top:50 }, { duration: 100 }); @@ -152,7 +159,7 @@ function load_children(my_id, top_value, load_user_data) { //The root is the source - jsPlumb.makeSource("block_" + my_id, root_end_point_options); + //jsPlumb.makeSource("block_" + my_id, root_end_point_options); /*$('#block_'+my_id).css({ position: 'absolute', @@ -160,13 +167,13 @@ function load_children(my_id, top_value, load_user_data) { left: '100px', top: '100px' });*/ - + } $.getJSON(url+'&a=load_children&load_user_data='+load_user_data+'&id='+my_id, {}, function(json) { console.log('getJSON reponse: ' + json) $.each(json,function(i, item) { if (debug) console.log('Loading children: #' + item.id + " " +item.name); - left_value = ix*space_between_blocks_x + center_x/2 - block_size / 2; + //left_value = ix*space_between_blocks_x + center_x/2 - block_size / 2; //top_value = 300; //Display::url($skill['name'], '#', array('id'=>'edit_block_'.$block_id, 'class'=>'edit_block')) //item.name = ''+item.name+''; @@ -202,7 +209,7 @@ function load_children(my_id, top_value, load_user_data) { element: "block_" + item.id, endp:endpoint }); - console.log('added to array skills' + item.id); + console.log('added to array skills id: ' + item.id+" - name: "+item.name); //console.log('connect sources'); @@ -212,6 +219,7 @@ function load_children(my_id, top_value, load_user_data) { ix++; */ }); jsPlumb.draggable(jsPlumb.getSelector(".skill_child")); + jsPlumb.draggable(jsPlumb.getSelector(".skill_root")); //Creating the organigram var sum=0; @@ -224,7 +232,8 @@ function load_children(my_id, top_value, load_user_data) { }); sum = sum / 2 - normal_weight/2 + q/2; //console.log(sum); - jsPlumb.animate('block_'+my_id, { left: sum, top:10 }, { duration: 100 }); + jsPlumb.animate('block_'+my_id, { left: sum, top:0 }, { duration: 100 }); + //$('#block_'+my_id).css('margin-bottom', "20px"); } ); } diff --git a/main/template/default/skill/skill_tree.tpl b/main/template/default/skill/skill_tree.tpl index 1582a6ac61..8ce06ab30c 100644 --- a/main/template/default/skill/skill_tree.tpl +++ b/main/template/default/skill/skill_tree.tpl @@ -139,29 +139,40 @@ jsPlumb.ready(function() { //Clicking in a box skill (we use live instead of bind because we're creating divs on the fly ) $(".open_block").live('click', function() { var id = $(this).attr('id'); + console.log('id :' + id); + console.log('parent'); + console.log(parents); //if is root if (parents[0] == id) { parents = [id]; } - if (parents[1] != id) { + if (parents[1] != id) { + console.log('parents.length ' +parents.length); + if (parents.length == 2 ) { hidden_parent = parents[0]; //console.log('deleting: '+parents[0]); //removing father - for (var i = 0; i < skills.length; i++) { - if ( skills[i].element == parents[0] ) { - //console.log('deleting :'+ skills[i].element + ' here '); - jsPlumb.deleteEndpoint(skills[i].endp); - $("#"+skills[i].element).remove(); + console.log("hidden_parent " + hidden_parent); + + for (var i = 0; i < skills.length; i++) { + console.log('looping '+skills[i].element + ': '); + if (skills[i].element == parents[0] ) { + console.log('deleting parent:'+ skills[i].element + ' here '); + //jsPlumb.deleteEndpoint(skills[i].endp); + jsPlumb.detachAllConnections(skills[i].element); + jsPlumb.removeAllEndpoints(skills[i].element); + $("#"+skills[i].element).remove(); } } parents.splice(0,1); parents.push(id); } - if ($(this).hasClass('first_window')) { + if ($(this).hasClass('first_window')) { + console.log('first_window'); //show the hidden_parent //if (hidden_parent != '') { parents = [hidden_parent, id]; @@ -261,7 +272,7 @@ jsPlumb.ready(function() { console.log('Import defaults'); jsPlumb.Defaults.Anchors = [ "BottomCenter", "TopCenter" ]; - // jsPlumb.DefaultDragOptions = { cursor: "pointer", zIndex:2000 }; + //jsPlumb.DefaultDragOptions = { cursor: "crosshair", zIndex:2000 }; jsPlumb.Defaults.Container = "skill_tree"; @@ -369,8 +380,8 @@ jsPlumb.ready(function() { // listen for clicks on connections, and offer to delete connections on click. jsPlumb.bind("click", function(conn, originalEvent) { - if (confirm("Delete connection from " + conn.sourceId + " to " + conn.targetId + "?")) - jsPlumb.detach(conn); + /*if (confirm("Delete connection from " + conn.sourceId + " to " + conn.targetId + "?")) + jsPlumb.detach(conn); */ }); } };