From acfb43936eb7c9fb187463534fcc3734c84e865e Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Wed, 29 Oct 2014 16:53:39 -0500 Subject: [PATCH] Allow delete searches skills profile - refs #7347 --- main/inc/ajax/skill.ajax.php | 12 ++++++++++++ main/inc/lib/skill.lib.php | 16 ++++++++++++++++ main/template/default/skill/profile_item.tpl | 5 +++-- main/template/default/skill/skill_wheel.tpl | 17 ++++++++++++++--- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/main/inc/ajax/skill.ajax.php b/main/inc/ajax/skill.ajax.php index cd3c7c13c0..dfd985fc16 100755 --- a/main/inc/ajax/skill.ajax.php +++ b/main/inc/ajax/skill.ajax.php @@ -332,6 +332,18 @@ switch ($action) { } } break; + case 'delete_profile': + if (api_is_platform_admin() || api_is_drh()) { + $profileId = $_REQUEST['profile']; + + $skillProfile = new SkillProfile(); + $isDeleted = $skillProfile->delete($profileId); + + echo json_encode(array( + 'status' => $isDeleted + )); + } + break; case 'skill_exists': $skill_data = $skill->get($_REQUEST['skill_id']); if (!empty($skill_data)) { diff --git a/main/inc/lib/skill.lib.php b/main/inc/lib/skill.lib.php index 4fc584f39d..8e2c94a899 100755 --- a/main/inc/lib/skill.lib.php +++ b/main/inc/lib/skill.lib.php @@ -66,6 +66,22 @@ class SkillProfile extends Model } return false; } + + /** + * Delete a skill profile + * @param int $id The skill profile id + * @return boolean Whether delete a skill profile + */ + public function delete($id) { + Database::delete( + $this->table_rel_profile, + array( + 'profile_id' => $id + ) + ); + + return parent::delete($id); + } } class SkillRelProfile extends Model diff --git a/main/template/default/skill/profile_item.tpl b/main/template/default/skill/profile_item.tpl index 1a485bc17d..df6ed587d5 100755 --- a/main/template/default/skill/profile_item.tpl +++ b/main/template/default/skill/profile_item.tpl @@ -3,8 +3,9 @@
diff --git a/main/template/default/skill/skill_wheel.tpl b/main/template/default/skill/skill_wheel.tpl index 669a4e5e03..55161a78ec 100644 --- a/main/template/default/skill/skill_wheel.tpl +++ b/main/template/default/skill/skill_wheel.tpl @@ -284,7 +284,7 @@ $(document).ready(function() { update_my_saved_profiles(); /* Click in profile */ - $("#saved_profiles").on("click", "a.load_profile", function() { + $("#saved_profiles").on("click", "li.load_profile", function() { profile_id = $(this).attr('rel'); $('#profile_id').attr('value',profile_id); $.ajax({ @@ -304,8 +304,19 @@ $(document).ready(function() { } }); }); - - + $("#saved_profiles").on('click', 'li.load_profile button.close', function () { + var $parent = $(this).parent(); + var profileId = $parent.attr('rel'); + + $.getJSON('{{ url }}&a=delete_profile', { + profile: profileId + }, function (response) { + if (response.status) { + $parent.remove(); + } + }); + }); + /* Wheel skill popup form */ /* Close button in gradebook select */