123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- var debug = 1;
- var skills = [];
- var parents = [];
- var first_parent = '';
- var duration_value = 500;
- var parents = ['block_1'];
- function clean_values() {
- skills = [];
- parents = ['block_1'];
- first_parent = '';
-
-
- jsPlumb.reset();
-
- $('.skill_root').remove();
- $('.skill_child').remove();
-
- open_block('block_1', 0, 1);
- }
- var editEndpointOptions = {
- isTarget:true,
- maxConnections:100,
- endpoint:"Rectangle",
- paintStyle:{
- fillStyle:"yellow" },
- detachable:false,
- connector:"Straight"
- };
- var done_arrow_color = '#73982C';
- var doneEndpointOptions = {
-
-
- endpoint:"Rectangle",
- paintStyle:{ width:1, height:1, fillStyle:done_arrow_color},
- isSource:false,
- scope:'blue rectangle',
- maxConnections:10,
- connectorStyle : {
- gradient:{ stops:[[0, done_arrow_color], [0.5, done_arrow_color], [1, done_arrow_color]] },
- lineWidth:5,
- strokeStyle:done_arrow_color
- },
- isTarget:false,
- setDraggableByDefault : false,
- connector:"Straight"
- };
- function cleanclass(obj) {
- obj.removeClass('first_window');
- obj.removeClass('second_window');
- obj.removeClass('third_window');
- }
- function open_parent(parent_id, id) {
- console.log("open_parent call : id " + id + " parent_id:" + parent_id);
- var numeric_parent_id = parent_id.split('_')[1];
- var numeric_id = id.split('_')[1];
- $('#'+id).css('top', '0px');
- load_parent(numeric_parent_id, numeric_id);
- }
- function open_block(id, load_user_data, create_root) {
- if (debug) console.log("open_block id : " + id+" load_user_data: " +load_user_data + ', create_root ' + create_root);
-
- var numeric_id = id.split('_')[1];
-
- for (var i = 0; i < skills.length; i++) {ranc
-
- if (jQuery.inArray(skills[i].element, parents) == -1) {
-
- jsPlumb.detachAllConnections(skills[i].element);
- jsPlumb.removeAllEndpoints(skills[i].element);
- $("#"+skills[i].element).remove();
- }
- }
- load_children(numeric_id, 0, load_user_data, create_root);
- }
- function load_children(my_id, top_value, load_user_data, create_root) {
- if (debug) console.log("load_children : my_id " + my_id + ", top_value:" + top_value +", load_user_data: "+load_user_data+", create_root: "+create_root);
-
-
- my_top_root = 150;
- my_top_children = 250;
-
- console.log('Loading root info by ajax '+my_id);
- var skill = null;
- $.ajax({
- async: false,
- url: url+'&a=get_skill_info&id='+my_id,
- success: function(json) {
- skill = jQuery.parseJSON(json);
- }
- });
-
- if (create_root == 1) {
-
- my_top_root = 0;
- my_top_children = 150;
-
- if (my_id == 1) {
- $('#skill_tree').append('<div id="block_'+my_id+'" class="skill_root first_window" >Root </div>');
- } else {
- $('#skill_tree').append('<div id="block_'+my_id+'" class="skill_root open_block first_window" >' +skill.name+'</div>');
- }
-
-
- skills.push({
- element: "block_" + my_id
- });
-
-
-
- }
-
-
-
- $.ajax({
- url: url+'&a=load_children&load_user_data='+load_user_data+'&id='+my_id,
- dataType: 'json',
- async: false,
- success: function(result) {
- if (result.success) {
- json = result.data;
-
- console.log('getJSON result: ' + result.success);
-
-
-
- var final_left =0;
- var normal_width = 0;
-
- $('.skill_child').each( function(){
- normal_width = $(this).width();
- return true;
- });
-
-
- final_left = $('body').width() / 2 - normal_width/2;
-
- console.log('normal_width -----> '+normal_width);
- console.log('body.width -----> '+$('body').width());
- console.log('final_left -----> '+final_left);
-
- $('#block_'+my_id).css('left', final_left+'px');
- $.each(json,function(i, item) {
-
-
-
- item.name = '<a href="#" class="edit_block" id="edit_block_'+item.id+'">'+item.name+'</a>';
- var status_class = ' ';
- my_edit_point_options = editEndpointOptions;
- if (item.passed == 1) {
- my_edit_point_options = doneEndpointOptions;
- status_class = 'done_window';
- }
- $('#skill_tree').append('<div id="block_'+item.id+ '" class="skill_child open_block '+status_class+'" >'+item.name+'</div>');
-
-
- $('#block_'+item.id).css('top', my_top_children+'px');
-
- if (create_root == 0) {
-
- }
-
-
-
-
- endpoint = jsPlumb.makeTarget("block_" + item.id, my_edit_point_options);
- jsPlumb.connect({source: "block_" + my_id, target:"block_" + item.id});
- skills.push({
- element: "block_" + item.id, endp:endpoint
- });
-
- });
- jsPlumb.draggable(jsPlumb.getSelector(".skill_child"));
-
- console.log('draggable');
- console.log('setting animate for block_'+my_id);
- console.log('final parents '+parents);
- }
- }
- });
- }
- function load_parent(parent_id, id) {
- if (debug) console.log("load_parent call : id " + id + " parent_id:" + parent_id);
- $.ajax({
- url: url+'&a=load_direct_parents&id='+id,
- async: false,
- success: function(json) {
- var json = jQuery.parseJSON(json);
- $.each(json,function(i,item) {
- if (item.parent_id == 0) {
- $('#skill_tree').append('<div id="block_'+item.id+ '" class="skill_root first_window ">'+item.name+'</div>');
- jsPlumb.connect({
- source: 'block_'+parent_id, target:'block_'+id
- });
- if (debug) console.log('setting NO--- first_parent ');
- first_parent = '';
- } else {
- $('#skill_tree').append('<div id="block_'+item.id+ '" class="open_block skill_child ">'+item.name+'</div>');
- jsPlumb.connect({
- source: 'block_'+parent_id, target:'block_'+id
- });
- if (debug) console.log('setting first_parent '+item.parent_id);
- first_parent = "block_" + item.parent_id;
- jsPlumb.draggable(jsPlumb.getSelector(".skill_root"));
- }
- my_top_root = 0;
- var normal_width = 0;
-
- $('.skill_child').each( function(){
- normal_width = $(this).width();
- return true;
- });
- final_left = $('body').width() / 2 - normal_width/2;
- console.log('normal_width -----> '+normal_width);
- console.log('body.width -----> '+$('body').width());
- console.log('final_left -----> '+final_left);
- $('#block_'+item.id).css('left', final_left+'px');
- jsPlumb.repaint('block_'+item.id);
-
-
-
-
- });
- }
- });
- }
- function checkLength( o, n, min, max ) {
- if ( o.val().length > max || o.val().length < min ) {
- o.addClass( "ui-state-error" );
- updateTips( "Length of " + n + " must be between " +min + " and " + max + "." );
- return false;
- } else {
- return true;
- }
- }
- function updateTips( t ) {
- tips = $( ".validateTips" )
- tips
- .text( t )
- .addClass( "ui-state-highlight" );
- setTimeout(function() {
- tips.removeClass( "ui-state-highlight", 1500 );
- }, 500 );
- }
|