From fd59d34aa2440e6258a90845eba9a1b9b4d3893d Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Thu, 17 Nov 2016 14:28:35 +0800 Subject: webui: Implement "showModal()" in "main.js" allowing use in others --- fg21sim/webui/static/js/main.js | 55 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'fg21sim/webui/static/js/main.js') diff --git a/fg21sim/webui/static/js/main.js b/fg21sim/webui/static/js/main.js index ea29e0f..8d843a9 100644 --- a/fg21sim/webui/static/js/main.js +++ b/fg21sim/webui/static/js/main.js @@ -94,6 +94,61 @@ var toggleBlock = function (toggle, targetBlock) { }; +/** + * Compose the notification contents and shown them in the modal box. + * + * The input `modalBox` may be a jQuery object or a jQuery selector of the + * target modal box. + * + * The input `data` may have the following attributes: + * - `icon` : FontAwesome icon (specified without the beginning `fa-`) + * - `message` : Main summary message + * - `code` : Error code if it is an error notification + * - `reason` : Reason of the error + * - `buttons` : A list of buttons, which have these attributes: + * + `text` : Button name + * + `class` : {String} Button classes + * + `click` : {Function} Function called on click. + * To close the modal, use `$.modal.close()` + */ +var showModal = function (modalBox, data) { + modalBox = $(modalBox); + // Empty previous contents + modalBox.html(""); + var p = $("

"); + if (data.icon) { + $("").addClass("fa fa-2x").addClass("fa-" + data.icon).appendTo(p); + } + if (data.message) { + $("").text(" " + data.message).appendTo(p); + } + modalBox.append(p); + if (data.code) { + modalBox.append($("

Error Code:

") + .append($("") + .addClass("label label-warning") + .text(data.code))); + } + if (data.reason) { + modalBox.append($("

Reason:

") + .append($("") + .addClass("label label-warning") + .text(data.reason))); + } + if (data.buttons) { + p = $("

").addClass("button-group"); + data.buttons.forEach(function (btn) { + $("