Commit e2447648 by Szeberényi Imre

Merge branch 'master' of https://git.ik.bme.hu/circle/cloud

parents 4da7b486 27f8bc06
...@@ -535,7 +535,6 @@ if get_env_variable('DJANGO_SAML', 'FALSE') == 'TRUE': ...@@ -535,7 +535,6 @@ if get_env_variable('DJANGO_SAML', 'FALSE') == 'TRUE':
SESSION_EXPIRE_AT_BROWSER_CLOSE = True SESSION_EXPIRE_AT_BROWSER_CLOSE = True
LOGIN_REDIRECT_URL = "/" LOGIN_REDIRECT_URL = "/"
AGENT_DIR = get_env_variable( AGENT_DIR = get_env_variable(
......
...@@ -27,83 +27,129 @@ $(function() { ...@@ -27,83 +27,129 @@ $(function() {
return false; return false;
}); });
/* operations */ function initAutocompleteSelect2($root) {
$('#ops, #vm-details-resources-disk, #vm-details-renew-op, #vm-details-pw-reset, #vm-details-add-interface, .operation-wrapper').on('click', '.operation', function(e) { $root.find('select[data-autocomplete-light-function="select2"]').each(function () {
var icon = $(this).children("i").addClass('fa-spinner fa-spin'); var $el = $(this);
$.ajax({ // már initelve?
type: 'GET', if ($el.hasClass('select2-hidden-accessible')) return;
url: $(this).attr('href'),
success: function(data) { var url = $el.data('autocomplete-light-url');
icon.removeClass("fa-spinner fa-spin"); var placeholder = $el.data('placeholder') || '';
$('body').append(data);
$('#confirmation-modal').modal('show'); $el.select2({
$('#confirmation-modal').on('hidden.bs.modal', function() { dropdownParent: $root, // bootstrap modal fókusz miatt
$('#confirmation-modal').remove(); width: 'resolve',
}); placeholder: placeholder,
allowClear: true,
$('#vm-migrate-node-list li input:checked').closest('li').addClass('panel-primary'); ajax: {
} url: url,
dataType: 'json',
delay: 250,
data: function (params) {
return { q: params.term, page: params.page || 1 };
},
processResults: function (data) {
// DAL autocomplete view tipikusan már {results: [...], pagination: {more: ...}}
return data;
}
},
// data-html="true" miatt: hagyjuk az HTML-t renderelődni
escapeMarkup: function (m) { return m; }
});
}); });
e.preventDefault(); }
});
function showConfirmationModal(data) {
// ha valamiért bent maradt egy régi modal, takarítsuk (örökölt kódnál előfordul)
$('#confirmation-modal').remove();
$('body').append(data);
var $modal = $('#confirmation-modal');
$modal.modal('show');
initAutocompleteSelect2($modal);
// egyszer fusson csak
$modal.one('hidden.bs.modal', function () {
$modal.remove();
});
return $modal;
}
/* operations */
$('#ops, #vm-details-resources-disk, #vm-details-renew-op, #vm-details-pw-reset, #vm-details-add-interface, .operation-wrapper')
.on('click', '.operation', function (e) {
e.preventDefault();
var $icon = $(this).children("i").addClass('fa-spinner fa-spin');
$.ajax({
type: 'GET',
url: $(this).attr('href'),
success: function (data) {
$icon.removeClass("fa-spinner fa-spin");
var $modal = showConfirmationModal(data);
// megmaradt a korábbi, specifikus UI tweak
$modal.find('#vm-migrate-node-list li input:checked').closest('li').addClass('panel-primary');
},
error: function () {
$icon.removeClass("fa-spinner fa-spin");
}
});
});
/* if the operation fails show the modal again */ /* if the operation fails show the modal again */
$("body").on("click", "#confirmation-modal #op-form-send", function() { $("body").on("submit", "#confirmation-modal form", function (e) {
var url = $(this).closest("form").prop("action"); e.preventDefault()
var $form = $(this);
var url = $form.attr("action");
$.ajax({ $.ajax({
url: url, url: url,
headers: {"X-CSRFToken": getCookie('csrftoken')}, headers: { "X-CSRFToken": getCookie('csrftoken') },
type: 'POST', type: 'POST',
data: $(this).closest('form').serialize(), data: $form.serialize(),
success: function(data, textStatus, xhr) { success: function (data) {
/* hide the modal we just submitted */ // mindig zárjuk le az aktuális modalt
$('#confirmation-modal').modal("hide"); $('#confirmation-modal').modal("hide");
/* if it was successful trigger a click event on activity, this will if (data.success) {
* - go to that tab
* - starts refreshing the activity
*/
if(data.success) {
$('a[href="#activity"]').trigger("click"); $('a[href="#activity"]').trigger("click");
if(data.with_reload) {
// when the activity check stops the page will reload if (data.with_reload) {
reload_vm_detail = true; reload_vm_detail = true;
} }
/* if there are messages display them */ if (data.messages && data.messages.length > 0) {
if(data.messages && data.messages.length > 0) {
addMessage(data.messages.join("<br />"), data.success ? "success" : "danger"); addMessage(data.messages.join("<br />"), data.success ? "success" : "danger");
} }
} } else {
else { // a bezárás után nyissuk meg az új (hibás) modalt
/* if the post was not successful wait for the modal to disappear $('#confirmation-modal').one('hidden.bs.modal', function () {
* then append the new modal showConfirmationModal(data);
*/
$('#confirmation-modal').on('hidden.bs.modal', function() {
$('body').append(data);
$('#confirmation-modal').modal('show');
$('#confirmation-modal').on('hidden.bs.modal', function() {
$('#confirmation-modal').remove();
});
}); });
} }
}, },
error: function(xhr, textStatus, error) { error: function (xhr) {
$('#confirmation-modal').modal("hide"); $('#confirmation-modal').modal("hide");
if (xhr.status == 500) { if (xhr.status === 500) {
addMessage("500 Internal Server Error", "danger"); addMessage("500 Internal Server Error", "danger");
} else { } else {
addMessage(xhr.status + " Unknown Error", "danger"); addMessage(xhr.status + " Unknown Error", "danger");
} }
} }
}); });
return false; return false;
}); });
function decideActivityRefresh() { function decideActivityRefresh() {
var check = false; var check = false;
/* if something is still spinning */ /* if something is still spinning */
......
...@@ -29,6 +29,39 @@ $(function () { ...@@ -29,6 +29,39 @@ $(function () {
return false; return false;
}); });
function initAutocompleteSelect2($root) {
$root.find('select[data-autocomplete-light-function="select2"]').each(function () {
var $el = $(this);
// már initelve?
if ($el.hasClass('select2-hidden-accessible')) return;
var url = $el.data('autocomplete-light-url');
var placeholder = $el.data('placeholder') || '';
$el.select2({
dropdownParent: $root, // bootstrap modal fókusz miatt
width: 'resolve',
placeholder: placeholder,
allowClear: true,
ajax: {
url: url,
dataType: 'json',
delay: 250,
data: function (params) {
return { q: params.term, page: params.page || 1 };
},
processResults: function (data) {
// DAL autocomplete view tipikusan már {results: [...], pagination: {more: ...}}
return data;
}
},
// data-html="true" miatt: hagyjuk az HTML-t renderelődni
escapeMarkup: function (m) { return m; }
});
});
}
$('.group-create, .group-import, .group-export, .node-create, .tx-tpl-ownership, .group-delete, .node-delete, .disk-remove, .template-delete, .delete-from-group, .group-remove-all-btn, .lease-delete').click(function(e) { $('.group-create, .group-import, .group-export, .node-create, .tx-tpl-ownership, .group-delete, .node-delete, .disk-remove, .template-delete, .delete-from-group, .group-remove-all-btn, .lease-delete').click(function(e) {
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
...@@ -37,6 +70,7 @@ $(function () { ...@@ -37,6 +70,7 @@ $(function () {
$('body').append(data); $('body').append(data);
var modal = $('#confirmation-modal'); var modal = $('#confirmation-modal');
modal.modal('show'); modal.modal('show');
initAutocompleteSelect2(modal);
modal.on('hidden.bs.modal', function() { modal.on('hidden.bs.modal', function() {
modal.remove(); modal.remove();
}); });
......
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