2023-03-08 01:56:41 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
import QtQml.Models 2.15
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
2023-06-06 11:59:50 +00:00
|
|
|
import StatusQ.Controls.Validators 0.1
|
2023-03-08 01:56:41 +00:00
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Popups.Dialog 0.1
|
|
|
|
|
|
|
|
import AppLayouts.Profile.controls 1.0
|
|
|
|
|
|
|
|
StatusDialog {
|
|
|
|
id: root
|
|
|
|
|
2023-06-06 11:59:50 +00:00
|
|
|
property var containsSocialLink: function (text, url) {return false}
|
2023-03-08 01:56:41 +00:00
|
|
|
property int linkType: -1
|
|
|
|
property string icon
|
|
|
|
|
2024-03-08 09:27:45 +00:00
|
|
|
property int index
|
2023-03-08 01:56:41 +00:00
|
|
|
property string linkText
|
|
|
|
property string linkUrl
|
|
|
|
|
2024-03-08 09:27:45 +00:00
|
|
|
signal updateLinkRequested(string index, string linkText, string linkUrl)
|
|
|
|
signal removeLinkRequested(string index)
|
2023-03-08 01:56:41 +00:00
|
|
|
|
|
|
|
implicitWidth: 480 // design
|
|
|
|
|
2024-03-03 12:06:52 +00:00
|
|
|
title: ProfileUtils.linkTypeToText(linkType) ? qsTr("Edit %1 link").arg(ProfileUtils.linkTypeToText(linkType)) : qsTr("Edit custom Link")
|
2023-03-08 01:56:41 +00:00
|
|
|
|
|
|
|
footer: StatusDialogFooter {
|
|
|
|
leftButtons: ObjectModel {
|
|
|
|
StatusButton {
|
|
|
|
type: StatusButton.Danger
|
|
|
|
text: qsTr("Delete")
|
|
|
|
onClicked: {
|
2024-03-08 09:27:45 +00:00
|
|
|
root.removeLinkRequested(root.index)
|
2023-03-08 01:56:41 +00:00
|
|
|
root.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rightButtons: ObjectModel {
|
|
|
|
StatusButton {
|
|
|
|
text: qsTr("Update")
|
2023-06-06 11:59:50 +00:00
|
|
|
enabled: linkTarget.valid && (!customTitle.visible || customTitle.valid)
|
2023-03-08 01:56:41 +00:00
|
|
|
onClicked: {
|
2024-03-08 09:27:45 +00:00
|
|
|
root.updateLinkRequested(root.index, customTitle.text, ProfileUtils.addSocialLinkPrefix(linkTarget.text, root.linkType))
|
2023-03-08 01:56:41 +00:00
|
|
|
root.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onAboutToShow: {
|
|
|
|
if (linkType === Constants.socialLinkType.custom)
|
|
|
|
customTitle.input.edit.forceActiveFocus()
|
|
|
|
else
|
|
|
|
linkTarget.input.edit.forceActiveFocus()
|
|
|
|
}
|
|
|
|
|
|
|
|
onClosed: destroy()
|
|
|
|
|
|
|
|
contentItem: ColumnLayout {
|
|
|
|
width: root.availableWidth
|
2024-10-15 19:26:12 +00:00
|
|
|
spacing: Theme.halfPadding
|
2023-03-08 01:56:41 +00:00
|
|
|
|
|
|
|
StaticSocialLinkInput {
|
|
|
|
id: customTitle
|
|
|
|
Layout.fillWidth: true
|
|
|
|
visible: root.linkType === Constants.socialLinkType.custom
|
|
|
|
placeholderText: ""
|
|
|
|
label: qsTr("Change title")
|
|
|
|
linkType: Constants.socialLinkType.custom
|
|
|
|
icon: "language"
|
|
|
|
text: root.linkText
|
|
|
|
charLimit: Constants.maxSocialLinkTextLength
|
|
|
|
input.tabNavItem: linkTarget.input.edit
|
2023-06-06 11:59:50 +00:00
|
|
|
|
|
|
|
validators: [
|
|
|
|
StatusValidator {
|
|
|
|
name: "text-validation"
|
|
|
|
validate: (value) => {
|
|
|
|
return value.trim() !== ""
|
|
|
|
}
|
|
|
|
errorMessage: qsTr("Invalid title")
|
|
|
|
},
|
|
|
|
StatusValidator {
|
|
|
|
name: "check-social-link-existence"
|
|
|
|
validate: (value) => {
|
|
|
|
return !root.containsSocialLink(value,
|
|
|
|
ProfileUtils.addSocialLinkPrefix(linkTarget.text, root.linkType))
|
|
|
|
}
|
2024-03-03 12:06:52 +00:00
|
|
|
errorMessage: root.linkType === Constants.socialLinkType.custom ?
|
|
|
|
qsTr("Title and link combination already added") :
|
|
|
|
qsTr("Username already added")
|
2023-06-06 11:59:50 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
onValidChanged: {linkTarget.validate(true)}
|
|
|
|
onTextChanged: {linkTarget.validate(true)}
|
2023-03-08 01:56:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StaticSocialLinkInput {
|
|
|
|
id: linkTarget
|
|
|
|
Layout.fillWidth: true
|
2024-10-15 19:26:12 +00:00
|
|
|
Layout.topMargin: customTitle.visible ? Theme.padding : 0
|
2023-03-08 01:56:41 +00:00
|
|
|
placeholderText: ""
|
2024-03-03 12:06:52 +00:00
|
|
|
label: ProfileUtils.linkTypeToDescription(linkType) || qsTr("Edit your link")
|
2023-03-08 01:56:41 +00:00
|
|
|
linkType: root.linkType
|
|
|
|
icon: root.icon
|
|
|
|
text: root.linkUrl
|
|
|
|
input.tabNavItem: customTitle.input.edit
|
2023-06-06 11:59:50 +00:00
|
|
|
|
|
|
|
validators: [
|
|
|
|
StatusValidator {
|
|
|
|
name: "link-validation"
|
|
|
|
validate: (value) => {
|
|
|
|
return value.trim() !== "" && Utils.validLink(ProfileUtils.addSocialLinkPrefix(value, root.linkType))
|
|
|
|
}
|
|
|
|
errorMessage: qsTr("Invalid %1").arg(ProfileUtils.linkTypeToDescription(linkTarget.linkType).toLowerCase() || qsTr("link"))
|
|
|
|
},
|
|
|
|
StatusValidator {
|
|
|
|
name: "check-social-link-existence"
|
|
|
|
validate: (value) => {
|
|
|
|
return !root.containsSocialLink(customTitle.text,
|
|
|
|
ProfileUtils.addSocialLinkPrefix(value, root.linkType))
|
|
|
|
}
|
|
|
|
errorMessage: root.linkType === Constants.socialLinkType.custom?
|
2024-03-03 12:06:52 +00:00
|
|
|
qsTr("Title and link combination already added") :
|
|
|
|
qsTr("Username already added")
|
2023-06-06 11:59:50 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
onValidChanged: {customTitle.validate(true)}
|
|
|
|
onTextChanged: {customTitle.validate(true)}
|
2023-03-08 01:56:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|