diff --git a/main/inc/ajax/skill.ajax.php b/main/inc/ajax/skill.ajax.php
index d3fb3f7a98..ff3c8c6e4b 100644
--- a/main/inc/ajax/skill.ajax.php
+++ b/main/inc/ajax/skill.ajax.php
@@ -75,9 +75,7 @@ switch ($action) {
}
}
-
- Display::display_no_header();
-
+ Display::display_no_header();
Display::$global_template->assign('order_user_list', $ordered_user_list);
Display::$global_template->assign('total_search_skills', $count_skills);
@@ -132,7 +130,22 @@ switch ($action) {
} else {
echo 0;
}
- break;
+ break;
+ case 'get_skills_by_profile':
+ $skill_rel_profile = new SkillRelProfile();
+ $profile_id = isset($_REQUEST['profile_id']) ? $_REQUEST['profile_id'] : null;
+ $skills = $skill_rel_profile->get_skills_by_profile($profile_id);
+ echo json_encode($skills);
+ break;
+ case 'get_saved_profiles':
+ $skill_profile = new SkillProfile();
+ $profiles = $skill_profile->get_all();
+
+ Display::display_no_header();
+ Display::$global_template->assign('profiles', $profiles);
+ echo Display::$global_template->fetch('default/skill/profile_item.tpl');
+
+ break;
case 'get_skills':
$load_user_data = isset($_REQUEST['load_user_data']) ? $_REQUEST['load_user_data'] : null;
//$parent_id = intval($_REQUEST['parent_id']);
@@ -201,11 +214,12 @@ switch ($action) {
} else {
echo 0;
}
- break;
+ break;
case 'save_profile':
$skill_profile = new SkillProfile();
$params = $_REQUEST;
- $params['skills'] = isset($_SESSION['skills']) ? $_SESSION['skills'] : null;
+ //$params['skills'] = isset($_SESSION['skills']) ? $_SESSION['skills'] : null;
+ $params['skills'] = $params['skill_id'];
$skill_data = $skill_profile->save($params);
if (!empty($skill_data)) {
echo 1;
diff --git a/main/template/default/skill/profile_item.tpl b/main/template/default/skill/profile_item.tpl
new file mode 100644
index 0000000000..ec72046e10
--- /dev/null
+++ b/main/template/default/skill/profile_item.tpl
@@ -0,0 +1,11 @@
+{% if profiles is not null %}
+
{{"SkillProfiles"|get_lang}}
+
+
+{% endif %}
\ No newline at end of file
diff --git a/main/template/default/skill/skill_wheel.tpl b/main/template/default/skill/skill_wheel.tpl
index bcca9cd2c6..5aadcab8cc 100644
--- a/main/template/default/skill/skill_wheel.tpl
+++ b/main/template/default/skill/skill_wheel.tpl
@@ -86,11 +86,15 @@ function check_skills_sidebar() {
});
}
-function fill_skill_search_li(skill_id, skill_name) {
- return ' '+skill_name+'';
+function fill_skill_search_li(skill_id, skill_name, checked) {
+ checked_condition = '';
+ if (checked == 1) {
+ checked_condition = 'checked=checked';
+ }
+
+ return ' '+skill_name+'';
}
-
-
+
function check_skills_edit_form() {
//selecting only selected users
$("#parent_id option:selected").each(function() {
@@ -192,8 +196,7 @@ function delete_gradebook_from_skill(skill_id, gradebook_id) {
});
}
-function submit_profile_search_form() {
- $("#skill_wheel").remove();
+function return_skill_list_from_profile_search() {
var skill_list = {};
if ($("#profile_search li").length != 0) {
@@ -204,6 +207,13 @@ function submit_profile_search_form() {
}
});
}
+ return skill_list;
+}
+
+function submit_profile_search_form() {
+ $("#skill_wheel").remove();
+
+ var skill_list = return_skill_list_from_profile_search();
if (skill_list.length != 0) {
skill_list = { 'skill_id' : skill_list };
@@ -223,6 +233,14 @@ function submit_profile_search_form() {
}
+function add_skill_in_profile_list(skill_id, skill_name) {
+ if ($('#profile_match_item_'+skill_id).length == 0 ) {
+ $('#profile_search').append(''+skill_name+' ');
+ } else {
+ $('#profile_match_item_'+skill_id).remove();
+ }
+}
+
$(document).ready(function() {
/* Skill search */
@@ -230,11 +248,7 @@ $(document).ready(function() {
$("#skill_holder").on("click", "input.skill_to_select", function() {
skill_id = $(this).attr('rel');
skill_name = $(this).attr('name');
- if ($('#profile_match_item_'+skill_id).length == 0 ) {
- $('#profile_search').append(''+skill_name+' ');
- } else {
- $('#profile_match_item_'+skill_id).remove();
- }
+ add_skill_in_profile_list(skill_id, skill_name);
});
/* URL link when searching skills */
@@ -246,21 +260,51 @@ $(document).ready(function() {
/* Profile matcher */
-
-
+
/* Submit button */
$("#search_profile_form").submit(function() {
submit_profile_search_form();
+ return false;
+ });
+
+ $("#save_profile_form_button").submit(function() {
+ open_save_profile_popup();
+ return false;
});
/* Close button in profile matcher items */
$("#profile_search").on("click", "a.closebutton", function() {
- skill_id = $(this).attr('rel');
+ skill_id = $(this).attr('rel');
$('input[id=skill_to_select_id_'+skill_id+']').attr('checked', false);
$('#profile_match_item_'+skill_id).remove();
submit_profile_search_form();
- });
-
+ });
+
+ //Fill saved profiles list
+ update_my_saved_profiles();
+
+ /* Click in profile */
+ $("#saved_profiles").on("click", "a.load_profile", function() {
+ profile_id = $(this).attr('rel');
+ $.ajax({
+ url: '{{ url }}&a=get_skills_by_profile&profile_id='+profile_id,
+ success:function(json) {
+ skill_list = jQuery.parseJSON(json);
+ $('#skill_holder').empty();
+ jQuery.each(skill_list, function(index, skill_id) {
+ skill_info = get_skill_info(skill_id);
+ li = fill_skill_search_li(skill_id, skill_info.name, 1);
+ $("#skill_holder").append(li);
+ add_skill_in_profile_list(skill_id, skill_info.name);
+ });
+
+ submit_profile_search_form();
+
+
+ }
+ });
+ });
+
/* Wheel skill popup form */
@@ -317,6 +361,15 @@ $(document).ready(function() {
width : 600,
height : 550
});
+
+ //Save search profile dialog
+ $("#dialog-form-profile").dialog({
+ autoOpen: false,
+ modal : true,
+ width : 500,
+ height : 400
+ });
+
/* ...adding "+1" to "y" function's params is really funny */
/* Exexute the calculation based on a JSON file provided */
@@ -583,6 +636,50 @@ $(document).ready(function() {
}
}
+ function open_save_profile_popup() {
+ $("#dialog-form-profile").dialog({
+ buttons: {
+ "{{ "Save"|get_lang }}" : function() {
+ var params = $("#save_profile_form").serialize();
+ var skill_list = return_skill_list_from_profile_search();
+ skill_list = { 'skill_id' : skill_list };
+ skill_params = $.param(skill_list);
+
+ $.ajax({
+ url: '{{ url }}&a=save_profile&'+params+'&'+skill_params,
+ success:function(data) {
+ if (data == 1 ) {
+ update_my_saved_profiles();
+ alert("{{"Saved"|get_lang}}");
+ } else {
+ alert("{{ "Error"|get_lang }}");
+ }
+
+ $("#dialog-form-profile").dialog("close");
+ $("#name").attr('value', '');
+ $("#description").attr('value', '');
+
+ }
+ });
+ }
+ },
+ close: function() {
+ $("#name").attr('value', '');
+ $("#description").attr('value', '');
+ }
+ });
+ $("#dialog-form-profile").dialog("open");
+ }
+
+ function update_my_saved_profiles() {
+ $.ajax({
+ url: '{{ url }}&a=get_saved_profiles',
+ success:function(data) {
+ $("#saved_profiles").html(data);
+ }
+ });
+ }
+
function open_popup(d) {
//Cleaning selected
$("#gradebook_id").find('option').remove();
@@ -610,26 +707,27 @@ $(document).ready(function() {
jQuery.each(skill.gradebooks, function(index, data) {
$("#gradebook_id").append('