more comprehensible vc form display flow

This commit is contained in:
fbsanchez 2019-10-03 11:04:13 +02:00
parent 2ec659baac
commit 722ba58085
2 changed files with 45 additions and 34 deletions

View File

@ -1403,8 +1403,15 @@ function copyVisualConsoleItem(baseUrl, vcId, vcItemId, callback) {
};
}
/**
* When invoking modals from JS, some DOM id could be repeated.
* This method cleans DOM to avoid duplicated IDs.
*/
function cleanupDOM() {
$("#modalVCItemForm").empty();
}
/* Defined in operations/visual_console/view.php */
/* global showMsg,cleanupDOM,$,load_modal */
/* global handleFormResponse,$,load_modal */
function createOrUpdateVisualConsoleItem(
visualConsole,
asyncTaskManager,
@ -1420,7 +1427,17 @@ function createOrUpdateVisualConsoleItem(
target: $("#modalVCItemForm"),
form: "itemForm",
url: baseUrl + "ajax.php",
ajax_callback: showMsg,
ajax_callback: function(response) {
var item = handleFormResponse(response);
if (item == false) {
// Error.
return;
}
// Success.
console.log(item);
},
cleanup: cleanupDOM,
modal: {
title: title,

View File

@ -541,7 +541,7 @@ ui_require_css_file('form');
/**
* Process ajax responses and shows a dialog with results.
*/
function showMsg(data) {
function handleFormResponse(data) {
var title = "<?php echo __('Success'); ?>";
var text = '';
var failed = 0;
@ -564,6 +564,7 @@ ui_require_css_file('form');
});
}
if (failed == 1) {
$('#modalVCItemFormMsg').empty();
$('#modalVCItemFormMsg').html(text);
$('#modalVCItemFormMsg').dialog({
@ -580,24 +581,17 @@ ui_require_css_file('form');
class: "ui-widget ui-state-default ui-corner-all ui-button-text-only sub ok submit-next",
text: 'OK',
click: function(e) {
if (!failed) {
$(".ui-dialog-content").dialog("close");
$('.info').hide();
cleanupDOM();
} else {
$(this).dialog('close');
}
}
}
]
});
// Failed.
return false;
}
/**
* When invoking modals from JS, some DOM id could be repeated.
* This method cleans DOM to avoid duplicated IDs.
*/
function cleanupDOM() {
$("#modalVCItemForm").empty();
// Success, return result.
return data['result'];
}
</script>