From 6c90631576a61bfe8ee843d8f454d5759a2a5bb0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Fri, 23 Apr 2021 15:12:57 +0200 Subject: [PATCH] =?utf8?q?MaterialComponents:=20Materialize=20modals=20als?= =?utf8?q?=20Ersatz=20f=C3=BCr=20kivi.popup=5Fdialog?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- js/kivi.Materialize.js | 64 ++++++++++++++++++++++++++++++++++++++++++ js/kivi.js | 3 ++ 2 files changed, 67 insertions(+) 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 || { }; -- 2.20.1