2022-08-30 16:27:00 +00:00
|
|
|
import QtQuick 2.14
|
2022-08-31 12:35:28 +00:00
|
|
|
import QtQuick.Layouts 1.14
|
2022-08-30 16:27:00 +00:00
|
|
|
|
2022-08-31 12:35:28 +00:00
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Controls.Validators 0.1
|
2022-08-30 16:27:00 +00:00
|
|
|
|
2023-01-17 23:03:08 +00:00
|
|
|
ColumnLayout {
|
2023-01-18 19:54:14 +00:00
|
|
|
id: root
|
|
|
|
|
|
|
|
property int mode: HoldingTypes.Mode.Add
|
2022-08-31 12:35:28 +00:00
|
|
|
property alias domainName: domainNameInput.text
|
|
|
|
property alias domainNameValid: domainNameInput.valid
|
2023-01-18 19:54:14 +00:00
|
|
|
property alias addButtonEnabled: addOrUpdateButton.enabled
|
|
|
|
|
2023-01-24 21:49:07 +00:00
|
|
|
property var reservedNames: []
|
|
|
|
|
2023-01-18 19:54:14 +00:00
|
|
|
signal addClicked
|
|
|
|
signal updateClicked
|
|
|
|
signal removeClicked
|
2022-08-31 12:35:28 +00:00
|
|
|
|
|
|
|
spacing: 0
|
|
|
|
|
2023-01-24 21:49:07 +00:00
|
|
|
onReservedNamesChanged: domainNameInput.validate()
|
|
|
|
|
2022-08-31 12:35:28 +00:00
|
|
|
StatusInput {
|
|
|
|
id: domainNameInput
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
2023-01-17 23:03:08 +00:00
|
|
|
Layout.topMargin: 23
|
2022-08-31 12:35:28 +00:00
|
|
|
|
|
|
|
minimumHeight: 36
|
|
|
|
maximumHeight: 36
|
|
|
|
topPadding: 0
|
|
|
|
bottomPadding: 0
|
|
|
|
font.pixelSize: 13
|
|
|
|
input.placeholderText: "name.eth"
|
|
|
|
|
2023-01-24 21:49:07 +00:00
|
|
|
errorMessageCmp.visible: false
|
|
|
|
|
2022-08-31 12:35:28 +00:00
|
|
|
validators: StatusRegularExpressionValidator {
|
|
|
|
// TODO: check ens domain validator
|
2023-01-17 23:03:08 +00:00
|
|
|
regularExpression: /^(\*\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)?$/i
|
2023-01-24 21:49:07 +00:00
|
|
|
errorMessage: alreadyUsed
|
|
|
|
? qsTr("This condition has already been added")
|
|
|
|
: qsTr("This is not ENS name")
|
|
|
|
|
|
|
|
property bool alreadyUsed: false
|
2023-01-17 23:03:08 +00:00
|
|
|
|
|
|
|
validate: function (value) {
|
2023-01-24 21:49:07 +00:00
|
|
|
alreadyUsed = reservedNames.includes(value)
|
|
|
|
|
|
|
|
return (value === "*.eth" || regularExpression.test(value))
|
|
|
|
&& !alreadyUsed
|
2023-01-17 23:03:08 +00:00
|
|
|
}
|
2022-08-31 12:35:28 +00:00
|
|
|
}
|
2023-03-23 09:54:16 +00:00
|
|
|
onVisibleChanged: {
|
|
|
|
if(visible)
|
|
|
|
forceActiveFocus()
|
|
|
|
}
|
|
|
|
onKeyPressed: {
|
|
|
|
if(!addOrUpdateButton.enabled) return
|
|
|
|
|
|
|
|
if(event.key === Qt.Key_Enter || event.key === Qt.Key_Return)
|
|
|
|
addOrUpdateButton.clicked()
|
|
|
|
}
|
2022-08-31 12:35:28 +00:00
|
|
|
|
2023-06-12 15:02:27 +00:00
|
|
|
KeyNavigation.backtab: domainNameInput
|
|
|
|
|
2022-08-31 12:35:28 +00:00
|
|
|
Component.onCompleted: {
|
|
|
|
if (text) {
|
|
|
|
input.dirty = true
|
|
|
|
validate()
|
|
|
|
}
|
2023-03-23 09:54:16 +00:00
|
|
|
forceActiveFocus()
|
2022-08-31 12:35:28 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-17 23:03:08 +00:00
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.topMargin: 17
|
|
|
|
|
|
|
|
text: qsTr("Put *. before ENS name to include all subdomains in permission")
|
|
|
|
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
font.pixelSize: 13
|
|
|
|
lineHeight: 18
|
|
|
|
lineHeightMode: Text.FixedHeight
|
|
|
|
}
|
2023-01-18 19:54:14 +00:00
|
|
|
|
2023-01-24 21:49:07 +00:00
|
|
|
Item {
|
|
|
|
Layout.topMargin: 8
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: Math.max(18, errorText.height) // by design
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
id: errorText
|
|
|
|
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
|
|
|
text: domainNameInput.errorMessageCmp.text
|
|
|
|
|
|
|
|
font.pixelSize: 13
|
|
|
|
lineHeight: 18
|
|
|
|
lineHeightMode: Text.FixedHeight
|
|
|
|
|
|
|
|
color: Theme.palette.dangerColor1
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-18 19:54:14 +00:00
|
|
|
StatusButton {
|
|
|
|
id: addOrUpdateButton
|
|
|
|
|
|
|
|
text: (root.mode === HoldingTypes.Mode.Add) ? qsTr("Add") : qsTr("Update")
|
2023-01-24 21:49:07 +00:00
|
|
|
Layout.topMargin: 13 // by design
|
2023-01-18 19:54:14 +00:00
|
|
|
Layout.preferredHeight: 44 // by design
|
|
|
|
Layout.fillWidth: true
|
|
|
|
onClicked: root.mode === HoldingTypes.Mode.Add
|
|
|
|
? root.addClicked() : root.updateClicked()
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusFlatButton {
|
|
|
|
text: qsTr("Remove")
|
|
|
|
Layout.topMargin: 16 // by design
|
|
|
|
Layout.preferredHeight: 44 // by design
|
|
|
|
Layout.fillWidth: true
|
2023-01-24 21:49:07 +00:00
|
|
|
visible: root.mode === HoldingTypes.Mode.UpdateOrRemove
|
2023-01-18 19:54:14 +00:00
|
|
|
type: StatusBaseButton.Type.Danger
|
|
|
|
|
|
|
|
onClicked: root.removeClicked()
|
|
|
|
}
|
2022-08-30 16:27:00 +00:00
|
|
|
}
|