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
|
|
|
|
|
|
|
|
property string uuid
|
|
|
|
property string linkText
|
|
|
|
property string linkUrl
|
|
|
|
|
|
|
|
signal updateLinkRequested(string uuid, string linkText, string linkUrl)
|
|
|
|
signal removeLinkRequested(string uuid)
|
|
|
|
|
|
|
|
implicitWidth: 480 // design
|
|
|
|
|
|
|
|
title: ProfileUtils.linkTypeToText(linkType) || qsTr("Modify Custom Link")
|
|
|
|
|
|
|
|
footer: StatusDialogFooter {
|
|
|
|
leftButtons: ObjectModel {
|
|
|
|
StatusButton {
|
|
|
|
type: StatusButton.Danger
|
|
|
|
text: qsTr("Delete")
|
|
|
|
onClicked: {
|
|
|
|
root.removeLinkRequested(root.uuid)
|
|
|
|
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: {
|
|
|
|
root.updateLinkRequested(root.uuid, customTitle.text, ProfileUtils.addSocialLinkPrefix(linkTarget.text, root.linkType))
|
|
|
|
root.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onAboutToShow: {
|
|
|
|
if (linkType === Constants.socialLinkType.custom)
|
|
|
|
customTitle.input.edit.forceActiveFocus()
|
|
|
|
else
|
|
|
|
linkTarget.input.edit.forceActiveFocus()
|
|
|
|
}
|
|
|
|
|
|
|
|
onClosed: destroy()
|
|
|
|
|
|
|
|
contentItem: ColumnLayout {
|
|
|
|
width: root.availableWidth
|
|
|
|
spacing: Style.current.halfPadding
|
|
|
|
|
|
|
|
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))
|
|
|
|
}
|
|
|
|
errorMessage: root.linkType === Constants.socialLinkType.custom?
|
|
|
|
qsTr("Name and link combination already added") :
|
|
|
|
qsTr("Link already added")
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
onValidChanged: {linkTarget.validate(true)}
|
|
|
|
onTextChanged: {linkTarget.validate(true)}
|
2023-03-08 01:56:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StaticSocialLinkInput {
|
|
|
|
id: linkTarget
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.topMargin: customTitle.visible ? Style.current.padding : 0
|
|
|
|
placeholderText: ""
|
|
|
|
label: ProfileUtils.linkTypeToDescription(linkType) || qsTr("Modify your link")
|
|
|
|
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?
|
|
|
|
qsTr("Name and link combination already added") :
|
|
|
|
qsTr("Link already added")
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
onValidChanged: {customTitle.validate(true)}
|
|
|
|
onTextChanged: {customTitle.validate(true)}
|
2023-03-08 01:56:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|