status-desktop/ui/app/AppLayouts/Onboarding/popups/KeycardCreatePINModal.qml

116 lines
3.4 KiB
QML
Raw Normal View History

2021-09-24 12:03:57 +00:00
import QtQuick 2.13
import QtQuick.Controls 2.13
2021-10-05 09:12:10 +00:00
import QtQuick.Layouts 1.13
2021-10-05 09:12:10 +00:00
import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1
2021-09-24 12:03:57 +00:00
import StatusQ.Controls 0.1
2021-10-05 09:12:10 +00:00
import StatusQ.Popups 0.1
import utils 1.0 as Imports
import "../../../../shared"
import "../../../../shared/controls"
import "../../../../shared/keycard"
2021-09-24 12:03:57 +00:00
2021-10-05 09:12:10 +00:00
StatusModal {
2021-09-24 12:03:57 +00:00
property bool firstPINFieldValid: false
property bool repeatPINFieldValid: false
property string pinValidationError: ""
property string repeatPINValidationError: ""
2021-10-01 10:22:51 +00:00
property bool submitted: false
2021-09-24 12:03:57 +00:00
signal submitBtnClicked(string pin)
2021-09-24 12:03:57 +00:00
id: popup
2021-10-05 09:12:10 +00:00
header.title: qsTr("Create PIN")
anchors.centerIn: parent
2021-09-24 12:03:57 +00:00
height: 500
onOpened: {
2021-10-01 10:22:51 +00:00
submitted = false
2021-09-24 12:03:57 +00:00
firstPINField.text = "";
firstPINField.forceActiveFocus(Qt.MouseFocusReason)
}
2021-10-05 09:12:10 +00:00
contentItem: Item {
Input {
id: firstPINField
anchors.rightMargin: 56
anchors.leftMargin: 56
anchors.top: parent.top
anchors.topMargin: 88
placeholderText: qsTr("New PIN")
textField.echoMode: TextInput.Password
onTextChanged: {
[firstPINFieldValid, pinValidationError] =
Imports.Utils.validatePINs("first", firstPINField, repeatPINField);
}
2021-09-24 12:03:57 +00:00
}
2021-10-05 09:12:10 +00:00
Input {
id: repeatPINField
enabled: firstPINFieldValid
anchors.rightMargin: 0
anchors.leftMargin: 0
anchors.right: firstPINField.right
anchors.left: firstPINField.left
anchors.top: firstPINField.bottom
anchors.topMargin: 32
placeholderText: qsTr("Confirm PIN")
textField.echoMode: TextInput.Password
Keys.onReturnPressed: function(event) {
if (submitBtn.enabled) {
submitBtn.clicked(event)
}
}
onTextChanged: {
[repeatPINFieldValid, repeatPINValidationError] =
Imports.Utils.validatePINs("repeat", firstPINField, repeatPINField);
2021-09-24 12:03:57 +00:00
}
}
2021-10-05 09:12:10 +00:00
StatusBaseText {
id: validationError
text: {
if (pinValidationError !== "") return pinValidationError;
if (repeatPINValidationError !== "") return repeatPINValidationError;
return "";
}
anchors.top: repeatPINField.bottom
anchors.topMargin: 20
anchors.right: parent.right
anchors.left: parent.left
horizontalAlignment: Text.AlignHCenter
color: Theme.palette.dangerColor1
font.pixelSize: 11
2021-09-24 12:03:57 +00:00
}
2021-10-05 09:12:10 +00:00
StatusBaseText {
text: qsTr("Create a 6 digit long PIN")
wrapMode: Text.WordWrap
anchors.right: parent.right
anchors.left: parent.left
horizontalAlignment: Text.AlignHCenter
anchors.bottom: parent.bottom
anchors.bottomMargin: 20
color: Theme.palette.directColor1
font.pixelSize: 12
}
2021-09-24 12:03:57 +00:00
}
2021-10-05 09:12:10 +00:00
rightButtons: [
2021-09-24 12:03:57 +00:00
StatusButton {
id: submitBtn
text: qsTr("Create PIN")
enabled: firstPINFieldValid && repeatPINFieldValid
onClicked: {
2021-10-01 10:22:51 +00:00
submitted = true
submitBtnClicked()
2021-10-01 10:22:51 +00:00
popup.close()
2021-09-24 12:03:57 +00:00
}
}
2021-10-05 09:12:10 +00:00
]
2021-09-24 12:03:57 +00:00
}