Warning, /network/angelfish/lib/contents/ui/JavaScriptDialogSheet.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2020 Jonah BrĂ¼chert <jbb@kaidan.im>
0002 //
0003 // SPDX-License-Identifier: GPL-2.0-or-later
0004 
0005 import QtQuick 2.7
0006 import QtQuick.Controls 2.2 as Controls
0007 import org.kde.kirigami 2.20 as Kirigami
0008 import QtQuick.Layouts 1.2
0009 
0010 import QtWebEngine 1.4
0011 
0012 Kirigami.PromptDialog {
0013     id: root
0014     property JavaScriptDialogRequest request
0015     
0016     onAccepted: root.request.dialogAccept()
0017     onRejected: root.request.dialogReject()
0018 
0019     onVisibleChanged: {
0020         if (root.visible) {
0021             switch(request.type) {
0022             case JavaScriptDialogRequest.DialogTypeAlert:
0023                 root.standardButtons = Kirigami.Dialog.Close;
0024                 root.customFooterActions = [];
0025                 inputField.visible = false;
0026                 break;
0027             case JavaScriptDialogRequest.DialogTypeConfirm:
0028                 root.standardButtons = Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel;
0029                 root.customFooterActions = [];
0030                 inputField.visible = false;
0031                 break;
0032             case JavaScriptDialogRequest.DialogTypePrompt:
0033                 root.standardButtons = Kirigami.Dialog.Cancel;
0034                 root.customFooterActions = [root.submitAction];
0035                 inputField.text = "";
0036                 inputField.visible = true;
0037                 break;
0038             case JavaScriptDialogRequest.DialogTypeBeforeUnload:
0039                 root.standardButtons = Kirigami.Dialog.NoButton
0040                 root.customFooterActions = [root.leavePageAction];
0041                 inputField.visible = false;
0042                 break;
0043             }
0044         } else {
0045             root.request.dialogReject()
0046         }
0047     }
0048     
0049     title: i18n("This page says")
0050     
0051     ColumnLayout {
0052         spacing: Kirigami.Units.smallSpacing
0053         
0054         Controls.Label {
0055             Layout.fillWidth: true
0056             wrapMode: Text.Wrap
0057             text: {
0058                 if (request) {
0059                     if (request.message) {
0060                         return request.message
0061                     }
0062 
0063                     if (request.type == JavaScriptDialogRequest.DialogTypeBeforeUnload) {
0064                         return i18n("The website asks for confirmation that you want to leave. Unsaved information might not be saved.")
0065                     }
0066                 }
0067 
0068                 return ""
0069             }
0070         }
0071         
0072         Controls.TextField {
0073             id: inputField
0074             Layout.fillWidth: true
0075         }
0076     }
0077 
0078     property var leavePageAction: Kirigami.Action {
0079         text: i18n("Leave page")
0080         onTriggered: {
0081             root.request.dialogAccept()
0082             root.close()
0083         }
0084     }
0085     
0086     property var submitAction: Kirigami.Action {
0087         text: i18n("Submit")
0088         icon.name: "dialog-ok"
0089         onTriggered: {
0090             root.request.dialogAccept(inputField.text)
0091             root.close()
0092         }
0093     }
0094 }