Commit efcda103 by Oláh István Gergely

dashboard: add remove_trait js script, add data-pk to template

parent 85ae443d
...@@ -196,6 +196,31 @@ $(function() { ...@@ -196,6 +196,31 @@ $(function() {
} }
// remove trait
$('.node-details-remove-trait').click(function() {
var to_remove = $(this).data("trait-pk");
var clicked = $(this);
$.ajax({
type: 'POST',
url: location.href,
headers: {"X-CSRFToken": getCookie('csrftoken')},
data: {'to_remove': to_remove},
success: function(re) {
if(re['message'].toLowerCase() == "success") {
$(clicked).closest(".label").fadeOut(500, function() {
$(this).remove();
});
}
},
error: function() {
addMessage(re['message'], 'danger');
}
});
return false;
});
// refresh the given contents, parameter is the array of contents, in pair // refresh the given contents, parameter is the array of contents, in pair
function contentrefresh(elements,callbacks){ function contentrefresh(elements,callbacks){
for (var i = 0; i < elements.length; i+=2) { for (var i = 0; i < elements.length; i+=2) {
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
{% for t in node.traits.all %} {% for t in node.traits.all %}
<div class="label label-success label-tag" style="display: inline-block"> <div class="label label-success label-tag" style="display: inline-block">
{{ t }} {{ t }}
<a href="#" class="node-details-remove-trait"><i class="icon-remove"></i></a> <a data-trait-pk="{{ t.pk }}" href="#" class="node-details-remove-trait"><i class="icon-remove"></i></a>
</div> </div>
{% endfor %} {% endfor %}
{% else %} {% else %}
......
...@@ -531,8 +531,7 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView): ...@@ -531,8 +531,7 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
try: try:
to_remove = request.POST.get('to_remove') to_remove = request.POST.get('to_remove')
self.object = self.get_object() self.object = self.get_object()
self.object.traits.remove(to_remove)
self.object.tags.remove(to_remove)
message = u"Success" message = u"Success"
except: # note this won't really happen except: # note this won't really happen
message = u"Not success" message = u"Not success"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment