var mdDialogDefaultOpts = { get: function (name, _default) { var opts = _default; var cookieOpts = cfs_getCookie(name); if (cookieOpts && cookieOpts != "") { var optsArr = (cookieOpts + "").split("^"); var optsKeys = Object.keys(_default); for (var x = 0; x < optsArr.length; x++) { var optKey = optsKeys[x]; if (Array.isArray(_default[optKey])) { _default[optKey] = optsArr[x].split(","); } else if (typeof _default[optKey] == "boolean") { _default[optKey] = (optsArr[x] == "true"); } else { _default[optKey] = optsArr[x]; } } } return opts; }, set: function (name, _value) { var stringy = "", valKeys = Object.keys(_value); for (var x = 0; x < valKeys.length; x++) { stringy += _value[valKeys[x]] + "^"; } cfs_setCookie(name, stringy, 365); } }; var dialogErrorShown = false; function mdDialogCloseBox() { $(".md-dialog, #md-dialog-blackout").hide(); $("body").css("overflow", "auto"); } function mdDialogCloseError() { if (dialogErrorShown) { $(".md-dialog, #md-dialog-blackout").hide(); $("body").css("overflow", "auto"); dialogErrorShown = false; } } function showSimpleDialogError(img, title, body, withCountdown) { var _htm = ""; _htm += "" + title + ""; _htm += "

" + title + "

"; _htm += "

" + body + "

"; if (withCountdown) { _htm += "Trying again in 60 seconds."; } dialogErrorShown = true; mdDialogBox(null, _htm, null, false, false, [], false, true, true); $("#md-dialog-box").addClass("error-modal"); } function showSimpleDialog(body) { mdDialogBox("", body, null, false, false, [], false, false, false, true); } function mdDialogMessage(message) { mdDialogBox("", "

" + message + "

", [{ text: "Close", click: function () { mdDialogCloseBox(); } }], false, false, null, false, true); } function mdDialogMaxToggle() { $('.md-dialog').toggleClass('maxxed'); if ($('.md-dialog').hasClass("maxxed")) { $(".md-dialog .mdDialogMax > i").removeClass("mdi-window-maximize").addClass("mdi-dock-window"); } else { $(".md-dialog .mdDialogMax > i").addClass("mdi-window-maximize").removeClass("mdi-dock-window"); } mdAutoSize("md-dialog-box-true-undefined"); } function mdDialogBox(title, body, options, fullHeight, sideSheet, headerOptions, noAnimate, prompt, noClose, halfWidth, closeFunc, fitChild, md3) { if (md3) return md3DialogBox(title, body, options, fullHeight, sideSheet, headerOptions, noAnimate, prompt, noClose, halfWidth, closeFunc, fitChild); var dialogId = "md-dialog-box"; // + fullHeight + "-" + sideSheet; if (fullHeight || sideSheet) { dialogId += "-" + fullHeight + "-" + sideSheet; } var container = document.getElementById(dialogId); var blackout = document.getElementById("md-dialog-blackout"); if (blackout == null) { blackout = document.createElement("div"); $(blackout).attr("id", "md-dialog-blackout"); document.body.appendChild(blackout); } if (container == null) { container = document.createElement("div"); $(container).attr("id", dialogId).addClass("md-dialog"); document.body.appendChild(container); } $(container).removeClass("full-height").removeClass("modal").removeClass("side-sheet").removeClass("prompt").removeClass("half-width").removeClass("fit-child"); var bodyOnly = (title === null && options === null); var _html = ""; if (title === null) { if (noClose !== true) { _html += "
" + (fullHeight === true ? "" : "") + "
"; } } else { _html += "
" + (noClose === true ? "" : "") + "" + (fullHeight === true ? "" : "") + "

" + title + "

"; } _html += "
" + body + "
"; if (options !== null && options.length > 0) { _html += ""; } _html += "
"; $(container).html(_html); if (fullHeight === true) $(container).addClass("full-height"); if (prompt === true) $(container).addClass("prompt"); if (halfWidth === true) $(container).addClass("half-width"); if (fitChild === true) $(container).addClass("fit-child"); $(container).addClass((sideSheet === true ? "side-sheet" : "modal")); $(options).each(function () { var opt = this; var bt = document.createElement("a"); $(bt).html(opt.text).click(function () { opt.click(); if (opt.noClose !== true) { mdDialogCloseBox(); } }); if (opt.left === true) { $(bt).addClass("left"); } if (opt.class) { $(bt).addClass(opt.class); } $("#" + dialogId + " footer").append(bt); }); $(headerOptions).each(function () { var opt = this; var bt = document.createElement("a"); $(bt).addClass("toolbar-button").html(opt.text).click(function () { opt.click(); }); $("#" + dialogId + " header.dialog").append(bt); }); $(container).show(); try { renderTooltips(); } catch (e) { } if (sideSheet === true) { if (noAnimate === true) { $(container).css({ right: "-0" }); } else { $(container).css({ right: "-580px" }); $(container).animate({ right: 0 }, 400); } } if (fullHeight) { /* If we're editing a full height dialog, hide any side-sheets */ $(".md-dialog.side-sheet").animate({ right: "-580px" }, 500); } if ($('.wysiwyg-editor', container).length > 0) { $('.wysiwyg-editor', container).trumbowyg({ autogrow: false, btns: [ ['strong', 'em', 'underline'], ['unorderedList', 'orderedList'] ] }); } if (fullHeight) { $(window).resize(function () { mdAutoSize(dialogId); }); setTimeout(function () { mdAutoSize(dialogId); }, 5); } $(blackout).show(); $(blackout).unbind("click"); if (noClose !== true) { $(blackout).click(function () { mdDialogCloseBox(); if (closeFunc) { closeFunc(); } }); } $('a.mdDialogClose').click(function () { mdDialogCloseBox(); if (closeFunc) { closeFunc(); } }); $("body").css("overflow", "hidden"); modalResizer(); } // Bridge between old md modal and new md3 modal, aiming for 100% compatibility function md3DialogBox(title, body, options, fullHeight, sideSheet, headerOptions, noAnimate, prompt, noClose, halfWidth, closeFunc, fitChild) { let opts = ''; if (fullHeight === true) opts += "fullheight "; if (noAnimate === true) opts += "noanimate "; if (prompt === true) opts += ("prompt "); if (halfWidth === true) opts += ("halfwidth "); if (fitChild === true) opts += ("fitchild "); if (noClose === true) opts += ("noclose "); const bodyOnly = title ? false : true; let buttons = []; $(options).each(function () { const opt = this; if (opt.show !== false) buttons.push({ type: opt.class, onclick: opt.click, label: opt.text, options: opt.left ? 'left' : '' }) }) // Construct body body = `
${body}
`; durell.cfs.onboarding.modal.create([ { type: "html", options: `md-compatible ${opts} large`, header: { title: title }, content: body, footer: buttons } ]) } function mdAutoSize(dialogId) { var reservedHeight = 0; $("#" + dialogId + " header, #" + dialogId + " footer, #" + dialogId + " article .filter-block:visible, #" + dialogId + " article .trumbowyg-box .trumbowyg-button-pane").each(function () { reservedHeight += $(this).outerHeight(); }); if ($("#" + dialogId + " article .trumbowyg-box .trumbowyg-editor").length > 0) { reservedHeight += 116; var availableHeight = $("#" + dialogId).height() - reservedHeight; $("#" + dialogId + " article .trumbowyg-box .trumbowyg-editor").height(availableHeight); } if ($("#" + dialogId + " article .report-builder").length > 0) { reservedHeight += 40; var availableHeight = $("#" + dialogId).height() - reservedHeight; $("#" + dialogId + " article .report-builder").height(availableHeight); } if ($("#" + dialogId + " article .trumbowyg-box .message-body.trumbowyg-editor").length > 0) { reservedHeight += 56; var availableHeight = $("#" + dialogId).height() - reservedHeight; $("#" + dialogId + " article .trumbowyg-box .message-body.trumbowyg-editor").height(availableHeight); } } function mdDialogError(text, dialogId) { var dialog; if (!dialogId) { dialog = $(".md-dialog").eq(0); } else { dialog = $("#" + dialogId); } var current = dialog.find("footer .error"); if (current.length == 0) { if (dialog.find("footer a.left").length > 0) { dialog.find("footer a.left").last().after("" + text + ""); } else { dialog.find("footer").prepend("" + text + ""); } } else { dialog.find("footer .error strong").html(text); dialog.find("footer .error").show(); } } function modalResizer() { if ($("section .md-card.modal").is(":visible")) { if ($(window).height() > $("section .md-card.modal").height()) { $("section .md-card.modal").css("overflow-y", "visible"); } else { $("section .md-card.modal").css("overflow-y", "auto"); } } } // ========================================= // New MD3 Dialog made as part of New Durell - idea is for MdDialog to hook into this eventually // ========================================= function createMD3Dialog(message, confirmText, cancelText, confirmOnClick, title = "", cancelButtonType = "Sub", halfCols = false) { const modal = [ { content: `

${message}

`, footer: [ { type: "Main", label: confirmText, onclick: confirmOnClick, options: !halfCols ? "half-bottom-margin" : "okcancel -ok-wider" }, { type: cancelButtonType, label: cancelText, onclick: function () { durell.cfs.modal.close($(this)); }, options: !halfCols? "": "okcancel -cancel-wider secondary" } ], options: 'small noclose', type: 'html' } ]; if (!durell.cfs.isEmpty(title)) { modal[0].header = { title: title }; } // Bit roundabout this references onboarding but not entirely sure how to go about decoupling it durell.cfs.onboarding.modal.create(modal); }