Commit 064dbddf by Kálmán Viktor

dashboard: js modal for all vm operations

parent 82a3942b
...@@ -34,6 +34,7 @@ $(function() { ...@@ -34,6 +34,7 @@ $(function() {
/* if the operation fails show the modal again */ /* if the operation fails show the modal again */
$("body").on("click", "#op-form-send", function() { $("body").on("click", "#op-form-send", function() {
var url = $(this).closest("form").prop("action"); var url = $(this).closest("form").prop("action");
$.ajax({ $.ajax({
url: url, url: url,
headers: {"X-CSRFToken": getCookie('csrftoken')}, headers: {"X-CSRFToken": getCookie('csrftoken')},
...@@ -44,9 +45,12 @@ $(function() { ...@@ -44,9 +45,12 @@ $(function() {
if(data.redirect) { if(data.redirect) {
$('a[href="#activity"]').trigger("click"); $('a[href="#activity"]').trigger("click");
if(data.messages.length > 0) {
addMessage(data.messages.join("<br />"), "danger");
}
} }
else { else {
var r = $('#confirmation-modal'); r.next('div').remove(); r.remove();
$('body').append(data); $('body').append(data);
$('#confirmation-modal').modal('show'); $('#confirmation-modal').modal('show');
$('#confirmation-modal').on('hidden.bs.modal', function() { $('#confirmation-modal').on('hidden.bs.modal', function() {
......
...@@ -19,9 +19,7 @@ Do you want to do the following operation on {{obj}}: ...@@ -19,9 +19,7 @@ Do you want to do the following operation on {{obj}}:
<div class="pull-right"> <div class="pull-right">
<a class="btn btn-default" href="{{object.get_absolute_url}}" <a class="btn btn-default" href="{{object.get_absolute_url}}"
data-dismiss="modal">{% trans "Cancel" %}</a> data-dismiss="modal">{% trans "Cancel" %}</a>
<button class="btn btn-danger" type="submit" <button class="btn btn-danger" type="submit" id="op-form-send">
{% if form %}id="op-form-send"{% endif %}
>
{% if op.icon %}<i class="icon-{{op.icon}}"></i> {% endif %}{{ op|capfirst }} {% if op.icon %}<i class="icon-{{op.icon}}"></i> {% endif %}{{ op|capfirst }}
</button> </button>
</div> </div>
......
...@@ -573,6 +573,19 @@ class VmOperationView(OperationView): ...@@ -573,6 +573,19 @@ class VmOperationView(OperationView):
model = Instance model = Instance
context_object_name = 'instance' # much simpler to mock object context_object_name = 'instance' # much simpler to mock object
def post(self, request, *args, **kwargs):
resp = super(VmOperationView, self).post(request, *args, **kwargs)
if request.is_ajax():
store = messages.get_messages(request)
store.used = True
return HttpResponse(
json.dumps({'redirect': resp.url,
'messages': [unicode(m) for m in store]}),
content_type="application=json"
)
else:
return resp
class FormOperationMixin(object): class FormOperationMixin(object):
......
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