Commit 064dbddf by Kálmán Viktor

dashboard: js modal for all vm operations

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