diff --git a/main/inc/lib/javascript/skills.js b/main/inc/lib/javascript/skills.js
index e1ecf9d34f..4731208054 100644
--- a/main/inc/lib/javascript/skills.js
+++ b/main/inc/lib/javascript/skills.js
@@ -105,8 +105,10 @@
load_parent(numeric_parent_id, numeric_id);
}
- /* When clicking a children block */
-
+ /* When clicking a children block
+ @param string block id i.e "block_1"
+ * */
+
function open_block(id) {
console.log("open_block id : " + id);
var numeric_id = id.split('_')[1];
@@ -217,10 +219,19 @@
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 + "." );
+ 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 );
}
\ No newline at end of file
diff --git a/main/inc/lib/model.lib.php b/main/inc/lib/model.lib.php
index c37e524623..83a53589b3 100644
--- a/main/inc/lib/model.lib.php
+++ b/main/inc/lib/model.lib.php
@@ -13,6 +13,8 @@ class Model {
var $table;
var $columns;
+ var $required;
+
// var $pk; some day this will be implemented
public function __construct() {
@@ -103,6 +105,20 @@ class Model {
public function save($params, $show_query = false) {
$params = $this->clean_parameters($params);
+
+ if (!empty($this->required)) {
+ $require_ok = true;
+ $kay_params = array_keys($params);
+ foreach ($this->required as $field) {
+ if (!in_array($field, $kay_params)) {
+ $require_ok = false;
+ }
+ }
+ if (!$require_ok) {
+ return false;
+ }
+ }
+
if (in_array('created_at', $this->columns)) {
$params['created_at'] = api_get_utc_datetime();
}
diff --git a/main/inc/lib/skill.lib.php b/main/inc/lib/skill.lib.php
index 7ff0e16965..c8ca2a2b2c 100644
--- a/main/inc/lib/skill.lib.php
+++ b/main/inc/lib/skill.lib.php
@@ -272,7 +272,8 @@ class SkillRelUser extends Model {
class Skill extends Model {
- var $columns = array('id', 'name','description', 'access_url_id');
+ var $columns = array('id', 'name','description', 'access_url_id');
+ var $required = array('name');
public function __construct() {
$this->table = Database::get_main_table(TABLE_MAIN_SKILL);
@@ -384,6 +385,7 @@ class Skill extends Model {
$skill_rel_gradebook = new SkillRelGradebook();
//Saving name, description
+
$skill_id = $this->save($params);
if ($skill_id) {
//Saving skill_rel_skill (parent_id, relation_type)
diff --git a/main/template/default/skill/skill_tree.tpl b/main/template/default/skill/skill_tree.tpl
index 9db8095559..6829936a8e 100644
--- a/main/template/default/skill/skill_tree.tpl
+++ b/main/template/default/skill/skill_tree.tpl
@@ -49,7 +49,57 @@ jsPlumb.bind("ready", function() {
}
);
- //On box click -(we use live instead of bind because we're creating divs on the fly )
+ //Add button
+
+ $("#add_item_link").click(function() {
+ $("#name").attr('value', '');
+ $("#description").attr('value', '');
+
+ $("#parent_id option:selected").removeAttr('selected');
+ $("#gradebook_id option:selected").removeAttr('selected');
+
+ $("#dialog-form").dialog("open");
+ });
+
+ var name = $( "#name" ),
+ description = $( "#description" ),
+ allFields = $( [] ).add( name ).add( description ), tips = $(".validateTips");
+
+ //Add button process
+
+ $("#dialog-form").dialog({
+ buttons: {
+ "Add" : function() {
+ var bValid = true;
+ bValid = bValid && checkLength( name, "name", 1, 255 );
+
+ if (bValid) {
+ var params = $("#add_item").serialize();
+
+ $.ajax({
+ url: url+'&a=add&'+params,
+ success:function(data) {
+
+ //new window
+ parent_id = $("#parent_id option:selected").attr('value');
+
+
+ //Great stuff
+ open_block('block_'+parent_id);
+
+ $("#dialog-form").dialog("close");
+ }
+ });
+ }
+ },
+ },
+ close: function() {
+ $("#name").attr('value', '');
+ $("#description").attr('value', '');
+ }
+ });
+
+ //Clicking 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');
@@ -107,6 +157,7 @@ jsPlumb.bind("ready", function() {
console.log('hidden_parent : ' + hidden_parent);
});
+ //Skill title click
$(".edit_block").live('click',function() {
var my_id = $(this).attr('id');
my_id = my_id.split('_')[2];
@@ -138,62 +189,8 @@ jsPlumb.bind("ready", function() {
return false;
});
- //Filling select
- $("#add_item_link").click(function() {
-
- $("#name").attr('value', '');
- $("#description").attr('value', '');
-
- $("#parent_id option:selected").removeAttr('selected');
- $("#gradebook_id option:selected").removeAttr('selected');
-
- $("#dialog-form").dialog("open");
-
- });
- var name = $( "#name" ),
- description = $( "#description" ),
- allFields = $( [] ).add( name ).add( description ), tips = $(".validateTips");
-
- $("#dialog-form").dialog({
- buttons: {
- "Add" : function() {
- var bValid = true;
- bValid = bValid && checkLength( name, "name", 1, 255 );
- var params = $("#add_item").serialize();
-
- $.ajax({
- url: url+'&a=add&'+params,
- success:function(data) {
-
- /*jsPlumb.connect({
- source : "block_2",
- target : "block_1",
- overlays : overlays
- });*/
-
- /*
- calEvent.title = $("#name").val();
- calEvent.start = calEvent.start;
- calEvent.end = calEvent.end;
- calEvent.allDay = calEvent.allDay;
- calEvent.description = $("#content").val();
- calendar.fullCalendar('updateEvent',
- calEvent,
- true // make the event "stick"
- );*/
-
- $("#dialog-form").dialog("close");
- }
- });
- },
- },
- close: function() {
- $("#name").attr('value', '');
- $("#description").attr('value', '');
- }
- });
-
+ //
$(".window").bind('click', function() {
var id = $(this).attr('id');
id = id.split('_')[1];
@@ -249,74 +246,26 @@ jsPlumb.bind("ready", function() {
jsPlumb.Defaults.Endpoint = "Rectangle";
jsPlumb.Defaults.Anchors = ["TopCenter", "TopCenter"];
- var connections = [];
- var updateConnections = function(conn, remove) {
- if (!remove) connections.push(conn);
- else {
- var idx = -1;
- for (var i = 0; i < connections.length; i++) {
- if (connections[i] == conn) {
- idx = i; break;
- }
- }
- if (idx != -1) connections.splice(idx, 1);
- }
- if (connections.length > 0) {
- var s = "current connections
| scope | source | target |
|---|---|---|
| " + connections[j].scope + " | " + "" + connections[j].sourceId + " | " + connections[j].targetId + " |