Skip to content

Commit d398414

Browse files
committed
Merge pull request #850 from antgonza/delete_prep_template
Delete prep template
2 parents 502774a + 5de0e08 commit d398414

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

qiita_pet/handlers/study_handlers/description_handlers.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,33 @@ def delete_raw_data(self, study, user, callback):
613613

614614
callback((msg, msg_level, tab, tab_id, None))
615615

616+
def delete_prep_template(self, study, user, callback):
617+
"""Delete the selected prep template
618+
619+
Parameters
620+
----------
621+
study : Study
622+
The current study object
623+
user : User
624+
The current user object
625+
callback : function
626+
The callback function to call with the results once the processing
627+
is done
628+
"""
629+
prep_template_id = int(self.get_argument('prep_template_id'))
630+
prep_id = PrepTemplate(prep_template_id).raw_data
631+
632+
try:
633+
PrepTemplate.delete(prep_template_id)
634+
msg = ("Prep template %d has been deleted" % prep_template_id)
635+
msg_level = "success"
636+
prep_id = None
637+
except Exception as e:
638+
msg = ("Couldn't remove prep template: %s" % str(e))
639+
msg_level = "danger"
640+
641+
callback((msg, msg_level, 'raw_data_tab', prep_id, None))
642+
616643
@authenticated
617644
def get(self, study_id):
618645
study, user = self._get_sudy_and_check_access(study_id)
@@ -640,7 +667,8 @@ def post(self, study_id):
640667
request_approval=self.request_approval,
641668
make_sandbox=self.make_sandbox,
642669
update_investigation_type=self.update_investigation_type,
643-
delete_raw_data=self.delete_raw_data)
670+
delete_raw_data=self.delete_raw_data,
671+
delete_prep_template=self.delete_prep_template)
644672

645673
# Get the action that we need to perform
646674
action = self.get_argument("action", None)

qiita_pet/templates/study_description.html

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@
152152
}
153153
}
154154

155-
156155
function delete_raw_data(raw_data_filetype, raw_data_id) {
157156
if (confirm('Are you sure you want to delete raw data: ' + raw_data_filetype + ' (ID: ' + raw_data_id + ')?')) {
158157
var form = $("<form>")
@@ -171,6 +170,26 @@
171170
}
172171
}
173172

173+
function delete_prep_template(data_type, prep_template_id) {
174+
if (confirm('Are you sure you want to delete prep template: ' + data_type + ' (ID: ' + prep_template_id + ')?')) {
175+
var form = $("<form>")
176+
.attr("action", window.location.href)
177+
.attr("method", "post")
178+
.append($("<input>")
179+
.attr("type", "hidden")
180+
.attr("name", "prep_template_id")
181+
.attr("value", prep_template_id))
182+
.append($("<input>")
183+
.attr("type", "hidden")
184+
.attr("name", "action")
185+
.attr("value", "delete_prep_template"));
186+
$("body").append(form);
187+
form.submit();
188+
} else {
189+
return false;
190+
}
191+
}
192+
174193
function make_public() {
175194
if (confirm("Are you sure you want to make this study public?")) {
176195
var form = $("<form>")

qiita_pet/templates/study_description_templates/prep_template_panel.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ <h4 class="modal-title" id="myModalLabel">Choose preprocessing parameters</h4>
4141
<div class="panel panel-default">
4242
<div class="panel-heading">
4343
<h4 class="panel-title">
44-
<a data-toggle="collapse" data-parent="#prep-accordion" href="#collapse{{prep_id}}">{{data_type}} (ID: {{prep_id}})</a>
44+
<a data-parent="#prep-accordion" href="#collapse{{prep_id}}" style="pointer-events: none; cursor: default;">{{data_type}} (ID: {{prep_id}})</a>
45+
<button class="close" title="Remove this prep template" type="button" onclick="delete_prep_template('{{data_type}}', {{prep_id}})">&nbsp; ×</button>
4546
</h4>
4647
</div>
4748
<div id="collapse{{prep_id}}" class="panel-collapse collapse in">

0 commit comments

Comments
 (0)