Browse Source

Allow delete searches skills profile - refs #7347

Angel Fernando Quiroz Campos 10 years ago
parent
commit
acfb43936e

+ 12 - 0
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)) {

+ 16 - 0
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

+ 3 - 2
main/template/default/skill/profile_item.tpl

@@ -3,8 +3,9 @@
         <div class="items_save">
             <ul class="holder_simple">
             {%for profile in profiles %}
-            <li class="bit-box">
-                <a class="load_profile" rel="{{ profile.id }}" href="#">{{ profile.name }}</a>
+            <li class="bit-box load_profile" rel="{{ profile.id }}" >
+                <button class="close">&times;</button>
+                <a href="#">{{ profile.name }}</a>
             </li>        
             {% endfor %}
             </ul>

+ 14 - 3
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 */