From: Sven Schöling Date: Fri, 23 Apr 2021 13:12:57 +0000 (+0200) Subject: MaterialComponents: Materialize modals als Ersatz für kivi.popup_dialog X-Git-Tag: kivitendo-mebil_0.1-0~9^2~85 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=6c90631576a61bfe8ee843d8f454d5759a2a5bb0;p=kivitendo-erp.git MaterialComponents: Materialize modals als Ersatz für kivi.popup_dialog --- diff --git a/js/kivi.Materialize.js b/js/kivi.Materialize.js index 83e4efb7f..56c5bbd5e 100644 --- a/js/kivi.Materialize.js +++ b/js/kivi.Materialize.js @@ -75,7 +75,71 @@ namespace("kivi.Materialize", function(ns) { showClearBtn: true, i18n: ns.build_i18n() }); + $('.modal').modal(); M.updateTextFields(); } + // alternative for kivi.popup_dialog. + // opens materialize modal instead. + // + // differences: M.modal can not load external content, so it needs to be fetched manually and inserted into the DOM. + ns.popup_dialog = function(params) { + console.log(params); + params = params || { }; + let id = params.id || 'jqueryui_popup_dialog'; + let $div; + let custom_close = params.dialog ? params.dialog.close : undefined; + let dialog_params = $.extend( + { // kivitendo default parameters. + // unlike classic layout, there is not fixed size, and M.modal is always... modal + onCloseStart: custom_close + }, + // User supplied options: + params.dialog || { }, + { // Options that must not be changed: + // close options already work + }); + + if (params.url) { + $.ajax({ + url: params.url, + data: params.data, + success: function(data) { + params.html = data; + params.url = undefined; + params.data = undefined; + ns.popup_dialog(params); + }, + error: function(x, status, error) { console.log(error); }, + dataType: 'text', + }); + return 1; + } + + if (params.html) { + $div = $('
'); + $div.attr('id', id) + $div.addClass("modal"); + let $modal_content = $('
'); + $modal_content.addClass('modal-content'); + $modal_content.html(params.html); + $div.append($modal_content); + $('body').append($div); + kivi.reinit_widgets(); + dialog_params.onCloseEnd = function() { $div.remove(); } + + $div.modal(dialog_params); + + } else if(params.id) { + $div = $('#' + params.id); + } else { + console.error("insufficient parameters to open dialog"); + return 0; + } + + $div.modal('open'); + + return true; + + } }); diff --git a/js/kivi.js b/js/kivi.js index b43028fb8..005cdd0e6 100644 --- a/js/kivi.js +++ b/js/kivi.js @@ -468,6 +468,9 @@ namespace("kivi", function(ns) { // - dialog: an optional object of options passed to the $.dialog() call // - load: an optional function that is called after the content has been loaded successfully (only if an AJAX call is made) ns.popup_dialog = function(params) { + if (kivi.Materialize) + return kivi.Materialize.popup_dialog(params); + var dialog; params = params || { };