Fixing skill creation

skala
Julio Montoya 14 years ago
parent 468d2d6cd8
commit a9836db3fa
  1. 9
      main/inc/ajax/skill.ajax.php
  2. 6
      main/inc/lib/gradebook.lib.php
  3. 39
      main/inc/lib/javascript/skills.js
  4. 21
      main/inc/lib/skill.lib.php
  5. 4
      main/inc/lib/skill.visualizer.lib.php
  6. 65
      main/template/default/skill/skill_tree.tpl

@ -35,15 +35,16 @@ switch ($action) {
}
echo json_encode($return_skills);
break;
case 'get_gradebooks':
case 'get_gradebooks':
$gradebooks = $gradebook_list = $gradebook->get_all();
$gradebook_list = array();
//only course gradebook
if (!empty($gradebooks)) {
foreach($gradebooks as $gradebook) {
if ($gradebook['parent_id'] == 0) {
//$gradebook['name'] = $gradebook['name'];
$gradebook_list[] = $gradebook;
//$gradebook['name'] = $gradebook['name'];
//$gradebook_list[] = $gradebook;
} else {
// $gradebook['name'] = $gradebook_list[$gradebook['parent_id']]['name'].' > '.$gradebook['name'];
//$gradebook_list[] = $gradebook;
@ -55,7 +56,9 @@ switch ($action) {
break;
case 'get_skills':
$load_user_data = isset($_REQUEST['load_user_data']) ? $_REQUEST['load_user_data'] : null;
$skills = $skill->get_all($load_user_data);
//$parent_id = intval($_REQUEST['parent_id']);
$id = intval($_REQUEST['id']);
$skills = $skill->get_all($load_user_data, false, $id);
echo json_encode($skills);
break;
case 'get_skill_info':

@ -21,8 +21,10 @@ class Gradebook extends Model {
$this->table_skill_rel_gradebook = Database::get_main_table(TABLE_MAIN_SKILL_REL_GRADEBOOK);
}
public function get_all() {
$gradebooks = parent::get_all();
public function get_all($options = array()) {
$gradebooks = parent::get_all($options);
foreach($gradebooks as &$gradebook) {
if (empty($gradebook['name'])) {
$gradebook['name'] = $gradebook['course_code'];

@ -124,12 +124,12 @@
//Modifying current block position
pos = $('#'+id).position();
left_value = center_x;
if (parents.length == 2) {
top_value = space_between_blocks_y + offset_y;
} else {
top_value = pos.left;
}
top_value = 100;
}
jsPlumb.animate(id, { left: left_value, top:top_value }, { duration:duration_value });
//Modifying root block position
@ -180,17 +180,18 @@
}
function load_children(my_id, top_value, load_user_data) {
console.log("load_children call : my_id " + my_id + " top_value:" + top_value);
console.log("load_children call : my_id " + my_id + " top_value:" + top_value);
//Loading children
var ix = 0;
$.getJSON(url+'&a=load_children&load_user_data='+load_user_data+'&id='+my_id, {},
function(json) {
$.each(json,function(i,item) {
$.each(json,function(i,item) {
console.log('Loading children: #' + item.id + " " +item.name);
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 = '<a href="#" class="edit_block" id="edit_block_'+item.id+'">'+item.name+'</a>';
item.name = '<a href="#" class="edit_block" id="edit_block_'+item.id+'">'+item.name+'</a>';
var status_class = ' ';
my_edit_point = editEndpoint;
@ -199,16 +200,32 @@
my_edit_point = doneEndpoint;
status_class = 'done_window';
}
$('body').append('<div id="block_'+item.id+ '" class="third_window open_block window '+status_class+'" >'+item.name+'</div>');
$('#block_'+item.id).css( {
position: 'absolute',
zIndex: 5000,
left: '10',
top: '10'
} );
//console.log('append div id = block_'+item.id);
//console.log('preparing = '+item.id);
var es = prepare("block_" + item.id, my_edit_point);
//console.log('preparing = '+my_id);
var e2 = prepare("block_" + my_id, my_edit_point);
jsPlumb.connect({source: es, target:e2});
jsPlumb.animate("block_" + item.id, {
jsPlumb.connect({source: es, target:e2});
//console.log('connect sources');
jsPlumb.animate("block_" + item.id, {
left: left_value, top : top_value
}, { duration:duration_value});
}, { duration : duration_value });
ix++;
});
}

@ -311,9 +311,26 @@ class Skill extends Model {
return $users;
}
function get_all($load_user_data = false, $user_id = false) {
function get_all($load_user_data = false, $user_id = false, $id = null, $parent_id = null) {
$id_condition = '';
if (isset($id)) {
$id = intval($id);
$id_condition = " WHERE id = $id";
}
if (isset($parent_id)) {
$parent_id = intval($parent_id);
if (empty($id_condition)) {
$id_condition = "WHERE parent_id = $parent_id";
} else {
$id_condition = " AND parent_id = $parent_id";
}
}
$sql = "SELECT id, name, description, parent_id, relation_type
FROM {$this->table} s INNER JOIN {$this->table_skill_rel_skill} ss ON (s.id = ss.skill_id) ";
FROM {$this->table} s INNER JOIN {$this->table_skill_rel_skill} ss ON (s.id = ss.skill_id)
$id_condition";
$result = Database::query($sql);
$skills = array();

@ -38,13 +38,13 @@
}
$this->html .= '<div id="block_'.$block_id.'" class = " open_block window '.$extra_class.' '.$class.'" style = "top:' . $position['y'] . 'px; left:' . $position['x'] . 'px;">';
$gradebook_string = '';
/*$gradebook_string = '';
if (!empty($skill['gradebooks'])) {
foreach ($skill['gradebooks'] as $gradebook) {
//uncomment this to show the gradebook tags
$gradebook_string .= Display::span($gradebook['name'], array('class'=>'label_tag gradebook','style'=>'width:50px')).'<br />';
}
}
} */
$skill['name'] = Display::url($skill['name'], '#', array('id'=>'edit_block_'.$block_id, 'class'=>'edit_block'));
$this->html .= $skill['name'].' '.$gradebook_string;

@ -26,21 +26,22 @@ jsPlumb.bind("ready", function() {
autoOpen: false,
modal : true,
width : 550,
height : 480,
height : 450,
});
//Filling skills select
$.getJSON( "{$url}&a=get_skills", {},
/*
$.getJSON("{$url}&a=get_skills&parent_id="+parents[0], {},
function(data) {
$.each(data, function(n, parent) {
// add a new option with the JSON-specified value and text
$("<option />").attr("value", parent.id).text(parent.name).appendTo("#parent_id");
});
}
);
);*/
//Filling gradebook select
$.getJSON( "{$url}&a=get_gradebooks", {},
$.getJSON("{$url}&a=get_gradebooks", {},
function(data) {
$.each(data, function(n, gradebook) {
// add a new option with the JSON-specified value and text
@ -53,12 +54,28 @@ jsPlumb.bind("ready", function() {
$("#add_item_link").click(function() {
$("#name").attr('value', '');
$("#description").attr('value', '');
$("#description").attr('value', '');
$("#parent_id option:selected").removeAttr('selected');
$("#gradebook_id option:selected").removeAttr('selected');
$("#gradebook_id option:selected").removeAttr('selected');
$("#dialog-form").dialog("open");
$("#dialog-form").dialog("open");
//Filling skills select
var my_id = 1;
if (parents.length > 1) {
my_id = parents[1].split('_')[1];
}
//Remove all options
$("#parent_id").find('option').remove();
$.getJSON("{$url}&a=get_skills&id="+my_id, {},
function(data) {
$.each(data, function(n, parent) {
// add a new option with the JSON-specified value and text
$("<option />").attr("value", parent.id).text(parent.name).appendTo("#parent_id");
});
}
);
});
var name = $( "#name" ),
@ -78,8 +95,7 @@ jsPlumb.bind("ready", function() {
$.ajax({
url: url+'&a=add&'+params,
success:function(data) {
success:function(data) {
//new window
parent_id = $("#parent_id option:selected").attr('value');
@ -112,13 +128,11 @@ jsPlumb.bind("ready", function() {
hidden_parent = parents[0];
//console.log('deleting: '+parents[0]);
//removing father
for (var i = 0; i < skills.length; i++) {
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();
//skills.splice(i,1)
}
}
parents.splice(0,1);
@ -216,7 +230,7 @@ jsPlumb.bind("ready", function() {
var e = jsPlumb.addEndpoint(elId, endpoint);
jsPlumbDemo.initjulio(e);
skills.push({
element:elId, endp:e
element: elId, endp:e
});
return e;
},
@ -224,14 +238,12 @@ jsPlumb.bind("ready", function() {
window.jsPlumbDemo = {
initjulio :function(e) {
},
initHover :function(elId) {
initHover :function(elId) {
$("#" + elId).click(function() {
var all = jsPlumb.getConnections({
source:elId
});
});
});
});
/*$("#" + elId).hover(
function() { $(this).addClass("bigdot-hover"); },
function() { $(this).removeClass("bigdot-hover"); }
@ -245,8 +257,6 @@ jsPlumb.bind("ready", function() {
jsPlumb.Defaults.Endpoint = "Rectangle";
jsPlumb.Defaults.Anchors = ["TopCenter", "TopCenter"];
jsPlumb.bind("jsPlumbConnection", function(e) {
//updateConnections(e.connection);
});
@ -264,7 +274,6 @@ jsPlumb.bind("ready", function() {
var divsWithWindowClass = jsPlumbDemo.getSelector(".window");
jsPlumb.draggable(divsWithWindowClass);
jsPlumbDemo.attachBehaviour();
}
};
@ -319,16 +328,14 @@ $(document).ready( function() {
};
})();
</script>
<h2>Skills</h2>
<a class="a_button gray" id="add_item_link" href="#">Add item</a>
<div style="z-index: 1000;position: absolute;">
<h2>Skills</h2>
<a s tyle="z-index: 1000"class="a_button gray" id="add_item_link" href="#">{"Add item"|get_lang}</a>
</div>
{$html}
<div id="dialog-form" style="display:none;">
<div id="dialog-form" style="display:none;z-index=10000;">
<p class="validateTips"></p>
<form id="add_item" name="form">
<input type="hidden" name="id" id="id"/>

Loading…
Cancel
Save